Changeset 15878
- Timestamp:
- Dec 16, 2007, 2:27:00 PM (18 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 11 edited
-
include/dvomath.h (modified) (1 diff)
-
include/shell.h (modified) (1 diff)
-
lib.shell/convert_to_RPN.c (modified) (6 diffs)
-
lib.shell/evaluate_stack.c (modified) (13 diffs)
-
lib.shell/expand_vars.c (modified) (7 diffs)
-
lib.shell/expand_vectors.c (modified) (7 diffs)
-
lib.shell/isolate_elements.c (modified) (7 diffs)
-
lib.shell/parse.c (modified) (7 diffs)
-
lib.shell/parse_commands.c (modified) (3 diffs)
-
lib.shell/stack_math.c (modified) (22 diffs)
-
lib.shell/string.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/include/dvomath.h
r11084 r15878 49 49 void clean_stack PROTO((StackVar *stack, int Nstack)); 50 50 void delete_stack PROTO((StackVar *stack, int Nstack)); 51 void clear_stack PROTO((StackVar *stack)); 52 void assign_stack PROTO((StackVar *stack, char *name, int type)); 53 51 54 int VV_binary PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op)); 52 55 int SV_binary PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op)); -
trunk/Ohana/src/opihi/include/shell.h
r15791 r15878 132 132 char *thiscomm PROTO((char *)); 133 133 char *nextcomm PROTO((char *)); 134 char *opihi_append PROTO((char *output, int *Noutput, char *start, char *stop)); 135 void interpolate_slash PROTO((char *line)); 134 136 135 137 /* macro functions (mapped to commands) */ -
trunk/Ohana/src/opihi/lib.shell/convert_to_RPN.c
r7917 r15878 97 97 /* pop previous, higher operators from OP stack to stack */ 98 98 for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type > type); j--) { 99 strcpy (stack[Nstack].name, op_stack[j].name); 100 stack[Nstack].type = op_stack[j].type; 99 move_stack (&stack[Nstack], &op_stack[j]); 101 100 Nstack ++; 102 101 Nop_stack --; 103 102 } 104 103 /* push operator on OP stack */ 105 strcpy (op_stack[Nop_stack].name, argv[i]); 106 op_stack[Nop_stack].type = type; 104 assign_stack (&op_stack[Nop_stack], argv[i], type); 107 105 Nop_stack ++; 108 106 break; … … 115 113 /* pop previous, higher or equal operators from OP stack to stack */ 116 114 for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type >= type); j--) { 117 strcpy (stack[Nstack].name, op_stack[j].name); 118 stack[Nstack].type = op_stack[j].type; 115 move_stack (&stack[Nstack], &op_stack[j]); 119 116 Nstack ++; 120 117 Nop_stack --; 121 118 } 122 119 /* push operator on OP stack */ 123 strcpy (op_stack[Nop_stack].name, argv[i]); 124 op_stack[Nop_stack].type = type; 120 assign_stack (&op_stack[Nop_stack], argv[i], type); 125 121 Nop_stack ++; 126 122 break; 127 123 case 2: 128 124 /* push operator on OP stack */ 129 strcpy (op_stack[Nop_stack].name, argv[i]); 130 op_stack[Nop_stack].type = type; 125 assign_stack (&op_stack[Nop_stack], argv[i], type); 131 126 Nop_stack ++; 132 127 break; … … 134 129 /* pop rest of operators from OP stack to stack, looking for '(' */ 135 130 for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != 2); j--) { 136 strcpy (stack[Nstack].name, op_stack[j].name); 137 stack[Nstack].type = op_stack[j].type; 131 move_stack (&stack[Nstack], &op_stack[j]); 138 132 Nstack ++; 139 133 Nop_stack --; … … 149 143 /* place the value (number or vector/matrix name) on stack */ 150 144 /* value of 'X' is used as sentinel until we sort out values */ 151 strcpy (stack[Nstack].name, argv[i]); 152 stack[Nstack].type = 'X'; 145 assign_stack (&stack[Nstack], argv[i], 'X'); 153 146 Nstack ++; 154 147 break; … … 163 156 goto cleanup; 164 157 } 165 strcpy (stack[Nstack].name, op_stack[j].name); 166 stack[Nstack].type = op_stack[j].type; 158 move_stack (&stack[Nstack], &op_stack[j]); 167 159 Nstack ++; 168 160 } … … 170 162 cleanup: 171 163 /*** free up unused stack space ***/ 172 clean_stack (op_stack, NSTACK); 164 165 // XXX there should not be any un-freed op_stacks at this point 166 // clean_stack (op_stack, NSTACK); 173 167 free (op_stack); 174 clean_stack (&stack[Nstack], NSTACK - Nstack); 168 169 // XXX there should not be any data on higher stack entries 170 // clean_stack (&stack[Nstack], NSTACK - Nstack); 175 171 REALLOCATE (stack, StackVar, MAX (Nstack, 1)); 176 172 *nstack = Nstack; -
trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c
r15006 r15878 22 22 if (*Nstack == 1) { 23 23 if (stack[0].type == 'S') { 24 free (tmp_stack.name);24 clear_stack (&tmp_stack); 25 25 return (TRUE); 26 26 } … … 38 38 } 39 39 push_error ("syntax error: not a math expression"); 40 free (tmp_stack.name);40 clear_stack (&tmp_stack); 41 41 return (FALSE); 42 42 } … … 63 63 sprintf (line, "syntax error: binary operator with one operand: %s\n", stack[i].name); 64 64 push_error (line); 65 free (tmp_stack.name);65 clear_stack (&tmp_stack); 66 66 return (FALSE); 67 67 } … … 84 84 sprintf (line, "syntax error: invalid operand for binary operation: %s or %s\n", stack[i-1].name, stack[i-2].name); 85 85 push_error (line); 86 free (tmp_stack.name);86 clear_stack (&tmp_stack); 87 87 return (FALSE); 88 88 } … … 90 90 delete_stack (&stack[i-1], 2); 91 91 for (j = i + 1; j < *Nstack; j++) { 92 copy_stack (&stack[j - 2], &stack[j]);92 move_stack (&stack[j - 2], &stack[j]); 93 93 } 94 94 *Nstack -= 2; … … 103 103 if (i < 1) { /* need one variable to operate on */ 104 104 push_error ("syntax error: unary operator with no operand"); 105 free (tmp_stack.name);106 return (FALSE); 107 } 108 105 clear_stack (&tmp_stack); 106 return (FALSE); 107 } 108 109 109 ONE_OP ("M", M_unary); 110 110 ONE_OP ("V", V_unary); … … 114 114 if (!strncasecmp (&stack[i - 1].type, "W", 1)) { 115 115 push_error ("syntax error: no valid string unary ops"); 116 free (tmp_stack.name);116 clear_stack (&tmp_stack); 117 117 return (FALSE); 118 118 } … … 121 121 delete_stack (&stack[i], 1); 122 122 for (j = i + 1; j < *Nstack; j++) { 123 copy_stack (&stack[j - 1], &stack[j]);123 move_stack (&stack[j - 1], &stack[j]); 124 124 } 125 125 init_stack (&tmp_stack); … … 129 129 } 130 130 } 131 free (tmp_stack.name);131 clear_stack (&tmp_stack); 132 132 133 133 if (*Nstack > 1) { … … 153 153 /* replace data with new stack variable */ 154 154 void move_stack (StackVar *stack1, StackVar *stack2) { 155 if (stack1[0].name != (char *) NULL) 156 free (stack1[0].name); 155 clear_stack (stack1); 157 156 copy_stack (stack1, stack2); 157 stack2[0].name = NULL; 158 158 } 159 159 … … 178 178 } 179 179 if (VERBOSE) gprint (GP_ERR, "free %s (name) (%d) (%lx)\n", stack[i].name, i, (long) stack[i].name); 180 free (stack[i].name); 181 stack[i].name = NULL; 180 clear_stack (&stack[i]); 182 181 } 183 182 … … 188 187 int i; 189 188 for (i = 0; i < Nstack; i++) { 190 free (stack[i].name);189 clear_stack (&stack[i]); 191 190 } 192 191 } … … 195 194 stack[0].buffer = NULL; 196 195 stack[0].vector = NULL; 197 stack[0].name = strncreate ("tmp", NCHARS); 198 } 196 stack[0].name = NULL; 197 } 198 199 void assign_stack (StackVar *stack, char *name, int type) { 200 stack->name = strcreate (name); 201 stack->type = type; 202 } 203 204 void clear_stack (StackVar *stack) { 205 if (stack->name == NULL) return; 206 free (stack->name); 207 stack->name = NULL; 208 return; 209 } -
trunk/Ohana/src/opihi/lib.shell/expand_vars.c
r10646 r15878 4 4 5 5 char *L, *N, *V0, *V1, *Val, *newline, *c, found; 6 int done, MacroDepth ;6 int done, MacroDepth, NLINE, Noff; 7 7 8 8 if (line == NULL) return (NULL); … … 10 10 11 11 found = FALSE; 12 ALLOCATE (newline, char, 1024); /* WARNING: this limits the length of the input line */ 12 NLINE = MAX (128, strlen(line)); 13 ALLOCATE (newline, char, NLINE); /* WARNING: this limits the length of the input line */ 13 14 14 15 V0 = thiscomm (line); … … 34 35 L++; 35 36 N++; 37 if (N - newline >= NLINE - 5) { 38 Noff = N - newline; 39 NLINE += 128; 40 REALLOCATE (newline, char, NLINE); 41 N = newline + Noff; 42 } 36 43 } 37 44 } … … 46 53 if (V0 == NULL) { 47 54 *N = *L; 55 if (N - newline >= NLINE - 5) { 56 Noff = N - newline; 57 NLINE += 128; 58 REALLOCATE (newline, char, NLINE); 59 N = newline + Noff; 60 } 48 61 continue; 49 62 } … … 54 67 *N = *L; 55 68 free (V0); 69 if (N - newline >= NLINE - 5) { 70 Noff = N - newline; 71 NLINE += 128; 72 REALLOCATE (newline, char, NLINE); 73 N = newline + Noff; 74 } 56 75 continue; 57 76 } … … 65 84 goto error; 66 85 } else { /* if we are executing a macro, attach the list depth to the front, pass on down the line */ 86 // XXX this is limiting!!! 67 87 ALLOCATE (c, char, 1024); 68 88 sprintf (c, "%d.%s", MacroDepth, V0); … … 79 99 for (; *Val != 0; N++, Val++) { 80 100 *N = *Val; /* place the value of the variable in the newline */ 101 if (N - newline >= NLINE - 5) { 102 Noff = N - newline; 103 NLINE += 128; 104 REALLOCATE (newline, char, NLINE); 105 N = newline + Noff; 106 } 81 107 } 82 108 N--; /* we overshoot on last loop */ -
trunk/Ohana/src/opihi/lib.shell/expand_vectors.c
r10073 r15878 3 3 char *expand_vectors (char *line) { 4 4 5 char *newline, *tmpline, *val;5 char *newline, *tmpline, strValue[128], *val; 6 6 char *L, *N, *p, *q, *w; 7 int n, I, size ;7 int n, I, size, showLength, NLINE, Noff; 8 8 double f1; 9 9 Vector *vec; … … 11 11 if (line == NULL) return (NULL); 12 12 13 ALLOCATE (newline, char, 1024); /* WARNING: this limits the length of the input line */14 ALLOCATE ( tmpline, char, 1024); /* WARNING: this limits the length of the input line */13 NLINE = MAX (128, strlen(line)); 14 ALLOCATE (newline, char, NLINE); 15 15 16 16 /* look for form fred[stuff] */ … … 19 19 if (L == NULL) { 20 20 free (newline); 21 free (tmpline);22 21 return (line); 23 22 } … … 35 34 if (p > q) goto dumpline; /* odd state: unmatched pair: ][ */ 36 35 n = (int) (q - p - 1); 36 val = NULL; 37 showLength = FALSE; 37 38 if (n == 0) { 38 ALLOCATE (val, char, 64); 39 sprintf (val, "-1"); 40 /* this choice of sentinel prevents us from using 41 x[-1], x[-2], and is not really needed */ 39 showLength = TRUE; 42 40 } else { 43 strncpy (tmpline, p+1, n); 44 tmpline[n] = 0; 41 tmpline = strncreate (p+1, n); 45 42 val = dvomath (1, &tmpline, &size, 0); 43 free (tmpline); 46 44 if (val == NULL) goto dumpline; /* not a valid vector subscript */ 47 45 } 48 I = atoi (val); 49 free (val); 46 I = 0; 47 if (val != NULL) { 48 I = atoi (val); 49 free (val); 50 } 50 51 51 52 /* find vector name */ … … 53 54 w ++; 54 55 n = (int)(p - w); 55 strncpy (tmpline, w, n); 56 tmpline[n] = 0; 56 tmpline = strncreate (w, n); 57 57 if ((vec = SelectVector (tmpline, OLDVECTOR, TRUE)) == NULL) goto dumpline; 58 free (tmpline); 58 59 59 60 /* find vector element */ 60 if ( I >= vec[0].Nelements) {61 if ((I >= vec[0].Nelements) || (I < -1*vec[0].Nelements)) { 61 62 gprint (GP_ERR, "vector subscript out of range\n"); 62 63 goto escape; 63 64 } 64 if ( I < 0) {65 if (showLength) { 65 66 f1 = vec[0].Nelements; 66 67 } else { 67 f1 = vec[0].elements[I]; 68 if (I < 0) { 69 f1 = vec[0].elements[vec[0].Nelements+I]; 70 } else { 71 f1 = vec[0].elements[I]; 72 } 68 73 } 69 74 if ((int)f1 == f1) 70 s printf (tmpline, "%.0f", f1);75 snprintf (strValue, 128, "%.0f", f1); 71 76 else 72 sprintf (tmpline, "%.9g", f1); 73 /* interpolate vector element */ 77 snprintf (strValue, 128, "%.9g", f1); 78 79 /* interpolate vector element into newline (being accumulated) */ 80 size = (N - newline) + (w - L) + strlen(strValue); 81 if (size >= NLINE) { 82 Noff = N - newline; 83 NLINE += 128 + strlen(strValue) + (w - L); 84 REALLOCATE (newline, char, NLINE); 85 N = newline + Noff; 86 } 87 74 88 n = (int) (w - L); 75 89 strncpy (N, L, n); 76 90 N += n; 77 n = strlen ( tmpline);78 strncpy (N, tmpline, n);91 n = strlen (strValue); 92 strncpy (N, strValue, n); 79 93 N += n; 80 94 L = q + 1; … … 82 96 83 97 dumpline: 98 size = (N - newline) + strlen(L); 99 if (size >= NLINE) { 100 Noff = N - newline; 101 NLINE += 128 + strlen(L); 102 REALLOCATE (newline, char, NLINE); 103 N = newline + Noff; 104 } 105 84 106 n = strlen (L); 85 107 strncpy (N, L, n); 86 108 N[n] = 0; 87 109 free (line); 88 free (tmpline);89 110 return (newline); 90 111 … … 92 113 free (line); 93 114 free (newline); 94 free (tmpline);95 115 return (NULL); 96 116 } -
trunk/Ohana/src/opihi/lib.shell/isolate_elements.c
r10073 r15878 8 8 9 9 /* local private static variables */ 10 int N char, Nout, NOUT;11 char ** out;10 int NCHAR, Nchar, Nout, NOUT; 11 char **myOutput; 12 12 13 13 char **isolate_elements (int Nin, char **in, int *nout) { … … 17 17 NOUT = Nin; 18 18 Nchar = Nout = 0; 19 ALLOCATE (out, char *, NOUT); 20 ALLOCATE (out[Nout], char, NCHARS); 19 NCHAR = 256; 20 ALLOCATE (myOutput, char *, NOUT); 21 ALLOCATE (myOutput[Nout], char, NCHAR); 21 22 22 23 for (i = 0; i < Nin; i++) { … … 35 36 /* check previous entry on line */ 36 37 if (Nchar) { 37 OpStat = IsAnOp ( out[Nout]);38 if ( out[Nout][0] == ')') OpStat = FALSE;38 OpStat = IsAnOp (myOutput[Nout]); 39 if (myOutput[Nout][0] == ')') OpStat = FALSE; 39 40 } else { 40 OpStat = IsAnOp ( out[Nout-1]);41 if ( out[Nout-1][0] == ')') OpStat = FALSE;41 OpStat = IsAnOp (myOutput[Nout-1]); 42 if (myOutput[Nout-1][0] == ')') OpStat = FALSE; 42 43 } 43 44 /* if - follows an operator, must be negator */ … … 67 68 /* check previous entry on line */ 68 69 if (Nchar) { 69 OpStat = IsAnOp ( out[Nout]);70 if ( out[Nout][0] == ')') OpStat = FALSE;70 OpStat = IsAnOp (myOutput[Nout]); 71 if (myOutput[Nout][0] == ')') OpStat = FALSE; 71 72 } else { 72 OpStat = IsAnOp ( out[Nout-1]);73 if ( out[Nout-1][0] == ')') OpStat = FALSE;73 OpStat = IsAnOp (myOutput[Nout-1]); 74 if (myOutput[Nout-1][0] == ')') OpStat = FALSE; 74 75 } 75 76 /* if + follows an operator, must be posator */ … … 91 92 if (posate) continue; 92 93 EndOfString (); 93 /* copy operator to out[Nout] */94 /* copy operator to myOutput[Nout] */ 94 95 InsertValue (in[i][j]); 95 96 if (negate) InsertValue ('-'); … … 131 132 132 133 /* one extra entry is allocated, free here */ 133 free ( out[Nout]);134 free (myOutput[Nout]); 134 135 *nout = Nout; 135 return ( out);136 return (myOutput); 136 137 137 138 } 138 139 139 140 void InsertValue (char c) { 140 out[Nout][Nchar] = c;141 myOutput[Nout][Nchar] = c; 141 142 Nchar ++; 142 out[Nout][Nchar] = 0; 143 if (Nchar >= NCHAR - 2) { 144 NCHAR += 256; 145 REALLOCATE (myOutput[Nout], char, NCHAR); 146 } 147 myOutput[Nout][Nchar] = 0; 143 148 } 144 149 145 150 void EndOfString () { 146 151 if (Nchar > 0) { 147 out[Nout][Nchar] = 0;152 myOutput[Nout][Nchar] = 0; 148 153 Nout ++; 149 154 Nchar = 0; … … 151 156 if (Nout >= NOUT - 1) { 152 157 NOUT += 10; 153 REALLOCATE ( out, char *, NOUT);158 REALLOCATE (myOutput, char *, NOUT); 154 159 } 155 ALLOCATE (out[Nout], char, NCHARS); 160 NCHAR = 256; 161 ALLOCATE (myOutput[Nout], char, NCHAR); 156 162 } 157 163 } -
trunk/Ohana/src/opihi/lib.shell/parse.c
r10073 r15878 1 1 # include "opihi.h" 2 2 3 void interpolate_slash (char *line);4 5 3 char *parse (char *line) { 6 4 7 5 double fval; 8 char *newline, *N, *L, *val, *B, *V, *V0, *V1, * end, *c1, *c2;9 int Nval, Nbytes, status, size ;6 char *newline, *N, *L, *val, *B, *V, *V0, *V1, *c1, *c2, *p; 7 int Nval, Nbytes, status, size, NLINE; 10 8 FILE *f; 11 9 Vector *vec; … … 64 62 65 63 /* val will hold the result */ 64 // XXX this is limiting!!! 66 65 ALLOCATE (val, char, 1024); 67 66 … … 153 152 154 153 /* case 3: {expression} */ 155 ALLOCATE (newline, char, 1024); 156 for (L = line, N = newline; *L != 0; L++, N++) { 157 158 /* copy elements from L (line) to N (newline) until we hit a '{' */ 159 for (; (*L != '{') && (*L != 0); L++, N++) *N = *L; 160 if (*L == 0) break; 161 162 if ((L != line) && (*(L-1) == 0x5c)) { 163 N--; 164 *N = *L; 154 NLINE = MAX (128, strlen (line)); 155 ALLOCATE (newline, char, NLINE); 156 memset (newline, 0, NLINE); 157 for (L = line; *L != 0; ) { 158 159 // copy elements from L (line) to newline up to first '{' 160 p = strchr (L, '{'); 161 newline = opihi_append (newline, &NLINE, L, p); 162 if (p == NULL) break; 163 L = p + 1; 164 165 // check for \{ at this point, replace \ in newline with { 166 if ((p > line) && (*(p - 1) == 0x5c)) { 167 N = newline + strlen(newline) - 1; 168 *N = '{'; // replace \ with { 165 169 continue; 166 170 } 167 171 168 172 /* check on the syntax of the line */ 169 L ++;173 L = p + 1; 170 174 c1 = strchr (L, '}'); 171 175 if (c1 == NULL) { … … 178 182 goto escape; 179 183 } 180 end = c1;181 184 *c1 = 0; 182 185 … … 188 191 goto escape; 189 192 } 193 194 /* interpolate vector element into newline (being accumulated) */ 195 newline = opihi_append (newline, &NLINE, val, NULL); 196 190 197 /* copy val to outline */ 191 for (V = val; *V != 0; V++,N++) *N = *V; 192 L = end; 193 N--; 198 L = c1 + 1; 194 199 free (val); val = (char *) NULL; 195 200 } 196 197 *N = 0; 201 198 202 free (line); line = (char *) NULL; 199 203 … … 204 208 return (newline); 205 209 206 error:210 error: 207 211 gprint (GP_ERR, "syntax error\n"); 208 212 209 escape:213 escape: 210 214 if (line != (char *) NULL) free (line); 211 215 if (val != (char *) NULL) free (val); … … 214 218 } 215 219 216 /* replace all instances of \A with A in line */ 217 void interpolate_slash (char *line) { 218 219 char *in, *out; 220 221 for (in = out = line; *in != 0; in++, out++) { 222 if (*in == 0x5c) in++; 223 *out = *in; 224 if (*in == 0) return; 225 } 226 *out = *in; 227 } 228 229 /* this routine looks for math and/or logic expressions that 230 need to be evaluated and passes them on to "parenthesis", 231 which evaluates the expression */ 232 233 /* There are two situations now which define an expression to 234 be evaluated: 235 1) $var = expression -- everything after the = must be a math expression or a string 236 2) {expression} -- everything within the {} must be a math expression 237 */ 238 239 /* case 1: $var = expression. test that 240 a) there is a $ as the first character 241 b) the variable defined by that $ is not null 242 c) there is an = sign following the variable 243 d) there is something following the = sign 244 */ 220 /* this routine looks for math and/or logic expressions that 221 need to be evaluated and passes them on to "parenthesis", 222 which evaluates the expression */ 223 224 /* There are two situations now which define an expression to 225 be evaluated: 226 1) $var = expression -- everything after the = must be a math expression or a string 227 2) {expression} -- everything within the {} must be a math expression 228 */ 229 230 /* case 1: $var = expression. test that 231 a) there is a $ as the first character 232 b) the variable defined by that $ is not null 233 c) there is an = sign following the variable 234 d) there is something following the = sign 235 */ 245 236 246 /* case 2: vect[N] = expression. check syntax:247 a) last char must be ]248 b) word must contain [249 c) between [ & ] must be an integer250 d) vector must exist251 e) there is an = sign following the first word252 f) there is something following the = sign253 */237 /* case 2: vect[N] = expression. check syntax: 238 a) last char must be ] 239 b) word must contain [ 240 c) between [ & ] must be an integer 241 d) vector must exist 242 e) there is an = sign following the first word 243 f) there is something following the = sign 244 */ 254 245 255 246 256 /* case 3: we hunt for '{', and then the first '}' and pass everything257 inbetween. no nested {{}}s are allowed! */247 /* case 3: we hunt for '{', and then the first '}' and pass everything 248 inbetween. no nested {{}}s are allowed! */ 258 249 259 250 /* thisword ALLOCATES -
trunk/Ohana/src/opihi/lib.shell/parse_commands.c
r2598 r15878 4 4 char **parse_commands (char *line, int *argc) { 5 5 6 int i, j,NARG;6 int i, NARG; 7 7 char *c; 8 8 char **argv; … … 21 21 for (i = 1; c != (char *) NULL; i++) { 22 22 argv[i] = thisword (c); 23 if (argv[i] == (char *) NULL) { 24 for (j = 0; j < i; j++) 25 free (argv[i]); 26 free (argv); 27 *argc = 0; 28 return (argv); 29 } 23 24 /* if one of the words does not parse (eg, ""), skip it */ 25 if (argv[i] == NULL) i--; 26 30 27 c = nextword (c); 31 28 if (i == NARG - 1) { … … 49 46 50 47 48 49 /* old code: 50 for (j = 0; j < i; j++) 51 free (argv[i]); 52 free (argv); 53 *argc = 0; 54 return (argv); 55 } 56 */ -
trunk/Ohana/src/opihi/lib.shell/stack_math.c
r14517 r15878 30 30 } 31 31 OUT[0].type = 'v'; /*** <<--- says this is a temporary matrix ***/ 32 strcpy (OUT[0].name, "tmp"); 32 33 33 M1 = V1[0].ptr; 34 34 M2 = V2[0].ptr; … … 128 128 free (V2[0].vector); 129 129 } 130 131 130 /* at the end, V1 and V2 are deleted only if they were temporary */ 131 132 clear_stack (V1); 133 clear_stack (V2); 132 134 return (TRUE); 133 135 … … 150 152 } 151 153 OUT[0].type = 'v'; /*** <<--- says this is a temporary matrix ***/ 152 strcpy (OUT[0].name, "tmp"); 154 153 155 M1 = V1[0].ptr; 154 156 M2 = V2[0].ptr; … … 243 245 free (V2[0].vector); 244 246 } 247 248 clear_stack (V1); 249 clear_stack (V2); 245 250 246 251 /* at the end, V1 and V2 are deleted only if they were temporary */ … … 265 270 } 266 271 OUT[0].type = 'v'; /*** <<--- says this is a temporary matrix ***/ 267 strcpy (OUT[0].name, "tmp"); 272 268 273 M1 = V1[0].ptr; 269 274 M2 = V2[0].ptr; … … 359 364 free (V1[0].vector); 360 365 } 366 367 clear_stack (V1); 368 clear_stack (V2); 369 361 370 /* at the end, V1 and V2 are deleted only if they were temporary */ 362 371 return (TRUE); … … 387 396 } 388 397 OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/ 389 strcpy (OUT[0].name, "tmp"); 398 390 399 M1 = V1[0].ptr; 391 400 M2 = V2[0].ptr; … … 524 533 free (V2[0].vector); 525 534 } 535 536 clear_stack (V1); 537 clear_stack (V2); 538 526 539 /* at the end, V1 and V2 are deleted only if they were temporary */ 527 540 return (TRUE); … … 551 564 } 552 565 OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/ 553 strcpy (OUT[0].name, "tmp"); 566 554 567 M1 = V1[0].ptr; 555 568 M2 = V2[0].ptr; … … 707 720 free (V2[0].buffer); 708 721 } 722 723 clear_stack (V1); 724 clear_stack (V2); 725 709 726 /* at the end, V1 and V2 are deleted only if they were temporary */ 710 727 return (TRUE); … … 734 751 } 735 752 OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/ 736 strcpy (OUT[0].name, "tmp"); 753 737 754 M1 = V1[0].ptr; 738 755 M2 = V2[0].ptr; … … 834 851 free (V2[0].buffer); 835 852 } 853 854 clear_stack (V1); 855 clear_stack (V2); 856 836 857 /* at the end, V1 and V2 are deleted only if they were temporary */ 837 858 return (TRUE); … … 858 879 } 859 880 OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/ 860 strcpy (OUT[0].name, "tmp"); 881 861 882 M1 = V1[0].ptr; 862 883 M2 = V2[0].ptr; … … 951 972 free (V1[0].buffer); 952 973 } 974 clear_stack (V1); 975 clear_stack (V2); 976 953 977 return (TRUE); 954 978 … … 973 997 } 974 998 OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/ 975 strcpy (OUT[0].name, "tmp"); 999 976 1000 M1 = V1[0].ptr; 977 1001 M2 = V2[0].ptr; … … 1066 1090 free (V2[0].buffer); 1067 1091 } 1092 clear_stack (V1); 1093 clear_stack (V2); 1094 1068 1095 return (TRUE); 1069 1096 … … 1080 1107 OUT[0].ptr = V1[0].ptr; 1081 1108 out = OUT[0].ptr; 1082 strcpy (OUT[0].name, "tmp"); 1109 1083 1110 1084 1111 switch (op[0]) { … … 1147 1174 OUT[0].Float = *(OUT[0].ptr); 1148 1175 OUT[0].type = 'S'; 1176 1177 clear_stack (V1); 1178 clear_stack (V2); 1179 1149 1180 return (TRUE); 1150 1181 … … 1192 1223 1193 1224 escape: 1194 strcpy (OUT[0].name, "tmp");1195 1225 OUT[0].Float = value; 1196 1226 OUT[0].type = 'S'; 1197 1227 OUT[0].ptr = &OUT[0].Float; 1228 1229 clear_stack (V1); 1230 clear_stack (V2); 1198 1231 return (TRUE); 1199 1232 … … 1244 1277 OUT[0].Float = *out; 1245 1278 OUT[0].type = 'S'; 1279 1280 clear_stack (V1); 1246 1281 return (TRUE); 1247 1282 … … 1309 1344 free (V1[0].vector[0].elements); 1310 1345 free (V1[0].vector); 1346 V1[0].vector = NULL; 1311 1347 } 1348 1349 clear_stack (V1); 1312 1350 return (TRUE); 1313 1351 … … 1390 1428 free (V1[0].buffer); 1391 1429 } 1430 1431 clear_stack (V1); 1392 1432 return (TRUE); 1393 1433 -
trunk/Ohana/src/opihi/lib.shell/string.c
r10732 r15878 249 249 return (c); 250 250 } 251 252 // append string defined by range start - stop to the end of output, which 253 // currently has an allocated size of Noutput. if this operation would overshoot Noutput, 254 // output is reallocated to a sufficiently large size 255 char *opihi_append (char *output, int *Noutput, char *start, char *stop) { 256 257 int N1, N2, outlen; 258 259 // a NULL end pointer means 'go to end of line' 260 if (stop == NULL) { 261 stop = start + strlen(start); 262 } 263 264 // enough space? 265 N1 = strlen(output); 266 N2 = stop - start; 267 outlen = N1 + N2; 268 if (outlen >= *Noutput) { 269 *Noutput = outlen + 128; 270 REALLOCATE (output, char, *Noutput); 271 memset (&output[N1], 0, N2 + 128); 272 } 273 274 strncat (output, start, stop - start); 275 return output; 276 } 277 278 /* replace all instances of \A with A in line */ 279 void interpolate_slash (char *line) { 280 281 char *in, *out; 282 283 for (in = out = line; *in != 0; in++, out++) { 284 if (*in == 0x5c) in++; 285 *out = *in; 286 if (*in == 0) return; 287 } 288 *out = *in; 289 }
Note:
See TracChangeset
for help on using the changeset viewer.
