vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / xmem / lib / diag / GetAtoms.c
blob493d512635681dd16fb7cee718284234117197fa
1 /**************************************************************************/
2 /* String to upper case */
3 /**************************************************************************/
5 void StrToUpper(inp,out)
6 char *inp;
7 char *out; {
9 int i;
10 AtomType at;
11 char *cp;
13 for (i=0; i<strlen(inp); i++) {
14 cp = &(inp[i]);
15 at = atomhash[(int) (*cp)];
16 if ((at == Alpha) && (*cp >= 'a')) *cp -= ' ';
17 out[i] = *cp;
19 out[i] = 0;
22 /**************************************************************************/
23 /* Chop up a command line into atom values. */
24 /**************************************************************************/
26 void GetAtoms(char *buf) {
28 int i, nb;
29 char *cp, *ep;
30 AtomType at;
31 CmdId cid;
32 OprId oid;
35 /* Repeat the last command on blank command buffer */
37 if (( buf == NULL)
38 || ( *buf == '.')) return;
40 /* Start a new command */
42 pcnt = 0;
43 bzero((void *) &(vals[pcnt]),sizeof(ArgVal));
45 /* Break input string up into atoms */
47 cp = &buf[0];
49 while(True) {
50 at = atomhash[(int) (*cp)];
51 vals[pcnt].Pos = (unsigned int) (cp - &buf[0]);
53 switch (at) {
55 /* Numeric atom types have their value set to the value of */
56 /* the text string. The number of bytes field corresponds to */
57 /* the number of characters in the number. */
59 case Numeric:
60 vals[pcnt].Number = (int) strtoul(cp,&ep,0);
61 vals[pcnt].Type = Numeric;
62 cp = ep;
63 pcnt++;
64 break;
66 /* Alpha atom types are strings of letters and numbers starting with */
67 /* a letter. The text of the atom is placed in the text field of the */
68 /* atom. The number of bytes field is the number of characters in */
69 /* the name. Two special alpha strings "if" and "do", are converted */
70 /* into special atom types. */
72 case Alpha:
73 nb = 0;
74 while (at == Alpha) {
75 vals[pcnt].Text[nb] = *cp;
76 nb++; cp++;
77 if (nb >= MAX_ARG_LENGTH) break;
78 at = atomhash[(int) (*cp)];
80 vals[pcnt].Text[nb] = 0; /* Zero terminate string */
81 vals[pcnt].Type = Alpha;
82 for (i=0; i<CmdCMDS; i++) {
83 cid = cmds[i].Id;
84 if (strcmp(cmds[i].Name,vals[pcnt].Text) == 0)
85 vals[pcnt].CId = cid;
87 pcnt++;
88 break;
90 /* Seperators can be as long as they like, the only interesting */
91 /* data about them is their byte counts. */
93 case Seperator:
94 while (at == Seperator ) at = atomhash[(int) (*(++cp))];
95 break;
97 /* Comments are enclosed between a pair of percent marks, the only */
98 /* character not allowed in a comment is a terminator, just incase */
99 /* someone has forgotten to end one. */
101 case Comment:
102 at = atomhash[(int) (*(++cp))];
103 while (at != Comment ) {
104 at = atomhash[(int) (*(cp++))];
105 if (at == Terminator) return;
107 break;
109 /* Operator atoms have the atom value set to indicate which operator */
110 /* the atom is. The text and number of byte fields are also set. */
112 case Operator:
113 nb = 0;
114 while (at == Operator) {
115 vals[pcnt].Text[nb] = *cp;
116 nb++; cp++;
117 if (nb >= MAX_ARG_LENGTH) break;
118 at = atomhash[(int) *cp];
120 vals[pcnt].Text[nb] = 0; /* Zero terminate string */
121 vals[pcnt].Type = Operator;
122 for (i=0; i<OprOPRS; i++) {
123 oid = oprs[i].Id;
124 if (strcmp(oprs[oid].Name,vals[pcnt].Text) == 0)
125 vals[pcnt].OId = oid;
127 pcnt++;
128 break;
130 /* These are simple single byte operators */
132 case Open: /* FIDO start block atom */
133 case Close: /* FIDO end block atom */
134 case Open_index: /* Start Object name block */
135 case Close_index: /* End of Object name block */
136 case Bit: /* Bit number specifier */
137 vals[pcnt].Type = at;
138 cp++; pcnt++;
139 break;
141 default:
142 vals[pcnt].Type = at;
143 cp++; pcnt++;
144 return;
149 /**************************************************************************/
150 /* Absorb white space */
151 /**************************************************************************/
153 char WhiteSpace(cp,ep)
154 char *cp;
155 char **ep; {
157 char c;
159 if (cp) {
160 while ((c = *cp)) {
161 if (atomhash[(int) c] != Seperator) break;
162 cp++;
164 *ep = cp;
165 return c;
167 return 0;