-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc2ps.cpp
More file actions
1924 lines (1748 loc) · 56.2 KB
/
c2ps.cpp
File metadata and controls
1924 lines (1748 loc) · 56.2 KB
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
/*
*
* C2ps.c : a C to PostScript program. Does the following:
*
* keywords => bold courier or times bold
* character string => ourier
* comments => italic courier or italic times
* regular test => courier or times
* linenumbers on lefththand side
* procedure names on righthand side
* date and full file name at top of page
*
* The C program should compile and execute on most computers. Has been
* tested on VAX/VMS, VAX/ULTRIX, RISC/ULTRIX and MS-DOS.
*
* The PostScript program is an ecapsulated PostScript program and should work
* on most printers. Has been tested on LN03R, LPS20 and
* Digital's PostScript previewer.
*
* Dag Framstad @NWO OSLENG::DAGFRA
* 20-NOV-1989
*
* Modifications: Steve Glaser @ SHR STARCH::GLASER 31 July 1990
* Steve Glaser @ SHR STARCH::GLASER 12 December 1990
*/
/*
* $Log: c2ps.cpp,v $
* Revision 3.5 2013-09-24 18:00:36-07 sglaser
* more updates
*
* Revision 3.4 2002-05-23 16:17:51-07 sglaser
* make it compile on linux
*
* Revision 3.3 2002/01/09 23:29:14 sglaser
* Remove prefix "/afs/pacelinesystems.com" from file names in listing output
*
* Revision 3.2 2002/01/09 23:18:23 sglaser
* switch to C++, make it compile again
*
* Revision 3.1 2002/01/09 21:40:11 sglaser
* change page trailers
*
* Revision 3.0 2002/01/09 21:38:52 sglaser
* *** empty log message ***
*
*
* Revision 2.6 2001/06/27 18:32:07 sglaser
* bugfix - allow # in non C/C++ files to work properly
* bugfix - use getcwd() to prevent buffer overflow bug
*
* Revision 2.5 2001/05/17 00:15:23 sglaser
* Y2K fix
*
* Revision 2.4 1999/01/20 22:49:59 sglaser
* add -verilog and -vera switches
*
* Revision 2.3 1998/04/07 16:05:30 sglaser
* add C2PS_DEFAULTS to -help
*
* Revision 2.2 1998/04/07 16:02:48 sglaser
* add -rotate to -help
*
* Revision 2.1 1998/04/07 16:00:33 sglaser
* Initial revision
*
* Revision 1.22 1995/06/22 20:28:19 glaser
* increase MAXCHARSINLINE to 10K
*
* Revision 1.21 1995/06/22 20:27:10 glaser
* unknown changes
*
* Revision 1.20 1994/02/16 05:32:22 glaser
* add .icc suffix defaulting to c++
*
* Revision 1.19 1994/01/18 23:25:16 glaser
* include errno.h to make alpha c89 happier
*
* Revision 1.18 1993/12/13 19:53:55 glaser
* s/Courier-Italic/Courier-Oblique/g (DEC PS Printers don't have Courier-Italic).
*
* Revision 1.17 1992/12/04 03:55:51 glaser
* bugfix -- prepend_args() -- arrays should be static
*
* Revision 1.16 1992/12/02 22:51:01 glaser
* add C2PS_DEFAULTS support, do argument debugging if argv[0] == "a.out"
*
* Revision 1.15 1992/10/14 18:46:39 glaser
* add -ext switch to default language from extension
*
* Revision 1.14 1992/10/14 18:21:23 glaser
* eliminate superfluous message
*
* Revision 1.13 1991/10/21 20:59:16 glaser
* don't print anything for zero length files
* (was printing a blank page 0 and getting the even/odd page count off (-2))
*
* Revision 1.12 1991/10/02 01:12:59 glaser
* fix type in September
*
* Revision 1.11 1991/08/14 15:31:48 glaser
* change todays_date to time_t (was long) for ANSI C compatability
*
* Revision 1.10 1991/08/14 15:22:40 glaser
* att -1 -2 -4 and -8 switches to force blank pages on n-up and duplesx printers
*
* Revision 1.9 1991/05/10 17:27:17 glaser
* close the input file so we don't run out of file descriptors
*
* Revision 1.8 91/03/27 21:15:51 glaser
* move date up so it won't collide with very long pathnames
*
* Revision 1.7 91/03/26 15:21:40 glaser
* bug fixes with line numbers and continuation lines
*
* Revision 1.6 91/03/15 20:05:55 glaser
* fix butg - make c++ mode work
*
* Revision 1.5 91/03/15 16:24:47 glaser
* add c++ support
* rework comment end detection to be more language independant
*
* Revision 1.4 91/03/15 16:20:49 glaser
* better error messages
*
* Revision 1.3 90/12/13 01:25:37 glaser
* add -trellis, -internal, -confidential, -restricted and -bottom
*
*
*/
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <unistd.h>
#ifdef VMS
#include <time.h>
#else
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <stdlib.h> /* for getenv() */
#endif
#define LINEWIDTH 12
#define NORMFSIZE 10
#define SMALLFSIZE 8
#define BIGFSIZE 12
#define MAXCHARSINLINE 10000
#define BOTTOM 72
#define BOTLINE BOTTOM - 2 * LINEWIDTH
#define LMARG 60
#define TRUE 1
#define FALSE 0
#define COMMENT_END_STAR_SLASH 1 /* C style comment */
#define COMMENT_END_NEWLINE 2 /* Trellis or C++ comment */
#ifndef MAXPATHLEN
#define MAXPATHLEN MAXCHARSINLINE
#endif
#define LANG_C 1
#define LANG_TRELLIS 2
#define LANG_CPP 3
#define LANG_VERILOG 4
#define LANG_VERA 5
int language = LANG_CPP; /* default is really based on suffix */
int language_set = 0;
char rcs_ident[] = "$Header: /home/sglaser/hw/pvt/sglaser/Source/RCS/c2ps.cpp,v 3.5 2013-09-24 18:00:36-07 sglaser Exp $";
static const char *c_keywords[] = {
"_align",
"asm",
"auto",
"break",
"case",
"char",
"const",
"continue",
"default",
"do",
"double",
"else",
"enum",
"entry",
"extern",
"float",
"for",
"fortran",
"globaldef",
"globalref",
"globalvalue",
"goto",
"if",
"int",
"long",
"noshare",
"readonly",
"register",
"return",
"short",
"signed",
"sizeof",
"static",
"struct",
"switch",
"typedef",
"union",
"unsigned",
"void",
"volatile",
"while",
0
};
static const char *cpp_keywords[] = {
"_align",
"asm",
"auto",
"break",
"case",
"catch",
"char",
"class",
"const",
"continue",
"default",
"delete",
"do",
"double",
"else",
"enum",
"extern",
"float",
"for",
"friend",
"goto",
"if",
"iinline",
"int",
"long",
"new",
"operator",
"private",
"protected",
"public",
"register",
"return",
"short",
"signed",
"sizeof",
"static",
"struct",
"switch",
"template",
"this",
"throw",
"try",
"typedef",
"union",
"unsigned",
"virtual",
"void",
"volatile",
"while",
0
};
static const char *trellis_keywords[] = {
"and",
"cand",
"cor",
"div",
"eqv",
"in",
"mod",
"or",
"xor",
"not",
"allocate",
"as",
"bind",
"builtin",
"component",
"define",
"exclude",
"field",
"from",
"get",
"inherit",
"is",
"operation",
"put",
"type_module",
"var",
"abstract",
"allocate_visible",
"base",
"constant",
"get_only",
"mutable",
"no_subtypes",
"override",
"private",
"public",
"put_only",
"returns",
"signals",
"subtype_of",
"subtype_visible",
"yeilds",
"begin",
"case",
"continue",
"do",
"else",
"elseif",
"end",
"except",
"exit",
"for",
"if",
"leave",
"loop",
"on",
"otherwise",
"resignal",
"return",
"signal",
"subtype",
"then",
"to",
"type_case",
"unless",
"when",
"with",
"yield",
0
};
static const char *verilog_keywords[] = {
"always", "and", "assign", "begin", "buf", "bufif0", "bufif1", "case",
"casex", "casez", "cmos", "deassign", "default", "defparam", "disable",
"edge", "else", "end", "endcase", "endmodule", "endfunction",
"endprimitive", "endspecify", "endtable", "endtask", "event", "for",
"force", "forever", "fork", "function", "highz0", "highz1", "if",
"ifnone", "initial", "inout", "input", "integer", "join", "large",
"macromodule", "medium", "module", "nand", "negedge", "nmos", "nor",
"not", "notif0", "notif1", "or", "output", "parameter", "pmos", "posedge",
"primitive", "pull0", "pull1", "pulldown", "rcmos", "real", "realtime",
"reg", "release", "repeat", "rnmos", "rpnos", "rtran", "rtranif0",
"rtranif1", "scalared", "small", "specify", "specparam", "strong0",
"strong1", "supply0", "supply1", "table", "task", "time", "tran",
"tranif0", "tranif1", "tri", "tri0", "tri1", "triand", "trior", "trireg",
"vectored", "wait", "weak0", "weak1", "while", "wire", "wor", "xnor",
"xor", 0
};
static const char *vera_keywords[] = {
"all", "any", "begin", "bind", "bind_var", "bit", "break", "breakpoint",
"case", "class", "continue", "coverage_block", "default", "depth", "else",
"end", "enum", "event", "extern", "extends", "for", "fork", "funciton",
"if", "inout", "input", "integer", "interface", "join", "local",
"negedge", "new", "none", "null", "output", "port", "posedge", "program",
"reg", "repeat", "return", "shadow", "soft", "state", "static", "super",
"task", "terminate", "this", "trans", "typedef", "var", "vector",
"verilog_node", "verilog_task", "void", "while", "with", 0};
static const char *no_keywords[] = {
0
};
/*
* indexed by language and thus must track the defines for LANG_*
*/
const char **keyword_array[] = {
no_keywords,
c_keywords,
trellis_keywords,
cpp_keywords,
verilog_keywords,
vera_keywords};
typedef struct key_begin_end {
const char *name;
int offset;
} key_begin_end_t;
static key_begin_end_t no_func_start_end[] = {{0, 0}};
static key_begin_end_t verilog_func_start_end[] = {
{"module", 1},
{"endmodule", -1},
{"task", 1},
{"endtask", -1},
{"function", 1},
{"endfunction", -1},
{0, 0}};
key_begin_end_t *func_start_end_array[] = {no_func_start_end, /* none */
no_func_start_end, /* C */
no_func_start_end, /* trellis */
no_func_start_end, /* C++ */
verilog_func_start_end, /* Verilo g */
no_func_start_end}; /* Vera */
struct paper_sizes {
const char *name;
int x;
int y;
} paper_sizes[] = {
{"-letter", 612, 792},
{"-a3", 594, 846},
{"-a4", 846, 1184},
{"-legal", 612, 1108},
{"-ledger", 792, 1224}};
#define MAX_PAPER_SIZE 4 /* -ledger */
const char *bottom_text = 0;
char *argv0,
*header_string = 0,
ifname[120],
ofname[120],
ifname_full[MAXPATHLEN],
ibuffer[MAXCHARSINLINE],
obuffer[MAXCHARSINLINE],
tmpbuffer[MAXCHARSINLINE],
timbuf[50],
cword[120],
curfuncs[120],
funcname[120],
txtchar = ' ';
int paper_size = 0,
fixed_font = FALSE,
rotate_text = FALSE,
txtmode,
process_mode,
moreonline,
comment_style,
lastwasbslash,
have_funcname,
top_of_page,
seen_directive,
seen_non_blank;
int i,
j,
x,
urx,
ury,
top,
topline,
pageno = 0,
page_skip = 1,
pagecount = 0,
duplex = 0,
lineno = 1,
func_depth = 0,
paren_depth = 0,
square_bracket_depth = 0,
func_name_search = 0,
ypos,
rmarg,
wrap_col,
ibuffp,
obuffp,
cwordp;
FILE *infile = NULL,
*outfile = NULL;
int IsKeyword(),
IsItAFunc();
void Usage(),
MakePaperSize(),
MakeProlog(),
PrintPage(),
MakeNewPage(),
PrintBlankPage(),
WriteBuffer(),
WriteFont(),
WriteLineNo(),
WhatToPutIn(),
PutWordInBuffer(),
WasKeyword(),
WasNotKeyword(),
WasAFunc(),
PutCharInWord(),
InComMode(),
StartComMode(),
StopTxtMode(),
InTxtMode(),
StartTxtMode(),
InFileMode(),
ParseFile(),
MakeTrailer(),
ResetForNewFile(),
ResetTimbuf();
void print_args(const char *tag, int argc, char **argv) {
int i;
if (strcmp(argv0, "a.out") == 0) {
printf("%s: argc = %d\n", tag, argc);
for (i = 0; i < argc; i++)
printf("argc[%d] = \"%s\"\n", i, argv[i]);
}
}
void
prepend_args(int *argc_ptr, char ***argv_ptr) {
#ifndef VMS
static char *new_argv[128];
static char argbuff[1024];
int count;
count = 1;
new_argv[0] = (*argv_ptr)[0];
print_args("prepend_args::before", *argc_ptr, *argv_ptr);
{
char *p = argbuff;
char *q = getenv("C2PS_DEFAULTS");
if (q == NULL)
return;
if (strlen(q) >= sizeof(argbuff)) {
fprintf(stderr, "c2ps: C2PS_DEFAULTS longer than %lu\n", sizeof(argbuff));
Usage();
}
do {
char *saved_p = p;
while (isgraph(*q)) { /* printable, not including space */
*p++ = *q++;
}
*p++ = '\0';
new_argv[count++] = saved_p;
new_argv[count] = NULL;
while (isspace(*q)) {
q++;
}
} while (*q != '\0');
}
print_args("prepend_args::middle 1", count, new_argv);
{
char **argv = *argv_ptr + 1;
while (*argv != NULL) {
new_argv[count++] = *argv++;
}
new_argv[count] = NULL;
}
print_args("prepend_args::middle 2", count, new_argv);
*argv_ptr = new_argv;
*argc_ptr = count;
print_args("prepend_args::after", *argc_ptr, *argv_ptr);
#endif
}
/*
* main entry point
*/
int
main(int argc, char **argv) {
char name[80];
char *dotpos;
int found_file_name;
// extern char *strrchr();
argv0 = argv[0];
print_args("main::before", argc, argv);
prepend_args(&argc, &argv);
print_args("main::after", argc, argv);
if (argc <= 1)
Usage();
found_file_name = FALSE;
ofname[0] = '\0';
for (i = 1; i < argc; i++) {
if ((argv[i][0] == '-') && (argv[i][1] != '\0')) {
if (found_file_name == FALSE) {
/*
* process options that must preceed any input file names
*/
for (j = 0; j <= MAX_PAPER_SIZE; j++) {
if (strcmp(argv[i], paper_sizes[j].name) == 0) {
paper_size = j;
goto next_option;
}
}
if ((strcmp(argv[i], "-o") == 0) && ((i + 1) < argc)) {
i++;
strcpy(ofname, argv[i]);
goto next_option;
}
}
/*
* process other options
*/
if ((strcmp(argv[i], "-hdr") == 0) && ((i + 1) < argc)) {
i++;
header_string = argv[i];
} else if (strcmp(argv[i], "-text") == 0) {
process_mode = 1;
goto next_option;
} else if (strcmp(argv[i], "-c") == 0) {
process_mode = 0;
language = LANG_C;
language_set = 1;
goto next_option;
} else if (strcmp(argv[i], "-trellis") == 0) {
process_mode = 0;
language = LANG_TRELLIS;
language_set = 1;
goto next_option;
} else if (strcmp(argv[i], "-c++") == 0) {
process_mode = 0;
language = LANG_CPP;
language_set = 1;
goto next_option;
} else if (strcmp(argv[i], "-verilog") == 0) {
process_mode = 0;
language = LANG_VERILOG;
language_set = 1;
goto next_option;
} else if (strcmp(argv[i], "-vera") == 0) {
process_mode = 0;
language = LANG_VERA;
language_set = 1;
goto next_option;
} else if (strcmp(argv[i], "-ext") == 0) {
process_mode = 0;
language = LANG_CPP;
language_set = 0;
goto next_option;
} else if (strcmp(argv[i], "-internal") == 0) {
bottom_text = "Nvidia Internal Use Only";
goto next_option;
} else if (strcmp(argv[i], "-confidential") == 0) {
bottom_text = "Nvidia Confidential";
goto next_option;
} else if (strcmp(argv[i], "-restricted") == 0) {
bottom_text = "Nvidia Restricted Distribution";
goto next_option;
} else if ((strcmp(argv[i], "-bottom") == 0) && i + 1 < argc) {
i++;
bottom_text = argv[i];
goto next_option;
} else if (strcmp(argv[i], "-proportional") == 0) {
fixed_font = FALSE;
goto next_option;
} else if (strcmp(argv[i], "-fixed") == 0) {
fixed_font = TRUE;
goto next_option;
} else if (strcmp(argv[i], "-rotate") == 0) {
rotate_text = TRUE;
goto next_option;
} else if (strcmp(argv[i], "-1") == 0) {
page_skip = 1;
goto next_option;
} else if (strcmp(argv[i], "-2") == 0) {
page_skip = 2;
goto next_option;
} else if (strcmp(argv[i], "-4") == 0) {
page_skip = 4;
goto next_option;
} else if (strcmp(argv[i], "-8") == 0) {
page_skip = 8;
goto next_option;
} else if (strcmp(argv[i], "-duplex") == 0) {
duplex = 1;
} else {
Usage();
}
} else {
if (ofname[0] == '\0') {
strcpy(ofname, argv[i]);
dotpos = strrchr(ofname, '.');
if (dotpos != NULL)
*dotpos = '\0';
strcat(ofname, ".ps");
}
if (outfile == NULL) {
if ((strcmp(ofname, "-") == 0) ||
(strcmp(ofname, "-.ps") == 0)) {
outfile = stdout;
} else {
if ((outfile = fopen(ofname, "w+")) == NULL) {
#ifdef VMS
fprintf(stderr, "%s: can't open '%s'\n", argv0, ofname);
#else
fprintf(stderr, "%s: can't open '%s' %s\n", argv0, ofname, strerror(errno));
#endif
exit(1);
}
}
MakePaperSize();
MakeProlog();
}
found_file_name = TRUE;
strcpy(ifname, argv[i]);
#ifdef VMS
strcpy(ifname_full, ifname);
#else
if (ifname[0] == '/') {
strcpy(ifname_full, ifname);
} else if (ifname[0] == '-') {
strcpy(ifname_full, "standard input");
} else {
getcwd(ifname_full, sizeof(ifname_full) - 2 - strlen(ifname));
strcat(ifname_full, "/");
strcat(ifname_full, ifname);
}
#endif
if (ifname[0] == '-') {
infile = stdin;
} else if ((infile = fopen(ifname, "r")) == NULL) {
#ifdef VMS
fprintf(stderr, "%s : can't open '%s'\n", argv0, ifname);
#else
fprintf(stderr, "%s : can't open '%s' %s\n", argv0, ifname, strerror(errno));
#endif
exit(1);
}
if (language_set == 0) {
dotpos = strrchr(ifname, '.');
if (dotpos != NULL) {
if ((strcmp(dotpos, ".c") == 0) ||
(strcmp(dotpos, ".h") == 0)) {
process_mode = 0;
language = LANG_C;
} else if ((strcmp(dotpos, ".cxx") == 0) ||
(strcmp(dotpos, ".hxx") == 0) ||
(strcmp(dotpos, ".icc") == 0) ||
(strcmp(dotpos, ".cpp") == 0) ||
(strcmp(dotpos, ".hpp") == 0) ||
(strcmp(dotpos, ".C") == 0) ||
(strcmp(dotpos, ".H") == 0) ||
(strcmp(dotpos, ".cc") == 0) ||
(strcmp(dotpos, ".hh") == 0) ||
(strcmp(dotpos, ".CC") == 0) ||
(strcmp(dotpos, ".HH") == 0)) {
process_mode = 0;
language = LANG_CPP;
} else if ((strcmp(dotpos, ".verilog") == 0) ||
(strcmp(dotpos, ".v") == 0) ||
(strcmp(dotpos, ".vh") == 0) ||
(strcmp(dotpos, ".vs") == 0)) {
process_mode = 0;
language = LANG_VERILOG;
} else if ((strcmp(dotpos, ".vr") == 0) ||
(strcmp(dotpos, ".vrh") == 0)) {
process_mode = 0;
language = LANG_VERA;
} else if ((strcmp(dotpos, ".trellis") == 0)) {
process_mode = 0;
language = LANG_TRELLIS;
} else {
/* -text */
process_mode = 1;
}
} else {
/* -text */
process_mode = 1;
}
}
ResetTimbuf();
ParseFile();
fclose(infile);
infile = NULL;
}
next_option:
if (i >= argc)
Usage();
}
if (outfile != NULL)
MakeTrailer();
exit(0);
}
/*
* Check if kword is a reserved word
*/
int IsKeyword(char *kword) {
const char **ptr = NULL;
int iskey = FALSE;
switch (language) {
case LANG_CPP:
case LANG_C:
case LANG_VERA:
/*
* keywords can't occur on preprocessor lines
*/
if ((obuffp > 0) && (obuffer[obuffp - 1] == '#'))
break;
/* fall through */
case LANG_TRELLIS:
case LANG_VERILOG:
/*
* search the appropriate keyword array
*/
for (ptr = keyword_array[language]; *ptr != NULL; ptr++) {
if (strcmp(*ptr, kword) == 0) {
iskey = TRUE;
break;
}
}
break;
}
return iskey;
}
/*
* Print usage help text when giving wrong command
*/
void Usage() {
fprintf(stderr, "usage: %s\t[-text | -trellis | -c | -c++ | -verilog]\n", argv0);
fprintf(stderr, "\t\t[-proportional | -fixed] [-o outputfile]\n");
fprintf(stderr, "\t\t[-letter | -a3 | -a4 | -legal | -ledger]\n");
fprintf(stderr, "\t\t[-internal | -confidential | -restricted | -bottom string] \n");
fprintf(stderr, "\t\t[-duplex] [-rotate] [-1 | -2 | -4 | -8] files\n");
fprintf(stderr, "default: %s -c -proportional -letter (modified by environment variable C2PS_DEFAULTS)\n", argv0);
exit(1);
}
/*
* Set new font
*
* 1: Font for ordinary text
* 2: Font for keywords
* 3: Font for texts
* 4: Font for comments
* 5: Font for linenumbers
* 6: Font for bottomtext
* 7: Font for toptext
* 8: Font for procedures
* 9: Font for page numbers
* 10: Font for text files
* default: What font?
*/
void WriteFont(int fn) {
switch (fn) {
case 1:
fprintf(outfile, "ordfn ");
break;
case 2:
fprintf(outfile, "keyfn ");
break;
case 3:
fprintf(outfile, "txtfn ");
break;
case 4:
fprintf(outfile, "comfn ");
break;
case 5:
fprintf(outfile, "linfn ");
break;
case 6:
fprintf(outfile, "botfn ");
break;
case 7:
fprintf(outfile, "topfn ");
break;
case 8:
fprintf(outfile, "prcfn ");
break;
case 9:
fprintf(outfile, "pagfn ");
break;
case 10:
fprintf(outfile, "filfn ");
break;
default:
if (process_mode == 1) WriteFont(10);
else if (txtmode) WriteFont(3);
else if (comment_style != 0) WriteFont(4);
else WriteFont(1);
}
}
/*
* Define the size of the PostScript BoundingBox depending on the papersize
*/
void MakePaperSize() {
if (rotate_text) {
urx = paper_sizes[paper_size].y;
ury = paper_sizes[paper_size].x;
} else {
urx = paper_sizes[paper_size].x;
ury = paper_sizes[paper_size].y;
}
ypos = top = ury - NORMFSIZE - 90;
topline = top + 2 * LINEWIDTH;
rmarg = urx - 36;
/*
* 4.65 points per character (8 pt courier).
* round down to the nearest multiple of 8 characters
*/
wrap_col = ((((rmarg - LMARG) * 100) / 465) / 8) * 8;
}
static const char *month[12] = {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"};
static const char *wday[7] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"};
time_t todays_date;
/*
* set the time buffer to the file timestamp or today's date
*/
void ResetTimbuf() {
struct tm *lt;
#ifndef VMS
struct stat statb;
#endif
#ifdef VMS
lt = localtime(&todays_date);
#else
if (infile == NULL) {
lt = localtime(&todays_date);
} else {
if (fstat(fileno(infile), &statb) != 0) {
#ifdef VMS
perror(argv0);
#else
fprintf(stderr, "%s: on '%s' #1 can't fstat(%d): %s\n", argv0, ifname, fileno(infile), strerror(errno));
#endif
}
lt = localtime(&statb.st_mtime);
}
#endif
if ((lt->tm_min == 0) && (lt->tm_sec == 0)
&& ((lt->tm_hour == 0) || (lt->tm_hour == 12))) {
snprintf(timbuf, sizeof(timbuf), "%s %d %s %04d at %s",
wday[lt->tm_wday],
lt->tm_mday,
month[lt->tm_mon],
lt->tm_year + 1900,
lt->tm_hour == 0 ? "12 midnight" : "12 noon");