From decwrl!lll-winken!uunet!allbery Sun Feb 18 00:51:02 PST 1990 Article 1344 of comp.sources.misc: Path: decwrl!lll-winken!uunet!allbery From: miguel@imag.imag.fr (Miguel Santana) Newsgroups: comp.sources.misc Subject: v10i073: A2ps v3.0 Message-ID: <79121@uunet.UU.NET> Date: 17 Feb 90 02:39:29 GMT Sender: allbery@uunet.UU.NET Organization: IMAG, University of Grenoble, France Lines: 1386 Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) Posting-number: Volume 10, Issue 73 Submitted-by: miguel@imag.imag.fr (Miguel Santana) Archive-name: a2ps3 This is version 3.0 of a2ps, a program to format an ascii file for printing in a postcript printer. The format used is nice and compact: normally two pages on each physical page, borders surrounding pages, headers with useful information (page number, printing date, file name), line numbering, etc. Very useful to archive listings of programs. A2ps offers many options: multiple copies, landscape and portrait mode, wide format, lines numbering, fold/cut lines too large, font size, etc. User could adapt the printing format to his own preferences with these options. Please, follow the instructions in README file to install a2ps in your computer. Use sh to unpacking. Miguel SANTANA ----------------------- cut here ----------------------- #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'README' <<'END_OF_FILE' XThis is version 3.0 of a2ps, a program to format an ascii file for Xprinting in a postcript printer. As the copyright indicates, this Xdistribution can be freely redistributed. X XInitial version was a shell program written by evan@csli (Evan XKirshenbaum). It was very slow and contained many bugs. A new Xversion was written in C for improve speed execution and portability. XMany new features and improvements have been added. X X XSome notes on the distribution: X X Installation is done by modifying and executing Makefile included X in this distribution. You must give a value to two variables: X - HEADER_PS a2ps will search there the file header.ps at execution X time. X - compiler compiler name, actually one of BSD, SYSV, ANSIC. Turbo X C and Microsoft C are considered ANSIC compilers. X You could also give your own values to following variables: X a) Physical page dimension. Dimensions must be real constants, X specifying inch values. X - HEIGHT sheet height X - WIDTH sheet width X Default values correspond to A4 format (11.64 x 8.27). In USA, you use X use in general 11.0 x 8.5. X b) Total lateral (left+right) or vertical (top+bottom) margins. It must X be also a real constant, specifying inchs (by default 1.2). X - MARGIN X c) Directory separator (by default '/') X - DIR_SEP char X X a2ps has been successfully ported to Unix 4.3BSD, Unix SystemV and X MSDOS. X X XThe a2ps distribution consists of the following files: X X README This message X Makefile X a2ps.c a2ps source X a2ps.1 a troff manual (man file) X header.ps postcript header used by a2ps X XDecide where you want to keep these files and move it there. XEdit "Makefile" and change the definition of HEADER_PS (to Xreflect the full pathname of header.ps) and of compiler name. XTo make a2ps do: X X make a2ps X XTo install it, do: X X make install X XFormat the manual entry using X X nroff -man a2ps.1 X X XPlease send problems and feedback to: X X miguel@imag.fr or miguel@imag.UUCP (uunet.uu.net!imag!miguel) X X Miguel SANTANA X LGI X IMAG-Campus X BP 53X X 38041 Grenoble Cedex END_OF_FILE if test 2116 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi chmod +x 'README' # end of 'README' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(1325 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X# X# Description: Makefile to construct and install a2ps. Don't forget X# to give your own values to define variables HEADER_PS and name of X# compiler (see OPTIONS). X# X# File: imag:/users/local/a2ps/Makefile X# Created: Mon Nov 29 14:05:39 1988 by miguel@imag (Miguel Santana) X# Version: 2.0 X# X X# Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr X# X# Permission is granted to copy and distribute this file in modified X# or unmodified form, whether for noncommercial or commercial use, X# provided (a) this copyright notice is preserved, (b) no attempt is X# made to restrict redistribution of this file, and (c) this file is X# not distributed as part of any collection whose redistribution is X# restricted by a compilation copyright. X# X XD =. X XO =. X XI =/usr/local/bin X XL =/usr/local/lib X XHEADER =a2ps.header.ps X XOPTIONS =-DHEADER_PS="\"$L/$(HEADER)\"" -DBSD -O X# Default values for HEIGHT, WIDTH, MARGIN and DIR_SEP (11.64, 8.27, 1.2, /). X XOBJS = a2ps.o X Xa2ps: a2ps.o X @echo -n "Compiling and linking a2ps ... " X @cc -o $D/xa2ps a2ps.o X @echo "done" X Xall: a2ps install X Xinstall:; @echo -n "Installing a2ps ... " X @cp xa2ps $I/a2ps X @cp header.ps $L/$(HEADER) X @echo "done" X Xshar:; @shar -b -oa2ps.shar README Makefile a2ps.1 a2ps.c header.ps X Xclean:; @rm -f $(OBJS) xa2ps X Xa2ps.o:; X cc -c $(OPTIONS) a2ps.c X END_OF_FILE if test 1325 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'a2ps.1' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'a2ps.1'\" else echo shar: Extracting \"'a2ps.1'\" \(4522 characters\) sed "s/^X//" >'a2ps.1' <<'END_OF_FILE' X.\" @(#)a2ps.man.1 2.0 11/29/88 X.\" X.TH A2PS 1L "24 July 1989" X.UC 4 X.SH NAME Xa2ps \- formats an ascii file for printing on a postscript printer X.SH SYNOPSIS X.B a2ps X[ X.B -#num X] [ X[ X.B -? X] [ X.B -b X] [ X.B -f X] [ X.B -fnum X] [ X[ X.B -h X] [ X.B -i X] [ X.B -n X] [ \fB-n\fP{\fBbfhinprsvw\fP} ] [ X.B -p X] [ X.B -r X] [ X.B -tnum X] [ X.B -v X] [ X.B -w X] [ X.I file X] ... X.SH DESCRIPTION X.I a2ps Xformats each named file for printing in a postscript printer; Xif no file is given, X.I a2ps Xreads from the standard input. XThe format used is nice and compact: normally Xtwo pages on each physical page, Xborders surrounding pages, headers with useful information (page number, Xprinting date, file name), line numbering, etc. Very useful to Xarchive listings of programs. X.PP XOptions offered by X.I a2ps Xare the following: X.TP 0.6i X.B -#num XTo get multiple copies of output, where X.I num Xis the number of copies desired of each file named. By default, you get Xonly one copy. X.TP 0.6i X.B -? XPrint usage information. X.TP 0.6i X.B -b XForce printing binary files. By default, binary files printing is Xstopped before second page (see -nb option). X.TP 0.6i X.B -f XFold lines too large to be printed inside the borders (default option). XMax size depends on format and font size used. X.TP 0.6i X.B -fnum XChanges font size to this value. Default values for font size are 6.8 in Xlandscape mode and 9.0 in portrait mode. Try other sizes if you think that Xthese values are too small (or big). X.TP 0.6i X.B -h XPrint usage information. X.TP 0.6i X.B -i XInterpret TAB, BS and FF characters (default option). TAB is replaced by Xenough spaces to reach next tab stop while BS and FF have their meanings. X.TP 0.6i X.B -n XOutput lines are preceded by line numbers, numbered sequentially from 1 X(default option). X.TP 0.6i X.B -nb XDon't print binary files. To detect such a file we make use of a Xvery simple heuristic: if the first page of the file contains at Xless 75% of non-printing characters, it's a binary file. First page Xis always printed. X.TP 0.6i X.B -nf XCut lines too large (don't fold). X.TP 0.6i X.B -nh XDon't print page headers. X.TP 0.6i X.B -ni XDon't interpret TAB, BS and FF characters. They will be printed Xaccording to -v option. X.TP 0.6i X.B -nn XDon't number output lines. X.TP 0.6i X.B -np XDon't print pages in portrait mode (see -p option) but in landscape mode. X.TP 0.6i X.B -nr XSheet numbering (see -r option) must be continue for all files (don't Xreset on new file). X.TP 0.6i X.B -ns XDon't print page surrounding borders. X.TP 0.6i X.B -nv XReplace non-printing characters by a space. X.TP 0.6i X.B -nw XDon't use wide format (see -w option). X.TP 0.6i X.B -p XPrint files in portrait mode, one page per physical sheet. XThe default option is to use landscape mode and print two pages on a physical Xsheet. This option may not be used with the -w option. X.TP 0.6i X.B -r XReset sheet numbering for each new file (default option). Sheet numbering Xis used to number physical pages (sheets printed) and is placed Xin the bottom of each physical page. It differs from page numbering: logical Xpages of file been printed. X.TP 0.6i X.B -tnum XSet TAB size to \fInum\fR (default 8). XThis option is ignored if \fB-ni\fR is specified (see below). X.TP 0.6i X.B -v XReplace non-printing characters so that they are visible and easy to identify X(default option). Control characters (ascii codes lower than 0x20) are Xprinted like ^X for ctrl-x; the delete character (hex 0x3f) is printed Xas ^?. Non ascii characters (with the high bit set) are printed as M- X(for meta) followed by the character of the low 7 bits. TAB, BS and FF are Xhandled like non-printing characters if -ni option was taked. X+ .TP 0.6i X.B -w XUse wide format pages. This will result in only one page per physical sheet Xbut in landscape mode. This option may not be used with the -p option. X.SH USAGE X.PP X.I A2ps Xsends formatted file to standard output. The user could redirect this output Xto a file, pipe it directly to a print command (like lpr), or pipe it to Xanother filter for further processing. X X.ti +0.5i Xa2ps file1 > file2 X X.ti +0.5i Xa2ps file1 | lpr -l -Pps X X.ti +0.5i Xa2ps -p file1 | psnup -n4 | lpr -l -Pps X.PP XDon't forget X.B -l Xoption in X.I lpr X, if you want that X.I lpr Xinterprets your postscript program. X.PP XThis filter must be used only with text files. Avoid specially output from XTeX, troff or any other such text formatters. X.SH "SEE ALSO" Xtgrind(1) lpr(1) pprps(1L) X.SH AUTHORS XEvan Kirshenbaum (evan@csli) for the initial version. X.br XMiguel Santana (miguel@imag.imag.fr) for versions 1.0, 2.0 et 3.0. X END_OF_FILE if test 4522 -ne `wc -c <'a2ps.1'`; then echo shar: \"'a2ps.1'\" unpacked with wrong size! fi # end of 'a2ps.1' fi if test -f 'a2ps.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'a2ps.c'\" else echo shar: Extracting \"'a2ps.c'\" \(18394 characters\) sed "s/^X//" >'a2ps.c' <<'END_OF_FILE' X/************************************************************************/ X/* */ X/* Description: Ascii to PostScript printer program. */ X/* File: imag:/users/local/a2ps/a2ps.c */ X/* Created: Mon Nov 28 15:22:15 1988 by miguel@imag (Miguel Santana) */ X/* Version: 2.0 */ X/* */ X/* Edit history: */ X/* 1) Derived of shell program written by evan@csli (Evan Kirshenbaum). */ X/* Written in C for improve speed execution and portability. Many */ X/* improvements have been added. */ X/* Fixes by Oscar Nierstrasz @ cui.uucp: */ X/* 2) Fixed incorrect handling of stdin (removed error if no file names)*/ X/* 3) Added start_page variable to eliminate blank pages printed for */ X/* files that are exactly multiples of 132 lines (e.g., man pages) */ X/* Modified by miguel@imag: */ X/* 4) Added new options at installation : sheet format (height/width in */ X/* inches), page format (number of columns per line and of lines per */ X/* page). */ X/* Modified by miguel@imag: */ X/* 5) Added new option to print n copies of a same document. */ X/* 6) Cut long filenames if don't fit in the page header. */ X/* Modified by Tim Clark (T.Clark@warwick.ac.uk): */ X/* 7) Two additional modes of printing (portrait and wide format modes) */ X/* 8) Fixed to cope with filenames which contain a character which must */ X/* be escaped in a PostScript string. */ X/* Modified by miguel@imag.fr to */ X/* 9) Add new option to suppress heading printing. */ X/* 10) Add new option to suppress page surrounding border printing. */ X/* 11) Add new option to change font size. Number of lines and columns */ X/* are now automatically adjusted, depending on font size and */ X/* printing mode used. */ X/* 12) Minor changes (best layout, usage message, etc). */ X/* */ X/************************************************************************/ X X/* X * Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr X * X * Permission is granted to copy and distribute this file in modified X * or unmodified form, for noncommercial use, provided (a) this copyright X * notice is preserved, (b) no attempt is made to restrict redistribution X * of this file, and (c) this file is not distributed as part of any X * collection whose redistribution is restricted by a compilation copyright. X*/ X X X#include X#include X#ifdef ANSIC X#include X#include X#else X#ifdef BSD X#include X#else X#ifdef SYSV X#include X#include X#include X#else Xerror ! X#endif X#endif X#endif X X#ifndef HEADER_PS X#define HEADER_PS "./header.ps" X#endif X X#ifndef WIDTH X#define WIDTH 8.27 X#endif X X#ifndef HEIGHT X#define HEIGHT 11.64 X#endif X X#ifndef MARGIN X#define MARGIN 1.2 X#endif X X#ifndef DIR_SEP X#define DIR_SEP '/' X#endif X X#define PORTRAIT_HEADER 0.29 X#define LANDSCAPE_HEADER 0.22 X#define PIXELS_INCH 72 X#define MAXFILENAME 20 X#define FALSE 0 X#define TRUE 1 X Xint fold_line(); Xvoid print_file(); Xchar cut_line(); Xint printchar(); Xvoid skip_page(); X X Xint column = 0; /* Column number (in current line) */ Xint line = 0; /* Line number (in current page) */ Xint line_number = 0; /* Source line number */ Xint first_page; /* First page for a file */ Xint nonprinting_chars, chars; /* Number of nonprinting and total chars */ Xint prefix_width; /* Width in characters for line prefix */ Xint pages = 0; /* Number of logical pages printed */ Xint sheets = 0; /* Number of physical pages printed */ Xint linesperpage; /* Lines per page */ Xint columnsperline; /* Characters per output line */ X Xdouble font_size = 0.0; /* Size of a char for body font */ Xint numbering = TRUE; /* Line numbering option */ Xint folding = TRUE; /* Line folding option */ Xint restart = TRUE; /* Restart page number at each file option */ Xint only_printable = FALSE; /* Replace non printable char by space option */ Xint interpret = TRUE; /* Interpret TAB, FF and BS chars option */ Xint print_binaries = FALSE; /* Force printing for binary files */ Xint copies_number = 1; /* Number of copies to print */ Xint landscape = TRUE; /* Otherwise portrait format sheets */ Xint wide_pages = FALSE; /* TRUE implies landscape, not twinpage */ Xint twinpage = TRUE; /* 2 pages per sheet if true, 1 otherwise */ Xint no_border = FALSE; /* TRUE if user don't want the border */ Xint no_header = FALSE; /* TRUE if user don't want the header */ Xint column_width = 8; /* default column tab width (8) */ X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X register int narg; X register char *arg; X double char_width, header_size; X double page_height, page_width; X int i; X extern double atof(); X X /* Option processing */ X arg = argv[narg = 1]; X while (narg < argc && arg[0] == '-') X { X switch (arg[1]) X { X case '?': /* help */ X goto usage; X case '#': /* n copies */ X copies_number = 0; X arg += 2; X while (*arg != NULL && isdigit(*arg)) X copies_number = copies_number*10 + (*arg++ - '0'); X if (*arg != NULL || copies_number <= 0) X goto usage; X break; X case 'b': /* print binary files */ X if (arg[2] != NULL) X goto usage; X print_binaries = TRUE; X break; X case 'f': /* change font size */ X if (arg[2] == NULL) { X folding = TRUE; X break; X } X if ((font_size = atof(&arg[2])) == 0.0) { X fprintf(stderr, "Wrong value for option -s\n"); X exit(1); X } X break; X case 'h': /* help */ X goto usage; X case 'i': /* interpret control chars */ X if (arg[2] != NULL) X goto usage; X interpret = TRUE; X break; X case 'n': /* number file lines */ X if (arg[2] == NULL) X { X numbering = TRUE; X break; X } X if (arg[3] != NULL) X goto usage; X switch (arg[2]) X { X case 'b': /* don't print binaries */ X print_binaries = FALSE; X break; X case 'f': /* cut lines too long */ X folding = FALSE; X break; X case 'h': /* don't print header */ X no_header = TRUE; X break; X case 'i': /* don't interpret ctrl chars */ X interpret = FALSE; X break; X case 'n': /* don't number lines */ X numbering = FALSE; X break; X case 'p': /* landscape format */ X landscape = TRUE; X break; X case 'r': /* don't restart sheet number */ X restart = FALSE; X break; X case 's': /* no surrounding border */ X no_border = TRUE; X break; X case 'v': /* only printable chars */ X only_printable = TRUE; X break; X case 'w': /* twin pages */ X wide_pages = FALSE; X break; X default: X goto usage; X } X break; X case 'p': /* portrait format */ X if (arg[2] != NULL) X goto usage; X if (wide_pages) { X fprintf(stderr, "a2ps: options -p and -w are incompatible\n"); X exit(1); X } X landscape = FALSE; X break; X case 'r': /* restart sheet number */ X if (arg[2] != NULL) X goto usage; X restart = TRUE; X break; X case 't': /* set tab size */ X if (arg[2] == NULL || (column_width = atoi(arg+2)) <= 0) X goto usage; X break; X case 'v': /* print control chars */ X if (arg[2] != NULL) X goto usage; X only_printable = FALSE; X break; X case 'w': /* wide format */ X if (arg[2] != NULL) X goto usage; X if (!landscape) { X fprintf(stderr, "a2ps: options -p and -w are incompatible\n"); X exit(1); X } X wide_pages = TRUE; X break; X default: X usage: X fprintf(stderr,"Usage: %s [options] [f1 f2 ... fn]\n", argv[0]); X fprintf(stderr,"options = -#num\t(number of copies to print)\n"); X fprintf(stderr," -?\t(print this information)\n"); X fprintf(stderr," -f\t(fold lines too large)\n"); X fprintf(stderr," -fnum\t(font size, num is a float number)\n"); X fprintf(stderr," -h\t(print this information)\n"); X fprintf(stderr," -i\t(interpret tab, bs and ff chars)\n"); X fprintf(stderr," -n\t(number line files)\n"); X fprintf(stderr," -p\t(print in portrait mode)\n"); X fprintf(stderr," -r\t(restart page number after each file)\n"); X fprintf(stderr," -tn\t(set tab size to n)\n"); X fprintf(stderr," -v\t(show non-printing chars in a clear form)\n"); X fprintf(stderr," -w\t(print in wide format)\n"); X fprintf(stderr," -nb\t(don't force printing binary files)\n"); X fprintf(stderr," -nf\t(don't fold lines)\n"); X fprintf(stderr," -nh\t(don't print the header)\n"); X fprintf(stderr," -ni\t(don't interpret special chars)\n"); X fprintf(stderr," -nn\t(don't number output lines)\n"); X fprintf(stderr," -np\t(don't print in portrait format)\n"); X fprintf(stderr," -nr\t(don't restart page number)\n"); X fprintf(stderr," -ns\t(don't print surrounding borders)\n"); X fprintf(stderr," -nv\t(replace non-printing chars by space)\n"); X fprintf(stderr," -nw\t(don't print in wide format)\n"); X exit(1); X } X arg = argv[++narg]; X } X if (arg != NULL && strcmp(arg, "?") == 0) X goto usage; X X twinpage = landscape && !wide_pages; X if (font_size == 0.0) X font_size = landscape ? 6.8 : 9.0; X page_height = (HEIGHT - MARGIN) * PIXELS_INCH; X page_width = (WIDTH - MARGIN) * PIXELS_INCH; X char_width = 0.6 * font_size; X if (landscape) { X header_size = no_header ? 0.0 : LANDSCAPE_HEADER * PIXELS_INCH; X linesperpage = ((page_width - header_size) / font_size) - 1; X if (wide_pages) X columnsperline = (page_height / char_width) - 1; X else X columnsperline = ((page_height / 2) / char_width) - 1; X } X else { X header_size = no_header ? 0.0 : PORTRAIT_HEADER * PIXELS_INCH; X linesperpage = ((page_height - header_size) / font_size) - 1; X columnsperline = (page_width / char_width) - 1; X } X if (linesperpage <= 0 || columnsperline <= 0) { X fprintf(stderr, "Font %g too big !!\n", font_size); X exit(1); X } X X /* Header printing (postcript prolog) */ X print_header(); X X /* Print files designated or standard input */ X prefix_width = numbering ? 6 : 1; X if (narg >= argc) X print_file("stdin"); X else X { X while (narg < argc) X { X if (freopen(arg, "r", stdin) == NULL) X { X fprintf(stderr, "Error opening %s\n", arg); X printf("\n%%%%Trailer\ncleanup\ndocsave restore end\n"); X exit(1); X } X print_file(arg); X arg = argv[++narg]; X } X } X X printf("\n%%%%Trailer\ncleanup\ndocsave restore end\n"); X} X Xvoid print_file(name) Xchar *name; X{ X register int c; X int start_line, continue_exit; X int char_width; X int start_page; X char new_name[MAXFILENAME+1]; X char *p; X X /* X * Boolean to indicates that previous char is \n (or interpreted \f) X * and a new page would be started, if more text follows X */ X start_page = FALSE; X X /* X * Printing binary files is not very useful. We stop printing X * if we detect one of these files. Our heuristic to detect them: X * if 50% characters of first page are non-printing characters, X * the file is a binary file. X * Option -b force binary files impression. X */ X first_page = TRUE; X nonprinting_chars = chars = 0; X X /* X * Preprocessing (before printing): X * - TABs expansion (see interpret option) X * - FF and BS interpretation X * - replace non printable characters by a space or a char sequence X * like: X * ^X for ascii codes < 0x20 (X = [@, A, B, ...]) X * ^? for del char X * M-c for ascii codes > 0x3f X * - prefix parents and backslash ['(', ')', '\'] by backslash X * (escape character in postcript) X */ X column = 0; X line = line_number = 0; X start_line = TRUE; X X if (strlen(name) > MAXFILENAME) { X cut_filename(name, new_name); X name = new_name; X } X putchar('('); X for (p = name; *p != NULL;) X printchar(*p++); X printf(") newfile\n"); X X if (restart) X printf("/sheet 1 def\n"); X X pages = 0; X skip_page(); X X c = getchar(); X while (c != EOF) X { X /* Form feed */ X if (c == '\f' && interpret) X { X /* Close current line */ X if (!start_line) X { X printf(") s\n"); X start_line = TRUE; X } X /* start a new page ? */ X if (start_page) X skip_page(); X /* Close current page and begin another */ X printf("endpage\n") ; X start_page = TRUE; X /* Verification for binary files */ X if (first_page && is_binaryfile(name)) X return; X line = 0; X if ((c = getchar()) == EOF) X break; X } X X /* Start a new line? */ X if (start_line) X { X if (start_page) X { /* only if there is something to print! */ X skip_page(); X start_page = FALSE ; X } X if (numbering) X printf("(%-5d ", ++line_number); X else X printf("( "); X start_line = FALSE; X } X X /* Interpret each character */ X switch (c) X { X case '\b': X if (!interpret) X goto print; X if (column) X column--; X putchar(c); X break; X case '\n': X column = 0; X start_line = TRUE; X printf(") s\n"); X if (++line >= linesperpage) X { X printf("endpage\n"); X start_page = TRUE ; X if (first_page && is_binaryfile(name)) X return; X line = 0; X } X break; X case '\t': X if (interpret) X { X continue_exit = FALSE; X do X { X if (++column + prefix_width > columnsperline) X if (folding) X { X if (fold_line(name) == FALSE) X return; X } X else X { X c = cut_line(); X continue_exit = TRUE; X break; X } X putchar(' '); X } while (column % column_width); X if (continue_exit) X continue; X break; X } X default: X print: X if (only_printable) X char_width = 1; X else X { X char_width = c > 0177 ? 2 : 0; X char_width += c < ' ' || c == 0177 ? 2 : 1; X } X if (prefix_width + (column += char_width) > columnsperline) X if (folding) X { X if (fold_line(name) == FALSE) X return; X } X else X { X c = cut_line(); X continue; X } X nonprinting_chars += printchar(c); X chars++; X break; X } X c = getchar(); X } X X if (!start_line) X printf(") s\n"); X if (!start_page) X printf("endpage\n"); X} X X/* X * Cut long filenames. X */ Xint cut_filename(old_name, new_name) Xchar *old_name, *new_name; X{ X register char *p; X register int i; X X p = old_name + (strlen(old_name)-1); X while (p >= old_name && *p != DIR_SEP) p--; X X for (i = 0, p++; *p != NULL && i < MAXFILENAME; i++) X *new_name++ = *p++; X *new_name = NULL; X} X X/* X * Fold a line too long. X */ Xint fold_line(name) Xchar *name; X{ X column = 0; X printf(") s\n"); X if (++line >= linesperpage) X { X printf("endpage\n"); X skip_page(); X if (first_page && is_binaryfile(name)) X return FALSE; X line = 0; X } X if (numbering) X printf("( "); X else X printf("( "); X X return TRUE; X} X X/* X * Cut a textline too long to the size of a page line. X */ Xchar cut_line() X{ X char c; X X while ((c = getchar()) != EOF && c != '\n' && c != '\f'); X return c; X} X X/* X * Print a char in a form accept by postscript printers. X */ Xint printchar(c) Xunsigned char c; X{ X if (c >= ' ' && c < 0177) X { X if (c == '(' || c == ')' || c == '\\') X putchar('\\'); X putchar(c); X return 0; X } X X if (only_printable) X { X putchar(' '); X return 1; X } X X if (c > 0177) X { X printf("M-"); X c &= 0177; X } X if (c < ' ') X { X putchar('^'); X if ((c = c + '@') == '(' || c == ')' || c == '\\') X putchar('\\'); X putchar(c); X } X else if (c == 0177) X printf("^?"); X else X putchar(c); X X return 1; X} X X/* X * Begins a new physical page. X */ Xvoid skip_page() X{ X pages++; X if (twinpage == FALSE || (pages & 0x1)) X { X sheets++; X printf("%%%%Page: %d %d\n", sheets, sheets); X } X printf("startpage\n"); X} X X/* X * Test if we have a binary file. X */ Xis_binaryfile(name) Xchar *name; X{ X first_page = FALSE; X if (!print_binaries && (nonprinting_chars*100 / chars) >= 75) X { X fprintf(stderr, "%s is a binary file: printing aborted\n", name); X return TRUE; X } X return FALSE; X} X Xprint_header() X{ X register int c; X FILE *f; X char *string; X#ifdef ANSIC X time_t date; X#else X#ifdef BSD X struct timeval date; X struct tm *p; X#else X#ifdef SYSV X struct timeb date; X#endif X#endif X#endif X X if ((f = fopen(HEADER_PS, "r")) == NULL) X { X fprintf(stderr, "Poscript header missing\n"); X exit(1); X } X X /* Initialize some postcript variables */ X printf("%%! a2ps 3.0\n\n"); X printf("/$a2psdict 100 dict def\n"); X printf("$a2psdict begin\n"); X printf("%% Initialize page description variables.\n"); X printf("/inch {72 mul} bind def\n"); X printf("/landscape %s def\n", landscape ? "true" : "false"); X printf("/twinpage %s def\n", twinpage ? "true" : "false"); X printf("/sheetheight %g inch def\n", HEIGHT); X printf("/sheetwidth %g inch def\n", WIDTH); X printf("/margin %g inch def\n", MARGIN); X printf("/noborder %s def\n", no_border ? "true" : "false"); X if (no_header) { X printf("/noheader true def\n"); X printf("/headersize 0.0 def\n"); X } X else { X printf("/noheader false def\n"); X printf("/headersize %g inch def\n", X landscape ? LANDSCAPE_HEADER : PORTRAIT_HEADER); X } X printf("/bodyfontsize %g def\n", font_size); X printf("/lines %d def\n", linesperpage); X printf("/columns %d def\n", columnsperline); X X /* Retrieve date and hour */ X#ifdef ANSIC X if (time(&date) == -1) X { X fprintf(stderr, "Error calculing time\n"); X exit(1); X } X string = ctime(&date); X X /* and print them */ X printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11); X#else X#ifdef BSD X (void) gettimeofday(&date, (struct timezone *)0); X p = localtime(&date.tv_sec); X string = asctime(p); X X /* and print them */ X printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11); X#else X#ifdef SYSV X (void)ftime(&date); X string = ctime(&date.time); X printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11); X#endif X#endif X#endif X X /* Header file printing */ X while ((c = getc(f)) != EOF) X putchar(c); X X X /* Close prolog */ X printf("%%%%EndProlog\n\n"); X X /* Ask for printing n copies */ X if (copies_number > 1) X printf("/#copies %d def\n", copies_number); X X /* Go on */ X printf("/docsave save def\n"); X printf("startdoc\n"); X} END_OF_FILE if test 18394 -ne `wc -c <'a2ps.c'`; then echo shar: \"'a2ps.c'\" unpacked with wrong size! fi # end of 'a2ps.c' fi if test -f 'header.ps' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'header.ps'\" else echo shar: Extracting \"'header.ps'\" \(8096 characters\) sed "s/^X//" >'header.ps' <<'END_OF_FILE' X%! PostScript Source Code X% X% File: imag:/users/local/a2ps/header.ps X% Created: Tue Nov 29 12:14:02 1988 by miguel@imag (Miguel Santana) X% Version: 2.0 X% Description: PostScript prolog for a2ps ascii to PostScript program. X% X% Edit History: X% - Original version by evan@csli (Evan Kirshenbaum). X% - Modified by miguel@imag to: X% 1) Correct an overflow bug when printing page number 10 (operator X% cvs). X% 2) Define two other variables (sheetwidth, sheetheight) describing X% the physical page (by default A4 format). X% 3) Minor changes (reorganization, comments, etc). X% - Modified by tullemans@apolloway.prl.philips.nl X% 1) Correct stack overflows with regard to operators cvs and copy. X% The resulting substrings where in some cases not popped off X% the stack, what can result in a stack overflow. X% 2) Replaced copypage and erasepage by showpage. Page througput X% degrades severely (see red book page 140) on our ps-printer X% after printing sheet 16 (i.e. page 8) of a file which was X% actually bigger. For this purpose the definitions of startdoc X% and startpage are changed. X% - Modified by Tim Clark to: X% 1) Print one page per sheet (portrait) as an option. X% 2) Reduce size of file name heading, if it's too big. X% 3) Save and restore PostScript state at begining/end. It now uses X% conventional %%Page %%Trailer markers. X% 4) Print one wide page per sheet in landscape mode as an option. X% - Modified by miguel@imag.fr to X% 1) Add new option to print n copies of a file. X% 2) Add new option to suppress heading printing. X% 3) Add new option to suppress page surrounding border printing. X% 4) Add new option to change font size. Number of lines and columns X% are now automatically adjusted, depending on font size and X% printing mode used. X% 5) Minor changes (best layout, usage message, etc). X% X X% Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr X% X% Permission is granted to copy and distribute this file in modified X% or unmodified form, for noncommercial use, provided (a) this copyright X% notice is preserved, (b) no attempt is made to restrict redistribution X% of this file, and (c) this file is not distributed as part of any X% collection whose redistribution is restricted by a compilation copyright. X% X X X% General macros. X/xdef {exch def} bind def X/getfont {exch findfont exch scalefont} bind def X X% Page description variables and inch function are defined by a2ps program. X X% Character size for differents fonts. X landscape X { /filenamefontsize 12 def } X { /filenamefontsize 16 def } Xifelse X/datefontsize filenamefontsize 0.8 mul def X/headermargin filenamefontsize 0.25 mul def X/bodymargin bodyfontsize 0.7 mul def X X% Font assignment to differents kinds of "objects" X/filenamefontname /Helvetica-Bold def X/stdfilenamefont filenamefontname filenamefontsize getfont def X/datefont /Helvetica datefontsize getfont def X/bodyfont /Courier bodyfontsize getfont def X X% Logical page attributs (a half of a real page or sheet). X/pagewidth X bodyfont setfont (0) stringwidth pop columns mul bodymargin dup add add X def X/pageheight X bodyfontsize lines mul bodymargin dup add add headersize add X def X X% Coordinates for upper corner of a logical page and for sheet number. X% Coordinates depend on format mode used. X% In twinpage mode, coordinate x of upper corner is not the same for left X% and right pages: upperx is an array of two elements, indexed by sheetside. X/rightmargin margin 3 div def X/leftmargin margin 2 mul 3 div def X/topmargin margin twinpage {3} {2} ifelse div def Xlandscape X{ % Landscape format X /uppery rightmargin pageheight add bodymargin add def X /sheetnumbery sheetwidth leftmargin pageheight add datefontsize add sub def X twinpage X { % Two logical pages X /upperx [ topmargin % upperx for left page X dup 2 mul pagewidth add % upperx for right page X ] def X /sheetnumberx sheetheight topmargin sub def X } X { /upperx [ topmargin dup ] def X /sheetnumberx sheetheight topmargin sub datefontsize sub def X } X ifelse X} X{ % Portrait format X /uppery topmargin pageheight add def X /upperx [ leftmargin dup ] def X /sheetnumberx sheetwidth rightmargin sub datefontsize sub def X /sheetnumbery X sheetheight X topmargin pageheight add datefontsize add headermargin add X sub X def X X} Xifelse X X% Strings used to make easy printing numbers X/pnum 12 string def X/empty 12 string def X X% Other initializations. X/datewidth date stringwidth pop def X/filenameroom X pagewidth X filenamefontsize 4 mul datewidth add (Page 999) stringwidth pop add X sub X def X X X% Function startdoc: initializes printer and global variables. X/startdoc X { /sheetside 0 def % sheet side that contains current page X /sheet 1 def % sheet number X } bind def X X% Function newfile: init file name and reset page number for each new file. X/newfile X { cleanup X /filename xdef X /filenamewidth filename stringwidth pop def X /filenamefont X filenamewidth filenameroom gt X { X filenamefontname X filenamefontsize filenameroom mul filenamewidth div X getfont X } X { stdfilenamefont } X ifelse X def X /pagenum 1 def X } bind def X X% Function printpage: Print a physical page. X/printpage X { /sheetside 0 def X twinpage X { noborder not X { sheetnumber } X if X } X { noheader noborder not and X { sheetnumber } X if X } X ifelse X showpage X% pagesave restore X /sheet sheet 1 add def X } bind def X X% Function cleanup: terminates printing, flushing last page if necessary. X/cleanup X { twinpage sheetside 1 eq and X { printpage } X if X } bind def X X% X% Function startpage: prints page header and page border and initializes X% printing of the file lines. X/startpage X { sheetside 0 eq X { % /pagesave save def X landscape X { sheetwidth 0 inch translate % new coordinates system origin X 90 rotate % landscape format X } if X } if X noborder not { printborder } if X noheader not { printheader } if X upperx sheetside get bodymargin add X uppery X bodymargin bodyfontsize add noheader {0} {headersize} ifelse add X sub X moveto X bodyfont setfont X } bind def X X% Function printheader: prints page header. X/printheader X { upperx sheetside get uppery headersize sub 1 add moveto X datefont setfont X gsave X datefontsize headermargin rmoveto X date show % date/hour X grestore X gsave X pagenum pnum cvs pop X pagewidth (Page 999) stringwidth pop sub X headermargin X rmoveto X (Page ) show pnum show % page number X grestore X empty pnum copy pop X gsave X filenamefont setfont X filenameroom filename stringwidth pop sub 2 div datewidth add X bodymargin 2 mul X add X headermargin X rmoveto X filename show % file name X grestore X } bind def X X% Function printborder: prints border page. X/printborder X { upperx sheetside get uppery moveto X gsave % print the four sides X pagewidth 0 rlineto % of the square X 0 pageheight neg rlineto X pagewidth neg 0 rlineto X closepath stroke X grestore X noheader not X { 0 headersize neg rmoveto pagewidth 0 rlineto stroke } X if X } bind def X X% X% Function endpage: adds a sheet number to the page (footnote) and prints X% the formatted page (physical impression). Activated at the end of each X% source page (lines reached or FF character). X/endpage X { /pagenum pagenum 1 add def X twinpage sheetside 0 eq and X { /sheetside 1 def } X { printpage } X ifelse X } bind def X X% Function sheetnumber: prints the sheet number. X/sheetnumber X { sheetnumberx sheetnumbery moveto X datefont setfont X sheet pnum cvs X dup stringwidth pop (0) stringwidth pop sub neg 0 rmoveto show X empty pnum copy pop X } bind def X X% Function s: print a source line X/s { gsave X show X grestore X 0 bodyfontsize neg rmoveto X } bind def END_OF_FILE if test 8096 -ne `wc -c <'header.ps'`; then echo shar: \"'header.ps'\" unpacked with wrong size! fi # end of 'header.ps' fi echo shar: End of shell archive. exit 0 -- Miguel SANTANA miguel@imag.fr or miguel@imag.UUCP (uunet.uu.net!imag!miguel)