Changeset 2801
- Timestamp:
- Dec 23, 2004, 7:36:01 AM (22 years ago)
- Location:
- trunk/Ohana/src/opihi/lib.shell
- Files:
-
- 5 edited
-
check_stack.c (modified) (3 diffs)
-
dvomath.c (modified) (1 diff)
-
evaluate_stack.c (modified) (6 diffs)
-
parse.c (modified) (4 diffs)
-
stack_math.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/check_stack.c
r2792 r2801 19 19 } 20 20 21 /** if we demand a scalar, interpret strings as strings */22 if (validsize == 0) {23 stack[i].type = 'W';24 continue;25 }26 27 21 /** if this is a matrix, find the dimensions and check with existing values **/ 28 22 if (IsBuffer (stack[i].name)) { … … 66 60 continue; 67 61 } 62 63 /* this is not a scalar, vector, or matrix. must be string */ 64 stack[i].type = 'W'; 65 66 /* let's not consider this an error 68 67 sprintf (line, "unknown object %s", stack[i].name); 69 68 push_error (line); 70 return (-1); 69 return (-1); 70 */ 71 71 } 72 72 } … … 80 80 return (size); 81 81 } 82 83 /* check stack identifies the data elements as scalar, vector, matrix, or word. 84 operators have already been identified. 85 check stack returns the total stack dimensionality (0,1,2) 86 on error, check stack returns -1 87 possible errors: 88 - mismatch with requested dimensionality 89 - mismatch in data dimensions 90 */ -
trunk/Ohana/src/opihi/lib.shell/dvomath.c
r2792 r2801 1 1 # include "opihi.h" 2 2 3 /* return value on success is temp vector/buffer name or scalar value 4 return value on error is NULL, all internals freed?*/5 3 /* return value on success is temp vector/buffer name or scalar value return value on error is NULL, all 4 internals freed. errors are sent to error stack. may be printed by calling function */ 5 6 6 char *dvomath (int argc, char **argv, int *size, int validsize) { 7 7 -
trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c
r2792 r2801 5 5 6 6 int i, j, Nvar, Nout, status; 7 char line[512]; 7 8 StackVar tmp_stack; 8 9 Nout = Nvar = 0; … … 26 27 return (TRUE); 27 28 } 28 push_error ("syntax error !");29 push_error ("syntax error: not a math expression"); 29 30 free (tmp_stack.name); 30 31 return (FALSE); … … 50 51 51 52 if (i < 2) { /* need two variables to operate on */ 52 fprintf (stderr, "syntax error\n"); 53 sprintf (line, "syntax error: binary operator with one operand: %s\n", stack[i].name); 54 push_error (line); 53 55 free (tmp_stack.name); 54 56 return (FALSE); … … 123 125 124 126 if (i < 1) { /* need one variable to operate on */ 125 fprintf (stderr, "syntax error\n");127 push_error ("syntax error: unary operator with no operand"); 126 128 free (tmp_stack.name); 127 129 return (FALSE); … … 137 139 /* there are no valid unary string operators */ 138 140 if (!strncasecmp (&stack[i - 1].type, "W", 1)) { 139 fprintf (stderr, "syntax error\n");141 push_error ("syntax error: no valid string unary ops"); 140 142 free (tmp_stack.name); 141 143 return (FALSE); … … 156 158 157 159 if (*Nstack > 1) { 158 fprintf (stderr, "syntax error\n");160 push_error ("syntax error in evaluation"); 159 161 return (FALSE); 160 162 } -
trunk/Ohana/src/opihi/lib.shell/parse.c
r2792 r2801 56 56 if (*V1 == 0) goto error; 57 57 58 /* command replacement. execute the line, place answer in val. */ 58 59 if (*V1 == '`') { 59 /* command replacement. execute the line, place answer in val. */60 60 61 61 /* look for end of line, must be ` */ … … 79 79 if (*B == '\n') *B = ' '; 80 80 } 81 } else { 81 } 82 83 /* simple variable assignment */ 84 if (*V1 != '`') { 82 85 /* dvomath returns a new string, or NULL, with the result of the expression */ 83 86 val = dvomath (1, &V1, &size, 0); … … 107 110 V = strncreate (N+1, L - N - 1); 108 111 109 /* expand value in parenthesis */112 /* expand value in brackets */ 110 113 val = dvomath (1, &V, &size, 0); 111 114 if (val == NULL) { … … 172 175 *c1 = 0; 173 176 174 /* value in brackets must be an expression of some sort */ 177 /* value in brackets must be a math expression of some sort. 178 isolated words are not valid here */ 175 179 val = dvomath (1, &L, &size, -1); 176 180 if (val == NULL) { -
trunk/Ohana/src/opihi/lib.shell/stack_math.c
r2792 r2801 10 10 int i, Nx; 11 11 float *out, *M1, *M2; 12 char line[512]; 12 13 13 14 Nx = V1[0].vector[0].Nelements; … … 104 105 break; 105 106 default: 106 fprintf (stderr, "error: op %c not defined!\n", op[0]); 107 sprintf (line, "error: op %c not defined!", op[0]); 108 push_error (line); 109 return (FALSE); 107 110 } 108 111 … … 127 130 int i, Nx; 128 131 float *out, *M1, *M2; 132 char line[512]; 129 133 130 134 Nx = V2[0].vector[0].Nelements; … … 213 217 break; 214 218 default: 215 fprintf (stderr, "error: op %c not defined!\n", op[0]); 219 sprintf (line, "error: op %c not defined!", op[0]); 220 push_error (line); 221 return (FALSE); 216 222 } 217 223 … … 231 237 int i, Nx; 232 238 float *out, *M1, *M2; 239 char line[512]; 233 240 234 241 Nx = V1[0].vector[0].Nelements; … … 317 324 break; 318 325 default: 319 fprintf (stderr, "error: op %c not defined!\n", op[0]); 326 sprintf (line, "error: op %c not defined!", op[0]); 327 push_error (line); 328 return (FALSE); 320 329 } 321 330 … … 335 344 int i, j, Nx, Ny; 336 345 float *out, *M1, *M2; 337 346 char line[512]; 347 338 348 Nx = V1[0].buffer[0].matrix.Naxis[0]; 339 349 Ny = V1[0].buffer[0].matrix.Naxis[1]; 340 350 if (Ny != V2[0].vector[0].Nelements) { 341 fprintf (stderr, "dimension mismatch\n");351 push_error ("dimension mismatch"); 342 352 return (FALSE); 343 353 } … … 462 472 break; 463 473 default: 464 fprintf (stderr, "error: op %c not defined!\n", op[0]); 474 sprintf (line, "error: op %c not defined!", op[0]); 475 push_error (line); 476 return (FALSE); 465 477 } 466 478 … … 486 498 int i, j, Nx, Ny; 487 499 float *out, *M1, *M2; 500 char line[512]; 488 501 489 502 Nx = V2[0].buffer[0].matrix.Naxis[0]; … … 628 641 break; 629 642 default: 630 fprintf (stderr, "error: op %c not defined!\n", op[0]); 643 sprintf (line, "error: op %c not defined!", op[0]); 644 push_error (line); 645 return (FALSE); 631 646 } 632 647 … … 651 666 int i, Nx, Ny; 652 667 float *out, *M1, *M2; 668 char line[512]; 653 669 654 670 Nx = V1[0].buffer[0].matrix.Naxis[0]; … … 743 759 break; 744 760 default: 745 fprintf (stderr, "error: op %c not defined!\n", op[0]); 761 sprintf (line, "error: op %c not defined!", op[0]); 762 push_error (line); 763 return (FALSE); 746 764 } 747 765 … … 768 786 int i, Nx, Ny; 769 787 float *out, *M1, *M2; 788 char line[512]; 770 789 771 790 Nx = V1[0].buffer[0].matrix.Naxis[0]; … … 856 875 break; 857 876 default: 858 fprintf (stderr, "error: op %c not defined!\n", op[0]); 877 sprintf (line, "error: op %c not defined!", op[0]); 878 push_error (line); 879 return (FALSE); 859 880 } 860 881 … … 873 894 int i, Nx, Ny; 874 895 float *out, *M1, *M2; 896 char line[512]; 875 897 876 898 Nx = V2[0].buffer[0].matrix.Naxis[0]; … … 960 982 break; 961 983 default: 962 fprintf (stderr, "error: op %c not defined!\n", op[0]); 984 sprintf (line, "error: op %c not defined!", op[0]); 985 push_error (line); 986 return (FALSE); 963 987 } 964 988 … … 976 1000 977 1001 float *M1, *M2, *out; 978 1002 char line[512]; 1003 979 1004 M1 = V1[0].ptr; 980 1005 M2 = V2[0].ptr; … … 1036 1061 break; 1037 1062 default: 1038 fprintf (stderr, "error: op %c not defined!\n", op[0]); 1063 sprintf (line, "error: op %c not defined!", op[0]); 1064 push_error (line); 1065 return (FALSE); 1039 1066 } 1040 1067 OUT[0].Float = *(OUT[0].ptr); … … 1047 1074 1048 1075 int value; 1049 1076 char line[512]; 1077 1050 1078 switch (op[0]) { 1051 1079 case 'E': … … 1056 1084 break; 1057 1085 default: 1058 fprintf (stderr, "error: op %c not valid\n", op[0]); 1086 sprintf (line, "error: op %c not defined!", op[0]); 1087 push_error (line); 1088 return (FALSE); 1059 1089 } 1060 1090
Note:
See TracChangeset
for help on using the changeset viewer.
