- Timestamp:
- May 23, 2020, 11:34:29 AM (6 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 5 edited
-
cmd.data/read_vectors.c (modified) (1 diff)
-
include/dvomath.h (modified) (2 diffs)
-
lib.shell/check_stack.c (modified) (1 diff)
-
lib.shell/evaluate_stack.c (modified) (3 diffs)
-
lib.shell/stack_math.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/read_vectors.c
r41341 r41363 335 335 value = thisword(ptr); 336 336 } 337 if (value == NULL) {value = strcreate ("");} // we need at least an empty string not a NULL 337 338 vec[i][0].elements.Str[Nelem] = value; // needs to be freed later. 338 339 break; -
trunk/Ohana/src/opihi/include/dvomath.h
r41341 r41363 102 102 void clear_stack PROTO((StackVar *stack)); 103 103 void assign_stack PROTO((StackVar *stack, char *name, StackVarType type)); 104 char *clean_stack_name PROTO((char *name)); 104 105 105 106 int SSS_trinary PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op)); … … 116 117 int SM_binary PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op)); 117 118 int SS_binary PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op)); 119 int LW_binary PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op)); 120 int WL_binary PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op)); 121 int LL_binary PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op)); 118 122 int WW_binary PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op)); 119 123 int S_unary PROTO((StackVar *OUT, StackVar *V1, char *op)); -
trunk/Ohana/src/opihi/lib.shell/check_stack.c
r40329 r41363 84 84 /* this is not a scalar, vector, or matrix. must be string */ 85 85 stack[i].type = ST_STRING; 86 87 /* I could strip the quotes from the name here, 88 but this might change the behavior for string tests 89 */ 90 91 // I cannot require quotes around a string here because variables are expanded upstream 86 92 } 87 93 } -
trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c
r40487 r41363 30 30 31 31 // A & B value types all have 2 possible values 32 // 32 33 # define TWO_OP(A,B,FUNC) { \ 33 34 if ((stack[i - 2].type == A) && (stack[i - 1].type == B)) { \ … … 163 164 } 164 165 166 // TWO_OP(A,B,OP) : A,B types all have a main value and a secondary value at A+1 or B+1: 167 // ST_MATRIX -> ST_MATRIX_TMP 168 // ST_VECTOR -> ST_VECTOR_TMP 169 // ST_SCALAR_INT -> ST_SCALAR_FLT 165 170 status = FALSE; 166 171 TWO_OP (ST_MATRIX,ST_MATRIX,MM_binary); 167 172 TWO_OP (ST_MATRIX,ST_VECTOR,MV_binary); 168 TWO_OP (ST_MATRIX,ST_SCALAR_INT,MS_binary); 173 TWO_OP (ST_MATRIX,ST_SCALAR_INT,MS_binary); // handles ST_SCALAR_INT and ST_SCALAR_FLT 169 174 170 175 TWO_OP (ST_VECTOR,ST_MATRIX,VM_binary); 171 176 TWO_OP (ST_VECTOR,ST_VECTOR,VV_binary); 172 TWO_OP (ST_VECTOR,ST_SCALAR_INT,VS_binary); 173 174 TWO_OP (ST_SCALAR_INT,ST_MATRIX,SM_binary); 175 TWO_OP (ST_SCALAR_INT,ST_VECTOR,SV_binary); 176 TWO_OP (ST_SCALAR_INT,ST_SCALAR_INT,SS_binary); 177 178 TWO_OP (ST_SCALAR_FLT,ST_MATRIX,SM_binary); 179 TWO_OP (ST_SCALAR_FLT,ST_VECTOR,SV_binary); 180 TWO_OP (ST_SCALAR_FLT,ST_SCALAR_INT,SS_binary); 177 TWO_OP (ST_VECTOR,ST_SCALAR_INT,VS_binary); // handles ST_SCALAR_INT and ST_SCALAR_FLT 178 179 TWO_OP (ST_SCALAR_INT,ST_MATRIX,SM_binary); // handles ST_SCALAR_INT and ST_SCALAR_FLT 180 TWO_OP (ST_SCALAR_INT,ST_VECTOR,SV_binary); // handles ST_SCALAR_INT and ST_SCALAR_FLT 181 TWO_OP (ST_SCALAR_INT,ST_SCALAR_INT,SS_binary); // handles ST_SCALAR_INT and ST_SCALAR_FLT 182 183 // XXX: this block is not needed 184 // TWO_OP (ST_SCALAR_FLT,ST_MATRIX,SM_binary); 185 // TWO_OP (ST_SCALAR_FLT,ST_VECTOR,SV_binary); 186 // TWO_OP (ST_SCALAR_FLT,ST_SCALAR_INT,SS_binary); 187 188 TWO_OP (ST_VECTOR,ST_STRING,LW_binary); 189 TWO_OP (ST_STRING,ST_VECTOR,WL_binary); 181 190 182 191 TWO_OP (ST_STRING,ST_STRING,WW_binary); … … 350 359 } 351 360 361 // strip off surrounding " and return newly allocated string 362 char *clean_stack_name (char *name) { 363 364 if (!name) return name; 365 366 char *tmpname = name; 367 if (name[0] == '"') tmpname ++; 368 369 char *output = strcreate (tmpname); 370 371 int Nchar = strlen(output); 372 if (Nchar == 0) return output; // empty string 373 374 // squash ending quotes: 375 if (output[Nchar - 1] == '"') output[Nchar - 1] = 0; 376 377 return output; 378 } 379 352 380 void assign_stack (StackVar *stack, char *name, StackVarType type) { 353 stack->name = strcreate (name);381 stack->name = strcreate(name); 354 382 stack->type = type; 355 383 } -
trunk/Ohana/src/opihi/lib.shell/stack_math.c
r41341 r41363 272 272 if (V1[0].vector[0].Nelements != V2[0].vector[0].Nelements) { 273 273 return (FALSE); 274 } 275 276 if ((V1->vector->type == OPIHI_STR) && (V2->vector->type == OPIHI_STR)) { 277 int status = LL_binary (OUT, V1, V2, op); 278 return status; 274 279 } 275 280 … … 1315 1320 return (TRUE); 1316 1321 1322 } 1323 1324 // vector string OP scalar string (called if V1 is vector, V2 is string) 1325 // V1 MUST be a string-valued vector 1326 int LW_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) { 1327 1328 char line[512]; // this is only used to report an error 1329 1330 if (V1->vector->type != OPIHI_STR) { 1331 snprintf (line, 512, "error: binary operation between numerical vector and string not defined"); 1332 push_error (line); 1333 return (FALSE); 1334 } 1335 1336 /* only 'N' and 'E' are allowed for WW_binary operations. anything else is either a 1337 syntax error or is a string which looks like a math expression. */ 1338 1339 if ((op[0] != 'N') && (op[0] != 'E')) { 1340 snprintf (line, 512, "error: op %c not defined for vector string operations!", op[0]); 1341 push_error (line); 1342 return (FALSE); 1343 } 1344 1345 int Nx = V1[0].vector[0].Nelements; 1346 1347 OUT[0].vector = InitVector (); 1348 OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/ 1349 1350 /* evaluate stack will only call WW_binary with one numerical value, 1351 and only in the case that the string did not parse to a number 1352 thus: string == number -> false */ 1353 1354 // output vector is an integer (result of strcmp test) 1355 MatchVector (OUT[0].vector, V1[0].vector, OPIHI_INT); 1356 opihi_int *out = OUT[0].vector[0].elements.Int; 1357 1358 // remove the quotes around the name (string value) here 1359 char *M2 = clean_stack_name(V2[0].name); 1360 1361 for (int i = 0; i < Nx; i++, out++) { 1362 char *M1 = V1[0].vector[0].elements.Str[i]; 1363 if (op[0] == 'E') { 1364 // *out = (M1 == NULL) || strcmp(M1, M2) ? 0 : 1; 1365 *out = strcmp(M1, M2) ? 0 : 1; 1366 } 1367 if (op[0] == 'N') { 1368 *out = strcmp(M1, M2) ? 1 : 0; 1369 } 1370 } 1371 1372 clear_stack (V1); 1373 clear_stack (V2); 1374 FREE (M2); 1375 1376 /* at the end, V1 and V2 are deleted only if they were temporary */ 1377 return (TRUE); 1378 } 1379 1380 // vector string OP scalar string (called if V2 is vector, V1 is string) 1381 // V2 MUST be a string-valued vector 1382 int WL_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) { 1383 1384 char line[512]; // this is only used to report an error 1385 1386 if (V2->vector->type != OPIHI_STR) { 1387 snprintf (line, 512, "error: binary operation between numerical vector and string not defined"); 1388 push_error (line); 1389 return (FALSE); 1390 } 1391 1392 /* only 'N' and 'E' are allowed for WW_binary operations. anything else is either a 1393 syntax error or is a string which looks like a math expression. */ 1394 1395 if ((op[0] != 'N') && (op[0] != 'E')) { 1396 snprintf (line, 512, "error: op %c not defined for vector string operations!", op[0]); 1397 push_error (line); 1398 return (FALSE); 1399 } 1400 1401 int Nx = V2[0].vector[0].Nelements; 1402 1403 OUT[0].vector = InitVector (); 1404 OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/ 1405 1406 /* evaluate stack will only call WW_binary with one numerical value, 1407 and only in the case that the string did not parse to a number 1408 thus: string == number -> false */ 1409 1410 // output vector is an integer (result of strcmp test) 1411 MatchVector (OUT[0].vector, V2[0].vector, OPIHI_INT); 1412 opihi_int *out = OUT[0].vector[0].elements.Int; 1413 1414 // remove the quotes around the name (string value) here 1415 char *M1 = clean_stack_name(V1[0].name); 1416 1417 for (int i = 0; i < Nx; i++, out++) { 1418 char *M2 = V2[0].vector[0].elements.Str[i]; 1419 if (op[0] == 'E') { 1420 *out = strcmp(M1, M2) ? 0 : 1; 1421 } 1422 if (op[0] == 'N') { 1423 *out = strcmp(M1, M2) ? 1 : 0; 1424 } 1425 } 1426 1427 clear_stack (V1); 1428 clear_stack (V2); 1429 FREE (M1); 1430 1431 /* at the end, V1 and V2 are deleted only if they were temporary */ 1432 return (TRUE); 1433 } 1434 1435 // vector string OP vector string (called by VV_binary above if both V1 & V2 are vector strings) 1436 int LL_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) { 1437 1438 char line[512]; // this is only used to report an error 1439 1440 if ((V1->vector->type != OPIHI_STR) || (V2->vector->type != OPIHI_STR)) { 1441 snprintf (line, 512, "error: binary operations between numerical vector and string vector not defined"); 1442 push_error (line); 1443 return (FALSE); 1444 } 1445 1446 /* only 'N' and 'E' are allowed for WW_binary operations. anything else is either a 1447 syntax error or is a string which looks like a math expression. */ 1448 1449 if ((op[0] != 'N') && (op[0] != 'E')) { 1450 snprintf (line, 512, "error: op %c not defined for vector string operations!", op[0]); 1451 push_error (line); 1452 return (FALSE); 1453 } 1454 1455 int Nx = V1[0].vector[0].Nelements; 1456 1457 OUT[0].vector = InitVector (); 1458 OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/ 1459 1460 // output vector is an integer (result of strcmp test) 1461 MatchVector (OUT[0].vector, V1[0].vector, OPIHI_INT); 1462 opihi_int *out = OUT[0].vector[0].elements.Int; 1463 1464 char **M1 = V1[0].vector[0].elements.Str; 1465 char **M2 = V2[0].vector[0].elements.Str; 1466 1467 for (int i = 0; i < Nx; i++, out++, M1++, M2++) { 1468 if (op[0] == 'E') { 1469 *out = strcmp(*M1, *M2) ? 0 : 1; 1470 } 1471 if (op[0] == 'N') { 1472 *out = strcmp(*M1, *M2) ? 1 : 0; 1473 } 1474 } 1475 1476 clear_stack (V1); 1477 clear_stack (V2); 1478 1479 /* at the end, V1 and V2 are deleted only if they were temporary */ 1480 return (TRUE); 1317 1481 } 1318 1482
Note:
See TracChangeset
for help on using the changeset viewer.
