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