8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / tbl / te.c
blob56ad4e102d5dc1efeccf8f1b79e4bf029a872711
1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
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.
15 #pragma ident "%Z%%M% %I% %E% SMI"
17 /* te.c: error message control, input line count */
18 #include "t..c"
19 #include <locale.h>
20 #include <errno.h>
21 #include <unistd.h>
22 #include <string.h>
24 void
25 error(char *s)
27 (void) fprintf(stderr, gettext("\n%s: line %d: %s\n"), ifile, iline, s);
28 (void) fprintf(stderr, gettext("tbl quits\n"));
29 exit(1);
32 char *
33 gets1(char *s, int len)
35 char *p;
36 int nbl;
37 while(len > 0)
39 iline++;
40 while ((p = fgets(s,len,tabin))==0)
42 if (swapin()==0)
43 return((char *)0);
46 while (*s) s++;
47 s--;
48 if (*s == '\n') {
49 *s-- = '\0';
50 } else {
51 if (!feof(tabin)) {
52 if (ferror(tabin))
53 error(strerror(errno));
54 else
55 error(gettext("Line too long"));
59 for(nbl=0; *s == '\\' && s>p; s--)
60 nbl++;
61 if (linstart && nbl % 2) /* fold escaped nl if in table */
63 s++;
64 len -= s - p;
65 continue;
67 break;
70 return(p);
73 # define BACKMAX 500
75 char backup[BACKMAX];
76 char *backp = backup;
78 void
79 un1getc(int c)
81 if (c=='\n')
82 iline--;
83 *backp++ = c;
84 if (backp >= backup+BACKMAX)
85 error(gettext("too much backup"));
88 int
89 get1char(void)
91 int c;
92 if (backp>backup)
93 c = *--backp;
94 else
95 c=getc(tabin);
96 if (c== EOF) /* EOF */
98 if (swapin() ==0)
99 error(gettext("unexpected EOF"));
100 c = getc(tabin);
102 if (c== '\n')
103 iline++;
104 return(c);