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