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

Defined functions

ascom defined in line 230; used 2 times
ccom defined in line 215; used 3 times
lookup defined in line 197; used 5 times
main defined in line 16; never used
type defined in line 28; used 1 times
  • in line 22

Defined variables

as defined in line 13; used 2 times
asc defined in line 9; used 1 times
buf defined in line 3; used 48 times
c defined in line 11; used 1 times
  • in line 98
fort defined in line 6; used 1 times
i defined in line 2; used 74 times
ibuf defined in line 15; used 5 times
in defined in line 1; used 18 times
wd defined in line 4; used 1 times
  • in line 65
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 966
Valid CSS Valid XHTML 1.0 Strict