Research V7 development
[unix-history] / usr / src / cmd / tbl / t1.c
CommitLineData
67305323
ML
1 /* t1.c: main control and input switching */
2#
3# include "t..c"
4#include <signal.h>
5# ifdef gcos
6/* required by GCOS because file is passed to "tbl" by troff preprocessor */
7# define _f1 _f
8extern FILE *_f[];
9# endif
10
11# ifdef unix
12# define MACROS "/usr/lib/tmac.s"
13# define PYMACS "/usr/lib/tmac.m"
14# endif
15
16# ifdef gcos
17# define MACROS "cc/troff/smac"
18# define PYMACS "cc/troff/mmac"
19# endif
20
21# define ever (;;)
22
23main(argc,argv)
24 char *argv[];
25{
26# ifdef unix
27int badsig();
28signal(SIGPIPE, badsig);
29# endif
30# ifdef gcos
31if(!intss()) tabout = fopen("qq", "w"); /* default media code is type 5 */
32# endif
33exit(tbl(argc,argv));
34}
35
36
37tbl(argc,argv)
38 char *argv[];
39{
40char line[512];
41/* required by GCOS because "stdout" is set by troff preprocessor */
42tabin=stdin; tabout=stdout;
43setinp(argc,argv);
44while (gets1(line))
45 {
46 fprintf(tabout, "%s\n",line);
47 if (prefix(".TS", line))
48 tableput();
49 }
50fclose(tabin);
51return(0);
52}
53int sargc;
54char **sargv;
55setinp(argc,argv)
56 char **argv;
57{
58 sargc = argc;
59 sargv = argv;
60 sargc--; sargv++;
61 if (sargc>0)
62 swapin();
63}
64swapin()
65{
66 while (sargc>0 && **sargv=='-')
67 {
68 if (match("-ms", *sargv))
69 {
70 *sargv = MACROS;
71 break;
72 }
73 if (match("-mm", *sargv))
74 {
75 *sargv = PYMACS;
76 break;
77 }
78 if (match("-TX", *sargv))
79 pr1403=1;
80 sargc--; sargv++;
81 }
82 if (sargc<=0) return(0);
83# ifdef unix
84/* file closing is done by GCOS troff preprocessor */
85 if (tabin!=stdin) fclose(tabin);
86# endif
87 tabin = fopen(ifile= *sargv, "r");
88 iline=1;
89# ifdef unix
90/* file names are all put into f. by the GCOS troff preprocessor */
91 fprintf(tabout, ".ds f. %s\n",ifile);
92# endif
93 if (tabin==NULL)
94 error("Can't open file");
95 sargc--;
96 sargv++;
97 return(1);
98}
99# ifdef unix
100badsig()
101{
102signal(SIGPIPE, 1);
103 exit(0);
104}
105# endif