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