home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume05 / a2ps.c < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  24.1 KB

  1. From decwrl!labrea!rutgers!mailrus!cwjcc!hal!ncoast!allbery Wed Dec 28 05:49:34 PST 1988
  2. Article 766 of comp.sources.misc:
  3. Path: granite!decwrl!labrea!rutgers!mailrus!cwjcc!hal!ncoast!allbery
  4. From: miguel@imag.imag.fr.UUCP (Miguel Santana)
  5. Newsgroups: comp.sources.misc
  6. Subject: v05i090: a2ps
  7. Message-ID: <4068@imag.imag.fr>
  8. Date: 23 Dec 88 01:24:15 GMT
  9. Sender: allbery@ncoast.UUCP
  10. Reply-To: miguel@imag.imag.fr.UUCP (Miguel Santana)
  11. Organization: IMAG, University of Grenoble, France
  12. Lines: 923
  13. Approved: allbery@ncoast.UUCP
  14.  
  15. Posting-number: Volume 5, Issue 90
  16. Submitted-by: "Miguel Santana" <miguel@imag.imag.fr.UUCP>
  17. Archive-name: a2ps.c
  18.  
  19. [Let's see now:  "UNIX" != "SYSV", and somewhere SYSV picked up <sys/timeb.h>.
  20. Somehow that doesn't agree with what I know... beware of the #ifdef's, people,
  21. they don't appear to be accurate in all cases.  (Actually, it looks more like
  22. "UNIX != XENIX", which is generally true.  Sigh.)  ++bsa]
  23.  
  24. This is a new version of a2ps, a program to format an ascii file for
  25. printing in a postcript printer. Initial version was a shell program
  26. written by evan@csli (Evan Kirshenbaum). It was very slow and contained
  27. many bugs. The new version was written in C for improve speed execution
  28. and portability. New features and improvements have been added (see
  29. README and a2ps.1).
  30.  
  31. Format used to print files is very nice and compact: two pages on each
  32. physical page, borders surrounding pages, headers with useful information
  33. (page number, printing date, file name), line numbering, etc. Very useful
  34. to archive listings of programs.
  35.  
  36. The a2ps distribution consists of the following files:
  37.  
  38.     README
  39.     Makefile
  40.     a2ps.c        a2ps source
  41.     a2ps.1        a troff manual (man file)
  42.     header.ps    postcript header used by a2ps
  43.  
  44. Please send problems and feedback to:
  45.  
  46.     miguel@imag.fr or miguel@imag.UUCP (uunet.uu.net!imag!miguel)
  47.  
  48.     Miguel SANTANA
  49.     LGI
  50.     IMAG-Campus
  51.     BP 53X
  52.     38041 Grenoble Cedex
  53.  
  54. ---- Cut Here and unpack ----
  55. #!/bin/sh
  56. # shar:    Shell Archiver  (v1.22)
  57. #
  58. #    Run the following text with /bin/sh to create:
  59. #      README
  60. #      Makefile
  61. #      a2ps.1
  62. #      a2ps.c
  63. #      header.ps
  64. #
  65. if test -f README; then echo "File README exists"; else
  66. echo "x - extracting README (Text)"
  67. sed 's/^X//' << 'SHAR_EOF' > README &&
  68. XThis is a new version of a2ps, a program to format an ascii file for
  69. Xprinting in a postcript printer. As the copyright indicates, this
  70. Xdistribution can be freely redistributed.
  71. X
  72. XInitial version was a shell program written by evan@csli (Evan
  73. XKirshenbaum). It was very slow and contained many bugs. The new
  74. Xversion was written in C for improve speed execution and portability.
  75. XNew features and improvements have been added.
  76. X
  77. X
  78. XSome notes on the distribution:
  79. X
  80. X    Installation is done by modifying and executing Makefile included
  81. X    in this distribution. You must give your own values to two variables:
  82. X    - HEADER_PS   a2ps will search there the file header.ps at execution
  83. X          time.
  84. X    - compiler      compiler name, actually one of UNIX, SYSV, ANSIC. Turbo
  85. X          C and Microsoft C are considered ANSIC compilers.
  86. X
  87. X    a2ps has been successfully ported to Unix 4.3BSD, Unix SystemV and
  88. X    MSDOS.
  89. X
  90. X
  91. XThe a2ps distribution consists of the following files:
  92. X
  93. X    README        This message
  94. X    Makefile
  95. X    a2ps.c        a2ps source
  96. X    a2ps.1        a troff manual (man file)
  97. X    header.ps    postcript header used by a2ps
  98. X
  99. XDecide where you want to keep these files and move it there.
  100. XEdit "Makefile" and change the definition of HEADER_PS (to
  101. Xreflect the full pathname of header.ps) and of compiler name.
  102. XTo make a2ps do:
  103. X
  104. X    make a2ps
  105. X
  106. XTo install it, do:
  107. X
  108. X    make install
  109. X
  110. XFormat the manual entry using
  111. X
  112. X    nroff -man a2ps.1
  113. X
  114. X
  115. XPlease send problems and feedback to:
  116. X
  117. X    miguel@imag.fr or miguel@imag.UUCP (uunet.uu.net!imag!miguel)
  118. X
  119. X    Miguel SANTANA
  120. X    LGI
  121. X    IMAG-Campus
  122. X    BP 53X
  123. X    38041 Grenoble Cedex
  124. SHAR_EOF
  125. chmod 0664 README || echo "restore of README fails"
  126. set `wc -c README`;Sum=$1
  127. if test "$Sum" != "1575"
  128. then echo original size 1575, current size $Sum;fi
  129. fi
  130. if test -f Makefile; then echo "File Makefile exists"; else
  131. echo "x - extracting Makefile (Text)"
  132. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  133. X#
  134. X# Description: Makefile to construct and install a2ps. Don't forget
  135. X# to give your own values to define variables HEADER_PS and name of
  136. X# compiler (see OPTIONS).
  137. X#
  138. X# File: imag:/users/local/a2ps/Makefile
  139. X# Created: Mon Nov 29 14:05:39 1988 by miguel@imag (Miguel Santana)
  140. X# Version: 2.0
  141. X#
  142. X
  143. X# Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
  144. X#
  145. X# Permission is granted to copy and distribute this file in modified
  146. X# or unmodified form, whether for noncommercial or commercial use,
  147. X# provided (a) this copyright notice is preserved, (b) no attempt is
  148. X# made to restrict redistribution of this file, and (c) this file is
  149. X# not distributed as part of any collection whose redistribution is
  150. X# restricted by a compilation copyright.
  151. X#
  152. X
  153. XD    =.
  154. X
  155. XO    =.
  156. X
  157. XI    =/users/local/a2ps
  158. X
  159. XOPTIONS    =-DHEADER_PS="\"$I/header.ps\"" -DUNIX -O
  160. X
  161. XOBJS          = a2ps.o
  162. X
  163. Xall:        a2ps install
  164. X
  165. Xa2ps:        a2ps.o
  166. X        @echo -n "Compiling and linking a2ps ... "
  167. X        @cc -o $D/xa2ps a2ps.o
  168. X        @echo "done"
  169. X
  170. Xinstall:;    @echo -n "Installing a2ps ... "
  171. X        @cp xa2ps $I/a2ps
  172. X        @cp header.ps $I/header.ps
  173. X        @echo "done"
  174. X
  175. Xclean:;        @rm -f $(OBJS)
  176. X
  177. Xa2ps.o:;
  178. X        cc -c $(OPTIONS) a2ps.c
  179. X
  180. SHAR_EOF
  181. chmod 0664 Makefile || echo "restore of Makefile fails"
  182. set `wc -c Makefile`;Sum=$1
  183. if test "$Sum" != "1132"
  184. then echo original size 1132, current size $Sum;fi
  185. fi
  186. if test -f a2ps.1; then echo "File a2ps.1 exists"; else
  187. echo "x - extracting a2ps.1 (Text)"
  188. sed 's/^X//' << 'SHAR_EOF' > a2ps.1 &&
  189. X.\" @(#)a2ps.man.1 2.0 11/29/88
  190. X.\"
  191. X.TH A2PS 1L "November 29 1988"
  192. X.UC 4
  193. X.SH NAME
  194. Xa2ps \- formats an ascii file for printing in a postscript printer;
  195. Xvery nice and compact format for program listings.
  196. X.SH SYNOPSIS
  197. X.B a2ps
  198. X[ -b ] [ -f ] [ -i ] [ -n ] [ -n{bfinrv} ] [ -r ] [ -v ] [
  199. X.B file1
  200. X] [
  201. X.B file2
  202. X] [...]
  203. X.SH DESCRIPTION
  204. X.B a2ps
  205. Xformats files "file1", "file2", ... for printing in a postscript printer;
  206. Xif no file is given,
  207. X.B a2ps
  208. Xreads from the standard input.
  209. XFormat used is very nice and compact: two pages on each physical page,
  210. Xborders surrounding pages, headers with useful information (page number,
  211. Xprinting date, file name), line numbering, etc. Very useful to
  212. Xarchive listings of programs.
  213. X.PP
  214. XOptions offered by
  215. X.B a2ps
  216. Xare the following:
  217. X.TP 0.6i
  218. X.B -b
  219. XForce printing binary files. By default, binary files printing is
  220. Xstopped before second page (see -nb option).
  221. X.TP 0.6i
  222. X.B -f
  223. XFold lines too large to be printed inside the borders (default option).
  224. XMax size is actually 86 characters.
  225. X.TP 0.6i
  226. X.B -i
  227. XInterpret TAB, BS and FF characters (default option). TAB is replaced by
  228. Xenough spaces to reach next tab stop while BS and FF have their meanings.
  229. X.TP 0.6i
  230. X.B -n
  231. XOutput lines are preceded by line numbers, numbered sequentially from 1
  232. X(default option).
  233. X.TP 0.6i
  234. X.B -nb
  235. XDon't print binary files. To detect such a file we make use of a
  236. Xvery simple heuristic: if the first page of the file contains at
  237. Xless 75% of non-printing characters, it's a binary file. First page
  238. Xis always printed.
  239. X.TP 0.6i
  240. X.B -nf
  241. XCut lines too large (don't fold).
  242. X.TP 0.6i
  243. X.B -ni
  244. XDon't interpret TAB, BS and FF characters. They will be printed
  245. Xaccording to -v option.
  246. X.TP 0.6i
  247. X.B -nn
  248. XDon't number output lines.
  249. X.TP 0.6i
  250. X.B -nr
  251. XSheet numbering (see -r option) must be continue for all files (don't
  252. Xreset on new file).
  253. X.TP 0.6i
  254. X.B -nv
  255. XReplace non-printing characters by a space.
  256. X.TP 0.6i
  257. X.B -r
  258. XReset sheet numbering for each new file (default option). Sheet numbering
  259. Xis used to number physical pages (sheets printed) and is placed
  260. Xin the bottom of each physical page. It differs from page numbering: logical
  261. Xpages of file been printed.
  262. X.TP 0.6i
  263. X.B -v
  264. XReplace non-printing characters so that they are lisible and easy to identify
  265. X(default option). Control characters (ascii codes lower than 0x20) are
  266. Xprinted like ^X for ctrl-x; the delete character (hex 0x3f) is printed
  267. Xas ^?. Non ascii characters (with the high bit set) are printed as M-
  268. X(for meta) followed by the character of the low 7 bits. TAB, BS and FF are
  269. Xhandled like non-printing characters if -ni option was taked.
  270. X.SH USAGE
  271. X.PP
  272. X.B a2ps
  273. Xsends formatted file to standard output. User could redirect this output
  274. Xto a file or pipe it directly to a print command, like lpr in UNIX:
  275. X
  276. X.ti +0.5i
  277. Xa2ps file1 > file2
  278. X
  279. X.ti +0.5i
  280. Xa2ps file1 | lpr -l
  281. X.PP
  282. XDon't forget
  283. X.B -l
  284. Xoption in last line, if you want that 
  285. X.B lpr
  286. Xinterprets your postscript program.
  287. X.PP
  288. XThis filter must be used only with text files. Avoid specially output from
  289. XTeX, troff or any other text formatter.
  290. X.SH "SEE ALSO"
  291. Xpprps(1L) tgrind(1) lpr(1)
  292. X.SH AUTHORS
  293. XEvan Kirshenbaum (evan@csli) for the initial version.
  294. X.br
  295. XMiguel Santana (miguel@imag.imag.fr) for 2.0 version.
  296. SHAR_EOF
  297. chmod 0664 a2ps.1 || echo "restore of a2ps.1 fails"
  298. set `wc -c a2ps.1`;Sum=$1
  299. if test "$Sum" != "3182"
  300. then echo original size 3182, current size $Sum;fi
  301. fi
  302. if test -f a2ps.c; then echo "File a2ps.c exists"; else
  303. echo "x - extracting a2ps.c (Text)"
  304. sed 's/^X//' << 'SHAR_EOF' > a2ps.c &&
  305. X/************************************************************************/
  306. X/*                                    */
  307. X/* Description: Ascii to PostScript printer program.            */
  308. X/* File: imag:/users/local/a2ps/a2ps.c                    */
  309. X/* Created: Mon Nov 28 15:22:15 1988 by miguel@imag (Miguel Santana)    */
  310. X/* Version: 2.0                                */
  311. X/*                                    */
  312. X/* Edit history:                            */
  313. X/* 1) Derived of shell program written by evan@csli (Evan Kirshenbaum).    */
  314. X/*    Written in C for improve speed execution and portability. Many    */
  315. X/*    improvements have been added.                    */
  316. X/*                                    */
  317. X/************************************************************************/
  318. X
  319. X/*
  320. X * Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
  321. X *
  322. X * Permission is granted to copy and distribute this file in modified
  323. X * or unmodified form, for noncommercial use, provided (a) this copyright
  324. X * notice is preserved, (b) no attempt is made to restrict redistribution
  325. X * of this file, and (c) this file is not distributed as part of any
  326. X * collection whose redistribution is restricted by a compilation copyright.
  327. X*/
  328. X
  329. X
  330. X#include <stdio.h>
  331. X#ifdef ANSIC
  332. X#include <time.h>
  333. X#else
  334. X#ifdef UNIX
  335. X#include <sys/time.h>
  336. X#else
  337. X#ifdef SYSV
  338. X#include <sys/types.h>
  339. X#include <sys/timeb.h>
  340. X#include <time.h>
  341. X#else
  342. Xerror !
  343. X#endif
  344. X#endif
  345. X#endif
  346. X
  347. X#ifndef    HEADER_PS
  348. X#define    HEADER_PS    "./header.ps"
  349. X#endif
  350. X#define    LINESPERPAGE    66
  351. X#define    COLUMNSPERLINE    86
  352. X
  353. X#define    FALSE        0
  354. X#define    TRUE        1
  355. X
  356. Xint fold_line();
  357. Xvoid print_file();
  358. Xchar cut_line();
  359. X
  360. X
  361. Xint column = 0;            /* Column number (in current line) */
  362. Xint line = 0;            /* Line number (in current page) */
  363. Xint line_number = 0;        /* Source line number */
  364. Xint first_page;            /* First page for a file */
  365. Xint nonprinting_chars, chars;    /* Number of nonprinting and total chars */
  366. Xint prefix_width;        /* Width in characters for line prefix */
  367. Xint numbering = TRUE;        /* Line numbering option */
  368. Xint folding = TRUE;        /* Line folding option */
  369. Xint restart = TRUE;        /* Restart page number at each file option */
  370. Xint only_printable = FALSE;    /* Replace non printable char by space option */
  371. Xint interpret = TRUE;        /* Interpret TAB, FF and BS chars option */
  372. Xint print_binaries = FALSE;    /* Force printing for binary files */ 
  373. X
  374. Xmain(argc, argv)
  375. Xint argc;
  376. Xchar *argv[];
  377. X{
  378. X   int narg;
  379. X   char *arg;
  380. X
  381. X   /* Option processing */
  382. X   arg = argv[narg = 1];
  383. X   while (narg < argc && arg[0] == '-')
  384. X   {
  385. X      switch (arg[1])
  386. X      {
  387. X      case 'b':
  388. X     if (arg[2] != NULL)
  389. X        goto usage;
  390. X     print_binaries = TRUE;
  391. X     break;
  392. X      case 'f':
  393. X     if (arg[2] != NULL)
  394. X        goto usage;
  395. X     folding = TRUE;
  396. X     break;
  397. X      case 'i':
  398. X     if (arg[2] != NULL)
  399. X        goto usage;
  400. X     interpret = TRUE;
  401. X     break;
  402. X      case 'n':
  403. X     if (arg[2] == NULL)
  404. X     {
  405. X        numbering = TRUE;
  406. X        break;
  407. X     }
  408. X     if (arg[3] != NULL)
  409. X        goto usage;
  410. X     switch (arg[2])
  411. X     {
  412. X     case 'b':
  413. X        print_binaries = FALSE;
  414. X        break;
  415. X     case 'f':
  416. X        folding = FALSE;
  417. X        break;
  418. X     case 'i':
  419. X        interpret = FALSE;
  420. X        break;
  421. X     case 'n':
  422. X        numbering = FALSE;
  423. X        break;
  424. X     case 'r':
  425. X        restart = FALSE;
  426. X        break;
  427. X     case 'v':
  428. X        only_printable = TRUE;
  429. X        break;
  430. X     default:
  431. X        goto usage;
  432. X     }
  433. X     break;
  434. X      case 'r':
  435. X     if (arg[2] != NULL)
  436. X        goto usage;
  437. X     restart = TRUE;
  438. X     break;
  439. X      case 'v':
  440. X     if (arg[2] != NULL)
  441. X        goto usage;
  442. X     only_printable = FALSE;
  443. X     break;
  444. X      default:
  445. X      usage:
  446. X     fprintf(stderr,
  447. X         "usage: a2ps [-n{bfinrv}] [-b] [-f] [-i] [-n] [-r] [-v] [f1 f2 ... fn]");
  448. X     exit(1);
  449. X      }
  450. X      arg = argv[++narg];
  451. X   }
  452. X   if (narg >= argc)
  453. X      goto usage;
  454. X
  455. X   /* Header printing (postcript prolog) */
  456. X   print_header();
  457. X
  458. X   /* Print files designated or standard input */
  459. X   prefix_width = numbering ? 6 : 1;
  460. X   if (narg >= argc)
  461. X      print_file("stdin");
  462. X   else
  463. X   {
  464. X      while (narg < argc)
  465. X      {
  466. X     if (freopen(arg, "r", stdin) == NULL)
  467. X     {
  468. X        fprintf(stderr, "Error opening %s\n", arg);
  469. X        printf("cleanup\n");
  470. X        exit(1);
  471. X     }
  472. X     print_file(arg);
  473. X     arg = argv[++narg];
  474. X      }
  475. X   }
  476. X
  477. X   printf("cleanup\n");
  478. X}
  479. X
  480. Xvoid print_file(name)
  481. Xchar *name;
  482. X{
  483. X   register int c;
  484. X   int start_line, continue_exit;
  485. X   int char_width;
  486. X
  487. X   /*
  488. X    * Printing binary files is not very useful. We stop printing
  489. X    * if we detect one of these files. Our heuristic to detect them:
  490. X    * if 50% characters of first page are non-printing characters,
  491. X    * the file is a binary file.
  492. X    * Option -b force binary files impression.
  493. X    */
  494. X   first_page = TRUE;
  495. X   nonprinting_chars = chars = 0;
  496. X
  497. X   /*
  498. X    * Preprocessing (before printing):
  499. X    * - TABs expansion (see interpret option)
  500. X    * - FF and BS interpretation
  501. X    * - replace non printable characters by a space or a char sequence
  502. X    *   like:
  503. X    *     ^X for ascii codes < 0x20 (X = [@, A, B, ...])
  504. X    *     ^? for del char
  505. X    *     M-c for ascii codes > 0x3f
  506. X    * - prefix parents and backslash ['(', ')', '\'] by backslash
  507. X    *   (escape character in postcript)
  508. X    */
  509. X   column = 0;
  510. X   line = line_number = 0;
  511. X   start_line = TRUE;
  512. X   printf("(%s) newfile\n", name);
  513. X   if (restart)
  514. X      printf("/sheet 1 def\n");
  515. X   printf("startpage\n");
  516. X
  517. X   c = getchar();
  518. X   while (c != EOF)
  519. X   {
  520. X      /* Form feed */
  521. X      if (c == '\f' && interpret)
  522. X      {
  523. X     if (!start_line)
  524. X        printf(") s\n");
  525. X     start_line = TRUE;
  526. X     printf("endpage startpage\n");
  527. X     if (first_page && is_binaryfile(name))
  528. X        return;
  529. X     line = 0;
  530. X     if ((c = getchar()) == EOF)
  531. X        break;
  532. X      }
  533. X
  534. X      /* Start a new line? */
  535. X      if (start_line)
  536. X      {
  537. X     if (numbering)
  538. X        printf("(%-5d ", ++line_number);
  539. X     else
  540. X        printf("( ");
  541. X     start_line = FALSE;
  542. X      }
  543. X
  544. X      /* Interpret each character */
  545. X      switch (c)
  546. X      {
  547. X      case '\b':
  548. X     if (!interpret)
  549. X        goto print;
  550. X     if (column)
  551. X        column--;
  552. X     putchar(c);
  553. X     break;
  554. X      case '\n':
  555. X     column = 0;
  556. X     start_line = TRUE;
  557. X     printf(") s\n");
  558. X     if (++line >= LINESPERPAGE)
  559. X     {
  560. X        printf("endpage startpage\n");
  561. X        if (first_page && is_binaryfile(name))
  562. X           return;
  563. X        line = 0;
  564. X     }
  565. X     break;
  566. X      case '\t':
  567. X     if (interpret)
  568. X     {
  569. X        continue_exit = FALSE;
  570. X        do
  571. X        {
  572. X           if (++column + prefix_width > COLUMNSPERLINE)
  573. X          if (folding)
  574. X          {
  575. X             if (fold_line(name) == FALSE)
  576. X            return;
  577. X          }
  578. X          else
  579. X          {
  580. X             c = cut_line();
  581. X             continue_exit = TRUE;
  582. X             break;
  583. X          }
  584. X           putchar(' ');
  585. X        } while (column & 0x7);
  586. X        if (continue_exit)
  587. X           continue;
  588. X        break;
  589. X        }
  590. X      default:
  591. X      print:
  592. X     if (only_printable)
  593. X        char_width = 1;
  594. X     else
  595. X     {
  596. X        char_width = c > 0177 ? 2 : 0;
  597. X        char_width += c < ' ' || c == 0177 ? 2 : 1;
  598. X     }
  599. X     if (prefix_width + (column += char_width) > COLUMNSPERLINE)
  600. X        if (folding)
  601. X        {
  602. X           if (fold_line(name) == FALSE)
  603. X          return;
  604. X        }
  605. X        else
  606. X        {
  607. X           c = cut_line();
  608. X           continue;
  609. X        }
  610. X     if (c == '(' || c == ')' || c == '\\')
  611. X        putchar('\\');
  612. X     if (c >= ' ' && c < 0177)
  613. X        putchar(c);
  614. X     else
  615. X     {
  616. X        nonprinting_chars++;
  617. X        if (only_printable)
  618. X           putchar(' ');
  619. X        else
  620. X        {
  621. X           if (c > 0177)
  622. X           {
  623. X          printf("M-");
  624. X          c &= 0177;
  625. X           }
  626. X           if (c < ' ')
  627. X          printf("^%c", c+'@');
  628. X           else if (c == 0177)
  629. X          printf("^?");
  630. X           else
  631. X          putchar(c);
  632. X        }
  633. X     }
  634. X     chars++;
  635. X     break;
  636. X      }
  637. X      c = getchar();
  638. X   }
  639. X
  640. X   if (!start_line)
  641. X      printf(") s\n");
  642. X   printf("endpage\n");
  643. X}
  644. X
  645. Xint fold_line(name)
  646. Xchar *name;
  647. X{
  648. X   column = 0;
  649. X   printf(") s\n");
  650. X   if (++line >= LINESPERPAGE)
  651. X   {
  652. X      printf("endpage startpage\n");
  653. X      if (first_page && is_binaryfile(name))
  654. X     return FALSE;
  655. X      line = 0;
  656. X   }
  657. X   if (numbering)
  658. X      printf("(      ");
  659. X   else
  660. X      printf("( ");
  661. X
  662. X   return TRUE;
  663. X}
  664. X
  665. Xchar cut_line()
  666. X{
  667. X   char c;
  668. X
  669. X   while ((c = getchar()) != EOF && c != '\n' && c != '\f');
  670. X   return c;
  671. X}
  672. X
  673. Xis_binaryfile(name)
  674. Xchar *name;
  675. X{
  676. X   first_page = FALSE;
  677. X   if (!print_binaries && (nonprinting_chars*100 / chars) >= 75)
  678. X   {
  679. X      fprintf(stderr, "%s is a binary file: printing aborted\n", name);
  680. X      return TRUE;
  681. X   }
  682. X   return FALSE;
  683. X}
  684. X
  685. Xprint_header()
  686. X{
  687. X   register int c;
  688. X   FILE *f;
  689. X   char *string;
  690. X#ifdef ANSIC
  691. X   time_t date;
  692. X#else
  693. X#ifdef UNIX
  694. X   struct timeval date;
  695. X   struct tm *p;
  696. X#else
  697. X#ifdef SYSV
  698. X    struct timeb date;
  699. X#endif
  700. X#endif
  701. X#endif
  702. X
  703. X   if ((f = fopen(HEADER_PS, "r")) == NULL)
  704. X   {
  705. X      fprintf(stderr, "Poscript header missing\n");
  706. X      exit(1);
  707. X   }
  708. X
  709. X   /* Header file printing */
  710. X   while ((c = getc(f)) != EOF)
  711. X      putchar(c);
  712. X
  713. X   /* Retrieve date and hour */
  714. X#ifdef ANSIC
  715. X   if (time(&date) == -1)
  716. X   {
  717. X      fprintf(stderr, "Error calculing time\n");
  718. X      exit(1);
  719. X   }
  720. X   string = ctime(&date);
  721. X
  722. X   /* and print them */
  723. X   printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11);
  724. X#else
  725. X#ifdef UNIX
  726. X   (void) gettimeofday(&date, (struct timezone *)0);
  727. X   p = localtime(&date.tv_sec);
  728. X   string = asctime(p);
  729. X
  730. X   /* and print them */
  731. X   printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11);
  732. X#else
  733. X#ifdef SYSV
  734. X   (void)ftime(&date);
  735. X   string = ctime(&date.time);
  736. X   printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11);
  737. X#endif
  738. X#endif
  739. X#endif
  740. X
  741. X   /* Go on */
  742. X   printf("startdoc\n");
  743. X}
  744. SHAR_EOF
  745. chmod 0664 a2ps.c || echo "restore of a2ps.c fails"
  746. set `wc -c a2ps.c`;Sum=$1
  747. if test "$Sum" != "9038"
  748. then echo original size 9038, current size $Sum;fi
  749. fi
  750. if test -f header.ps; then echo "File header.ps exists"; else
  751. echo "x - extracting header.ps (Text)"
  752. sed 's/^X//' << 'SHAR_EOF' > header.ps &&
  753. X%!  PostScript Source Code
  754. X%
  755. X%  File: imag:/users/local/a2ps/header.ps
  756. X%  Created: Tue Nov 29 12:14:02 1988 by miguel@imag (Miguel Santana)
  757. X%  Version: 2.0
  758. X%  Description: PostScript prolog for a2ps ascii to PostScript program.
  759. X% 
  760. X%  Edit History:
  761. X%  - Original version by evan@csli (Evan Kirshenbaum).
  762. X%  - Modified by miguel@imag to:
  763. X%    1) Correct an overflow bug when printing page number 10 (operator
  764. X%    cvs).
  765. X%    2) Define two other variables (sheetwidth, sheetheight) describing
  766. X%    the physical page (actually A4 format).
  767. X%    3) Minor changes (reorganization, comments, etc).
  768. X%
  769. X
  770. X% Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
  771. X%
  772. X% Permission is granted to copy and distribute this file in modified
  773. X% or unmodified form, for noncommercial use, provided (a) this copyright
  774. X% notice is preserved, (b) no attempt is made to restrict redistribution
  775. X% of this file, and (c) this file is not distributed as part of any
  776. X% collection whose redistribution is restricted by a compilation copyright.
  777. X%
  778. X
  779. X
  780. X% General macros.
  781. X/xdef {exch def} bind def
  782. X/inch {72 mul} bind def
  783. X/getfont {exch findfont exch scalefont} bind def
  784. X
  785. X% Dimensions of a physical page.
  786. X/sheetwidth 11.7 inch def
  787. X/sheetheight 8.25 inch def
  788. X
  789. X% Character size for differents fonts.
  790. X/filenamefontsize 12 def
  791. X/datefontsize filenamefontsize 2 sub def
  792. X/headerfontsize filenamefontsize 4 add def
  793. X/bodyfontsize 6.8 def
  794. X
  795. X% Font assignment to differents kinds of "objects"
  796. X/filenamefont /Helvetica-Bold filenamefontsize getfont def
  797. X/datefont /Helvetica datefontsize getfont def
  798. X/bodyfont /Courier bodyfontsize getfont def
  799. X
  800. X
  801. X% Logical page attributs (a half of a real page or sheet).
  802. X/linesperpage 66 def
  803. X/sidemargin 4 def
  804. X/topmargin 4 def
  805. X/pagewidth 
  806. X   bodyfont setfont (0) stringwidth pop 86 mul sidemargin dup add add
  807. X   def
  808. X/pageheight
  809. X   bodyfontsize linesperpage mul topmargin dup add add headerfontsize add
  810. X   def
  811. X
  812. X% Upper corner for a logical page. Coordinate x is not the same for left
  813. X% and right pages: upperx is an array of two elements, indexed by sheetside.
  814. X/uppery sheetheight pageheight add 2 div def
  815. X/upperx [ sheetwidth pagewidth 2 mul sub 3 div    % upperx for left page
  816. X          dup 2 mul pagewidth add        % upperx for right page
  817. X        ] def
  818. X
  819. X% String used to make easy printing numbers
  820. X/pnum 12 string def
  821. X/empty 12 string def
  822. X
  823. X
  824. X% Function startdoc: initializes printer and global variables.
  825. X/startdoc
  826. X    { sheetheight 0 inch translate    % new origin for the coordinate system
  827. X      90 rotate                % landscape format
  828. X      /sheetside 0 def            % sheet side that contains current page
  829. X      /sheet 1 def            % sheet number
  830. X    } bind def
  831. X
  832. X% Function newfile: init file name and reset page number for each new file.
  833. X/newfile
  834. X    { /filename xdef
  835. X      /pagenum 1 def 
  836. X      cleanup
  837. X    } bind def
  838. X
  839. X% Function cleanup: terminates printing, flushing last page if necessary.
  840. X/cleanup
  841. X    { sheetside 1 eq
  842. X         { /sheetside 0 def
  843. X           sheetnumber
  844. X           /sheet sheet 1 add def
  845. X           copypage
  846. X           erasepage
  847. X         }
  848. X      if
  849. X    } bind def
  850. X
  851. X%
  852. X% Function startpage: prints page header and page border and initializes
  853. X% printing of the file lines.
  854. X/startpage
  855. X    { printheader
  856. X      printborder
  857. X      upperx sheetside get  sidemargin  add
  858. X      uppery topmargin sub  bodyfontsize  sub  headerfontsize  sub
  859. X         moveto
  860. X      bodyfont setfont
  861. X    } bind def
  862. X
  863. X% Function printheader: prints page header.
  864. X/printheader
  865. X    { upperx sheetside get  uppery headerfontsize sub 1 add  moveto
  866. X      datefont setfont
  867. X      gsave
  868. X        sidemargin 2 rmoveto date show                % date/hour
  869. X      grestore
  870. X      gsave
  871. X        pagenum pnum cvs
  872. X        pagewidth sidemargin sub pnum stringwidth pop sub
  873. X        (Page ) stringwidth pop sub 3 rmoveto
  874. X        (Page ) show pnum show                    % page number
  875. X      grestore
  876. X      empty pnum copy
  877. X      gsave
  878. X        filenamefont setfont
  879. X        pagewidth filename stringwidth pop sub 2 div 2 rmoveto
  880. X        filename show                        % file name
  881. X      grestore
  882. X    } bind def
  883. X
  884. X% Function printborder: prints border page.
  885. X/printborder 
  886. X    { upperx sheetside get uppery moveto
  887. X      gsave                    % print the four sides
  888. X        pagewidth 0 rlineto            % of the square
  889. X        0 pageheight neg rlineto
  890. X        pagewidth neg 0 rlineto
  891. X        closepath stroke
  892. X      grestore
  893. X      0 headerfontsize neg rmoveto pagewidth 0 rlineto stroke
  894. X    } bind def
  895. X
  896. X%
  897. X% Function endpage: adds a sheet number to the page (footnote) and prints
  898. X% the formatted page (physical impression). Activated at the end of each
  899. X% source page (linesperpage reached or FF character).
  900. X/endpage
  901. X   { sheetside 1 eq
  902. X        { /sheetside 0 def
  903. X          sheetnumber
  904. X          copypage
  905. X          erasepage 
  906. X          /sheet sheet 1 add def
  907. X        }
  908. X        { /sheetside 1 def }
  909. X     ifelse
  910. X     /pagenum pagenum 1 add def
  911. X    } bind def
  912. X
  913. X% Function sheetnumber: prints the sheet number.
  914. X/sheetnumber
  915. X    { sheetwidth  upperx 0 get  sub  sidemargin  add
  916. X      sheetheight  uppery  sub  headerfontsize  sub
  917. X         moveto
  918. X      datefont setfont
  919. X      sheet pnum cvs show
  920. X      empty pnum copy
  921. X    } bind def
  922. X
  923. X% Function s: print a source line
  924. X/s  { gsave
  925. X        show
  926. X      grestore
  927. X      0 bodyfontsize neg rmoveto
  928. X    } bind def
  929. SHAR_EOF
  930. chmod 0664 header.ps || echo "restore of header.ps fails"
  931. set `wc -c header.ps`;Sum=$1
  932. if test "$Sum" != "5200"
  933. then echo original size 5200, current size $Sum;fi
  934. fi
  935. exit 0
  936. -- 
  937. Miguel SANTANA   miguel@imag.fr or miguel@imag.UUCP (uunet.uu.net!imag!miguel)
  938.  
  939.  
  940.