xref: /illumos-gate/usr/src/cmd/tbl/t1.c (revision 6dde88b51419b99fe0aab8e56184c693945826b8)
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  /* t1.c: main control and input switching */
16 #
17 #include <locale.h>
18 # include "t..c"
19 #include <signal.h>
20 #include <stdlib.h>
21 
22 # ifdef gcos
23 /* required by GCOS because file is passed to "tbl" by troff preprocessor */
24 # define _f1 _f
25 extern FILE *_f[];
26 # endif
27 
28 # ifdef unix
29 # define MACROS "/usr/doctools/tmac/tmac.s"
30 # define MACROSS "/usr/share/lib/tmac/s"
31 # define PYMACS "/usr/doctools/tmac/tmac.m"
32 # define PYMACSS "/usr/share/lib/tmac/m"
33 # define MEMACSS "/usr/share/lib/tmac/e"
34 # endif
35 
36 # ifdef gcos
37 # define MACROS "cc/troff/smac"
38 # define PYMACS "cc/troff/mmac"
39 # endif
40 
41 # define ever (;;)
42 
43 void	setinp(int, char **);
44 
45 int
46 main(int argc, char **argv)
47 {
48 # ifdef unix
49 void badsig();
50 # endif
51 	(void) setlocale(LC_ALL, "");
52 #if !defined(TEXT_DOMAIN)
53 #define TEXT_DOMAIN "SYS_TEST"
54 #endif
55 	(void) textdomain(TEXT_DOMAIN);
56 # ifdef unix
57 signal(SIGPIPE, badsig);
58 # endif
59 # ifdef gcos
60 if(!intss()) tabout = fopen("qq", "w"); /* default media code is type 5 */
61 # endif
62 exit(tbl(argc,argv));
63 }
64 
65 int
66 tbl(int argc, 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 
82 int sargc;
83 char **sargv;
84 
85 void
86 setinp(int argc, char **argv)
87 {
88 	sargc = argc;
89 	sargv = argv;
90 	sargc--; sargv++;
91 	if (sargc>0)
92 		swapin();
93 }
94 
95 int
96 swapin(void)
97 {
98 	while (sargc>0 && **sargv=='-') /* Mem fault if no test on sargc */
99 		{
100 		if (sargc<=0) return(0);
101 		if (match("-me", *sargv))
102 			{
103 			*sargv = MEMACSS;
104 			break;
105 			}
106 		if (match("-ms", *sargv))
107 			{
108 			*sargv = MACROSS;
109 			break;
110 			}
111 		if (match("-mm", *sargv))
112 			{
113 			*sargv = PYMACSS;
114 			break;
115 			}
116 		if (match("-TX", *sargv))
117 			pr1403=1;
118 		else {
119 			(void) fprintf(stderr, gettext("tbl: Invalid option "
120 			    "(%s).\n"), *sargv);
121 			(void) fprintf(stderr, gettext("Usage: tbl [ -me ] "
122 			    "[ -mm ] [ -ms ] [ filename ] ...\n"));
123 			exit(1);
124 		}
125 		sargc--; sargv++;
126 		}
127 	if (sargc<=0) return(0);
128 # ifdef unix
129 /* file closing is done by GCOS troff preprocessor */
130 	if (tabin!=stdin) fclose(tabin);
131 # endif
132 	tabin = fopen(ifile= *sargv, "r");
133 	iline=1;
134 # ifdef unix
135 /* file names are all put into f. by the GCOS troff preprocessor */
136 	fprintf(tabout, ".ds f. %s\n",ifile);
137 # endif
138 	if (tabin==NULL)
139 		error(gettext("Can't open file"));
140 	sargc--;
141 	sargv++;
142 	return(1);
143 }
144 
145 # ifdef unix
146 void
147 badsig(void)
148 {
149 signal(SIGPIPE, SIG_IGN);
150  exit(0);
151 }
152 # endif
153