Changeset 2792 for trunk/Ohana/src/opihi
- Timestamp:
- Dec 22, 2004, 1:23:23 PM (22 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 8 edited
-
cmd.basic/run_if.c (modified) (1 diff)
-
include/dvomath.h (modified) (1 diff)
-
lib.shell/check_stack.c (modified) (5 diffs)
-
lib.shell/dvomath.c (modified) (1 diff)
-
lib.shell/evaluate_stack.c (modified) (4 diffs)
-
lib.shell/expand_vectors.c (modified) (1 diff)
-
lib.shell/parse.c (modified) (1 diff)
-
lib.shell/stack_math.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.basic/run_if.c
r2598 r2792 30 30 /* determine value of conditional expression */ 31 31 val = dvomath (1, &argv[1], &size, 0); 32 if (val == NULL) { /* try expression as string op string */ 33 char **stack; 34 int Nstack; 32 if (val == NULL) return (FALSE); 33 logic = atof (val); /* warning: round-off error is a danger */ 35 34 36 stack = isolate_elements (1, &argv[1], &Nstack);37 if (Nstack != 5) goto syntax;38 if (strcmp (stack[0], "(")) goto syntax;39 if (strcmp (stack[4], ")")) goto syntax;40 equals = -1;41 if (!strcmp (stack[2], "==")) equals = TRUE;42 if (!strcmp (stack[2], "!=")) equals = TRUE;43 if (equals == -1) goto syntax;44 logic = FALSE;45 if (equals && !strcmp (stack[1], stack[3])) logic = TRUE;46 if (!equals && strcmp (stack[1], stack[3])) logic = TRUE;47 } else {48 logic = atof (val); /* warning: round-off error is a danger */49 }50 35 if (BreakOnTrue) { 51 36 if (logic) { -
trunk/Ohana/src/opihi/include/dvomath.h
r2598 r2792 50 50 char **isolate_elements PROTO((int argc, char **argv, int *nstack)); 51 51 StackVar *convert_to_RPN PROTO((int argc, char **argv, int *nstack)); 52 int check_stack PROTO((StackVar *stack, int Nstack ));52 int check_stack PROTO((StackVar *stack, int Nstack, int validsize)); 53 53 int evaluate_stack PROTO((StackVar *stack, int *Nstack)); 54 54 void init_stack PROTO((StackVar *stack)); -
trunk/Ohana/src/opihi/lib.shell/check_stack.c
r2598 r2792 1 1 # include "opihi.h" 2 2 3 int check_stack (StackVar *stack, int Nstack ) {3 int check_stack (StackVar *stack, int Nstack, int validsize) { 4 4 5 int i, Nx, Ny, Nv ;5 int i, Nx, Ny, Nv, size; 6 6 char *c, line[128]; 7 7 … … 10 10 for (i = 0; i < Nstack; i++) { 11 11 if (stack[i].type == 'X') { 12 12 13 /** if this is a number, put it on the list of scalers and move on **/ 13 14 stack[i].Float = strtod (stack[i].name, &c); … … 17 18 continue; 18 19 } 20 21 /** if we demand a scalar, interpret strings as strings */ 22 if (validsize == 0) { 23 stack[i].type = 'W'; 24 continue; 25 } 26 19 27 /** if this is a matrix, find the dimensions and check with existing values **/ 20 28 if (IsBuffer (stack[i].name)) { … … 38 46 continue; 39 47 } 48 40 49 /** if this is a vector, find the dimensions and check with existing values **/ 41 50 if (IsVector (stack[i].name)) { … … 63 72 } 64 73 65 /* we return a value which is 1 greater than the object dimension */ 66 if (Nx != -1) return (2); 67 if (Nv != -1) return (1); 68 return (0); 74 /* return object dimensions */ 75 size = 0; 76 if (Nv != -1) size = 1; 77 if (Nx != -1) size = 2; 78 if (validsize == -1) return (size); 79 if (validsize != size) return (-1); 80 return (size); 69 81 } -
trunk/Ohana/src/opihi/lib.shell/dvomath.c
r2598 r2792 22 22 23 23 /* distinguish scalar, vector, matrix, check dimensions */ 24 *size = check_stack (stack, Nstack); 25 if ((validsize != -1) && (validsize != *size)) goto error; 24 *size = check_stack (stack, Nstack, validsize); 26 25 if (*size < 0) goto error; 27 26 -
trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c
r2598 r2792 26 26 return (TRUE); 27 27 } 28 fprintf (stderr, "syntax error!\n");28 push_error ("syntax error!"); 29 29 free (tmp_stack.name); 30 30 return (FALSE); … … 54 54 return (FALSE); 55 55 } 56 57 /* this could be macro generated... */ 58 # define TWO_OP(A,B,FUNC) \ 59 if (!strncasecmp (&stack[i - 2].type, A, 1) && !strncasecmp (&stack[i - 1].type, B, 1)) \ 60 status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); 61 62 TWO_OP ("M","M",MM_binary); 63 TWO_OP ("M","V",MV_binary); 64 TWO_OP ("M","S",MS_binary); 65 TWO_OP ("V","M",VM_binary); 66 TWO_OP ("V","V",VV_binary); 67 TWO_OP ("V","S",VS_binary); 68 TWO_OP ("S","M",SM_binary); 69 TWO_OP ("S","V",SV_binary); 70 TWO_OP ("S","S",SS_binary); 71 TWO_OP ("W","W",WW_binary); 72 73 /* 56 74 if (!strncasecmp (&stack[i - 2].type, "V", 1) && !strncasecmp (&stack[i - 1].type, "V", 1)) 57 75 status = VV_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); … … 72 90 if (!strncasecmp (&stack[i - 2].type, "S", 1) && !strncasecmp (&stack[i - 1].type, "S", 1)) 73 91 status = SS_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); 92 if (!strncasecmp (&stack[i - 2].type, "X", 1) && !strncasecmp (&stack[i - 1].type, "X", 1)) 93 status = XX_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); 94 */ 95 96 /* string op number is not valid */ 97 if (!strncasecmp (&stack[i - 2].type, "W", 1) && strncasecmp (&stack[i - 1].type, "W", 1)) { 98 free (tmp_stack.name); 99 return (FALSE); 100 } 101 if (strncasecmp (&stack[i - 2].type, "W", 1) && !strncasecmp (&stack[i - 1].type, "W", 1)) { 102 free (tmp_stack.name); 103 return (FALSE); 104 } 105 74 106 if (!status) { 75 107 free (tmp_stack.name); … … 102 134 if (!strncasecmp (&stack[i - 1].type, "S", 1)) 103 135 S_unary (&tmp_stack, &stack[i - 1], stack[i].name); 136 137 /* there are no valid unary string operators */ 138 if (!strncasecmp (&stack[i - 1].type, "W", 1)) { 139 fprintf (stderr, "syntax error\n"); 140 free (tmp_stack.name); 141 return (FALSE); 142 } 104 143 105 144 move_stack (&stack[i-1], &tmp_stack); -
trunk/Ohana/src/opihi/lib.shell/expand_vectors.c
r2598 r2792 37 37 ALLOCATE (val, char, 64); 38 38 sprintf (val, "-1"); 39 /* this choice of sentinel prevents us from using 40 x[-1], x[-2], and is not really needed */ 39 41 } else { 40 42 strncpy (tmpline, p+1, n); 41 43 tmpline[n] = 0; 42 44 val = dvomath (1, &tmpline, &size, 0); 43 if (val == NULL) goto dumpline; /* not really a vector*/45 if (val == NULL) goto dumpline; /* not a valid vector subscript */ 44 46 } 45 47 /* find vector name */ -
trunk/Ohana/src/opihi/lib.shell/parse.c
r2598 r2792 56 56 if (*V1 == 0) goto error; 57 57 58 /* command replacement. execute the line, place answer in val. */59 58 if (*V1 == '`') { 59 /* command replacement. execute the line, place answer in val. */ 60 60 61 61 /* look for end of line, must be ` */ -
trunk/Ohana/src/opihi/lib.shell/stack_math.c
r2598 r2792 1043 1043 1044 1044 } 1045 1046 int WW_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) { 1047 1048 int value; 1049 1050 switch (op[0]) { 1051 case 'E': 1052 value = strcmp (V1[0].name, V2[0].name) ? 0 : 1; 1053 break; 1054 case 'N': 1055 value = strcmp (V1[0].name, V2[0].name) ? 1 : 0; 1056 break; 1057 default: 1058 fprintf (stderr, "error: op %c not valid\n", op[0]); 1059 } 1060 1061 strcpy (OUT[0].name, "tmp"); 1062 OUT[0].Float = value; 1063 OUT[0].type = 'S'; 1064 OUT[0].ptr = &OUT[0].Float; 1065 return (TRUE); 1066 1067 } 1068 1045 1069 1046 1070 int S_unary (StackVar *OUT, StackVar *V1, char *op) {
Note:
See TracChangeset
for help on using the changeset viewer.
