xref: /onnv-gate/usr/src/cmd/tbl/t1.c (revision 381:1a7f0e46092a)
1*381Smuffin /*
2*381Smuffin  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
3*381Smuffin  * Use is subject to license terms.
4*381Smuffin  */
5*381Smuffin 
6*381Smuffin /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
70Sstevel@tonic-gate /*	  All Rights Reserved  	*/
80Sstevel@tonic-gate 
90Sstevel@tonic-gate /*
100Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
110Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
120Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
130Sstevel@tonic-gate  */
140Sstevel@tonic-gate 
15*381Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
160Sstevel@tonic-gate 
170Sstevel@tonic-gate  /* t1.c: main control and input switching */
180Sstevel@tonic-gate #
190Sstevel@tonic-gate #include <locale.h>
200Sstevel@tonic-gate # include "t..c"
210Sstevel@tonic-gate #include <signal.h>
22*381Smuffin #include <stdlib.h>
23*381Smuffin 
240Sstevel@tonic-gate # ifdef gcos
250Sstevel@tonic-gate /* required by GCOS because file is passed to "tbl" by troff preprocessor */
260Sstevel@tonic-gate # define _f1 _f
270Sstevel@tonic-gate extern FILE *_f[];
280Sstevel@tonic-gate # endif
290Sstevel@tonic-gate 
300Sstevel@tonic-gate # ifdef unix
310Sstevel@tonic-gate # define MACROS "/usr/doctools/tmac/tmac.s"
320Sstevel@tonic-gate # define MACROSS "/usr/share/lib/tmac/s"
330Sstevel@tonic-gate # define PYMACS "/usr/doctools/tmac/tmac.m"
340Sstevel@tonic-gate # define PYMACSS "/usr/share/lib/tmac/m"
350Sstevel@tonic-gate # define MEMACSS "/usr/share/lib/tmac/e"
360Sstevel@tonic-gate # endif
370Sstevel@tonic-gate 
380Sstevel@tonic-gate # ifdef gcos
390Sstevel@tonic-gate # define MACROS "cc/troff/smac"
400Sstevel@tonic-gate # define PYMACS "cc/troff/mmac"
410Sstevel@tonic-gate # endif
420Sstevel@tonic-gate 
430Sstevel@tonic-gate # define ever (;;)
440Sstevel@tonic-gate 
45*381Smuffin void	setinp(int, char **);
46*381Smuffin 
47*381Smuffin int
main(int argc,char ** argv)48*381Smuffin main(int argc, char **argv)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate # ifdef unix
510Sstevel@tonic-gate void badsig();
520Sstevel@tonic-gate # endif
530Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
540Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
550Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
560Sstevel@tonic-gate #endif
570Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
580Sstevel@tonic-gate # ifdef unix
590Sstevel@tonic-gate signal(SIGPIPE, badsig);
600Sstevel@tonic-gate # endif
610Sstevel@tonic-gate # ifdef gcos
620Sstevel@tonic-gate if(!intss()) tabout = fopen("qq", "w"); /* default media code is type 5 */
630Sstevel@tonic-gate # endif
640Sstevel@tonic-gate exit(tbl(argc,argv));
650Sstevel@tonic-gate }
660Sstevel@tonic-gate 
67*381Smuffin int
tbl(int argc,char ** argv)68*381Smuffin tbl(int argc, char **argv)
690Sstevel@tonic-gate {
700Sstevel@tonic-gate char line[BIGBUF];
710Sstevel@tonic-gate /* required by GCOS because "stdout" is set by troff preprocessor */
720Sstevel@tonic-gate tabin=stdin; tabout=stdout;
730Sstevel@tonic-gate setinp(argc,argv);
740Sstevel@tonic-gate while (gets1(line, sizeof line))
750Sstevel@tonic-gate 	{
760Sstevel@tonic-gate 	fprintf(tabout, "%s\n",line);
770Sstevel@tonic-gate 	if (prefix(".TS", line))
780Sstevel@tonic-gate 		tableput();
790Sstevel@tonic-gate 	}
800Sstevel@tonic-gate fclose(tabin);
810Sstevel@tonic-gate return(0);
820Sstevel@tonic-gate }
83*381Smuffin 
840Sstevel@tonic-gate int sargc;
850Sstevel@tonic-gate char **sargv;
86*381Smuffin 
87*381Smuffin void
setinp(int argc,char ** argv)88*381Smuffin setinp(int argc, char **argv)
890Sstevel@tonic-gate {
900Sstevel@tonic-gate 	sargc = argc;
910Sstevel@tonic-gate 	sargv = argv;
920Sstevel@tonic-gate 	sargc--; sargv++;
930Sstevel@tonic-gate 	if (sargc>0)
940Sstevel@tonic-gate 		swapin();
950Sstevel@tonic-gate }
96*381Smuffin 
97*381Smuffin int
swapin(void)98*381Smuffin swapin(void)
990Sstevel@tonic-gate {
1000Sstevel@tonic-gate 	while (sargc>0 && **sargv=='-') /* Mem fault if no test on sargc */
1010Sstevel@tonic-gate 		{
1020Sstevel@tonic-gate 		if (sargc<=0) return(0);
1030Sstevel@tonic-gate 		if (match("-me", *sargv))
1040Sstevel@tonic-gate 			{
1050Sstevel@tonic-gate 			*sargv = MEMACSS;
1060Sstevel@tonic-gate 			break;
1070Sstevel@tonic-gate 			}
1080Sstevel@tonic-gate 		if (match("-ms", *sargv))
1090Sstevel@tonic-gate 			{
1100Sstevel@tonic-gate 			*sargv = MACROSS;
1110Sstevel@tonic-gate 			break;
1120Sstevel@tonic-gate 			}
1130Sstevel@tonic-gate 		if (match("-mm", *sargv))
1140Sstevel@tonic-gate 			{
1150Sstevel@tonic-gate 			*sargv = PYMACSS;
1160Sstevel@tonic-gate 			break;
1170Sstevel@tonic-gate 			}
1180Sstevel@tonic-gate 		if (match("-TX", *sargv))
1190Sstevel@tonic-gate 			pr1403=1;
1200Sstevel@tonic-gate 		else {
1210Sstevel@tonic-gate 			(void) fprintf(stderr, gettext("tbl: Invalid option "
1220Sstevel@tonic-gate 			    "(%s).\n"), *sargv);
1230Sstevel@tonic-gate 			(void) fprintf(stderr, gettext("Usage: tbl [ -me ] "
1240Sstevel@tonic-gate 			    "[ -mm ] [ -ms ] [ filename ] ...\n"));
1250Sstevel@tonic-gate 			exit(1);
1260Sstevel@tonic-gate 		}
1270Sstevel@tonic-gate 		sargc--; sargv++;
1280Sstevel@tonic-gate 		}
1290Sstevel@tonic-gate 	if (sargc<=0) return(0);
1300Sstevel@tonic-gate # ifdef unix
1310Sstevel@tonic-gate /* file closing is done by GCOS troff preprocessor */
1320Sstevel@tonic-gate 	if (tabin!=stdin) fclose(tabin);
1330Sstevel@tonic-gate # endif
1340Sstevel@tonic-gate 	tabin = fopen(ifile= *sargv, "r");
1350Sstevel@tonic-gate 	iline=1;
1360Sstevel@tonic-gate # ifdef unix
1370Sstevel@tonic-gate /* file names are all put into f. by the GCOS troff preprocessor */
1380Sstevel@tonic-gate 	fprintf(tabout, ".ds f. %s\n",ifile);
1390Sstevel@tonic-gate # endif
1400Sstevel@tonic-gate 	if (tabin==NULL)
1410Sstevel@tonic-gate 		error(gettext("Can't open file"));
1420Sstevel@tonic-gate 	sargc--;
1430Sstevel@tonic-gate 	sargv++;
1440Sstevel@tonic-gate 	return(1);
1450Sstevel@tonic-gate }
146*381Smuffin 
1470Sstevel@tonic-gate # ifdef unix
148*381Smuffin void
badsig(void)149*381Smuffin badsig(void)
1500Sstevel@tonic-gate {
1510Sstevel@tonic-gate signal(SIGPIPE, SIG_IGN);
1520Sstevel@tonic-gate  exit(0);
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate # endif
155