Debian Codegraph @

texk/xdvipsk/dosection.c

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