Commit | Line | Data |
---|---|---|
c1ff2dc1 BJ |
1 | int in; |
2 | int i 0; | |
3 | char buf[512]; | |
4 | int *wd { | |
5 | &buf[0]}; | |
6 | char *pasc[]{ | |
7 | "program",0}; | |
8 | char *fort[]{ | |
9 | "function","subroutine","common","dimension","block","integer", | |
10 | "real","data","double",0}; | |
11 | char *asc[]{ | |
12 | "sys","mov","tst","clr","jmp",0}; | |
13 | char *c[]{ | |
14 | "int","char","float","double","struct","extern",0}; | |
15 | char *as[]{ | |
16 | "globl","byte","even","text","data","bss","comm",0}; | |
17 | int ibuf[260]; | |
18 | main(argc, argv) | |
19 | char **argv; | |
20 | { | |
21 | ||
22 | while(argc > 1) { | |
23 | printf("%s: ", argv[1]); | |
24 | type(argv[1]); | |
25 | argc--; | |
26 | argv++; | |
27 | } | |
28 | } | |
29 | ||
30 | type(file) | |
31 | char *file; | |
32 | { | |
33 | int j,nl; | |
34 | char ch; | |
35 | int mbuf[20]; | |
36 | ||
37 | if(stat(file, mbuf) < 0) { | |
38 | printf("cannot stat\n"); | |
39 | return; | |
40 | } | |
41 | switch(mbuf[2]&060000) { | |
42 | ||
43 | case 020000: | |
44 | if(mbuf[6] == -1) { | |
45 | printf("quota (%l/%l)\n", mbuf[7], mbuf[8]); | |
46 | return; | |
47 | } | |
48 | printf("character"); | |
49 | goto spcl; | |
50 | ||
51 | case 040000: | |
52 | printf("directory\n"); | |
53 | return; | |
54 | ||
55 | case 060000: | |
56 | printf("block"); | |
57 | ||
58 | spcl: | |
59 | printf(" special (%d/%d)\n", | |
60 | (mbuf[6]>>8)&0377, | |
61 | mbuf[6]&0377); | |
62 | return; | |
63 | } | |
64 | ||
65 | ibuf[0] = open(file, 0); | |
66 | if(ibuf[0] < 0) { | |
67 | printf("cannot open\n"); | |
68 | return; | |
69 | } | |
70 | in = read(ibuf[0], buf, 512); | |
71 | switch(*wd) { | |
72 | ||
73 | case 0404: | |
74 | printf("pascal object\n"); | |
75 | goto out; | |
76 | case 0410: | |
77 | printf("pure "); | |
78 | goto exec; | |
79 | ||
80 | case 0411: | |
81 | printf("separate "); | |
82 | ||
83 | case 0407: | |
84 | exec: | |
85 | printf("executable"); | |
86 | if(wd[4] != 0) | |
87 | printf(" not stripped"); | |
88 | printf("\n"); | |
89 | goto out; | |
90 | ||
91 | case 0177555: | |
92 | printf("old archive\n"); | |
93 | goto out; | |
94 | ||
95 | case 0177545: | |
96 | printf("archive\n"); | |
97 | goto out; | |
98 | } | |
99 | ||
100 | i = 0; | |
101 | if (pascom() == 0) | |
102 | goto notpas; | |
103 | if (lookup(pasc) == 1) { | |
104 | printf("pascal program"); | |
105 | goto outa; | |
106 | } | |
107 | notpas: | |
108 | i = 0; | |
109 | if(ccom() == 0)goto notc; | |
110 | while(buf[i] == '#'){ | |
111 | j = i; | |
112 | while(buf[i++] != '\n'){ | |
113 | if(i - j > 255){ | |
114 | printf("data\n"); | |
115 | goto out; | |
116 | } | |
117 | if(i >= in)goto notc; | |
118 | } | |
119 | if(ccom() == 0)goto notc; | |
120 | } | |
121 | check: | |
122 | if(lookup(c) == 1){ | |
123 | while((ch = buf[i++]) != ';' && ch != '{')if(i >= in)goto notc; | |
124 | printf("c program"); | |
125 | goto outa; | |
126 | } | |
127 | nl = 0; | |
128 | while(buf[i] != '('){ | |
129 | if(buf[i] <= 0){ | |
130 | printf("data\n"); | |
131 | goto out; | |
132 | } | |
133 | if(buf[i] == ';'){ | |
134 | i++; | |
135 | goto check; | |
136 | } | |
137 | if(buf[i++] == '\n') | |
138 | if(nl++ > 6)goto notc; | |
139 | if(i >= in)goto notc; | |
140 | } | |
141 | while(buf[i] != ')'){ | |
142 | if(buf[i++] == '\n') | |
143 | if(nl++ > 6)goto notc; | |
144 | if(i >= in)goto notc; | |
145 | } | |
146 | while(buf[i] != '{'){ | |
147 | if(buf[i++] == '\n') | |
148 | if(nl++ > 6)goto notc; | |
149 | if(i >= in)goto notc; | |
150 | } | |
151 | printf("c program"); | |
152 | goto outa; | |
153 | notc: | |
154 | i = 0; | |
155 | while(buf[i] == 'c' || buf[i] == '#'){ | |
156 | while(buf[i++] != '\n')if(i >= in)goto notfort; | |
157 | } | |
158 | if(lookup(fort) == 1){ | |
159 | printf("fortran"); | |
160 | goto outa; | |
161 | } | |
162 | notfort: | |
163 | i=0; | |
164 | if(ascom() == 0)goto notas; | |
165 | j = i-1; | |
166 | if(buf[i] == '.'){ | |
167 | i++; | |
168 | if(lookup(as) == 1){ | |
169 | printf("assembler program"); | |
170 | goto outa; | |
171 | } | |
172 | else if(buf[j] == '\n'){ | |
173 | printf("roff, nroff, or eqn input"); | |
174 | goto outa; | |
175 | } | |
176 | } | |
177 | while(lookup(asc) == 0){ | |
178 | if(ascom() == 0)goto notas; | |
179 | while(buf[i] != '\n' && buf[i++] != ':') | |
180 | if(i >= in)goto notas; | |
181 | while(buf[i] == '\n' || buf[i] == ' ' || buf[i] == '\t')if(i++ >= in)goto notas; | |
182 | j = i-1; | |
183 | if(buf[i] == '.'){ | |
184 | i++; | |
185 | if(lookup(as) == 1){ | |
186 | printf("assembler program"); | |
187 | goto outa; | |
188 | } | |
189 | else if(buf[j] == '\n'){ | |
190 | printf("roff, nroff, or eqn input"); | |
191 | goto outa; | |
192 | } | |
193 | } | |
194 | } | |
195 | printf("assembler program"); | |
196 | goto outa; | |
197 | notas: | |
198 | for(i=0; i < in; i++)if(buf[i] <= 0){ | |
199 | printf("data\n"); | |
200 | goto out; | |
201 | } | |
202 | if((mbuf[2] & 00111) != 0) | |
203 | printf("commands"); | |
204 | else printf("probably text"); | |
205 | outa: | |
206 | while(i < in) | |
207 | if(buf[i++] <= 0){ | |
208 | printf(" with garbage\n"); | |
209 | goto out; | |
210 | } | |
211 | while((in = read(ibuf[0],buf,512)) > 0) | |
212 | for(i = 0; i < in; i++) | |
213 | if(buf[i] <= 0){ | |
214 | printf(" with garbage\n"); | |
215 | goto out; | |
216 | } | |
217 | printf("\n"); | |
218 | out: | |
219 | close(ibuf[0]); | |
220 | } | |
221 | lookup(tab) | |
222 | char *tab[]; | |
223 | { | |
224 | char r; | |
225 | int k,j,l; | |
226 | while(buf[i] == ' ' || buf[i] == '\t' || buf[i] == '\n')i++; | |
227 | for(j=0; tab[j] != 0; j++){ | |
228 | l=0; | |
229 | for(k=i; ((r=tab[j][l++]) == buf[k] && r != '\0');k++); | |
230 | if(r == '\0') | |
231 | if(buf[k] == ' ' || buf[k] == '\n' || buf[k] == '\t' | |
232 | || buf[k] == '{' || buf[k] == '/'){ | |
233 | i=k; | |
234 | return(1); | |
235 | } | |
236 | } | |
237 | return(0); | |
238 | } | |
239 | ccom(){ | |
240 | char cc; | |
241 | while((cc = buf[i]) == ' ' || cc == '\t' || cc == '\n')if(i++ >= in)return(0); | |
242 | if(buf[i] == '/' && buf[i+1] == '*'){ | |
243 | i =+ 2; | |
244 | while(buf[i] != '*' || buf[i+1] != '/'){ | |
245 | if(buf[i] == '\\')i =+ 2; | |
246 | else i++; | |
247 | if(i >= in)return(0); | |
248 | } | |
249 | if((i =+ 2) >= in)return(0); | |
250 | } | |
251 | if(buf[i] == '\n')if(ccom() == 0)return(0); | |
252 | return(1); | |
253 | } | |
254 | ascom(){ | |
255 | while(buf[i] == '/'){ | |
256 | i++; | |
257 | while(buf[i++] != '\n')if(i >= in)return(0); | |
258 | while(buf[i] == '\n')if(i++ >= in)return(0); | |
259 | } | |
260 | return(1); | |
261 | } | |
262 | pascom() | |
263 | { | |
264 | register cc; | |
265 | ||
266 | top: | |
267 | while((cc = buf[i]) == ' ' || cc == '\t' || cc == '\n') | |
268 | if(i++ >= in) | |
269 | return(0); | |
270 | if (buf[i] == '{') { | |
271 | i++; | |
272 | while(buf[i] != '}') | |
273 | if (++i >= in) | |
274 | return(0); | |
275 | i++; | |
276 | goto top; | |
277 | } | |
278 | if (buf[i] == '(' && buf[i+1] == '*') { | |
279 | i =+ 2; | |
280 | while(buf[i] != '*' || buf[i+1] != ')') | |
281 | if (++i >= in) | |
282 | return(0); | |
283 | if ((i =+ 2) >= in) | |
284 | return(0); | |
285 | goto top; | |
286 | } | |
287 | return(1); | |
288 | } |