home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / ps / boxps < prev    next >
Text File  |  1991-02-26  |  10KB  |  421 lines

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