Changeset 30115
- Timestamp:
- Dec 20, 2010, 8:36:52 AM (15 years ago)
- Location:
- branches/eam_branches/ipp-20101205/Ohana/src/opihi
- Files:
-
- 3 edited
-
include/shell.h (modified) (1 diff)
-
lib.shell/command.c (modified) (5 diffs)
-
lib.shell/parse.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101205/Ohana/src/opihi/include/shell.h
r27790 r30115 76 76 char *expand_vars PROTO((char *line)); 77 77 char *expand_vectors PROTO((char *line)); 78 char *parse PROTO(( char *line));78 char *parse PROTO((int *status, char *line)); 79 79 char **parse_commands PROTO((char *, int *)); 80 80 void welcome PROTO((void)); -
branches/eam_branches/ipp-20101205/Ohana/src/opihi/lib.shell/command.c
r30081 r30115 10 10 Command *cmd; 11 11 12 // rawline = NULL; 12 // the input line is never NULL 13 if (!line) { fprintf (stderr, "programming error\n"); abort(); } 14 13 15 rawline = strcreate (line); 14 16 … … 20 22 } 21 23 22 XXX: check for NULL return from expand_* and raise error23 24 24 /* expand anything of the form $fred or $fred$sam, etc */ 25 25 line = expand_vars (line); /* line is freed here, new one allocated */ 26 if (!line) goto escape; 27 26 28 /* expand anything of the form fred[N] */ 27 29 line = expand_vectors (line); /* line is freed here, new one allocated */ 30 if (!line) goto escape; 28 31 29 32 // print the line with the variables and vectors expanded, but before evaluating … … 31 34 if (VERBOSE_SHELL == OPIHI_VERBOSE_ON) gprint (GP_ERR, "opihi: %s\n", line); 32 35 33 /* solve math expresions, assign variable, if needed */ 34 line = parse (line); /* line is freed here, new one allocated */ 35 /* any entry in line of the form {foo} returns value or tmp vector / buffer */ 36 /* solve math expresions, assign variable, if needed. any entry in line of the form {foo} 37 * returns value or tmp vector / buffer */ 38 line = parse (&status, line); /* line is freed here, new one allocated */ 39 if (!status) goto escape; 36 40 37 41 /* we may have reallocated line, return new pointer */ … … 41 45 if (argc == 0) { 42 46 FREE (rawline); 47 set_int_variable ("STATUS", TRUE); 43 48 return (TRUE); /* empty command or assignment */ 44 49 } … … 76 81 FREE (rawline); 77 82 return (status); 83 84 escape: 85 set_int_variable ("STATUS", FALSE); 86 87 # if (DEBUG) 88 gprint (GP_ERR, "command: %s, status: %d\n", line, FALSE); 89 # endif 90 91 FREE (rawline); 92 return FALSE; 78 93 } 79 94 -
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.
