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