home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2606 < prev    next >
Internet Message Format  |  1991-01-24  |  10KB

  1. From: klamer@mi.eltn.utwente.nl (Klamer Schutte -- Universiteit Twente)
  2. Newsgroups: alt.sources
  3. Subject: boxps: several postscript pages on one page
  4. Message-ID: <klamer.664726837@mi.eltn.utwente.nl>
  5. Date: 24 Jan 91 14:20:37 GMT
  6.  
  7. The program boxps makes it possible to put several postscript pages
  8. in reduced size on one page.
  9.  
  10. I assume this already is done earlier and better. However, i didn't
  11. knew where to get it, so i wrote it myself.
  12.  
  13. Note this is a quick hack to get this job done. No responsibility for any
  14. behaviour provided.
  15.  
  16. Klamer (.signature at end)
  17.  
  18. echo x - README
  19. sed '/^X/s///' > README << '/'
  20. XCopyright Klamer Schutte 1991
  21. XThis software should not be sold without permission of the author.
  22. XFree redistribution of original or modified sources of this program
  23. Xis allowed.
  24. X
  25. XThe program boxps makes it possible to put several postscript pages
  26. Xin reduced size on one page.
  27. X
  28. XThere are two source files, boxps.c and err.c. Boxps.c is the real thing;
  29. Xerr.c is just my standard error handler. But to compile without any changes
  30. Xyou need err.c so i provide this one as well. It could be usefull on its
  31. Xown, though.
  32. X
  33. XThe program is developed and tested on a sun sparcstation 1 with SunOS 4.1
  34. XHowever, it is rather portable. The only difficult part is making the
  35. Xnew heading of the generated postscript file - but this can be skipped.
  36. XAlso the file err.c might not be to portable - but calls to fatal,
  37. Xerror and warning can easily be replaced by fprintf(stderr, and exit.
  38. X
  39. XBug fixes or enhancements as well as non-trivial ports are appreciated.
  40. X
  41. XKlamer Schutte
  42. XFaculty of electrical engineering -- University of Twente, The Netherlands
  43. Xklamer@mi.eltn.utwente.nl    {backbone}!mcsun!mi.eltn.utwente.nl!klamer
  44. /
  45. echo x - boxps.1
  46. sed '/^X/s///' > boxps.1 << '/'
  47. X\" Copyright Klamer Schutte 1991
  48. X\" This software should not be sold without permission of the author.
  49. X\" Free redistribution of original or modified sources of this program
  50. X\" is allowed.
  51. X
  52. X.TH BOXPS 1 "24 Januari 1991" "University of Twente"
  53. X.SH NAME 
  54. Xboxps \- put several postscript pages in reduced size on one page
  55. X.SH SYNOPSIS
  56. X.B boxps  [-x x_nr][-y y_nr][-lg][-Pprinter] [files]
  57. X.SH DESCRIPTION
  58. X.B Boxps
  59. Xtakes postscript files and makes it possible to display several of them on 
  60. Xone page. The
  61. X.B -x
  62. Xand
  63. X.B -y
  64. Xoptions gives the number of pages in the x resp. y direction. With the
  65. X.B -l
  66. Xoption output is redirected to the printer. The default printer is
  67. X.I postscipt,
  68. Xthis can be changed using the
  69. X.B -P
  70. Xoption. The
  71. X.B -g
  72. Xoption causes the postscript commands
  73. X.I gsave
  74. Xand 
  75. X.I grestore
  76. Xto be mapped to dummy functions. This can be necessary for broken programs
  77. Xwhich put a 
  78. X.I showpage
  79. Xin a
  80. X.I gsave/grestore
  81. Xpair. (Example: gnuplot).
  82. X.SH SEE ALSO
  83. Xpostscript(7).
  84. X.SH BUGS
  85. XThe whole system is not very robust.
  86. X
  87. XThe
  88. X.B -g
  89. Xoption redefines 
  90. X.I gsave 
  91. Xand 
  92. X.I grestore 
  93. Xglobally. So these operators are 
  94. Xinaccessable in the rest of the postscript program.
  95. X.SH AUTHOR
  96. XKlamer Schutte -- klamer@mi.eltn.utwente.nl
  97. /
  98. echo x - boxps.c
  99. sed '/^X/s///' > boxps.c << '/'
  100. X/*
  101. XCopyright Klamer Schutte 1991
  102. XThis software should not be sold without permission of the author.
  103. XFree redistribution of original or modified sources of this program
  104. Xis allowed.
  105. X*/
  106. X/*
  107. X *    boxps.c            KS 23/1/91
  108. X *
  109. X *    make several postscript pages one
  110. X */
  111. X
  112. X#include    <stdio.h>
  113. X#include        <sys/param.h>   /* */
  114. X#include        <pwd.h>         /* */
  115. X
  116. Xusage(name)
  117. Xchar    *name;
  118. X{
  119. X    fatal("Usage: %s [-x x_nr][-y y_nr][-lg][-Pprinter] [files]\n",
  120. X        name );
  121. X}
  122. X
  123. Xwrite_header(x,y,rotate,gsave,fp)
  124. Xint    x,y,rotate;
  125. Xint    gsave;
  126. XFILE    *fp;
  127. X{
  128. X        char    hostname[MAXHOSTNAMELEN];
  129. X        struct passwd   *pwd, *getpwuid();
  130. X        int     uid, cur_time;
  131. X
  132. X    int    i,j;
  133. X
  134. X        uid = getuid();
  135. X        pwd = getpwuid( uid );
  136. X        gethostname( hostname, MAXHOSTNAMELEN );
  137. X        fprintf(fp,"%%!\n%%%%Creator: %s:%s (%s)\n",
  138. X                hostname,
  139. X                pwd->pw_name, pwd->pw_gecos );
  140. X        cur_time = time( NULL );
  141. X        fprintf(fp,"%%%%CreationDate: %s%%%%EndComments\n",
  142. X                ctime( &cur_time ) );
  143. X    fprintf(fp,"statusdict begin /doprinterrors {true} def end\n");
  144. X    
  145. X    fprintf(fp,"/boxps 10 dict def boxps begin\n/WindowNumber -1 def\n");
  146. X
  147. X    fprintf(fp,"/XTArray [ ");
  148. X    for(i=0;i<x;i++)
  149. X        for(j=0;j<y;j++)
  150. X            fprintf(fp,"%g ", 8*72*i/(double)x );
  151. X    fprintf(fp," 0 ] def\n");
  152. X            
  153. X    fprintf(fp,"/YTArray [ ");
  154. X    for(i=0;i<x;i++)
  155. X        for(j=0;j<y;j++)
  156. X            fprintf(fp,"%g ", 11*72*j/(double)y );
  157. X    fprintf(fp," 0 ] def\n");
  158. X
  159. X    if (gsave)
  160. X        fprintf(fp,"/gsave {} def\n/grestore {} def {}\n");
  161. X
  162. X    fprintf(fp,"/showpage {\n");
  163. X    fprintf(fp,"initgraphics\n");
  164. X    fprintf(fp,"boxps begin\n");
  165. X    fprintf(fp,"WindowNumber 1 add dup /WindowNumber exch def\n");
  166. X    fprintf(fp,"dup XTArray exch get exch YTArray exch get translate\n");
  167. X    fprintf(fp, "end\n");
  168. X    fprintf(fp,"%g %g scale\n", 1.0/x, 1.0/y);
  169. X    /* should also set clippath! */
  170. X    fprintf(fp,"} def\n");
  171. X    fprintf(fp,"showpage\n");
  172. X}
  173. X
  174. Xwrite_trailer(x,y,rotate,fp)
  175. Xint    x,y,rotate;
  176. XFILE    *fp;
  177. X{
  178. X    fprintf(fp,"end\nshowpage\n");
  179. X}
  180. X
  181. Xcopy_file(fpin,name,fpout)
  182. XFILE    *fpin, *fpout;
  183. Xchar    *name;
  184. X{
  185. X    int    c;
  186. X
  187. X    while((c = getc(fpin)) != EOF)
  188. X        putc(c,fpout);
  189. X}
  190. X
  191. Xmain(argc,argv)
  192. Xint    argc;
  193. Xchar    *argv[];
  194. X{
  195. X    int    c, x=2, y=2, print = 0, rotate = 0, gsave = 0;
  196. X    char    *printer = "postscript";
  197. X    extern int    optind;
  198. X    extern char    *optarg;
  199. X    FILE        *out,*fp;
  200. X    char        buf[80];
  201. X
  202. X    while((c = getopt(argc,argv,"x:y:lrP:g")) != EOF)
  203. X        switch(c)
  204. X        {case 'x':
  205. X            x = atoi(optarg);
  206. X            break;
  207. X        case 'y':
  208. X            y = atoi(optarg);
  209. X            break;
  210. X        case 'r':
  211. X            rotate = 1;
  212. X            warning("%s: rotate not implemented\n", argv[0]);
  213. X            break;
  214. X        case 'P':
  215. X            printer = optarg;
  216. X            /* FALL THROUGH */
  217. X        case 'l':
  218. X            print = 1;
  219. X            break;
  220. X        case 'g':
  221. X            gsave = 1;
  222. X            break;
  223. X        default:
  224. X            usage(argv[0]);
  225. X        }
  226. X
  227. X    if (print)
  228. X    {
  229. X        sprintf(buf,"lpr -P%s",printer);
  230. X        out = popen(buf,"w");
  231. X        if (out == NULL)
  232. X            fatal("%s: Can't popen to %s\n", argv[0], buf );
  233. X    } else
  234. X        out = stdout;
  235. X
  236. X    write_header(x,y,rotate,gsave,out);
  237. X    if (argc - optind == 0)
  238. X        copy_file(stdin,"(stdin)",out);
  239. X    else
  240. X        for(;argc-optind;optind++)
  241. X        {
  242. X            fp = fopen( argv[optind], "r" );
  243. X            if (fp == NULL)
  244. X            {
  245. X                error("Can't open %s\n", argv[optind] );
  246. X                continue;
  247. X            }
  248. X            copy_file(fp,argv[optind],out);
  249. X            fclose(fp);
  250. X        }
  251. X    write_trailer(x,y,rotate,out);
  252. X
  253. X    if (print)
  254. X        pclose(out);
  255. X
  256. X    return 0;
  257. X}
  258. /
  259. echo x - err.3
  260. sed '/^X/s///' > err.3 << '/'
  261. X\" Copyright Klamer Schutte 1991
  262. X\" This software should not be sold without permission of the author.
  263. X\" Free redistribution of original or modified sources of this program
  264. X\" is allowed.
  265. X
  266. X.TH ERR 3 "25 July 1990" "University of Twente" "Utility routines"
  267. X.SH NAME 
  268. Xwarning, error, fatal \- consistent error handling
  269. X.SH SYNOPSIS
  270. X#include <setjmp.h>
  271. X.br
  272. X#include <err.h>
  273. X.LP
  274. Xwarning( fmt, ... )
  275. X.br
  276. Xchar *fmt;
  277. X.LP
  278. Xerror( fmt, ... )
  279. X.br
  280. Xchar *fmt;
  281. X.LP
  282. Xfatal( fmt, ... )
  283. X.br
  284. Xchar *fmt;
  285. X.LP
  286. Xfatal_nr( nr, fmt, ... )
  287. X.br
  288. Xint    nr;
  289. X.br
  290. Xchar *fmt;
  291. X.LP
  292. Xextern int err_nr_errors, err_nr_warnings;
  293. X.br
  294. Xextern int *err_warning_jmpbuf, *err_error_jmpbuf, *err_fatal_jmpbuf;
  295. X.SH DESCRIPTION
  296. XThese routines provide a way to handle all kind of errors in a consistent way.
  297. XThe differences between the routines are:
  298. X.I warning()
  299. Xis intended to be used when the error encountered is to be reported, but
  300. Xwill probably not harm the result.
  301. X.I error()
  302. Xshould be called when the error will harm the result (it will probably not be 
  303. Xvalid), but execution can continue;
  304. X.I fatal()
  305. Xshould be called when the error means that the program can not continue.
  306. X.I fatal()
  307. Xwill exit with a return value of 1;
  308. X.I fatal_nr()
  309. Xwill exit with the return value
  310. X.I nr.
  311. X.br
  312. XThe integers
  313. X.I err_nr_warnings
  314. Xand 
  315. X.I err_nr_errors
  316. Xhold the number of time these routines are called.
  317. X.br
  318. XThe
  319. X.I err_*_jmpbuf
  320. Xvariables are pointers to a 
  321. X.I jmp_buf.
  322. XWhen these are not NULL they should point to a valid
  323. X.I jmp_buf
  324. Xfor use by
  325. X.I longjmp(3).
  326. XIn this way the program can catch errors as generated by these routines.
  327. X.SH ARGUMENTS
  328. XThe string
  329. X.I fmt
  330. Xand trailing arguments are handled in the way of
  331. X.I printf(3).
  332. X.SH SEE ALSO
  333. Xsetjmp(3), printf(3), fprintf(3), exit(3).
  334. X.SH NOTE
  335. XObject in library /home/lib/libutil.a
  336. X.br
  337. Xerr.h can be found in /home/include.
  338. X.SH AUTHOR
  339. XKlamer Schutte
  340. /
  341. echo x - err.c
  342. sed '/^X/s///' > err.c << '/'
  343. X/*
  344. XCopyright Klamer Schutte 1991
  345. XThis software should not be sold without permission of the author.
  346. XFree redistribution of original or modified sources of this program
  347. Xis allowed.
  348. X*/
  349. X/*
  350. X *    error.c                Klamer Schutte 25/7/90
  351. X *
  352. X *    handle errors in a consistent way.
  353. X */
  354. X
  355. X#include    <stdio.h>
  356. X#include    <varargs.h>
  357. X#include    <setjmp.h>
  358. X
  359. Xint    err_nr_errors, err_nr_warnings;
  360. X/* what is the type of a pointer to a jmp_buf? On sun4 int * will do */
  361. Xint    *err_warning_jmpbuf, *err_error_jmpbuf, *err_fatal_jmpbuf;
  362. X
  363. X/*VARARGS1*/
  364. Xwarning( fmt, va_alist )
  365. Xchar    *fmt;
  366. Xva_dcl
  367. X{
  368. X    va_list    args;
  369. X
  370. X    va_start( args );
  371. X    vfprintf(stderr, fmt, args );
  372. X    va_end(args );
  373. X
  374. X    err_nr_warnings++;
  375. X
  376. X    if (err_warning_jmpbuf != NULL)
  377. X        longjmp( err_warning_jmpbuf, 1 );
  378. X}    
  379. X
  380. X/*VARARGS1*/
  381. Xerror( fmt, va_alist )
  382. Xchar    *fmt;
  383. Xva_dcl
  384. X{
  385. X    va_list    args;
  386. X
  387. X    va_start( args );
  388. X    vfprintf(stderr, fmt, args );
  389. X    va_end(args );
  390. X
  391. X    err_nr_errors++;
  392. X
  393. X    if (err_error_jmpbuf != NULL)
  394. X        longjmp( err_error_jmpbuf, 1 );
  395. X}    
  396. X
  397. X/*VARARGS2*/
  398. Xfatal_exit_nr( nr, fmt, va_alist )
  399. Xint    nr;
  400. Xchar    *fmt;
  401. Xva_dcl
  402. X{
  403. X    va_list    args;
  404. X
  405. X    va_start( args );
  406. X    vfprintf(stderr, fmt, args );
  407. X    va_end(args );
  408. X
  409. X    if (err_fatal_jmpbuf != NULL)
  410. X        longjmp( err_fatal_jmpbuf, 1 );
  411. X
  412. X    exit( nr );
  413. X}    
  414. X
  415. X/*VARARGS1*/
  416. Xfatal( fmt, va_alist )
  417. Xchar    *fmt;
  418. Xva_dcl
  419. X{
  420. X    va_list    args;
  421. X
  422. X    va_start( args );
  423. X    vfprintf(stderr, fmt, args );
  424. X    va_end(args );
  425. X
  426. X    if (err_fatal_jmpbuf != NULL)
  427. X        longjmp( err_fatal_jmpbuf, 1 );
  428. X
  429. X    exit( 1 );
  430. X}    
  431. /
  432. -- 
  433. Klamer Schutte
  434. Faculty of electrical engineering -- University of Twente, The Netherlands
  435. klamer@mi.eltn.utwente.nl    {backbone}!mcsun!mi.eltn.utwente.nl!klamer
  436.