Changeset 30614 for trunk/Ohana/src/opihi/lib.shell/parse.c
- Timestamp:
- Feb 13, 2011, 11:28:01 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/lib.shell/parse.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/parse.c
r27491 r30614 1 1 # include "opihi.h" 2 2 3 char *parse ( char *line) {3 char *parse (int *status, char *line) { 4 4 5 5 double fval; 6 6 float *fptr; 7 7 char *newline, *N, *L, *val, *B, *V, *V0, *V1, *c1, *c2, *p; 8 int Nx, Ny, Nbytes, status, size, NLINE, isBuffer, inRange;8 int Nx, Ny, Nbytes, filestatus, size, NLINE, isBuffer, inRange; 9 9 FILE *f; 10 10 Vector *vec; 11 11 Buffer *buf; 12 13 *status = TRUE; 12 14 13 15 Ny = 0; … … 49 51 } 50 52 53 if (!strncmp (V1, "+=", 2)) { 54 V1 ++; 55 if (*V1 == 0) goto error; 56 V1 ++; 57 if (*V1 == 0) goto error; 58 59 val = get_variable (V0); 60 if (val == NULL) { 61 fval = 0.0; 62 } else { 63 fval = atof (val); 64 } 65 66 /* dvomath returns a new string, or NULL, with the result of the expression */ 67 val = dvomath (1, &V1, &size, 0); 68 if (val == NULL) goto error; 69 fval += atof(val); 70 // save the result 71 set_variable (V0, fval); 72 goto escape; 73 } 74 75 if (!strncmp (V1, "-=", 2)) { 76 V1 ++; 77 if (*V1 == 0) goto error; 78 V1 ++; 79 if (*V1 == 0) goto error; 80 81 val = get_variable (V0); 82 if (val == NULL) { 83 fval = 0.0; 84 } else { 85 fval = atof (val); 86 } 87 88 /* dvomath returns a new string, or NULL, with the result of the expression */ 89 val = dvomath (1, &V1, &size, 0); 90 if (val == NULL) goto error; 91 fval -= atof(val); 92 // save the result 93 set_variable (V0, fval); 94 goto escape; 95 } 96 51 97 /* not an assignement, syntax error */ 52 98 if (*V1 != '=') goto error; … … 73 119 Nbytes = fread (val, 1, 1023, f); 74 120 val[Nbytes] = 0; 75 status = pclose (f);121 filestatus = pclose (f); 76 122 free (B); 77 123 78 if ( status) gprint (GP_ERR, "warning: exit status of command %d\n",status);124 if (filestatus) gprint (GP_ERR, "warning: exit status of command %d\n", filestatus); 79 125 80 126 /* convert all but last return to ' '. drop last return */ … … 88 134 } 89 135 } 136 // save the resulting value 137 set_str_variable (V0, val); 138 goto escape; /* frees temp variables */ 139 } 140 141 /* simple variable assignment */ 142 /* dvomath returns a new string, or NULL, with the result of the expression */ 143 val = dvomath (1, &V1, &size, 0); 144 if (val == NULL) { 145 while (OHANA_WHITESPACE (*V1)) V1++; 146 val = strcreate (V1); 90 147 } 91 92 /* simple variable assignment */ 93 if (*V1 != '`') { 94 /* dvomath returns a new string, or NULL, with the result of the expression */ 95 val = dvomath (1, &V1, &size, 0); 96 if (val == NULL) { 97 while (OHANA_WHITESPACE (*V1)) V1++; 98 val = strcreate (V1); 99 } 100 } 101 /* both dvomath and command replacement create (char *) val */ 148 // save the result 102 149 set_str_variable (V0, val); 103 150 goto escape; /* frees temp variables */ … … 172 219 if (!inRange) { 173 220 gprint (GP_ERR, "no element %d,%d\n", Nx, Ny); 174 goto e scape;221 goto error; 175 222 } 176 223 if (Nx < 0) Nx += buf[0].header.Naxis[0]; … … 188 235 if (!inRange) { 189 236 gprint (GP_ERR, "no element %d\n", Nx); 190 goto e scape;237 goto error; 191 238 } 192 239 if (Nx < 0) Nx += vec[0].Nelements; … … 197 244 } 198 245 } 199 200 246 goto escape; 201 247 } … … 226 272 if (c1 == NULL) { 227 273 gprint (GP_ERR, "no close brackets!\n"); 228 goto e scape;274 goto error; 229 275 } 230 276 c2 = strchr (L, '{'); 231 277 if ((c2 != NULL) && (c2 < c1)) { 232 278 gprint (GP_ERR, "can't nest brackets!\n"); 233 goto e scape;279 goto error; 234 280 } 235 281 *c1 = 0; … … 240 286 if (val == NULL) { 241 287 print_error (); 242 goto e scape;288 goto error; 243 289 } 244 290 … … 257 303 258 304 REALLOCATE (newline, char, strlen (newline) + 1); 305 *status = TRUE; 259 306 return (newline); 260 307 261 308 error: 262 309 gprint (GP_ERR, "syntax error\n"); 263 264 escape: 310 // assignment or increment operation: free line and return NULL 265 311 if (line != (char *) NULL) free (line); 266 312 if (val != (char *) NULL) free (val); 267 313 if (V0 != (char *) NULL) free (V0); 314 *status = FALSE; 315 return NULL; 316 317 escape: 318 // assignment or increment operation: free line and return NULL 319 if (line != (char *) NULL) free (line); 320 if (val != (char *) NULL) free (val); 321 if (V0 != (char *) NULL) free (V0); 322 *status = TRUE; 268 323 return (NULL); 269 324 }
Note:
See TracChangeset
for help on using the changeset viewer.
