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