new copyright; att/bsd/shared
[unix-history] / usr / src / usr.bin / struct / struct / 1.form.c
CommitLineData
0fc6e47b
KB
1/*-
2 * %sccs.include.proprietary.c%
3 */
4
0804b2a5 5#ifndef lint
0fc6e47b
KB
6static char sccsid[] = "@(#)1.form.c 4.3 (Berkeley) %G%";
7#endif /* not lint */
0804b2a5
RH
8
9#include <stdio.h>
10#include "1.defs.h"
11#include "def.h"
a53b0533
KB
12
13/*
14 * The following are used in <stdio.h> but are defines as constants
15 * in 1.defs.h -- since their values are never used here we simply
16 * discard them. XXX
17 */
18#undef _r
19#undef _p
20
0804b2a5
RH
21extern int linechar, errflag, debug;
22extern int (*input)(), (*unput)();
23
24
25
26uptolow(c) /*translates upper to lower case */
27int c;
28 {
29 if ('A' <= c && c <= 'Z')
30 return(c+'a'-'A');
31 else
32 return(c);
33 }
34
35rdfree(func)
36int (*func)();
37 {
38 int c;
39 while ( (c = (*input)()) != '\n')
40 {
41 (*func)(c);
42 }
43 }
44
45rdstand(func)
46int (*func)();
47 {
48 int c;
49 while ( (c=(*input)()) != '\n')
50 {
51 (*func)(c);
52 }
53 }
54
55labfree(func) /* labels in freeform input */
56int (*func)();
57 {
58 int c;
59 int temp[6];
60 int j;
61 for (j = 0; j < 5; ++j)
62 {
63 while ( (c = (*input)()) == ' ' || c == '\t' );
64 if (c == '\n')
65 {
66 if (j != 0)
67 {
68 temp[j] = '\0';
69 error("label without code - ignored:","","");
70 }
71 }
72 if (c < '0' || c > '9')
73 {
74 (*unput)(c);
75 break;
76 }
77 else
78 {
79 temp[j] = c;
80 (*func)(c);
81 }
82 }
83 for ( ; j < 5; ++j)
84 (*func)(' ');
85 }
86
87labstand(func) /* labels in standard form input */
88int (*func)();
89 {
90 int c;
91 int j;
92
93 for (j = 0; j < 5; ++j)
94 {
95 c = (*input)();
96 if (c == '\n')
97 {
98 error("line shorter than 5 characters","","");
99 errflag = 1;
100 (*unput)('\n');
101 }
102 if (c == '\t' || c == '\n')
103 {
104 for ( ;j<5; ++j)
105 (*func)(' ');
106 return;
107 }
108 (*func)(c);
109 }
110 (*input)(); /* throw away continuation char */
111 }
112
113
114
115contfree() /* identify continuation lines in free-form input */
116 {
117 return(nonblchar(_diglet,0)); /* any non-alpha non-digit */
118 }
119
120
121nonblchar(class,yesno)
122int class,yesno;
123 {
124#define CARDSIZE 121
125 int temp[CARDSIZE];
126 int j;
127 for (j=0; (temp[j]=(*input)()) == ' ' || temp[j] == '\t'; ++j)
128 if (j>=CARDSIZE-1)
129 {
130 temp[CARDSIZE-1] = '\0';
131 error ("line unexpectedly long","","");
132 break;
133 }
134 if (temp[j]!=EOF && classmatch(temp[j],class)==yesno)
135 return(1);
136 else
137 {
138 for ( ; j >= 0; --j)
139 (*unput)(temp[j]);
140 return(0);
141 }
142 }
143
144
145contstand() /* continuation lines in standard form input */
146 {
147 int temp[6];
148 int i;
149
150 for (i = 0; i < 6; ++i)
151 {
152 temp[i] = (*input)();
153 if (temp[i] == '\t' || temp[i] == '\n' || temp[i] == '\0' || temp[i] == EOF)
154 {
155 for ( ;i >= 0; --i)
156 (*unput)(temp[i]);
157 return(0);
158 }
159 }
160 if (temp[5] != '0' && temp[5] != ' ')
161 return(1);
162 else
163 {
164 for ( i = 5 ; i >= 0; --i)
165 (*unput)(temp[i]);
166 return(0);
167 }
168 }
169
170
171
172comstand(posafter) /* standard form comments */
173int posafter;
174 {
175 int c;
176 c = (*input)();
177 if (!posafter)
178 (*unput)(c);
179 if (c == 'c' || c == '*' || c== '#')
180 return(1);
181 else
182 return(0);
183 }
184
185
186comfree(posafter)
187int posafter;
188 {
189 return(comstand(posafter));
190 }
191int (*rline[])() = {rdfree,rdstand};
192int (*comment[])() = {comfree,comstand};
193int (*getlabel[])() = {labfree, labstand};
194int (*chkcont[])() = {contfree,contstand};
195
196blankline()
197 {
198 if ( nonblchar(_nl,1) ) /* first non-blank is nl */
199 {
200 (*unput) ('\n');
201 return(1);
202 }
203 else return(0);
204 }
205
206#define maxunbp 80
207char unbuf[maxunbp+1];
208int unbp;
209
210empseek(linebeg)
211int linebeg;
212 {
213 unbp = 0;
214 if (fseek(infd,(long)(linebeg+rtnbeg),0) == -1)
215 faterr("in disk seek","","");
216 }
217
218inchar()
219 {
220 if (unbp > 0)
221 return( unbuf[--unbp] );
222 else
223 {
224 return( uptolow(getc(infd)) );
225 }
226 }
227
228
229unchar(c)
230int c;
231 {
232 if (unbp >= maxunbp)
233 faterr("dec.rat: unbuf size exceeded","","");
234 if(c!=EOF)unbuf[unbp++] = c;
235 }