/
dpost.c
1931 lines (1513 loc) · 45.7 KB
/
dpost.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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* dpost - troff post-processor for PostScript printers.
*
* A program that translates output generated by the device independent troff
* into PostScript. Much was borrowed from dimpress and dps (formally dlzw),
* and even though the code has changed, credit has to be given to Richard
* Flood for his early work on the PostScript driver.
*
* The big change is in the font table routines. The old binary format and
* makedev are gone. dpost and troff now read ASCII tables, and both skip
* unrecognized entries in the ASCII tables. That means problems, like where
* to put the real name of the PostScript font, have disappeared. The added
* flexibility means some overhead translating the ASCII tables, but the
* overhead isn't too bad.
*
* dpost can also now calculate a reasonably tight BoundingBox, which helps
* picture inclusion. The calculations, by default, are disabled. Couldn't
* justify the overhead for a comment, particularly one that's only needed
* occasionally. Use the -B option to get the comment.
*
* Output produced by dpost is still nonconforming. Definitions made in pages
* and exported to the job's global environment are the primary problem. It's
* an efficient approach, but means pages are not independent. Violations are
* bracketed by %%BeginGlobal and %%EndGlobal comments and can be pulled into
* the prologue by utility programs (like postreverse) that recognize the new
* comments.
*
* The program handles files formatted for any device, although the best and
* most efficient output is generated when the font and description files
* match PostScript's resident fonts. Emulation is relatively expensive, and
* can produce output files that are more than twice the size of the input
* files.
*
* Several different methods can be used to encode lines of text. What's done
* depends on the value assigned to encoding. Print time should decrease as
* encoding increases (up to MAXENCODING). Setting encoding to 3 (or higher)
* is not normally recommended. It's fast and produces very compact output,
* but rounding errors in troff's width tables can accumulate and lead to a
* ragged right margin. encoding can be changed on the command line using the
* -e option.
*
* PostScript fonts don't support all of troff's characters. Some are built
* by special PostScript procedures in directory *fontdir/devpost/charlib.
* The charlib approach is not meant to replace user defined fonts. It was
* a quick implementation designed to handle characters that aren't used
* often - charlib should not be overused! The charlib lookup is triggered
* when a character in a font table is assigned a code less than 32.
*
* Most defaults are set in the prologue, but can be changed by options. The
* -P option passes arbitrary PostScript into the setup section of the output
* file. It can be used to set (or change) values that can't be accessed by
* other options. For example,
*
* dpost -P'/useclippath false def' file > file.ps
*
* defines useclippath to be false. Everything passed through using the -P
* (-C to copy a file) options become part of the job's global environment.
* Definitions override defaults in the prologue.
*
* dpost expects to find the following procedures in the prologue:
*
* setup
*
* mark ... setup -
*
* Initialization procedure mainly responsible for setting up an
* appropriate coordinate system.
*
* pagesetup
*
* page pagesetup -
*
* Called at the start of each page, immediately after the page
* level save. Argument is the current page number.
*
* setdecoding
*
* num setdecoding -
*
* Select the decoding procedure used to print text strings encoded
* by dpost. num is whatever has been assigned to encoding.
*
* f
*
* size font f -
*
* Set the font and size used for character imaging. The font name
* argument is (normally) the name troff used. Mapping to the real
* PostScript font name is made using the fontname field in the
* ASCII width tables.
*
* m
*
* x y m -
*
* Move to point (x, y). Not used for positioning words in text
* strings.
*
* t
*
* mark text t mark
*
* Everything on the stack (up to the mark) is treated as a line
* of text to be decoded and printed. What's on the stack depends
* on encoding.
*
* w
*
* string x y w -
*
* Print a single word starting at position (x, y). Only used in
* the more complicated encoding schemes, like the ones based on
* widthshow.
*
* done
*
* Make sure the last page prints. Always called, but only needed
* when printing more than one page on each sheet of paper.
*
* output language from troff:
* all numbers are character strings
*
* sn size in points
* fn font as number from 1-n
* cx ascii character x
* Cxyz funny char xyz. terminated by white space
* Hn go to absolute horizontal position n
* Vn go to absolute vertical position n (down is positive)
* hn go n units horizontally (relative)
* vn ditto vertically
* nnc move right nn, then print c (exactly 2 digits!)
* (this wart is an optimization that shrinks output file size
* about 35% and run-time about 15% while preserving ascii-ness)
* Dt ...\n draw operation 't':
* Dl x y line from here by x,y
* Dc d circle of diameter d with left side here
* De x y ellipse of axes x,y with left side here
* Da x1 y1 x2 y2 arc counter-clockwise from current point (x, y) to
* (x + x1 + x2, y + y1 + y2)
* D~ x y x y ... wiggly line by x,y then x,y ...
* nb a end of line (information only -- no action needed)
* b = space before line, a = after
* p new page begins -- set v to 0
* #...\n comment
* x ...\n device control functions:
* x i init
* x T s name of device is s
* x r n h v resolution is n/inch
* h = min horizontal motion, v = min vert
* x p pause (can restart)
* x s stop -- done forever
* x t generate trailer
* x f n s font position n contains font s
* x H n set character height to n
* x S n set slant to N
*
* Subcommands like "i" are often spelled out like "init".
*
*/
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <math.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#include "comments.h" /* structuring comments */
#include "gen.h" /* general purpose definitions */
#include "path.h" /* prologue and a few other files */
#include "ext.h" /* external variable declarations */
#include "font.h" /* font table definitions */
#include "dpost.h" /* a few definitions just used here */
#include "motion.h" /* positioning macros */
#include "draw.h"
#include "color.h"
#include "pictures.h"
static void init_signals(void);
static void header(void);
static void options(void);
static void setpaths(char *);
static void setup(void);
static void arguments(void);
static void done(void);
static void account(void);
static void conv(FILE *);
static void devcntrl(FILE *);
static void loadfont(int, char *, char *);
static void loadspecial(void);
static void t_init(void);
static void t_page(int);
static int t_font(char *);
static void setfont(int);
static void t_sf(void);
static void t_charht(int);
static void t_slant(int);
static void oput(int);
static void starttext(void);
static void endstring(void);
static void endline(void);
static void addchar(int);
static void addoctal(int);
static void charlib(int);
static void exportstring(char *);
static void redirect(int);
void put1(int c);
char *prologue = DPOST; /* the PostScript prologue */
char *colorfile = COLOR; /* color support */
char *drawfile = DRAW; /* drawing routines */
char *formfile = FORMFILE; /* multiple pages on each sheet */
char *baselinefile = BASELINE; /* for text along curved baseline */
char *fontdir = FONTDIR; /* font table directories */
char *hostfontdir = NULL; /* host resident font directory */
char *realdev = DEVNAME; /* use these width tables */
char dwb_devname[20] = ""; /* job formatted for this device */
Fontmap fontmap[] = FONTMAP; /* font translation table - emulation */
char *useencoding = NULL; /* text font encoding - from -E option */
int copies = 1; /* copies of each sheet */
int printed = 0; /* pages processed and printed */
int formsperpage = 1; /* pages on each sheet of paper */
int picflag = ON; /* enable/disable picture inclusion */
int encoding = DFLTENCODING; /* how text is translated to PostScript */
int realencoding = DFLTENCODING; /* where we started */
int maxencoding = MAXENCODING; /* max that users can select */
int landscape = FALSE; /* for BoundingBox calculations only */
double magnification = 1.0;
double xoffset = 0.0;
double yoffset = 0.0;
int smnt; /* special fonts start here */
int devres; /* device resolution */
int unitwidth; /* and unitwidth - from DESC file */
char downloaded[MAXCH+32+ALPHABET]; /* status of charlib characters */
int nfonts = 0; /* number of font positions */
int size = 10; /* current point size */
int font = 0; /* and font position */
int hpos = 0; /* where troff wants to be */
int vpos = 0;
float lastw = 0; /* width of the last input character */
int lastc = 0; /* its name (or index) - for charlib() */
int fontheight = 0; /* points from x H ... */
int fontslant = 0; /* angle from x S ... */
int res; /* resolution assumed in input file */
float widthfac = 1.0; /* for emulation = res/devres */
int lastsize = -1; /* for tracking printer's current size */
int lastfont = -1; /* current font */
float lastx = -1; /* and current position */
int lasty = -1;
int lastend; /* where last character on this line was */
int seenpage = FALSE; /* expect fonts are now all mounted */
int gotspecial = FALSE; /* append special fonts - emulation */
float pointslop = SLOP; /* horizontal error in points */
int slop; /* and machine units */
int rvslop; /* to extend box in reverse video mode */
int textcount = 0; /* strings accumulated so far */
int stringstart = 0; /* where the next one starts */
int spacecount = 0; /* spaces in current string */
Line line[MAXSTACK+3]; /* data about words accumulated so far */
char strings[STRINGSPACE]; /* strings temporarily saved here */
char *strptr; /* next free slot in strings[] */
FILE *tf = NULL; /* most output goes here */
FILE *fp_acct = NULL; /* accounting file */
char *optnames = "a:c:e:m:n:o:p:tw:x:y:A:BC:E:J:F:H:L:OP:R:S:T:DI";
extern int gotcolor; /* read *colorfile when TRUE */
extern Font fonts[]; /* data about every font we see */
extern Font *dwb_mount[]; /* troff mounts fonts here */
/*****************************************************************************/
int
main(int agc, char **agv)
{
/*
*
* Translates output from troff into PostScript. Input files must be formatted
* for the same device. Each input file begins on a new page.
*
*/
argc = agc; /* global so everyone can use them */
argv = agv;
prog_name = argv[0]; /* for error messages */
init_signals(); /* interrupt handling */
header(); /* structuring comments */
options(); /* command line options */
arguments(); /* translate the input files */
done(); /* add trailing comments etc. */
account(); /* job accounting data */
return (x_stat);
} /* End of main */
/*****************************************************************************/
static void
init_signals(void)
{
/*
*
* Make sure we handle interrupts.
*
*/
if ( signal(SIGINT, interrupt) == SIG_IGN ) {
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
signal(SIGHUP, SIG_IGN);
} else {
signal(SIGHUP, interrupt);
signal(SIGQUIT, interrupt);
} /* End else */
signal(SIGTERM, interrupt);
} /* End of init_signals */
/*****************************************************************************/
static void
header(void)
{
int ch;
int old_optind = optind;
/*
*
* Scan the option list for things needed now (e.g. prologue file), but could
* be changed from defaults. An attempt to follow to Adobe's 2.0 structuring
* conventions.
*
*/
while ( (ch = getopt(argc, argv, optnames)) != EOF )
if ( ch == 'L' )
setpaths(optarg);
else if ( ch == 'B' )
dobbox = TRUE;
else if ( ch == '?' )
ERROR(FATAL, 0, (stderr, " "));
optind = old_optind; /* restored for options() */
fprintf(stdout, "%s", NONCONFORMING);
fprintf(stdout, "%s %s\n", VERSION, PROGRAMVERSION);
fprintf(stdout, "%s %s\n", DOCUMENTFONTS, ATEND);
fprintf(stdout, "%s %s\n", PAGES, ATEND);
if ( dobbox == TRUE )
fprintf(stdout, "%s %s\n", BOUNDINGBOX, ATEND);
fprintf(stdout, "%s", ENDCOMMENTS);
if ( cat(prologue) == FALSE )
ERROR(FATAL, 1, (stderr, "can't read %s", prologue));
if ( DOROUND )
cat(ROUNDPAGE);
fprintf(stdout, "%s", ENDPROLOG);
fprintf(stdout, "%s", BEGINSETUP);
fprintf(stdout, "mark\n");
} /* End of header */
/*****************************************************************************/
static void
options(void)
{
int ch;
extern char *optarg;
extern int optind;
/*
*
* Command line options - there are too many!
*
*/
while ( (ch = getopt(argc, argv, optnames)) != EOF ) {
switch ( ch ) {
case 'a': /* aspect ratio */
fprintf(stdout, "/aspectratio %s def\n", optarg);
break;
case 'c': /* number of copies */
copies = atoi(optarg);
fprintf(stdout, "/#copies %s store\n", optarg);
break;
case 'e': /* select the encoding scheme */
if ( (encoding = atoi(optarg)) < 0 || encoding > MAXENCODING )
encoding = DFLTENCODING;
realencoding = encoding;
break;
case 'm': /* magnification */
magnification = atof(optarg);
fprintf(stdout, "/magnification %s def\n", optarg);
break;
case 'n': /* forms per page */
formsperpage = atoi(optarg);
fprintf(stdout, "%s %s\n", FORMSPERPAGE, optarg);
fprintf(stdout, "/formsperpage %s def\n", optarg);
break;
case 'o': /* output page list */
out_list(optarg);
break;
case 'p': /* landscape or portrait mode */
landscape = (*optarg == 'l') ? TRUE : FALSE;
if ( landscape == TRUE )
fprintf(stdout, "/landscape true def\n");
else fprintf(stdout, "/landscape false def\n");
break;
case 't': /* compatibility */
break;
case 'w': /* line width - for drawing */
fprintf(stdout, "/linewidth %s def\n", optarg);
break;
case 'x': /* shift horizontally */
xoffset = atof(optarg);
fprintf(stdout, "/xoffset %s def\n", optarg);
break;
case 'y': /* shift vertically */
yoffset = atof(optarg);
fprintf(stdout, "/yoffset %s def\n", optarg);
break;
case 'A': /* job accounting */
case 'J':
if ( (fp_acct = fopen(optarg, "a")) == NULL )
ERROR(FATAL, 1,
(stderr, "can't open accounting file %s", optarg));
break;
case 'B': /* enable BoundingBox calculations */
dobbox = TRUE;
fprintf(stdout, "/rotation 1 def\n");
fprintf(stdout, "/gotpagebbox true def\n");
break;
case 'C': /* copy file to output */
if ( cat(optarg) == FALSE )
ERROR(FATAL, 1, (stderr, "can't read %s", optarg));
break;
case 'E': /* text font encoding - override DESC */
useencoding = optarg;
break;
case 'F': /* font table directory */
fontdir = optarg;
break;
case 'H': /* host resident font directory */
hostfontdir = optarg;
break;
case 'L': /* prologue file */
setpaths(optarg); /* already been done in header() */
break;
case 'O': /* disable picture inclusion */
picflag = OFF;
break;
case 'P': /* copy string to output */
fprintf(stdout, "%s\n", optarg);
break;
case 'R': /* global or page level request */
saverequest(optarg);
break;
case 'S': /* horizontal position error */
if ( (pointslop = atof(optarg)) < 0 )
pointslop = 0;
break;
case 'T': /* target printer */
realdev = optarg;
break;
case 'D': /* debug flag */
debug = ON;
tf = stdout;
break;
case 'I': /* ignore FATAL errors */
ignore = ON;
break;
case '?': /* don't know the option */
ERROR(FATAL, 0, (stderr, " "));
break;
default:
ERROR(FATAL, 1, (stderr, "missing case for option %c", ch));
break;
} /* End switch */
} /* End while */
argc -= optind;
argv += optind;
} /* End of options */
/*****************************************************************************/
static void
setpaths(char *name)
{
char *path;
/*
*
* Extends the -L option to permit modification of more than just the prologue
* file pathname. Syntax is -Lpath or -Lname:path. For debugging and development
* only!
*
*/
for ( path = name; *path; path++ )
if ( *path == ':' || *path == ' ' ) {
while ( *path == ':' || *path == ' ' ) path++;
break;
} /* End if */
if ( *path == '\0' ) /* didn't find "name:" prefix */
path = name;
if ( path == name || strncmp(name, "prologue", strlen("prologue")) == 0 )
prologue = path;
else if ( strncmp(name, "draw", strlen("draw")) == 0 )
drawfile = path;
else if ( strncmp(name, "color", strlen("color")) == 0 )
colorfile = path;
else if ( strncmp(name, "form", strlen("form")) == 0 )
formfile = path;
else if ( strncmp(name, "baseline", strlen("baseline")) == 0 )
baselinefile = path;
} /* End of setpaths */
/*****************************************************************************/
static void
setup(void)
{
double t;
/*
*
* Job and BoundingBox initialization. Called once from t_init() - must know
* the resolution before generating the PostScript call to setup. dpost only
* includes an encoding file if it's set in the DESC file or requested with
* the -E option.
*
*/
writerequest(0, stdout); /* global requests e.g. manual feed */
fprintf(stdout, "/resolution %d def\n", res);
if ( useencoding != NULL || fontencoding != NULL )
setencoding((useencoding != NULL) ? useencoding : fontencoding);
fprintf(stdout, "setup\n");
fprintf(stdout, "%d setdecoding\n", realencoding);
if ( formsperpage > 1 ) { /* multiple pages */
if ( cat(formfile) == FALSE )
ERROR(FATAL, 1, (stderr, "can't read %s", formfile));
fprintf(stdout, "%d setupforms\n", formsperpage);
} /* End if */
fprintf(stdout, "%s", ENDSETUP);
if ( dobbox == TRUE ) { /* ctm[] - must agree with prologue */
translate(pagewidth/2.0, pageheight/2.0);
if ( landscape == TRUE ) {
rotate(90.0);
t = pagewidth;
pagewidth = pageheight;
pageheight = t;
} /* End if */
translate(-pagewidth/2.0, pageheight/2.0);
translate(72.0 * xoffset, -72.0 * yoffset);
scale(magnification, magnification);
scale(72.0/devres, 72.0/devres);
} /* End if */
} /* End of setup */
/*****************************************************************************/
static void
arguments(void)
{
FILE *fp;
/*
*
* Everything else is an input file. No arguments or '-' means stdin.
*
*/
if ( argc < 1 )
conv(stdin);
else
while ( argc > 0 ) {
if ( strcmp(*argv, "-") == 0 )
fp = stdin;
else if ( (fp = fopen(*argv, "r")) == NULL )
ERROR(FATAL, 1, (stderr, "can't open %s", *argv));
conv(fp);
if ( fp != stdin )
fclose(fp);
argc--;
argv++;
} /* End while */
} /* End of arguments */
/*****************************************************************************/
static void
done(void)
{
int i;
int n;
/*
*
* Force out the last page and add trailing comments.
*
*/
fprintf(stdout, "%s", TRAILER);
fprintf(stdout, "done\n");
fprintf(stdout, "%s %d\n", PAGES, printed);
for ( i = 0, n = 0; i < MAXFONTS+1; i++ )
if ( (fonts[i].flags & USED) && fonts[i].fontname != NULL ) {
if ( n++ == 0 )
fprintf(stdout, "%s", DOCUMENTFONTS);
else if ( (n - 1) % 8 == 0 )
fprintf(stdout, "\n%s", CONTINUECOMMENT);
fprintf(stdout, " %s", fonts[i].fontname);
} /* End if */
if ( n > 0 )
putc('\n', stdout);
if ( dobbox == TRUE )
writebbox(stdout, BOUNDINGBOX, 10);
} /* End of done */
/*****************************************************************************/
static void
account(void)
{
/*
*
* Accounting record to fp_acct - provided it's not NULL.
*
*/
if ( fp_acct != NULL )
fprintf(fp_acct, " print %d\n copies %d\n", printed, copies);
} /* End of account */
/*****************************************************************************/
static void
conv(FILE *fp)
{
register int c;
int m, n, n1, m1;
char str[50];
char ch;
/*
*
* Read troff output from file fp and translate it into PostScript. The final
* t_page() call means input files start on a new page.
*
*/
redirect(-1); /* do output only after a page command */
lineno = 1;
while ((c = getc(fp)) != EOF) {
switch (c) {
case '\n': /* just count this line */
lineno++;
break;
case ' ': /* when input is text */
case 0: /* occasional noise creeps in */
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
/* two motion digits plus a character */
hmot((c-'0')*10 + getc(fp)-'0');
put1(getc(fp));
break;
case 'c': /* single ascii character */
put1(getc(fp));
break;
case 'C': /* special character */
fscanf(fp, "%s", str);
put1(chindex(str));
break;
case 'N': /* character at position n */
fscanf(fp, "%d", &m);
flushtext();
oput(m);
break;
case 'D': /* drawing functions */
flushtext();
getdraw();
if ( size != lastsize )
t_sf();
switch ((c=getc(fp))) {
case 'p': /* draw a path */
while (fscanf(fp, "%d %d", &n, &m) == 2)
drawline(n, m);
lineno++;
break;
case 'l': /* draw a line */
fscanf(fp, "%d %d %c", &n, &m, &ch);
n1 = ch;
drawline(n, m);
break;
case 'c': /* circle */
fscanf(fp, "%d", &n);
drawcirc(n);
break;
case 'e': /* ellipse */
fscanf(fp, "%d %d", &m, &n);
drawellip(m, n);
break;
case 'a': /* counter-clockwise arc */
case 'A': /* clockwise arc */
fscanf(fp, "%d %d %d %d", &n, &m, &n1, &m1);
drawarc(n, m, n1, m1, c);
break;
case 'q': /* spline without end points */
drawspline(fp, 1);
lineno++;
break;
case '~': /* wiggly line */
drawspline(fp, 2);
lineno++;
break;
default:
ERROR(FATAL, 1, (stderr, "unknown drawing function %c", c));
break;
} /* End switch */
break;
case 's': /* use this point size */
fscanf(fp, "%d", &size); /* ignore fractional sizes */
break;
case 'f': /* use font mounted here */
fscanf(fp, "%s", str);
setfont(t_font(str));
break;
case 'H': /* absolute horizontal motion */
fscanf(fp, "%d", &n);
hgoto(n);
break;
case 'h': /* relative horizontal motion */
fscanf(fp, "%d", &n);
hmot(n);
break;
case 'w': /* word space */
break;
case 'V': /* absolute vertical position */
fscanf(fp, "%d", &n);
vgoto(n);
break;
case 'v': /* relative vertical motion */
fscanf(fp, "%d", &n);
vmot(n);
break;
case 'p': /* new page */
fscanf(fp, "%d", &n);
t_page(n);
break;
case 'n': /* end of line */
while ( (c = getc(fp)) != '\n' && c != EOF ) ;
hgoto(0);
lineno++;
break;
case '#': /* comment */
while ( (c = getc(fp)) != '\n' && c != EOF ) ;
lineno++;
break;
case 'x': /* device control function */
devcntrl(fp);
lineno++;
break;
default:
ERROR(FATAL, 1, (stderr, "unknown input character %o %c", c, c));
done();
} /* End switch */
} /* End while */
t_page(-1); /* print the last page */
flushtext();
} /* End of conv */
/*****************************************************************************/
static void
devcntrl(FILE *fp)
{
char str[50], buf[256], str1[100];
int c, n;
/*
*
* Interpret device control commands, ignoring any we don't recognize. The
* "x X ..." commands are a device dependent collection generated by troff's
* \X'...' request.
*
*/
fscanf(fp, "%s", str);
switch ( str[0] ) {
case 'f': /* load font in a position */
fscanf(fp, "%d %s", &n, str);
fgets(buf, sizeof buf, fp); /* in case there's a filename */
ungetc('\n', fp); /* fgets() goes too far */
str1[0] = '\0'; /* in case there's nothing to come in */
sscanf(buf, "%s", str1);
loadfont(n, str, str1);
break;
case 'i': /* initialize */
t_init();
break;
case 'p': /* pause */
break;
case 'r': /* resolution assumed when prepared */
fscanf(fp, "%d", &res);
break;
case 's': /* stop */
case 't': /* trailer */
flushtext();
break;
case 'H': /* char height */
fscanf(fp, "%d", &n);
t_charht(n);
break;
case 'S': /* slant */
fscanf(fp, "%d", &n);
t_slant(n);
break;
case 'T': /* device name */
fscanf(fp, "%s", dwb_devname);
break;
case 'X': /* copy through - from troff */
fscanf(fp, " %[^: \n]:", str);
fgets(buf, sizeof(buf), fp);
ungetc('\n', fp);
if ( strcmp(str, "PI") == 0 || strcmp(str, "PictureInclusion") == 0 )
picture(buf);
else if ( strcmp(str, "InlinePicture") == 0 )
inlinepic(fp, buf);
else if ( strcmp(str, "BeginPath") == 0 )
beginpath(buf, FALSE);
else if ( strcmp(str, "DrawPath") == 0 )
drawpath(buf, FALSE);
else if ( strcmp(str, "BeginObject") == 0 )
beginpath(buf, TRUE);
else if ( strcmp(str, "EndObject") == 0 )
drawpath(buf, TRUE);
else if ( strcmp(str, "NewBaseline") == 0 )
newbaseline(buf);
else if ( strcmp(str, "DrawText") == 0 )
drawtext(buf);
else if ( strcmp(str, "SetText") == 0 )
settext(buf);
else if ( strcmp(str, "SetColor") == 0 ) {
newcolor(buf);
setcolor();
} else if ( strcmp(str, "INFO") == 0 ) {
flushtext();
fprintf(tf, "%%INFO%s", buf);
} else if ( strcmp(str, "PS") == 0 || strcmp(str, "PostScript") == 0 ) {
flushtext();
fprintf(tf, "%s", buf);
} else if ( strcmp(str, "ExportPS") == 0 ) { /* dangerous!! */
if ( tf == stdout ) {
restore();
fprintf(tf, "%s", buf);
save();
} /* End if */
} /* End else */
break;
} /* End switch */
while ( (c = getc(fp)) != '\n' && c != EOF ) ;
} /* End of devcntrl */
/*****************************************************************************/
static void
loadfont(int m, char *f, char *name)
{