Blob


1 /* t1.c: main control and input switching */
2 #
3 # include "t.h"
5 # define MACROS "/usr/lib/tmac.s"
6 # define PYMACS "/usr/lib/tmac.m"
9 # define ever (;;)
11 void
12 main(int argc, char *argv[])
13 {
14 exits(tbl(argc, argv)? "error" : 0);
15 }
18 int
19 tbl(int argc, char *argv[])
20 {
21 char line[5120];
22 /*int x;*/
23 /*x=malloc((char *)0); uncomment when allocation breaks*/
24 Binit(&tabout, 1, OWRITE);
25 setinp(argc, argv);
26 while (gets1(line, sizeof(line))) {
27 Bprint(&tabout, "%s\n", line);
28 if (prefix(".TS", line))
29 tableput();
30 }
31 Bterm(tabin);
32 return(0);
33 }
36 int sargc;
37 char **sargv;
39 void
40 setinp(int argc, char **argv)
41 {
42 sargc = argc;
43 sargv = argv;
44 sargc--;
45 sargv++;
46 if (sargc > 0)
47 swapin();
48 else {
49 tabin = (Biobuf*)getcore(sizeof(Biobuf), 1);
50 Binit(tabin, 0, OREAD);
51 }
52 }
55 int
56 swapin(void)
57 {
58 char *name;
59 while (sargc > 0 && **sargv == '-') {
60 if (match("-ms", *sargv)) {
61 *sargv = MACROS;
62 break;
63 }
64 if (match("-mm", *sargv)) {
65 *sargv = PYMACS;
66 break;
67 }
68 if (match("-TX", *sargv))
69 pr1403 = 1;
70 if (match("-", *sargv))
71 break;
72 sargc--;
73 sargv++;
74 }
75 if (sargc <= 0)
76 return(0);
77 /* file closing is done by GCOS troff preprocessor */
78 if(tabin)
79 Bterm(tabin);
80 ifile = *sargv;
81 name = ifile;
82 if (match(ifile, "-")) {
83 tabin = (Biobuf*)getcore(sizeof(Biobuf), 1);
84 Binit(tabin, 0, OREAD);
85 } else
86 tabin = Bopen(ifile, OREAD);
87 iline = 1;
88 Bprint(&tabout, ".ds f. %s\n", ifile);
89 Bprint(&tabout, ".lf %d %s\n", iline, name);
90 if (tabin == 0)
91 error("Can't open file");
92 sargc--;
93 sargv++;
94 return(1);
95 }