1: /* if command */
   2: 
   3: int ap;
   4: int ac;
   5: char    **av;
   6: 
   7: main(argc, argv)
   8: char *argv[];
   9: {
  10: 
  11:     argv[argc] = 0;
  12:     ac = argc; av = argv; ap = 1;
  13:     if (argc<2) return;
  14:     if (exp())
  15:         if(doex(0)) {
  16:             write(1, "no command\n", 11);
  17:             seek(0, 0, 2);
  18:         }
  19: }
  20: 
  21: char *nxtarg() {
  22: 
  23:     if (ap>ac) return(0*ap++);
  24:     return(av[ap++]);
  25: }
  26: 
  27: exp(s) {
  28:     int p1;
  29: 
  30:     p1 = e1();
  31:     if (eq(nxtarg(), "-o")) return(p1 | exp());
  32:     ap--;
  33:     return(p1);
  34: }
  35: 
  36: e1() {
  37:     int p1;
  38: 
  39:     p1 = e2();
  40:     if (eq(nxtarg(), "-a")) return (p1 & e1());
  41:     ap--;
  42:     return(p1);
  43: }
  44: 
  45: e2() {
  46:     if (eq(nxtarg(), "!"))
  47:         return(!e3());
  48:     ap--;
  49:     return(e3());
  50: }
  51: 
  52: e3() {
  53:     int p1, ccode;
  54:     register char *a;
  55: 
  56:     ccode = 0;
  57:     if ((a=nxtarg())==0) goto err;
  58:     if(eq(a, "(")) {
  59:         p1 = exp();
  60:         if(!eq(nxtarg(), ")")) goto err;
  61:         return(p1);
  62:     }
  63: 
  64:     if(eq(a, "-r"))
  65:         return(tio(nxtarg(), 0));
  66: 
  67:     if(eq(a, "-w"))
  68:         return(tio(nxtarg(), 1));
  69: 
  70:     if(eq(a, "-c"))
  71:         return(tcreat(nxtarg()));
  72: 
  73:     if(eq(a, "{")) { /* execute a command for exit code */
  74:         if(fork()) /*parent*/ wait(&ccode);
  75:         else { /*child*/
  76:             doex(1);
  77:             goto err;
  78:         }
  79:         while((a=nxtarg()) && (!eq(a,"}")));
  80:         return(ccode? 0 : 1);
  81:     }
  82: 
  83:     p1 = nxtarg();
  84:     if (p1==0) goto err;
  85:     if(eq(p1, "="))
  86:         return(eq(a, nxtarg()));
  87: 
  88:     if(eq(p1, "!="))
  89:         return(!eq(a, nxtarg()));
  90: err:
  91:     write(1, "if error\n", 9);
  92:     exit(9);
  93: }
  94: 
  95: tio(a, f) {
  96: 
  97:     a = open(a, f);
  98:     if (a>=0) {
  99:         close(a);
 100:         return(1);
 101:     }
 102:     return(0);
 103: }
 104: 
 105: tcreat(a) {
 106:     return(1);
 107: }
 108: 
 109: eq(a, b)
 110: char *a, *b;
 111: {
 112:     register int i;
 113: 
 114:     i = 0;
 115: l:
 116:     if(a[i] != b[i])
 117:         return(0);
 118:     if(a[i++] == '\0')
 119:         return(1);
 120:     goto l;
 121: }
 122: 
 123: doex(earg) {
 124: 
 125:     register int np, i, c;
 126:     char *nargv[50], *ncom, *na;
 127: 
 128:     np = 0;
 129:     while (na=nxtarg()) {
 130:         if(earg && eq(na,"}")) break;
 131:         nargv[np++] = na;
 132:     }
 133:     if(earg && (!eq(na, "}"))) return(9);
 134:     nargv[np] = 0;
 135:     if (np==0) return(earg);
 136:     execv(nargv[0], nargv, np);
 137:     i = 0;
 138:     ncom = "/usr/bin/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 139:     while(c=nargv[0][i])  {
 140:         ncom[9+i++] = c;
 141:     }
 142:     ncom[9+i] = '\0';
 143:     execv(ncom+4, nargv, np);
 144:     execv(ncom, nargv, np);
 145:     return(1);
 146: }

Defined functions

doex defined in line 123; used 2 times
e1 defined in line 36; used 2 times
e2 defined in line 45; used 1 times
  • in line 39
e3 defined in line 52; used 2 times
eq defined in line 109; used 16 times
exp defined in line 27; used 3 times
main defined in line 7; never used
nxtarg defined in line 21; used 13 times
tcreat defined in line 105; used 1 times
  • in line 71
tio defined in line 95; used 2 times

Defined variables

ac defined in line 4; used 2 times
ap defined in line 3; used 7 times
av defined in line 5; used 2 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 964
Valid CSS Valid XHTML 1.0 Strict