static char sccsid
[] = "@(#)file.c 4.4 (Berkeley) 4.4";
* file - determine type of file
char *troff
[] = { /* new troff intermediate lang */
"x","T","res","init","font","202","V0","p1",0};
"function","subroutine","common","dimension","block","integer",
"real","data","double",0};
"chmk","mov","tst","clr","jmp",0};
"int","char","float","double","struct","extern",0};
"globl","byte","align","text","data","comm",0};
if (argc
>1 && argv
[1][0]=='-' && argv
[1][1]=='f') {
if ((fl
= fopen(argv
[2], "r")) == NULL
) {
printf("Can't open %s\n", argv
[2]);
while ((p
= fgets(ap
, 128, fl
)) != NULL
) {
if (lstat(file
, &mbuf
) < 0) {
switch (mbuf
.st_mode
& S_IFMT
) {
printf("symbolic link\n");
printf(" special (%d/%d)\n", major(mbuf
.st_rdev
), minor(mbuf
.st_rdev
));
in
= read(ifile
, buf
, BUFSIZ
);
printf("jfr or pdp-11 unix 411 executable\n");
if(((int *)buf
)[4] != 0) {
printf(" (old format symbol table)");
printf("very old archive\n");
if(strncmp(buf
, "!<arch>\n__.SYMDEF", 17) == 0 ) {
printf("archive random library\n");
if (strncmp(buf
, "!<arch>\n", 8)==0) {
if (mbuf
.st_size
% 512 == 0) { /* it may be a PRESS file */
lseek(ifile
, -512L, 2); /* last block */
if (read(ifile
, buf
, BUFSIZ
) > 0
&& *(short int *)buf
== 12138) {
if(ccom() == 0)goto notc
;
if(ccom() == 0)goto notc
;
while((ch
= buf
[i
++]) != ';' && ch
!= '{')if(i
>= in
)goto notc
;
printf("c program text");
printf("c program text");
while(buf
[i
] == 'c' || buf
[i
] == '#'){
while(buf
[i
++] != '\n')if(i
>= in
)goto notfort
;
printf("fortran program text");
if(ascom() == 0)goto notas
;
printf("assembler program text");
else if(buf
[j
] == '\n' && isalpha(buf
[j
+2])){
printf("roff, nroff, or eqn input text");
if(ascom() == 0)goto notas
;
while(buf
[i
] != '\n' && buf
[i
++] != ':')
while(buf
[i
] == '\n' || buf
[i
] == ' ' || buf
[i
] == '\t')if(i
++ >= in
)goto notas
;
printf("assembler program text");
else if(buf
[j
] == '\n' && isalpha(buf
[j
+2])){
printf("roff, nroff, or eqn input text");
printf("assembler program text");
for(i
=0; i
< in
; i
++)if(buf
[i
]&0200){
if (buf
[0]=='\100' && buf
[1]=='\357') {
printf("troff (CAT) output\n");
if (mbuf
.st_mode
&((S_IEXEC
)|(S_IEXEC
>>3)|(S_IEXEC
>>6)))
else if (troffint(buf
, in
))
printf("troff intermediate output text");
else if (english(buf
, in
))
if((buf
[i
++]&0377) > 127){
printf(" with garbage\n");
/* if next few lines in then read whole file looking for nulls ...
while((in = read(ifile,buf,BUFSIZ)) > 0)
printf(" with garbage\n");
if (fstat(ifile
, &stb
) < 0)
if (N_STROFF(ex
)+sizeof(off_t
) > stb
.st_size
)
for (k
= 0; k
< 6; k
++) {
while (i
< n
&& buf
[i
] != '\n')
while(buf
[i
] == ' ' || buf
[i
] == '\t' || buf
[i
] == '\n')i
++;
for(j
=0; tab
[j
] != 0; j
++){
for(k
=i
; ((r
=tab
[j
][l
++]) == buf
[k
] && r
!= '\0');k
++);
if(buf
[k
] == ' ' || buf
[k
] == '\n' || buf
[k
] == '\t'
|| buf
[k
] == '{' || buf
[k
] == '/'){
while((cc
= buf
[i
]) == ' ' || cc
== '\t' || cc
== '\n')if(i
++ >= in
)return(0);
if(buf
[i
] == '/' && buf
[i
+1] == '*'){
while(buf
[i
] != '*' || buf
[i
+1] != '/'){
if(buf
[i
] == '\\')i
+= 2;
if((i
+= 2) >= in
)return(0);
if(buf
[i
] == '\n')if(ccom() == 0)return(0);
while(buf
[i
++] != '\n')if(i
>= in
)return(0);
while(buf
[i
] == '\n')if(i
++ >= in
)return(0);
int ct
[NASC
], j
, vow
, freq
, rare
;
int badpun
= 0, punct
= 0;
if (n
<50) return(0); /* no point in statistics on squibs */
vow
= ct
['a'] + ct
['e'] + ct
['i'] + ct
['o'] + ct
['u'];
freq
= ct
['e'] + ct
['t'] + ct
['a'] + ct
['i'] + ct
['o'] + ct
['n'];
rare
= ct
['v'] + ct
['j'] + ct
['k'] + ct
['q'] + ct
['x'] + ct
['z'];
if (2*ct
[';'] > ct
['e']) return(0);
if ( (ct
['>']+ct
['<']+ct
['/'])>ct
['e']) return(0); /* shell file test */
return (vow
*5 >= n
-ct
[' '] && freq
>= 10*rare
);