Debian Codegraph @

texk/dvipsk/dosection.c

raw
1 /*
2 * Code to output PostScript commands for one section of the document.
3 */
4 #include "dvips.h" /* The copyright notice in that file is included too! */
5 /*
6 * The external declarations:
7 */
8 #include "protos.h"
9
10 static int psfont;
11 #ifdef HPS
12 int pagecounter;
13 #endif
14
15 /*
16 * Now we have the main procedure.
17 */
18 void
19 dosection(sectiontype *s, int c)
20 {
21 charusetype *cu;
22 integer prevptr;
23 int np;
24 int k;
25 integer thispage = 0;
26 char buf[300]; /* really 253 */
27
28 bmenc_startsection() ;
29 dopsfont(s);
30 #ifdef HPS
31 if (HPS_FLAG) pagecounter = 0;
32 #endif
33
34 if (multiplesects) {
35 setup();
36 }
37 cmdout("TeXDict");
38 cmdout("begin");
39 numout(hpapersize);
40 numout(vpapersize);
41 doubleout(mag);
42 numout((integer)DPI);
43 numout((integer)VDPI);
44 /* possibly lines in eps files are supposed to be <= 255;
45 not worth testing the limits merely to output a long file name. */
46 snprintf(buf, sizeof(buf), "(%.250s)", fulliname);
47 cmdout(buf);
48 newline();
49 cmdout("@start");
50 if (multiplesects)
51 cmdout("bos");
52 /*
53 * We insure raster is even-word aligned, because download might want that.
54 */
55 if (bytesleft & 1) {
56 bytesleft--;
57 raster++;
58 }
59 cleanres();
60 cu = (charusetype *) (s + 1);
61 psfont = 1;
62 while (cu->fd) {
63 if (cu->psfused)
64 cu->fd->psflag = EXISTS;
65 download(cu++, psfont++);
66 }
67 fonttableout();
68 if (! multiplesects) {
69 cmdout("end");
70 setup();
71 }
72 for (cu=(charusetype *)(s+1); cu->fd; cu++)
73 cu->fd->psflag = 0;
74 while (c > 0) {
75 c--;
76 prevptr = s->bos;
77 if (! reverse)
78 fseek(dvifile, (long)prevptr, 0);
79 np = s->numpages;
80 while (np-- != 0) {
81 if (reverse)
82 fseek(dvifile, (long)prevptr, 0);
83 pagenum = signedquad();
84 if ((evenpages && (pagenum & 1)) || (oddpages && (pagenum & 1)==0) ||
85 (pagelist && !InPageList(pagenum))) {
86 if (reverse) {
87 skipover(36);
88 prevptr = signedquad()+1;
89 } else {
90 skipover(40);
91 skippage();
92 skipnop();
93 }
94 ++np; /* this page wasn't counted for s->numpages */
95 continue;
96 }
97 /*
98 * We want to take the base 10 log of the number. It's probably
99 * small, so we do it quick.
100 */
101 if (! quiet) {
102 int t = pagenum, i = 0;
103 if (t < 0) {
104 t = -t;
105 i++;
106 }
107 do {
108 i++;
109 t /= 10;
110 } while (t > 0);
111 if (pagecopies < 20)
112 i += pagecopies - 1;
113 if (i + prettycolumn > STDOUTSIZE) {
114 fprintf(stderr, "\n");
115 prettycolumn = 0;
116 }
117 prettycolumn += i + 1;
118 #ifdef SHORTINT
119 fprintf(stderr, "[%ld", pagenum);
120 #else /* ~SHORTINT */
121 fprintf(stderr, "[%d", pagenum);
122 #endif /* ~SHORTINT */
123 fflush(stderr);
124 }
125 skipover(36);
126 prevptr = signedquad()+1;
127 for (k=0; k<pagecopies; k++) {
128 if (k == 0) {
129 if (pagecopies > 1)
130 thispage = ftell(dvifile);
131 } else {
132 fseek(dvifile, (long)thispage, 0);
133 if (prettycolumn + 1 > STDOUTSIZE) {
134 fprintf(stderr, "\n");
135 prettycolumn = 0;
136 }
137 fprintf(stderr, ".");
138 fflush(stderr);
139 prettycolumn++;
140 }
141 dopage();
142 }
143 if (! quiet) {
144 fprintf(stderr, "] ");
145 fflush(stderr);
146 prettycolumn += 2;
147 }
148 if (! reverse)
149 skipnop();
150 }
151 }
152 if (! multiplesects && ! disablecomments) {
153 newline();
154 fprintf(bitfile, "%%%%Trailer\n");
155 }
156 if (multiplesects) {
157 if (! disablecomments) {
158 newline();
159 fprintf(bitfile, "%%DVIPSSectionTrailer\n");
160 }
161 cmdout("eos");
162 cmdout("end");
163 }
164 #ifdef HPS
165 if (HPS_FLAG) cmdout("\nend"); /* close off HPSDict */
166 #endif
167 if (multiplesects && ! disablecomments) {
168 newline();
169 fprintf(bitfile, "%%DVIPSEndSection\n");
170 linepos = 0;
171 }
172 }
173 /*
174 * Handle a list of pages for dvips. Code based on dvi2ps 2.49,
175 * maintained by Piet van Oostrum, [email protected]. Collected and
176 * modularized for inclusion in dvips by [email protected].
177 */
178
179 #include <ctype.h>
180 #define MAXPAGE (1000000000) /* assume no pages out of this range */
181 struct p_list_str {
182 struct p_list_str *next; /* next in a series of alternates */
183 integer ps_low, ps_high; /* allowed range */
184 } *ppages = 0; /* the list of allowed pages */
185
186 /*-->InPageList*/
187 /**********************************************************************/
188 /****************************** InPageList **************************/
189 /**********************************************************************/
190 /* Return true iff i is one of the desired output pages */
191
192 int
193 InPageList(integer i)
194 {
195 register struct p_list_str *pl = ppages;
196
197 while (pl) {
198 if ( i >= pl -> ps_low && i <= pl -> ps_high)
199 return 1; /* success */
200 pl = pl -> next;
201 }
202 return 0;
203 }
204
205 static void
206 InstallPL(integer pslow, integer pshigh)
207 {
208 register struct p_list_str *pl;
209
210 pl = (struct p_list_str *)mymalloc((integer)(sizeof *pl));
211 pl -> next = ppages;
212 pl -> ps_low = pslow;
213 pl -> ps_high = pshigh;
214 ppages = pl;
215 }
216
217 /* Parse a string representing a list of pages. Return 0 iff ok. As a
218 side effect, the page selection(s) is (are) prepended to ppages. */
219
220 int
221 ParsePages(register char *s)
222 {
223 register int c; /* current character */
224 register integer n = 0, /* current numeric value */
225 innumber; /* true => gathering a number */
226 integer ps_low = 0, ps_high = 0;
227 int range, /* true => saw a range indicator */
228 negative = 0; /* true => number being built is negative */
229
230 #define white(x) ((x) == ' ' || (x) == '\t' || (x) == ',')
231
232 range = 0;
233 innumber = 0;
234 for (;;) {
235 c = *s++;
236 if ( !innumber && !range) {/* nothing special going on */
237 if (c == 0)
238 return 0;
239 if (white (c))
240 continue;
241 }
242 if (c == '-' && !innumber) {
243 innumber++;
244 negative++;
245 n = 0;
246 continue;
247 }
248 if ('0' <= c && c <= '9') { /* accumulate numeric value */
249 if (!innumber) {
250 innumber++;
251 negative = 0;
252 n = c - '0';
253 continue;
254 }
255 n *= 10;
256 n += negative ? '0' - c : c - '0';
257 continue;
258 }
259 if (c == '-' || c == ':') {/* here's a range */
260 if (range)
261 return (-1);
262 if (innumber) { /* have a lower bound */
263 ps_low = n;
264 }
265 else
266 ps_low = -MAXPAGE;
267 range++;
268 innumber = 0;
269 continue;
270 }
271 if (c == 0 || white (c)) {/* end of this range */
272 if (!innumber) { /* no upper bound */
273 ps_high = MAXPAGE;
274 if (!range) /* no lower bound either */
275 ps_low = -MAXPAGE;
276 }
277 else { /* have an upper bound */
278 ps_high = n;
279 if (!range) { /* no range => lower bound == upper */
280 ps_low = ps_high;
281 }
282 }
283 InstallPL (ps_low, ps_high);
284 if (c == 0)
285 return 0;
286 range = 0;
287 innumber = 0;
288 continue;
289 }
290 return (-1);
291 }
292 #undef white
293 }