| 1 | #include "head.h" |
| 2 | |
| 3 | /* decode() - read a line from standard input and decode it */ |
| 4 | |
| 5 | decode(p) |
| 6 | char *p; { |
| 7 | register char c, *q; |
| 8 | integ = scallf = reflag = colonflag = 0; |
| 9 | proc[0] = cmd = args[0] = var[0] = '\0'; |
| 10 | argsp = args; |
| 11 | |
| 12 | if (eqany(*p, "/?")) { /* regular expression */ |
| 13 | c = *p; |
| 14 | redir = (c == '/'); |
| 15 | reflag = 1; |
| 16 | p++; |
| 17 | if (*p == '\n' || *p == c) return(0); |
| 18 | q = re; |
| 19 | while(*p != c && *p != '\n') *q++ = *p++; |
| 20 | *q = '\0'; |
| 21 | return(0); |
| 22 | } |
| 23 | |
| 24 | if (*p == '!') { /* shell escape */ |
| 25 | for (q = p; *q != '\n'; q++) ; |
| 26 | *q = '\0'; |
| 27 | system(p+1); |
| 28 | return(0); |
| 29 | } |
| 30 | |
| 31 | if (*p == '\n') { |
| 32 | cmd = '\n'; |
| 33 | return(0); |
| 34 | } |
| 35 | |
| 36 | if (*p == ':') { |
| 37 | colonflag++; |
| 38 | } |
| 39 | |
| 40 | while (*p != '\n') { /* decode item by item */ |
| 41 | |
| 42 | if (number(*p)) { /* decimal number */ |
| 43 | if(integ) { |
| 44 | error("Too many numbers"); |
| 45 | return(1); |
| 46 | } |
| 47 | integ = readint(&p); |
| 48 | continue; |
| 49 | } |
| 50 | |
| 51 | if (varchar(*p) || eqany(*p, COMMANDS)) { |
| 52 | /* proc, variable or command */ |
| 53 | if (cmd != '\0') { |
| 54 | p = cpall(args, p); |
| 55 | continue; |
| 56 | } |
| 57 | q = p; |
| 58 | while (varchar(*q) || number(*q) || eqany(*q,COMMANDS)) |
| 59 | q++; |
| 60 | if (*q == '(') { /* procedure call */ |
| 61 | if (proc[0] != '\0') { |
| 62 | error("Too many procedure calls"); |
| 63 | return(1); |
| 64 | } |
| 65 | scallf = 1; |
| 66 | p = cpname(proc, p); |
| 67 | p = cpall(args, p); |
| 68 | continue; |
| 69 | } |
| 70 | if (*q == ':') { /* procedure name */ |
| 71 | colonflag++; |
| 72 | p = cpname(proc, p); |
| 73 | continue; |
| 74 | } |
| 75 | if (*q == '$') { /* variable name */ |
| 76 | p = cpname(var, p); |
| 77 | continue; |
| 78 | } |
| 79 | if (((q-p == 1 && eqany(*p,COMMANDS) && |
| 80 | (proc[0]=='\0' || eqany(*p, "abcd"))) || |
| 81 | (integ && eqany(*p,COMMANDS))|| eqany(*p, "+-")) |
| 82 | && !(*p=='-' && *(p+1) == '>')) |
| 83 | { /* command */ |
| 84 | cmd = *p++; |
| 85 | if (eqany(cmd, "acers")) { |
| 86 | while(*p == ' ') |
| 87 | p++; |
| 88 | p = cpall(args, p); |
| 89 | } |
| 90 | continue; |
| 91 | } |
| 92 | /* otherwise, its a variable */ |
| 93 | if (var[0] != '\0') { |
| 94 | error("Too many variable names"); |
| 95 | return(1); |
| 96 | } |
| 97 | p = cpname(var, p); |
| 98 | if (*p == '\n') { |
| 99 | cmd = '/'; |
| 100 | continue; |
| 101 | } |
| 102 | if (cmd == '\0') cmd = *p ? *p : '/'; |
| 103 | p++; |
| 104 | p = cpall(args,p); |
| 105 | continue; |
| 106 | } |
| 107 | p++; /* otherwise ignore p */ |
| 108 | } |
| 109 | return(0); |
| 110 | } |