- Timestamp:
- Dec 20, 2010, 8:36:52 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101205/Ohana/src/opihi/lib.shell/parse.c
r27491 r30115 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; … … 73 75 Nbytes = fread (val, 1, 1023, f); 74 76 val[Nbytes] = 0; 75 status = pclose (f);77 filestatus = pclose (f); 76 78 free (B); 77 79 78 if ( status) gprint (GP_ERR, "warning: exit status of command %d\n",status);80 if (filestatus) gprint (GP_ERR, "warning: exit status of command %d\n", filestatus); 79 81 80 82 /* convert all but last return to ' '. drop last return */ … … 91 93 92 94 /* 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 } 95 /* dvomath returns a new string, or NULL, with the result of the expression */ 96 val = dvomath (1, &V1, &size, 0); 97 if (val == NULL) { 98 while (OHANA_WHITESPACE (*V1)) V1++; 99 val = strcreate (V1); 100 } 101 101 /* both dvomath and command replacement create (char *) val */ 102 102 set_str_variable (V0, val); … … 172 172 if (!inRange) { 173 173 gprint (GP_ERR, "no element %d,%d\n", Nx, Ny); 174 goto e scape;174 goto error; 175 175 } 176 176 if (Nx < 0) Nx += buf[0].header.Naxis[0]; … … 188 188 if (!inRange) { 189 189 gprint (GP_ERR, "no element %d\n", Nx); 190 goto e scape;190 goto error; 191 191 } 192 192 if (Nx < 0) Nx += vec[0].Nelements; … … 197 197 } 198 198 } 199 200 199 goto escape; 201 200 } … … 226 225 if (c1 == NULL) { 227 226 gprint (GP_ERR, "no close brackets!\n"); 228 goto e scape;227 goto error; 229 228 } 230 229 c2 = strchr (L, '{'); 231 230 if ((c2 != NULL) && (c2 < c1)) { 232 231 gprint (GP_ERR, "can't nest brackets!\n"); 233 goto e scape;232 goto error; 234 233 } 235 234 *c1 = 0; … … 240 239 if (val == NULL) { 241 240 print_error (); 242 goto e scape;241 goto error; 243 242 } 244 243 … … 257 256 258 257 REALLOCATE (newline, char, strlen (newline) + 1); 258 *status = TRUE; 259 259 return (newline); 260 260 261 261 error: 262 262 gprint (GP_ERR, "syntax error\n"); 263 264 escape: 263 // assignment or increment operation: free line and return NULL 265 264 if (line != (char *) NULL) free (line); 266 265 if (val != (char *) NULL) free (val); 267 266 if (V0 != (char *) NULL) free (V0); 267 *status = FALSE; 268 return NULL; 269 270 escape: 271 // assignment or increment operation: free line and return NULL 272 if (line != (char *) NULL) free (line); 273 if (val != (char *) NULL) free (val); 274 if (V0 != (char *) NULL) free (V0); 275 *status = TRUE; 268 276 return (NULL); 269 277 }
Note:
See TracChangeset
for help on using the changeset viewer.
