new copyright; att/bsd/shared
[unix-history] / usr / src / usr.bin / struct / struct / 1.line.c
CommitLineData
0fc6e47b
KB
1/*-
2 * %sccs.include.proprietary.c%
3 */
4
264a0334 5#ifndef lint
0fc6e47b
KB
6static char sccsid[] = "@(#)1.line.c 4.2 (Berkeley) %G%";
7#endif /* not lint */
264a0334
RH
8
9#include <stdio.h>
10#
11#include "def.h"
12#define bufsize 1601
13char buffer[bufsize];
14int bufcount;
15extern int errflag;
16long stchars; /* counts number of chars at most recent \n read */
17#ifndef unix
18long ostchars;
19extern long ftell();
20#endif
21int newline; /* counts number of lines read so far in file */
22extern int rdfree(), comfree(),labfree(), contfree();
23extern int rdstand(), comstand(), labstand(), contstand();
24extern int (*rline[])();
25extern int (*comment[])();
26extern int (*getlabel[])();
27extern int (*chkcont[])();
28
29
30
31flush()
32 {bufcount = 0; }
33
34addchar(c)
35 {
36 buffer[bufcount++] = c;
37 }
38
39getline(lastline,lastchar,linecom,charcom)
40int *lastline, *linecom;
41long *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;
70if (debug == 40)
71fprintf(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
82int linechars; /* counts number of chars read so far in current line */
83long newchar; /* counts number of chars read so far in file */
84
85
86input1()
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
105unput1(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