blob: 1e6cbf1140ce358f8c5f800685cb984bff664afd [file] [log] [blame]
rsc5cedca12004-05-15 23:24:00 +00001/* t1.c: main control and input switching */
2#
3# include "t.h"
4
5# define MACROS "/usr/lib/tmac.s"
6# define PYMACS "/usr/lib/tmac.m"
7
8
9# define ever (;;)
10
wkj8a3cbc12004-05-17 02:23:43 +000011void
rsc5cedca12004-05-15 23:24:00 +000012main(int argc, char *argv[])
13{
wkj8a3cbc12004-05-17 02:23:43 +000014 exits(tbl(argc, argv)? "error" : 0);
rsc5cedca12004-05-15 23:24:00 +000015}
16
17
18int
19tbl(int argc, char *argv[])
20{
21 char line[5120];
22 /*int x;*/
23 /*x=malloc((char *)0); uncomment when allocation breaks*/
wkj8a3cbc12004-05-17 02:23:43 +000024 Binit(&tabout, 1, OWRITE);
rsc5cedca12004-05-15 23:24:00 +000025 setinp(argc, argv);
26 while (gets1(line, sizeof(line))) {
wkj8a3cbc12004-05-17 02:23:43 +000027 Bprint(&tabout, "%s\n", line);
rsc5cedca12004-05-15 23:24:00 +000028 if (prefix(".TS", line))
29 tableput();
30 }
wkj8a3cbc12004-05-17 02:23:43 +000031 Bterm(tabin);
rsc5cedca12004-05-15 23:24:00 +000032 return(0);
33}
34
35
36int sargc;
37char **sargv;
38
39void
40setinp(int argc, char **argv)
41{
42 sargc = argc;
43 sargv = argv;
44 sargc--;
45 sargv++;
46 if (sargc > 0)
47 swapin();
wkj8a3cbc12004-05-17 02:23:43 +000048 else {
49 tabin = (Biobuf*)getcore(sizeof(Biobuf), 1);
50 Binit(tabin, 0, OREAD);
51 }
rsc5cedca12004-05-15 23:24:00 +000052}
53
54
55int
56swapin(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)
wkj8a3cbc12004-05-17 02:23:43 +000079 Bterm(tabin);
rsc5cedca12004-05-15 23:24:00 +000080 ifile = *sargv;
81 name = ifile;
82 if (match(ifile, "-")) {
wkj8a3cbc12004-05-17 02:23:43 +000083 tabin = (Biobuf*)getcore(sizeof(Biobuf), 1);
84 Binit(tabin, 0, OREAD);
rsc5cedca12004-05-15 23:24:00 +000085 } else
wkj8a3cbc12004-05-17 02:23:43 +000086 tabin = Bopen(ifile, OREAD);
rsc5cedca12004-05-15 23:24:00 +000087 iline = 1;
wkj8a3cbc12004-05-17 02:23:43 +000088 Bprint(&tabout, ".ds f. %s\n", ifile);
89 Bprint(&tabout, ".lf %d %s\n", iline, name);
rsc5cedca12004-05-15 23:24:00 +000090 if (tabin == 0)
91 error("Can't open file");
92 sargc--;
93 sargv++;
94 return(1);
95}