1 /*-
2 * %sccs.include.proprietary.c%
3 */
4
5 #ifndef lint
6 static char sccsid[] = "@(#)1.line.c 8.1 (Berkeley) 06/06/93";
7 #endif /* not lint */
8
9 #include <stdio.h>
10 #
11 #include "def.h"
12 #define bufsize 1601
13 char buffer[bufsize];
14 int bufcount;
15 extern int errflag;
16 long stchars; /* counts number of chars at most recent \n read */
17 #ifndef unix
18 long ostchars;
19 extern long ftell();
20 #endif
21 int newline; /* counts number of lines read so far in file */
22 extern int rdfree(), comfree(),labfree(), contfree();
23 extern int rdstand(), comstand(), labstand(), contstand();
24 extern int (*rline[])();
25 extern int (*comment[])();
26 extern int (*getlabel[])();
27 extern int (*chkcont[])();
28
29
30
flush()31 flush()
32 {bufcount = 0; }
33
addchar(c)34 addchar(c)
35 {
36 buffer[bufcount++] = c;
37 }
38
getline(lastline,lastchar,linecom,charcom)39 getline(lastline,lastchar,linecom,charcom)
40 int *lastline, *linecom;
41 long *lastchar, *charcom;
42 /* set *lastline to number of last line of statement,
43 set *lastchar to number of last char of statement,
44 set *linecom to number of last line of comment preceding statement */
45 {
46
47 int i;
48 flush();
49 while ( unput1(input1()) != EOF)
50 {
51 while ( (*comment[inputform])(0) || blankline() )
52 {
53 (*rline[inputform])(addchar);
54 flush();
55 }
56 *linecom = newline;
57 /* set charcom to number of last char of comment, starting at 0
58 if at start of file and no comment, will be -1 */
59 *charcom = stchars - 1;
60 if (unput1(input1()) == EOF) break;
61 (*getlabel[inputform])(addchar);
62 (*rline[inputform])(addchar);
63
64 while ( blankline() || ( !(*comment[inputform])(0) && (*chkcont[inputform])() ))
65 (*rline[inputform])(addchar);
66
67 addchar('\0');
68 *lastline = newline;
69 *lastchar = stchars - 1;
70 if (debug == 40)
71 fprintf(stderr,"line %d; bufcount: %d\n",newline,bufcount);
72
73 for (i = 5; i < bufcount; ++i)
74 if (buffer[i] == ' ' || buffer[i] == '\t' || buffer[i] == '\n')
75 buffer[i] = '~';
76 return(bufcount);
77 }
78 return(-1);
79 }
80
81
82 int linechars; /* counts number of chars read so far in current line */
83 long newchar; /* counts number of chars read so far in file */
84
85
input1()86 input1()
87 {
88 static int c;
89 if (c == '\n') linechars = 0;
90 c = inchar();
91 ++linechars;
92 ++newchar;
93 if (c == '\n')
94 {
95 ++newline;
96 #ifdef unix
97 stchars = newchar;
98 #else
99 ostchars=stchars; stchars=ftell(infd);
100 #endif
101 }
102 return(c);
103 }
104
unput1(c)105 unput1(c)
106 {
107 --linechars;
108 --newchar;
109 unchar(c);
110 if (c == '\n')
111 {
112 #ifdef unix
113 stchars = newchar;
114 #else
115 stchars=ostchars;
116 #endif
117 --newline;
118 }
119 return(c);
120 }
121
122
123
124
125