Changeset 30614
- Timestamp:
- Feb 13, 2011, 11:28:01 AM (15 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 7 edited
- 1 copied
-
doc/image-graph-overlay.txt (copied) (copied from branches/eam_branches/ipp-20101205/Ohana/src/opihi/doc/image-graph-overlay.txt )
-
include/dvoshell.h (modified) (3 diffs)
-
include/shell.h (modified) (1 diff)
-
lib.shell/VectorOps.c (modified) (1 diff)
-
lib.shell/command.c (modified) (5 diffs)
-
lib.shell/expand_vars.c (modified) (1 diff)
-
lib.shell/parse.c (modified) (10 diffs)
-
lib.shell/stack_math.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/include/dvoshell.h
r28958 r30614 107 107 MEAS_XCCD_ERR, 108 108 MEAS_YCCD_ERR, 109 MEAS_POS_SYS_ERR, 109 110 MEAS_XMOSAIC, 110 111 MEAS_YMOSAIC, … … 116 117 MEAS_IMAGE_ID, 117 118 MEAS_PSF_QF, 119 MEAS_PSF_QF_PERFECT, 118 120 MEAS_PSF_CHISQ, 119 121 MEAS_PSF_NDOF, … … 218 220 IMAGE_Y_UL_FP, 219 221 IMAGE_Y_UR_FP, 222 IMAGE_X_ERR_SYS, 223 IMAGE_Y_ERR_SYS, 224 IMAGE_MAG_ERR_SYS, 225 IMAGE_NFIT_PHOTOM, 226 IMAGE_NFIT_ASTROM, 227 IMAGE_NLINK_PHOTOM, 228 IMAGE_NLINK_ASTROM 220 229 }; 221 230 -
trunk/Ohana/src/opihi/include/shell.h
r27790 r30614 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)); -
trunk/Ohana/src/opihi/lib.shell/VectorOps.c
r20936 r30614 178 178 vec[0].Nelements = Nelements; 179 179 if (type == OPIHI_FLT) { 180 REALLOCATE (vec[0].elements.Flt, opihi_flt, Nelements);180 REALLOCATE (vec[0].elements.Flt, opihi_flt, MAX(1, Nelements)); 181 181 vec[0].type = OPIHI_FLT; 182 182 } else { 183 REALLOCATE (vec[0].elements.Int, opihi_int, Nelements);183 REALLOCATE (vec[0].elements.Int, opihi_int, MAX(1, Nelements)); 184 184 vec[0].type = OPIHI_INT; 185 185 } -
trunk/Ohana/src/opihi/lib.shell/command.c
r27790 r30614 10 10 Command *cmd; 11 11 12 // rawline = NULL; 13 rawline = strcreate (line); 12 // the input line is never NULL 13 if (!line) { fprintf (stderr, "programming error\n"); abort(); } 14 15 rawline = strcreate (line); // used for error messages which should echo the unparsed line 14 16 15 17 /* force a space between ! and first word: !ls becomes ! ls */ … … 22 24 /* expand anything of the form $fred or $fred$sam, etc */ 23 25 line = expand_vars (line); /* line is freed here, new one allocated */ 26 if (!line) goto escape; 27 24 28 /* expand anything of the form fred[N] */ 25 29 line = expand_vectors (line); /* line is freed here, new one allocated */ 30 if (!line) goto escape; 26 31 27 32 // print the line with the variables and vectors expanded, but before evaluating … … 29 34 if (VERBOSE_SHELL == OPIHI_VERBOSE_ON) gprint (GP_ERR, "opihi: %s\n", line); 30 35 31 /* solve math expresions, assign variable, if needed */ 32 line = parse (line); /* line is freed here, new one allocated */ 33 /* 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; 34 40 35 41 /* we may have reallocated line, return new pointer */ … … 39 45 if (argc == 0) { 40 46 FREE (rawline); 47 set_int_variable ("STATUS", TRUE); 41 48 return (TRUE); /* empty command or assignment */ 42 49 } … … 74 81 FREE (rawline); 75 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 93 if (VERBOSE_SHELL != OPIHI_VERBOSE_OFF) gprint (GP_ERR, "error on line: %s\n", rawline); 94 95 // return the current value of line, in case it was modified 96 *outline = line; 97 return FALSE; 76 98 } 77 99 -
trunk/Ohana/src/opihi/lib.shell/expand_vars.c
r15878 r30614 64 64 /* variable assignment (skip these variables) */ 65 65 if ((L == line) && (V1 != NULL)) { 66 if ((*V1 == '=') || !strcmp (V1, "++") || !strcmp (V1, "--")) { 66 int isAssignment; 67 68 isAssignment = FALSE; 69 isAssignment |= (V1[0] == '='); 70 isAssignment |= (V1[0] == '+') && (V1[1] == '='); 71 isAssignment |= (V1[0] == '-') && (V1[1] == '='); 72 isAssignment |= (V1[0] == '+') && (V1[1] == '+'); 73 isAssignment |= (V1[0] == '-') && (V1[1] == '-'); 74 75 if (isAssignment) { 67 76 *N = *L; 68 77 free (V0); -
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 } -
trunk/Ohana/src/opihi/lib.shell/stack_math.c
r27435 r30614 972 972 *out = OP; \ 973 973 } \ 974 clear_stack (V1); \ 975 return (TRUE); \ 974 goto escape; \ 976 975 } \ 977 976 if ((V1->vector->type == OPIHI_INT) && (FTYPE == 'S')) { \ … … 982 981 *out = OP; \ 983 982 } \ 984 clear_stack (V1); \ 985 return (TRUE); \ 983 goto escape; \ 986 984 } \ 987 985 if ((V1->vector->type == OPIHI_INT) && (FTYPE == 's')) { \ … … 992 990 *out = OP; \ 993 991 } \ 994 clear_stack (V1); \ 995 return (TRUE); \ 992 goto escape; \ 996 993 } } 997 994 … … 1035 1032 # undef V_FUNC 1036 1033 1034 escape: 1035 1037 1036 if (V1[0].type == 'v') { 1038 1037 free (V1[0].vector[0].elements.Ptr);
Note:
See TracChangeset
for help on using the changeset viewer.
