- Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathdospecial.c
executable file
·689 lines (643 loc) · 18.9 KB
/
dospecial.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
Date: Thu, 4Aug199417:23:12-0400 (EDT)
From: GOLDEN@huhept.harvard.edu
To: ginsparg@qfwfq.lanl.gov
Cc: GOLDEN@huhept.harvard.edu
Subject: P.S.
Ifyoupostthatonxxx, besuretotellpeoplethatthenewversionofdvips
maynotworkwiththeoldversion (asof5.491) oftex.pro. (Ifoundoutthe
hardwaythattheoldversionofdvipsdoesn'tworkwiththenewtex.pro.)
Theyreallyshoulddoafullinstall.
-------------------------------------------------------
From: HUHEPL::GOLDEN3-AUG-199417:41:35.70
To: SMTP%"rokicki@cs.stanford.edu"
CC: GOLDEN
Subj: htmlspecialsindvips
Ihavemadeamodificationtodospecial.cindvipssothatitnowignoresthe
"html:"special. Thisisanew \specialcommandthatisusedtocreate
hypertextlinksinTeXdocuments. Thepresentversion, 5.55orearlier,
produceerrorswhensuchspecialscomeup. Iwouldlikethistobeincludedin
anewversionofdvips.
Thefilebelowisthemodifiedversion.
-MitchGolden
golden@physics.harvard.edu
----------------------------------------------------------------------------
/*
* This routine handles special commands;
* predospecial() is for the prescan, dospecial() for the real thing.
*/
#include"dvips.h"/* The copyright notice in that file is included too! */
#include<ctype.h>
externintatoi();
externvoidfil2ps();
externFILE*search();
externintsystem();
/*
* These are the external routines called:
*/
/**/
#ifdefTPIC
/*
* Fri Mar 9 1990 jourdan@minos.inria.fr (MJ)
* Upgraded to accommodate tpic release 2.0 extended output language.
* Should prove upward compatible!
*/
/*
* Wed Aug 3 1994 golden@physics.harvard.edu (MG)
* Now ignores html: specials, for use with hypertex files
*/
externvoidsetPenSize();
externvoidflushPath();
externvoidflushDashed();
externvoidflushDashed();
externvoidaddPath();
externvoidarc();
externvoidflushSpline();
externvoidshadeLast();
externvoidwhitenLast();
externvoidblackenLast();
externvoidSetShade() ;
#endif
externshalfworddvibyte() ;
externintadd_header() ;
externvoidhvpos() ;
externvoidfigcopyfile() ;
externvoidnlcmdout() ;
externvoidcmdout() ;
externvoidnumout() ;
externvoidscout() ;
externvoidstringend() ;
externvoiderror() ;
externvoidpsflush() ;
externvoidemspecial() ;
/* IBM: color - begin */
externvoidpushcolor() ;
externvoidpopcolor() ;
externvoidresetcolorstack() ;
externvoidbackground() ;
/* IBM: color - end */
externcharerrbuf[] ;
externshalfwordlinepos;
externBooleanusesspecial ;
externBooleanusescolor ; /* IBM: color */
externintlandscape ;
externchar*paperfmt ;
externchar*nextstring;
externchar*maxstring;
externchar*oname;
externFILE*bitfile;
externintquiet;
externfontdesctype*curfnt ;
externintactualdpi ;
externintvactualdpi ;
externintegerhh, vv;
externintlastfont ;
externrealconv ;
externrealvconv ;
externintegerhpapersize, vpapersize ;
externBooleanpprescan ;
externchar*figpath ;
externintprettycolumn ;
externBooleandisablecomments ;
#ifdefDEBUG
externintegerdebug_flag;
#endif
externvoidscanfontcomments() ;
externvoidhandlepapersize() ;
staticintspecialerrors=20 ;
structbangspecial {
structbangspecial*next ;
charactualstuff[1] ; /* more space will actually be allocated */
} *bangspecials=NULL ;
voidspecerror(s)
char*s ;
{
if (specialerrors>0) {
error(s) ;
specialerrors-- ;
} elseif (specialerrors==0) {
error("more errors in special, being ignored . . .") ;
specialerrors-- ;
}
}
staticvoidtrytobreakout(p)
register char*p ;
{
register inti ;
register intinstring=0 ;
intlastc=0 ;
i=0 ;
(void)putc('\n', bitfile) ;
while (*p) {
if (i>65&&*p==' '&&instring==0) {
(void)putc('\n', bitfile) ;
i=0 ;
} else {
(void)putc(*p, bitfile) ;
i++ ;
}
if (*p=='('&&lastc!='\\')
instring=1 ;
elseif (*p==')'&&lastc!='\\')
instring=0 ;
lastc=*p ;
p++ ;
}
(void)putc('\n', bitfile) ;
}
staticvoiddobs(q)
register structbangspecial*q ;
{
if (q) {
dobs(q->next) ;
trytobreakout(q->actualstuff) ;
}
}
void
outbangspecials() {
if (bangspecials) {
cmdout("TeXDict") ;
cmdout("begin") ;
cmdout("@defspecial\n") ;
dobs(bangspecials) ;
cmdout("\n@fedspecial") ;
cmdout("end") ;
}
}
/* We recommend that new specials be handled by the following general
* (and extensible) scheme, in which the user specifies one or more
* `key=value' pairs separated by spaces.
* The known keys are given in KeyTab; they take values
* of one of the following types:
*
* None: no value, just a keyword (in which case the = sign is omitted)
* String: the value should be "<string without double-quotes"
* or '<string without single-quotes'
* Integer: the value should be a decimal integer (%d format)
* Number: the value should be a decimal integer or real (%f format)
* Dimension: like Number, but will be multiplied by the scaledsize
* of the current font and converted to default PostScript units
* (Actually, strings are allowed in all cases; the delimiting quotes
* are simply stripped off if present.)
*
*/
typedefenum {None, String, Integer, Number, Dimension} ValTyp;
typedefstruct {
char*Entry;
ValTypType;
} KeyDesc;
#defineNKEYS (sizeof(KeyTab)/sizeof(KeyTab[0]))
KeyDescKeyTab[] = {{"psfile", String}, /* j==0 in the routine below */
{"ifffile", String}, /* j==1 */
{"tekfile", String}, /* j==2 */
{"hsize", Number},
{"vsize", Number},
{"hoffset", Number},
{"voffset", Number},
{"hscale", Number},
{"vscale", Number},
{"angle", Number},
{"llx", Number},
{"lly", Number},
{"urx", Number},
{"ury", Number},
{"rwi", Number},
{"rhi", Number},
{"clip", None}};
#ifdefVMS
#ifndef__GNUC__/* GNUC tolower is too simple */
#defineTolower tolower
#endif
#else
#ifdefVMCMS/* IBM: VM/CMS */
#defineTolower __tolower
#else
#ifdefMVSXA/* IBM: MVS/XA */
#defineTolower __tolower
#else
/*
* compare strings, ignore case
*/
charTolower(c)
register charc ;
{
if ('A' <= c&&c <= 'Z')
return(c+32) ;
else
return(c) ;
}
#endif
#endif/* IBM: VM/CMS */
#endif
intIsSame(a, b)
char*a, *b;
{
for( ; *a!='\0'; ) {
if( Tolower(*a) !=Tolower(*b) )
return( 0 );
a++ ;
b++ ;
}
return( *b=='\0' );
}
char*KeyStr, *ValStr ; /* Key and String values found */
longValInt ; /* Integer value found */
floatValNum ; /* Number or Dimension value found */
char*GetKeyVal(str,tno) /* returns NULL if none found, else next scan point */
char*str ; /* starting point for scan */
int*tno ; /* table entry number of keyword, or -1 if keyword not found */
{
register char*s ;
register inti ;
register chart ;
for (s=str; *s <= ' '&&*s; s++) ; /* skip over blanks */
if (*s=='\0')
return (NULL) ;
KeyStr=s ;
while (*s>' '&&*s!='=') s++ ;
if (0!= (t=*s))
*s++=0 ;
for(i=0; i<NKEYS; i++)
if( IsSame(KeyStr, KeyTab[i].Entry) )
goto found ;
*tno=-1;
return (s) ;
found: *tno=i ;
if (KeyTab[i].Type==None)
return (s) ;
if (t&&t <= ' ') {
for (; *s <= ' '&&*s; s++) ; /* now look for the value part */
if ((t=*s)=='=')
s++ ;
}
ValStr="" ;
if ( t=='=' ) {
while (*s <= ' '&&*s)
s++ ;
if (*s=='\''||*s=='\"')
t=*s++ ; /* get string delimiter */
elset=' ' ;
ValStr=s ;
while (*s!=t&&*s)
s++ ;
if (*s)
*s++=0 ;
}
switch (KeyTab[i].Type) {
caseInteger:
if(sscanf(ValStr,"%ld",&ValInt)!=1) {
sprintf(errbuf,"Non-integer value (%s) given for keyword %s",
ValStr, KeyStr) ;
specerror(errbuf) ;
ValInt=0 ;
}
break ;
caseNumber:
caseDimension:
if(sscanf(ValStr,"%f",&ValNum)!=1) {
sprintf(errbuf,"Non-numeric value (%s) given for keyword %s",
ValStr, KeyStr) ;
specerror(errbuf) ;
ValNum=0.0 ;
}
if (KeyTab[i].Type==Dimension) {
if (curfnt==NULL)
error("! No font selected") ;
ValNum=ValNum* ((double)curfnt->scaledsize) *conv*72 / DPI ;
}
break ;
default: break ;
}
return (s) ;
}
/*
* Now our routines. We get the number of bytes specified and place them
* into the string buffer, and then parse it. Numerous conventions are
* supported here for historical reasons.
*/
voidpredospecial(numbytes, scanning)
integernumbytes ;
Booleanscanning ;
{
register char*p=nextstring ;
register inti=0 ;
intj ;
if (nextstring+numbytes>maxstring)
error("! out of string space in predospecial") ;
for (i=numbytes; i>0; i--)
#ifdefVMCMS/* IBM: VM/CMS */
*p++=ascii2ebcdic[(char)dvibyte()] ;
#else
#ifdefMVSXA/* IBM: MVS/XA */
*p++=ascii2ebcdic[(char)dvibyte()] ;
#else
*p++= (char)dvibyte() ;
#endif/* IBM: VM/CMS */
#endif
if (pprescan)
return ;
while (p[-1] <= ' '&&p>nextstring)
p-- ; /* trim trailing blanks */
if (p==nextstring) return ; /* all blank is no-op */
*p=0 ;
p=nextstring ;
while (*p <= ' ')
p++ ;
#ifdefDEBUG
if (dd(D_SPECIAL))
(void)fprintf(stderr, "Preprocessing special: %s\n", p) ;
#endif
/*
* We use strncmp() here to also pass things like landscape()
* or landscape: or such.
*/
if (strncmp(p, "landscape", 9)==0) {
if (hpapersize||vpapersize)
error(
"both landscape and papersize specified: ignoring landscape") ;
else
landscape=1 ;
return ;
} elseif (strncmp(p, "papersize", 9)==0) {
p+=9 ;
while (*p=='='||*p==' ')
p++ ;
if (hpapersize==0||vpapersize==0) {
if (landscape) {
error(
"both landscape and papersize specified: ignoring landscape") ;
landscape=0 ;
}
handlepapersize(p, &hpapersize, &vpapersize) ;
}
return ;
}
if (strncmp(p, "xtex:", 5)==0) return ;
/* Don't do anything with html specials - MG 8/3/94 */
if (strncmp(p, "html:", 5)==0) return ;
usesspecial=1 ; /* now the special prolog will be sent */
if (strncmp(p, "header", 6)==0) {
char*q ;
p+=6 ;
while ((*p <= ' '||*p=='='||*p=='(') &&*p!=0)
p++ ;
q=p ; /* we will remove enclosing parentheses */
p=p+strlen(p) -1 ;
while ((*p <= ' '||*p==')') &&p >= q)
p-- ;
p[1] =0 ;
if (p >= q)
(void)add_header(q) ;
}
/* IBM: color - added section here for color header and color history */
if (strncmp(p, "background", 10) ==0) {
usescolor=1 ;
p+=11 ;
while ( *p <= ' ' ) p++ ;
background(p) ;
}
if (strncmp(p, "color", 5) ==0) {
usescolor=1 ;
p+=6 ;
while ( *p <= ' ' ) p++ ;
if (strncmp(p, "push", 4) ==0 ) {
p+=5 ;
while ( *p <= ' ' ) p++ ;
pushcolor(p, 0) ;
} elseif (strncmp(p, "pop", 3) ==0 ) {
popcolor(0) ;
} else {
resetcolorstack(p,0) ;
}
} /* IBM: color - end changes */
elseif (*p=='!') {
register structbangspecial*q ;
p++ ;
q= (structbangspecial*)mymalloc((integer)
(sizeof(structbangspecial) +strlen(p))) ;
(void)strcpy(q->actualstuff, p) ;
q->next=bangspecials ;
bangspecials=q ;
} elseif (scanning&&*p!='"'&&
(p=GetKeyVal(p, &j)) !=NULL&&j==0)
scanfontcomments(ValStr) ;
}
intmaccess(s)
char*s ;
{
FILE*f=search(figpath, s, "r") ;
if (f)
fclose(f) ;
return (f!=0) ;
}
char*tasks[] = { 0, "iff2ps", "tek2ps" } ;
staticcharpsfile[511] ;
voiddospecial(numbytes)
integernumbytes ;
{
register char*p=nextstring ;
register inti=0 ;
intj, systemtype=0 ;
register char*q ;
Booleanpsfilewanted=1 ;
char*task=0 ;
charcmdbuf[111] ;
if (nextstring+i>maxstring)
error("! out of string space in dospecial") ;
for (i=numbytes; i>0; i--)
#ifdefVMCMS/* IBM: VM/CMS */
*p++=ascii2ebcdic[(char)dvibyte()] ;
#else
#ifdefMVSXA/* IBM: MVS/XA */
*p++=ascii2ebcdic[(char)dvibyte()] ;
#else
*p++= (char)dvibyte() ;
#endif/* IBM: VM/CMS */
#endif
while (p[-1] <= ' '&&p>nextstring)
p-- ; /* trim trailing blanks */
if (p==nextstring) return ; /* all blank is no-op */
*p=0 ;
p=nextstring ;
while (*p <= ' ')
p++ ;
#ifdefDEBUG
if (dd(D_SPECIAL))
(void)fprintf(stderr, "Processing special: %s\n", p) ;
#endif
if (strncmp(p, "em:", 3)==0) { /* emTeX specials in emspecial.c */
emspecial(p);
return;
}
if (strncmp(p, "ps:", 3)==0) {
psflush() ; /* now anything can happen. */
if (p[3]==':') {
if (strncmp(p+4, "[begin]", 7) ==0) {
hvpos() ;
trytobreakout(&p[11]);
} elseif (strncmp(p+4, "[end]", 5) ==0)
trytobreakout(&p[9]);
elsetrytobreakout(&p[4]);
} elseif (strncmp(p+3, " plotfile ", 10) ==0) {
char*sfp ;
hvpos() ;
p+=13;
/*
* Fixed to allow popen input for plotfile
* TJD 10/20/91
*/
while (*p==' ') p++;
if (*p=='"') {
p++;
for (sfp=p; *sfp&&*sfp!='"'; sfp++) ;
} else {
for (sfp=p; *sfp&&*sfp!=' '; sfp++) ;
}
*sfp='\0';
if (*p=='`')
figcopyfile(p+1, 1);
else
figcopyfile (p, 0);
/* End TJD changes */
} else {
hvpos() ;
trytobreakout(&p[3]);
psflush() ;
hvpos() ;
}
return;
}
if (strncmp(p, "landscape", 9)==0||strncmp(p, "header", 6)==0||
strncmp(p, "html:", 5)==0||/* Ignore! - MG 8/3/94 */
strncmp(p, "papersize", 9)==0||*p=='!')
return ; /* already handled in prescan */
/* IBM: color - begin changes */
if ( strncmp(p, "background", 10) ==0 )
return ; /* already handled in prescan */
if (strncmp(p, "color", 5) ==0) {
p+=6 ;
while ( *p <= ' ' ) p++ ;
if (strncmp(p, "push", 4) ==0 ) {
p+=4 ;
while ( *p <= ' ' ) p++ ;
pushcolor(p,1);
} elseif (strncmp(p, "pop", 3) ==0 ) {
popcolor(1) ;
} else {
resetcolorstack(p,1) ;
}
return ;
} /* IBM: color - end changes*/
#ifdefTPIC
/* ordered as in tpic 2.0 documentation for ease of cross-referencing */
if (strncmp(p, "pn ", 3) ==0) {setPenSize(p+2); return;}
if (strncmp(p, "pa ", 3) ==0) {addPath(p+2); return;}
if (strcmp(p, "fp") ==0) {flushPath(0); return;}
if (strcmp(p, "ip") ==0) {flushPath(1); return;} /* tpic 2.0 */
if (strncmp(p, "da ", 3) ==0) {flushDashed(p+2, 0); return;}
if (strncmp(p, "dt ", 3) ==0) {flushDashed(p+2, 1); return;}
if (strcmp(p, "sp") ==0) {flushSpline(p+2); return;} /* tpic 2.0 */
if (strncmp(p, "sp ", 3) ==0) {flushSpline(p+3); return;} /* tpic 2.0 */
if (strncmp(p, "ar ", 3) ==0) {arc(p+2, 0); return;} /* tpic 2.0 */
if (strncmp(p, "ia ", 3) ==0) {arc(p+2, 1); return;} /* tpic 2.0 */
if (strcmp(p, "sh") ==0) {shadeLast(p+2); return;} /* tpic 2.0 */
if (strncmp(p, "sh ", 3) ==0) {shadeLast(p+3); return;} /* tpic 2.0 */
if (strcmp(p, "wh") ==0) {whitenLast(); return;}
if (strcmp(p, "bk") ==0) {blackenLast(); return;}
if (strncmp(p, "tx ", 3) ==0) {SetShade(p+3); return;}
#endif
if (*p=='"') {
hvpos() ;
cmdout("@beginspecial") ;
cmdout("@setspecial") ;
trytobreakout(p+1) ;
cmdout("\n@endspecial") ;
return ;
}
/* At last we get to the key/value conventions */
psfile[0] ='\0';
hvpos();
cmdout("@beginspecial");
while( (p=GetKeyVal(p,&j)) !=NULL )
switch (j) {
case-1: /* for compatability with old conventions, we allow a file name
* to be given without the 'psfile=' keyword */
if (!psfile[0] &&maccess(KeyStr)==0) /* yes we can read it */
(void)strcpy(psfile,KeyStr) ;
else {
sprintf(errbuf, "Unknown keyword (%s) in \\special will be ignored",
KeyStr) ;
specerror(errbuf) ;
}
break ;
case0: case1: case2: /* psfile */
if (psfile[0]) {
sprintf(errbuf, "More than one \\special %s given; %s ignored",
"psfile", ValStr) ;
specerror(errbuf) ;
}
else (void)strcpy(psfile,ValStr) ;
task=tasks[j] ;
break ;
default: /* most keywords are output as PostScript procedure calls */
if (KeyTab[j].Type==Integer)
numout((integer)ValInt);
elseif (KeyTab[j].Type==String)
for (q=ValStr; *q; q++)
scout(*q) ;
elseif (KeyTab[j].Type==None) ;
else { /* Number or Dimension */
ValInt= (integer)(ValNum<0? ValNum-0.5 : ValNum+0.5) ;
if (ValInt-ValNum<0.001&&ValInt-ValNum>-0.001)
numout((integer)ValInt) ;
else {
(void)sprintf(cmdbuf, "%f", ValNum) ;
cmdout(cmdbuf) ;
}
}
(void)sprintf(cmdbuf, "@%s", KeyStr);
cmdout(cmdbuf) ;
}
cmdout("@setspecial");
if(psfile[0]) {
if (task==0) {
systemtype= (psfile[0]=='`') ;
figcopyfile(psfile+systemtype, systemtype);
} else {
fil2ps(task, psfile) ;
}
} elseif (psfilewanted)
specerror("No \\special psfile was given; figure will be blank") ;
cmdout("@endspecial");
}
externcharrealnameoffile[] ;
externchar*pictpath ;
voidfil2ps(task, iname)
char*task, *iname ;
{
charcmd[400] ;
FILE*f ;
if (0!= (f=search(pictpath, iname, "r"))) {
fclose(f) ;
} else {
fprintf(stderr, " couldn't open %s\n", iname) ;
return ;
}
if (!quiet) {
fprintf(stderr, " [%s", realnameoffile) ;
fflush(stderr) ;
}
if (oname&&oname[0] &&oname[0] !='-') {
putc(10, bitfile) ;
fclose(bitfile) ;
sprintf(cmd, "%s -f %s %s", task, realnameoffile, oname) ;
system(cmd) ;
if ((bitfile=fopen(oname, "a"))==NULL)
error("! couldn't reopen PostScript file") ;
linepos=0 ;
} else {
sprintf(cmd, "%s -f %s", task, realnameoffile) ;
system(cmd) ;
}
if (!quiet)
fprintf(stderr, "]") ;
}