xref: /illumos-gate/usr/src/cmd/tbl/t1.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*	Co/pyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2 /*	  All Rights Reserved  	*/
3 
4 
5 /*
6  * Copyright (c) 1980 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 /*
12  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13  * All Rights Reserved.
14  */
15 
16 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
17 
18  /* t1.c: main control and input switching */
19 #
20 #include <locale.h>
21 # include "t..c"
22 #include <signal.h>
23 # ifdef gcos
24 /* required by GCOS because file is passed to "tbl" by troff preprocessor */
25 # define _f1 _f
26 extern FILE *_f[];
27 # endif
28 
29 # ifdef unix
30 # define MACROS "/usr/doctools/tmac/tmac.s"
31 # define MACROSS "/usr/share/lib/tmac/s"
32 # define PYMACS "/usr/doctools/tmac/tmac.m"
33 # define PYMACSS "/usr/share/lib/tmac/m"
34 # define MEMACSS "/usr/share/lib/tmac/e"
35 # endif
36 
37 # ifdef gcos
38 # define MACROS "cc/troff/smac"
39 # define PYMACS "cc/troff/mmac"
40 # endif
41 
42 # define ever (;;)
43 
44 main(argc,argv)
45 	char *argv[];
46 {
47 # ifdef unix
48 void badsig();
49 # endif
50 	(void) setlocale(LC_ALL, "");
51 #if !defined(TEXT_DOMAIN)
52 #define TEXT_DOMAIN "SYS_TEST"
53 #endif
54 	(void) textdomain(TEXT_DOMAIN);
55 # ifdef unix
56 signal(SIGPIPE, badsig);
57 # endif
58 # ifdef gcos
59 if(!intss()) tabout = fopen("qq", "w"); /* default media code is type 5 */
60 # endif
61 exit(tbl(argc,argv));
62 }
63 
64 
65 tbl(argc,argv)
66 	char *argv[];
67 {
68 char line[BIGBUF];
69 /* required by GCOS because "stdout" is set by troff preprocessor */
70 tabin=stdin; tabout=stdout;
71 setinp(argc,argv);
72 while (gets1(line, sizeof line))
73 	{
74 	fprintf(tabout, "%s\n",line);
75 	if (prefix(".TS", line))
76 		tableput();
77 	}
78 fclose(tabin);
79 return(0);
80 }
81 int sargc;
82 char **sargv;
83 setinp(argc,argv)
84 	char **argv;
85 {
86 	sargc = argc;
87 	sargv = argv;
88 	sargc--; sargv++;
89 	if (sargc>0)
90 		swapin();
91 }
92 swapin()
93 {
94 	while (sargc>0 && **sargv=='-') /* Mem fault if no test on sargc */
95 		{
96 		if (sargc<=0) return(0);
97 		if (match("-me", *sargv))
98 			{
99 			*sargv = MEMACSS;
100 			break;
101 			}
102 		if (match("-ms", *sargv))
103 			{
104 			*sargv = MACROSS;
105 			break;
106 			}
107 		if (match("-mm", *sargv))
108 			{
109 			*sargv = PYMACSS;
110 			break;
111 			}
112 		if (match("-TX", *sargv))
113 			pr1403=1;
114 		else {
115 			(void) fprintf(stderr, gettext("tbl: Invalid option "
116 			    "(%s).\n"), *sargv);
117 			(void) fprintf(stderr, gettext("Usage: tbl [ -me ] "
118 			    "[ -mm ] [ -ms ] [ filename ] ...\n"));
119 			exit(1);
120 		}
121 		sargc--; sargv++;
122 		}
123 	if (sargc<=0) return(0);
124 # ifdef unix
125 /* file closing is done by GCOS troff preprocessor */
126 	if (tabin!=stdin) fclose(tabin);
127 # endif
128 	tabin = fopen(ifile= *sargv, "r");
129 	iline=1;
130 # ifdef unix
131 /* file names are all put into f. by the GCOS troff preprocessor */
132 	fprintf(tabout, ".ds f. %s\n",ifile);
133 # endif
134 	if (tabin==NULL)
135 		error(gettext("Can't open file"));
136 	sargc--;
137 	sargv++;
138 	return(1);
139 }
140 # ifdef unix
141 void badsig()
142 {
143 signal(SIGPIPE, SIG_IGN);
144  exit(0);
145 }
146 # endif
147