1 | #ifndef lint |
---|
2 | #define _NOTICE static char |
---|
3 | _NOTICE N1[] = "Copyright (c) 1985,1987 Adobe Systems Incorporated"; |
---|
4 | _NOTICE N2[] = "GOVERNMENT END USERS: See Notice file in TranScript library directory"; |
---|
5 | _NOTICE N3[] = "-- probably /usr/lib/ps/Notice"; |
---|
6 | _NOTICE RCSID[]="$Header: /afs/dev.mit.edu/source/repository/athena/bin/lpr/pstext.c,v 1.1 1993-10-12 05:20:35 probe Exp $"; |
---|
7 | #endif |
---|
8 | /* pstext.c |
---|
9 | * |
---|
10 | * Copyright (C) 1985,1987 Adobe Systems Incorporated. All rights reserved. |
---|
11 | * GOVERNMENT END USERS: See Notice file in TranScript library directory |
---|
12 | * -- probably /usr/lib/ps/Notice |
---|
13 | * |
---|
14 | * ultra-simple text formatter for PostScript |
---|
15 | * |
---|
16 | * pstext gets called when a text file gets spooled to a |
---|
17 | * PostScript printer. In this case, a text file is a |
---|
18 | * file without the PostScript magic number (%!). |
---|
19 | * |
---|
20 | * In BSD systems, pstext is fork/execed from the spooler |
---|
21 | * communications program, and has an argv like the spooler's. |
---|
22 | * In SYSV systems, pstext is run by the top-level interface |
---|
23 | * shell script, and has more control(?) and different args. |
---|
24 | * |
---|
25 | * If you want nicer listings, use enscript. |
---|
26 | * |
---|
27 | * RCSLOG: |
---|
28 | * $Log: not supported by cvs2svn $ |
---|
29 | * Revision 2.2 87/11/17 16:52:41 byron |
---|
30 | * Release 2.1 |
---|
31 | * |
---|
32 | * Revision 2.1.1.3 87/11/12 13:42:06 byron |
---|
33 | * Changed Government user's notice. |
---|
34 | * |
---|
35 | * Revision 2.1.1.2 87/04/23 10:26:53 byron |
---|
36 | * Copyright notice. |
---|
37 | * |
---|
38 | * Revision 2.1.1.1 86/06/02 10:30:19 shore |
---|
39 | * fixed formfeed processing -- produced incorrect PS files |
---|
40 | * |
---|
41 | * Revision 2.1 85/11/24 11:51:14 shore |
---|
42 | * Product Release 2.0 |
---|
43 | * |
---|
44 | * Revision 1.4 85/11/20 00:55:32 shore |
---|
45 | * Support for System V |
---|
46 | * argv changes to work with both |
---|
47 | * 4.2bsd and Sys V spooler interface |
---|
48 | * |
---|
49 | * Revision 1.3 85/06/16 20:31:19 shore |
---|
50 | * fixed page-break bug |
---|
51 | * |
---|
52 | * Revision 1.2 85/05/14 11:27:46 shore |
---|
53 | * fixed blank page bug |
---|
54 | * |
---|
55 | * |
---|
56 | */ |
---|
57 | |
---|
58 | #include <stdio.h> |
---|
59 | #include <ctype.h> |
---|
60 | #include "transcript.h" |
---|
61 | |
---|
62 | #define MAXWIDTH 132 |
---|
63 | #define MAXLINES 12 |
---|
64 | |
---|
65 | VOID StartPage(); |
---|
66 | |
---|
67 | private char buf[MAXLINES][MAXWIDTH];/* MAXLINE lines of MAXWIDTH chars */ |
---|
68 | private int maxcol[MAXLINES] = {-1};/* max col used in each lines */ |
---|
69 | |
---|
70 | private int width = 132; |
---|
71 | private int length = 66; |
---|
72 | private int indent = 0; |
---|
73 | private int controls; |
---|
74 | private char *prog; |
---|
75 | |
---|
76 | main(argc, argv) |
---|
77 | int argc; |
---|
78 | char **argv; |
---|
79 | { |
---|
80 | register char *cp; |
---|
81 | register int ch = 0; |
---|
82 | int lineno = 0; |
---|
83 | int npages = 1; |
---|
84 | int blanklines = 0; |
---|
85 | int donepage = 0; |
---|
86 | int done, linedone, maxline, i, col; |
---|
87 | int prevch; |
---|
88 | char tempfile[512]; |
---|
89 | char *l, *libdir; |
---|
90 | |
---|
91 | prog = *argv; |
---|
92 | |
---|
93 | /* initialize line buffer to blanks */ |
---|
94 | done = 0; |
---|
95 | for (cp = buf[0], l = buf[MAXLINES]; cp < l; *cp++ = ' '); |
---|
96 | |
---|
97 | /* put out header */ |
---|
98 | if ((libdir = envget("PSLIBDIR")) == NULL) libdir = LibDir; |
---|
99 | if (copyfile(mstrcat(tempfile,libdir,TEXTPRO,sizeof tempfile), stdout)) { |
---|
100 | fprintf(stderr,"%s: trouble copying text prolog\n",prog); |
---|
101 | exit(2); |
---|
102 | } |
---|
103 | while (!done) { |
---|
104 | col = indent; |
---|
105 | maxline = -1; |
---|
106 | linedone = 0; |
---|
107 | while (!linedone) { |
---|
108 | prevch = ch; |
---|
109 | switch (ch = getchar()) { |
---|
110 | case EOF: |
---|
111 | linedone = done = 1; |
---|
112 | break; |
---|
113 | case '\f': |
---|
114 | if ((lineno == 0) && (prevch == '\f')) { |
---|
115 | StartPage(npages); |
---|
116 | donepage = 1; |
---|
117 | } |
---|
118 | lineno = length; |
---|
119 | linedone = 1; |
---|
120 | break; |
---|
121 | case '\n': |
---|
122 | linedone = 1; |
---|
123 | break; |
---|
124 | case '\b': |
---|
125 | if (--col < indent) col = indent; |
---|
126 | break; |
---|
127 | case '\r': |
---|
128 | col = indent; |
---|
129 | break; |
---|
130 | case '\t': |
---|
131 | col = ((col - indent) | 07) + indent + 1; |
---|
132 | break; |
---|
133 | |
---|
134 | default: |
---|
135 | if ((col >= width) || |
---|
136 | (!controls && (!isascii(ch) || !isprint(ch)))) { |
---|
137 | col++; |
---|
138 | break; |
---|
139 | } |
---|
140 | for (i = 0; i < MAXLINES; i++) { |
---|
141 | if (i > maxline) maxline = i; |
---|
142 | cp = &buf[i][col]; |
---|
143 | if (*cp == ' ') { |
---|
144 | *cp = ch; |
---|
145 | if (col > maxcol[i]) |
---|
146 | maxcol[i] = col; |
---|
147 | break; |
---|
148 | } |
---|
149 | } |
---|
150 | col++; |
---|
151 | break; |
---|
152 | } |
---|
153 | } |
---|
154 | /* print out lines */ |
---|
155 | if (maxline == -1) { |
---|
156 | blanklines++; |
---|
157 | } |
---|
158 | else { |
---|
159 | if (blanklines) { |
---|
160 | if (!donepage) { |
---|
161 | StartPage(npages); |
---|
162 | donepage = 1; |
---|
163 | } |
---|
164 | if (blanklines == 1) { |
---|
165 | printf("B\n"); |
---|
166 | } |
---|
167 | else { |
---|
168 | printf("%d L\n", blanklines); |
---|
169 | } |
---|
170 | blanklines = 0; |
---|
171 | } |
---|
172 | for (i = 0; i <= maxline; i++) { |
---|
173 | if (!donepage) { |
---|
174 | StartPage(npages); |
---|
175 | donepage = 1; |
---|
176 | } |
---|
177 | putchar('('); |
---|
178 | for (cp = buf[i], l = cp+maxcol[i]; cp <= l;) { |
---|
179 | switch (*cp) { |
---|
180 | case '(': case ')': case '\\': |
---|
181 | putchar('\\'); |
---|
182 | default: |
---|
183 | putchar(*cp); |
---|
184 | *cp++ = ' '; |
---|
185 | } |
---|
186 | } |
---|
187 | printf(")%s\n", (i < maxline) ? "" : "S"); |
---|
188 | maxcol[i] = -1; |
---|
189 | } |
---|
190 | } |
---|
191 | if (++lineno >= length) { |
---|
192 | if (donepage) { |
---|
193 | npages++; |
---|
194 | printf("EndPage\n"); |
---|
195 | donepage = 0; |
---|
196 | } |
---|
197 | lineno = 0; |
---|
198 | blanklines = 0; |
---|
199 | } |
---|
200 | } |
---|
201 | if (lineno && donepage) { |
---|
202 | printf("EndPage\n"); |
---|
203 | donepage = 0; |
---|
204 | npages++; |
---|
205 | } |
---|
206 | printf("%%%%Trailer\n"); |
---|
207 | VOIDC fclose(stdout); |
---|
208 | exit(0); |
---|
209 | } |
---|
210 | |
---|
211 | VOID StartPage(n) int n; |
---|
212 | { |
---|
213 | printf("%%%%Page: %d %d\nStartPage\n",n,n); |
---|
214 | } |
---|