xref: /titanic_51/usr/src/cmd/tbl/t1.c (revision b55148877d473978f0b46d593fd6213fa526fcc5)
1*b5514887Smuffin /*
2*b5514887Smuffin  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
3*b5514887Smuffin  * Use is subject to license terms.
4*b5514887Smuffin  */
57c478bd9Sstevel@tonic-gate 
6*b5514887Smuffin /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
7*b5514887Smuffin /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
15*b5514887Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate  /* t1.c: main control and input switching */
187c478bd9Sstevel@tonic-gate #
197c478bd9Sstevel@tonic-gate #include <locale.h>
207c478bd9Sstevel@tonic-gate # include "t..c"
217c478bd9Sstevel@tonic-gate #include <signal.h>
22*b5514887Smuffin #include <stdlib.h>
23*b5514887Smuffin 
247c478bd9Sstevel@tonic-gate # ifdef gcos
257c478bd9Sstevel@tonic-gate /* required by GCOS because file is passed to "tbl" by troff preprocessor */
267c478bd9Sstevel@tonic-gate # define _f1 _f
277c478bd9Sstevel@tonic-gate extern FILE *_f[];
287c478bd9Sstevel@tonic-gate # endif
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate # ifdef unix
317c478bd9Sstevel@tonic-gate # define MACROS "/usr/doctools/tmac/tmac.s"
327c478bd9Sstevel@tonic-gate # define MACROSS "/usr/share/lib/tmac/s"
337c478bd9Sstevel@tonic-gate # define PYMACS "/usr/doctools/tmac/tmac.m"
347c478bd9Sstevel@tonic-gate # define PYMACSS "/usr/share/lib/tmac/m"
357c478bd9Sstevel@tonic-gate # define MEMACSS "/usr/share/lib/tmac/e"
367c478bd9Sstevel@tonic-gate # endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate # ifdef gcos
397c478bd9Sstevel@tonic-gate # define MACROS "cc/troff/smac"
407c478bd9Sstevel@tonic-gate # define PYMACS "cc/troff/mmac"
417c478bd9Sstevel@tonic-gate # endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate # define ever (;;)
447c478bd9Sstevel@tonic-gate 
45*b5514887Smuffin void	setinp(int, char **);
46*b5514887Smuffin 
47*b5514887Smuffin int
48*b5514887Smuffin main(int argc, char **argv)
497c478bd9Sstevel@tonic-gate {
507c478bd9Sstevel@tonic-gate # ifdef unix
517c478bd9Sstevel@tonic-gate void badsig();
527c478bd9Sstevel@tonic-gate # endif
537c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
547c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
557c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
567c478bd9Sstevel@tonic-gate #endif
577c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
587c478bd9Sstevel@tonic-gate # ifdef unix
597c478bd9Sstevel@tonic-gate signal(SIGPIPE, badsig);
607c478bd9Sstevel@tonic-gate # endif
617c478bd9Sstevel@tonic-gate # ifdef gcos
627c478bd9Sstevel@tonic-gate if(!intss()) tabout = fopen("qq", "w"); /* default media code is type 5 */
637c478bd9Sstevel@tonic-gate # endif
647c478bd9Sstevel@tonic-gate exit(tbl(argc,argv));
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate 
67*b5514887Smuffin int
68*b5514887Smuffin tbl(int argc, char **argv)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate char line[BIGBUF];
717c478bd9Sstevel@tonic-gate /* required by GCOS because "stdout" is set by troff preprocessor */
727c478bd9Sstevel@tonic-gate tabin=stdin; tabout=stdout;
737c478bd9Sstevel@tonic-gate setinp(argc,argv);
747c478bd9Sstevel@tonic-gate while (gets1(line, sizeof line))
757c478bd9Sstevel@tonic-gate 	{
767c478bd9Sstevel@tonic-gate 	fprintf(tabout, "%s\n",line);
777c478bd9Sstevel@tonic-gate 	if (prefix(".TS", line))
787c478bd9Sstevel@tonic-gate 		tableput();
797c478bd9Sstevel@tonic-gate 	}
807c478bd9Sstevel@tonic-gate fclose(tabin);
817c478bd9Sstevel@tonic-gate return(0);
827c478bd9Sstevel@tonic-gate }
83*b5514887Smuffin 
847c478bd9Sstevel@tonic-gate int sargc;
857c478bd9Sstevel@tonic-gate char **sargv;
86*b5514887Smuffin 
87*b5514887Smuffin void
88*b5514887Smuffin setinp(int argc, char **argv)
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate 	sargc = argc;
917c478bd9Sstevel@tonic-gate 	sargv = argv;
927c478bd9Sstevel@tonic-gate 	sargc--; sargv++;
937c478bd9Sstevel@tonic-gate 	if (sargc>0)
947c478bd9Sstevel@tonic-gate 		swapin();
957c478bd9Sstevel@tonic-gate }
96*b5514887Smuffin 
97*b5514887Smuffin int
98*b5514887Smuffin swapin(void)
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate 	while (sargc>0 && **sargv=='-') /* Mem fault if no test on sargc */
1017c478bd9Sstevel@tonic-gate 		{
1027c478bd9Sstevel@tonic-gate 		if (sargc<=0) return(0);
1037c478bd9Sstevel@tonic-gate 		if (match("-me", *sargv))
1047c478bd9Sstevel@tonic-gate 			{
1057c478bd9Sstevel@tonic-gate 			*sargv = MEMACSS;
1067c478bd9Sstevel@tonic-gate 			break;
1077c478bd9Sstevel@tonic-gate 			}
1087c478bd9Sstevel@tonic-gate 		if (match("-ms", *sargv))
1097c478bd9Sstevel@tonic-gate 			{
1107c478bd9Sstevel@tonic-gate 			*sargv = MACROSS;
1117c478bd9Sstevel@tonic-gate 			break;
1127c478bd9Sstevel@tonic-gate 			}
1137c478bd9Sstevel@tonic-gate 		if (match("-mm", *sargv))
1147c478bd9Sstevel@tonic-gate 			{
1157c478bd9Sstevel@tonic-gate 			*sargv = PYMACSS;
1167c478bd9Sstevel@tonic-gate 			break;
1177c478bd9Sstevel@tonic-gate 			}
1187c478bd9Sstevel@tonic-gate 		if (match("-TX", *sargv))
1197c478bd9Sstevel@tonic-gate 			pr1403=1;
1207c478bd9Sstevel@tonic-gate 		else {
1217c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext("tbl: Invalid option "
1227c478bd9Sstevel@tonic-gate 			    "(%s).\n"), *sargv);
1237c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext("Usage: tbl [ -me ] "
1247c478bd9Sstevel@tonic-gate 			    "[ -mm ] [ -ms ] [ filename ] ...\n"));
1257c478bd9Sstevel@tonic-gate 			exit(1);
1267c478bd9Sstevel@tonic-gate 		}
1277c478bd9Sstevel@tonic-gate 		sargc--; sargv++;
1287c478bd9Sstevel@tonic-gate 		}
1297c478bd9Sstevel@tonic-gate 	if (sargc<=0) return(0);
1307c478bd9Sstevel@tonic-gate # ifdef unix
1317c478bd9Sstevel@tonic-gate /* file closing is done by GCOS troff preprocessor */
1327c478bd9Sstevel@tonic-gate 	if (tabin!=stdin) fclose(tabin);
1337c478bd9Sstevel@tonic-gate # endif
1347c478bd9Sstevel@tonic-gate 	tabin = fopen(ifile= *sargv, "r");
1357c478bd9Sstevel@tonic-gate 	iline=1;
1367c478bd9Sstevel@tonic-gate # ifdef unix
1377c478bd9Sstevel@tonic-gate /* file names are all put into f. by the GCOS troff preprocessor */
1387c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".ds f. %s\n",ifile);
1397c478bd9Sstevel@tonic-gate # endif
1407c478bd9Sstevel@tonic-gate 	if (tabin==NULL)
1417c478bd9Sstevel@tonic-gate 		error(gettext("Can't open file"));
1427c478bd9Sstevel@tonic-gate 	sargc--;
1437c478bd9Sstevel@tonic-gate 	sargv++;
1447c478bd9Sstevel@tonic-gate 	return(1);
1457c478bd9Sstevel@tonic-gate }
146*b5514887Smuffin 
1477c478bd9Sstevel@tonic-gate # ifdef unix
148*b5514887Smuffin void
149*b5514887Smuffin badsig(void)
1507c478bd9Sstevel@tonic-gate {
1517c478bd9Sstevel@tonic-gate signal(SIGPIPE, SIG_IGN);
1527c478bd9Sstevel@tonic-gate  exit(0);
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate # endif
155