1*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2*0Sstevel@tonic-gate /* All Rights Reserved */ 3*0Sstevel@tonic-gate 4*0Sstevel@tonic-gate 5*0Sstevel@tonic-gate /* 6*0Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 7*0Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 8*0Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 9*0Sstevel@tonic-gate */ 10*0Sstevel@tonic-gate 11*0Sstevel@tonic-gate /* 12*0Sstevel@tonic-gate * Copyright 1983-1988,2003 Sun Microsystems, Inc. All rights reserved. 13*0Sstevel@tonic-gate * Use is subject to license terms. 14*0Sstevel@tonic-gate */ 15*0Sstevel@tonic-gate 16*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gate /* te.c: error message control, input line count */ 19*0Sstevel@tonic-gate # include "t..c" 20*0Sstevel@tonic-gate # include <locale.h> 21*0Sstevel@tonic-gate # include <errno.h> 22*0Sstevel@tonic-gate error(s) 23*0Sstevel@tonic-gate char *s; 24*0Sstevel@tonic-gate { 25*0Sstevel@tonic-gate fprintf(stderr, gettext("\n%s: line %d: %s\n"), ifile, iline, s); 26*0Sstevel@tonic-gate # ifdef unix 27*0Sstevel@tonic-gate fprintf(stderr, gettext("tbl quits\n")); 28*0Sstevel@tonic-gate exit(1); 29*0Sstevel@tonic-gate # endif 30*0Sstevel@tonic-gate # ifdef gcos 31*0Sstevel@tonic-gate fprintf(stderr, "run terminated due to error condition detected by tbl preprocessor\n"); 32*0Sstevel@tonic-gate exit(0); 33*0Sstevel@tonic-gate # endif 34*0Sstevel@tonic-gate } 35*0Sstevel@tonic-gate char * 36*0Sstevel@tonic-gate errmsg(errnum) 37*0Sstevel@tonic-gate int errnum; 38*0Sstevel@tonic-gate { 39*0Sstevel@tonic-gate extern int sys_nerr; 40*0Sstevel@tonic-gate extern char *sys_errlist[]; 41*0Sstevel@tonic-gate static char errmsgbuf[18]; 42*0Sstevel@tonic-gate if (errnum > sys_nerr) 43*0Sstevel@tonic-gate { 44*0Sstevel@tonic-gate sprintf(errmsgbuf, "Error %d", errnum); 45*0Sstevel@tonic-gate return (errmsgbuf); 46*0Sstevel@tonic-gate } 47*0Sstevel@tonic-gate else 48*0Sstevel@tonic-gate return (sys_errlist[errnum]); 49*0Sstevel@tonic-gate } 50*0Sstevel@tonic-gate char * 51*0Sstevel@tonic-gate gets1(s, len) 52*0Sstevel@tonic-gate char *s; 53*0Sstevel@tonic-gate int len; 54*0Sstevel@tonic-gate { 55*0Sstevel@tonic-gate char *p; 56*0Sstevel@tonic-gate int nbl; 57*0Sstevel@tonic-gate while(len > 0) 58*0Sstevel@tonic-gate { 59*0Sstevel@tonic-gate iline++; 60*0Sstevel@tonic-gate while ((p = fgets(s,len,tabin))==0) 61*0Sstevel@tonic-gate { 62*0Sstevel@tonic-gate if (swapin()==0) 63*0Sstevel@tonic-gate return(0); 64*0Sstevel@tonic-gate } 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate while (*s) s++; 67*0Sstevel@tonic-gate s--; 68*0Sstevel@tonic-gate if (*s == '\n') *s-- =0; 69*0Sstevel@tonic-gate else 70*0Sstevel@tonic-gate { 71*0Sstevel@tonic-gate if (!feof(tabin)) 72*0Sstevel@tonic-gate { 73*0Sstevel@tonic-gate if (ferror(tabin)) 74*0Sstevel@tonic-gate error(errmsg(errno)); 75*0Sstevel@tonic-gate else 76*0Sstevel@tonic-gate error(gettext("Line too long")); 77*0Sstevel@tonic-gate } 78*0Sstevel@tonic-gate } 79*0Sstevel@tonic-gate for(nbl=0; *s == '\\' && s>p; s--) 80*0Sstevel@tonic-gate nbl++; 81*0Sstevel@tonic-gate if (linstart && nbl % 2) /* fold escaped nl if in table */ 82*0Sstevel@tonic-gate { 83*0Sstevel@tonic-gate s++; 84*0Sstevel@tonic-gate len -= s - p; 85*0Sstevel@tonic-gate continue; 86*0Sstevel@tonic-gate } 87*0Sstevel@tonic-gate break; 88*0Sstevel@tonic-gate } 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate return(p); 91*0Sstevel@tonic-gate } 92*0Sstevel@tonic-gate # define BACKMAX 500 93*0Sstevel@tonic-gate char backup[BACKMAX]; 94*0Sstevel@tonic-gate char *backp = backup; 95*0Sstevel@tonic-gate un1getc(c) 96*0Sstevel@tonic-gate { 97*0Sstevel@tonic-gate if (c=='\n') 98*0Sstevel@tonic-gate iline--; 99*0Sstevel@tonic-gate *backp++ = c; 100*0Sstevel@tonic-gate if (backp >= backup+BACKMAX) 101*0Sstevel@tonic-gate error(gettext("too much backup")); 102*0Sstevel@tonic-gate } 103*0Sstevel@tonic-gate get1char() 104*0Sstevel@tonic-gate { 105*0Sstevel@tonic-gate int c; 106*0Sstevel@tonic-gate if (backp>backup) 107*0Sstevel@tonic-gate c = *--backp; 108*0Sstevel@tonic-gate else 109*0Sstevel@tonic-gate c=getc(tabin); 110*0Sstevel@tonic-gate if (c== EOF) /* EOF */ 111*0Sstevel@tonic-gate { 112*0Sstevel@tonic-gate if (swapin() ==0) 113*0Sstevel@tonic-gate error(gettext("unexpected EOF")); 114*0Sstevel@tonic-gate c = getc(tabin); 115*0Sstevel@tonic-gate } 116*0Sstevel@tonic-gate if (c== '\n') 117*0Sstevel@tonic-gate iline++; 118*0Sstevel@tonic-gate return(c); 119*0Sstevel@tonic-gate } 120