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