Changeset 42080
- Timestamp:
- Feb 28, 2022, 12:14:19 PM (4 years ago)
- Location:
- trunk/Ohana/src/opihi/lib.shell
- Files:
-
- 6 edited
-
VariableOps.c (modified) (6 diffs)
-
VectorOps.c (modified) (1 diff)
-
convert_to_RPN.c (modified) (1 diff)
-
evaluate_stack.c (modified) (2 diffs)
-
expand_vectors.c (modified) (1 diff)
-
stack_math.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/VariableOps.c
r39558 r42080 1 1 # include "opihi.h" 2 # define USE_DEPTH 1 2 3 3 4 Variable *variables; /* variable to store the list of all variables */ … … 27 28 28 29 int i; 29 char *local, *MacroName; 30 31 /* a local variable has the form (macroname).(varname) */ 32 MacroName = GetMacroName (); 30 char *local; 31 32 /* a local variable has the form (macroname).(depth).(varname) */ 33 char *MacroName = GetMacroName (); 34 int MacroDepth = GetMacroDepth (); 33 35 34 36 /* need to use a mutex to prevent two threads from changing variable list simultaneously */ … … 36 38 37 39 /* look for existing local variable */ 38 ALLOCATE (local, char, strlen(name) + strlen(MacroName) + 2); 39 sprintf (local, "%s.%s", MacroName, name); 40 int maxLen = strlen(name) + strlen(MacroName) + 16; 41 ALLOCATE (local, char, maxLen); 42 if (USE_DEPTH) { 43 snprintf (local, maxLen, "%s.%d.%s", MacroName, MacroDepth, name); 44 } else { 45 snprintf (local, maxLen, "%s.%s", MacroName, name); 46 } 40 47 for (i = 0; i < Nvariables; i++) { 41 48 if (!strcmp (local, variables[i].name)) { … … 59 66 60 67 int i; 61 char *local, *MacroName; 62 63 MacroName = GetMacroName (); 68 char *local; 69 70 char *MacroName = GetMacroName (); 71 int MacroDepth = GetMacroDepth (); 64 72 65 73 /* need to use a mutex to prevent two threads from changing variable list simultaneously */ … … 67 75 68 76 /* look for local variable first */ 69 ALLOCATE (local, char, strlen(name) + strlen(MacroName) + 2); 70 sprintf (local, "%s.%s", MacroName, name); 77 int maxLen = strlen(name) + strlen(MacroName) + 16; 78 ALLOCATE (local, char, maxLen); 79 if (USE_DEPTH) { 80 snprintf (local, maxLen, "%s.%d.%s", MacroName, MacroDepth, name); 81 } else { 82 snprintf (local, maxLen, "%s.%s", MacroName, name); 83 } 71 84 for (i = 0; i < Nvariables; i++) { 72 85 if (!strcmp (local, variables[i].name)) { … … 122 135 123 136 int i; 124 char *local, *MacroName; 125 126 MacroName = GetMacroName (); 137 char *local; 138 139 char *MacroName = GetMacroName (); 140 int MacroDepth = GetMacroDepth (); 127 141 128 142 /* look for local variable first */ 129 ALLOCATE (local, char, strlen(name) + strlen(MacroName) + 2); 130 sprintf (local, "%s.%s", MacroName, name); 143 int maxLen = strlen(name) + strlen(MacroName) + 16; 144 ALLOCATE (local, char, maxLen); 145 if (USE_DEPTH) { 146 snprintf (local, maxLen, "%s.%d.%s", MacroName, MacroDepth, name); 147 } else { 148 snprintf (local, maxLen, "%s.%s", MacroName, name); 149 } 131 150 132 151 /* need to use a mutex to prevent another thread from misleading on size of Nvariables */ -
trunk/Ohana/src/opihi/lib.shell/VectorOps.c
r41959 r42080 103 103 if (mode == OLDVECTOR) goto error; 104 104 // validate vector name syntax 105 // vector with ":" will be failed so I comment it out CCL 106 // if (!IsVectorNameValid(name)) { gprint (GP_ERR, "invalid vector name %s\n", name); return NULL; } 105 if (!IsVectorNameValid(name)) { gprint (GP_ERR, "invalid vector name %s\n", name); return NULL; } 107 106 pthread_mutex_lock (&mutex); 108 107 Nvectors ++; -
trunk/Ohana/src/opihi/lib.shell/convert_to_RPN.c
r41341 r42080 71 71 if (!strcmp (argv[i], "isnan")) { type = ST_UNARY; goto gotit; } 72 72 73 /* string-valid unary operations */ 74 if (!strcmp (argv[i], "isword")) { type = ST_UNARY; goto gotit; } 75 if (!strcmp (argv[i], "isnum")) { type = ST_UNARY; goto gotit; } 76 if (!strcmp (argv[i], "isint")) { type = ST_UNARY; goto gotit; } 77 if (!strcmp (argv[i], "isflt")) { type = ST_UNARY; goto gotit; } 78 if (!strcmp (argv[i], "length")) { type = ST_UNARY; goto gotit; } 79 73 80 /* binary operations */ 81 // NOTE: I archically use the first character of the function name in a switch to identify the operation 82 // I should re-work this with an enum which defines the operatino 74 83 if (!strcmp (argv[i], "^")) { type = ST_POWER; goto gotit; } 75 84 -
trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c
r41363 r42080 124 124 THREE_OP (ST_SCALAR_INT,SSS_trinary); 125 125 126 /* there are no valid unary string operators */126 /* there are no valid trinary string operators */ 127 127 snprintf (line, 512, "invalid operands for trinary operator %s (mismatch types?)\n(Note that the : in a trinary operation must be protected by spaces)", stack[i].name); 128 128 push_error (line); … … 260 260 ONE_OP (ST_SCALAR_FLT, S_unary); 261 261 262 /* there are no valid unary string operators */ 262 ONE_OP (ST_STRING, W_unary); 263 263 264 snprintf (line, 512, "invalid operand for unary operator %s (undefined value?)", stack[i].name); 264 265 push_error (line); -
trunk/Ohana/src/opihi/lib.shell/expand_vectors.c
r41959 r42080 135 135 // include/shell.h. A vector name cannot include a colon, while a variable name 136 136 // cannot include a dot. 137 // temporary remove ISVEC check until ":" issue fixed CCL 138 //for (w = p - 1; (w >= line) && !OHANA_WHITESPACE(*w) && ISVEC(*w); w--); 139 for (w = p - 1; (w >= line) && !OHANA_WHITESPACE(*w); w--); 137 138 for (w = p - 1; (w >= line) && !OHANA_WHITESPACE(*w) && ISVEC(*w); w--); 140 139 w ++; 141 140 n = (int)(p - w); -
trunk/Ohana/src/opihi/lib.shell/stack_math.c
r41363 r42080 1500 1500 if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) { \ 1501 1501 opihi_int M1 = V1[0].IntValue; \ 1502 OUT[0].type = ST_SCALAR_INT; \ 1503 OUT[0].IntValue = OP; \ 1504 clear_stack (V1); \ 1505 return (TRUE); \ 1506 } \ 1507 } 1508 1509 # define W_FUNC(OP,FTYPE) { \ 1510 if (V1->type == ST_SCALAR_FLT) { \ 1511 OUT[0].type = ST_SCALAR_FLT; \ 1512 OUT[0].FltValue = OP; \ 1513 clear_stack (V1); \ 1514 return (TRUE); \ 1515 } \ 1516 if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT)) { \ 1517 OUT[0].type = ST_SCALAR_FLT; \ 1518 OUT[0].FltValue = OP; \ 1519 clear_stack (V1); \ 1520 return (TRUE); \ 1521 } \ 1522 if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) { \ 1502 1523 OUT[0].type = ST_SCALAR_INT; \ 1503 1524 OUT[0].IntValue = OP; \ … … 1536 1557 if (!strcmp (op, "datan")) S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT); 1537 1558 if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), ST_SCALAR_FLT); 1538 if (!strcmp (op, "rnd")) S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT);1539 if (!strcmp (op, "drnd")) S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT);1540 if (!strcmp (op, "lrnd")) S_FUNC(0*M1 + lrand48(), ST_SCALAR_INT);1541 if (!strcmp (op, "mrnd")) S_FUNC(0*M1 + mrand48(), ST_SCALAR_INT);1542 1559 if (!strcmp (op, "not")) S_FUNC(!(M1), ST_SCALAR_INT); 1543 1560 if (!strcmp (op, "--")) S_FUNC(-1*M1, ST_SCALAR_INT); // NOTE: opihi_int is signed, … … 1545 1562 if (!strcmp (op, "isnan")) S_FUNC(isnan((opihi_flt)(M1)), ST_SCALAR_FLT); // XXX modify in future 1546 1563 1564 // these ops do not use the V1 value (W_FUNC does define a temp variable M1) 1565 if (!strcmp (op, "rnd")) W_FUNC(drand48(), ST_SCALAR_FLT); 1566 if (!strcmp (op, "drnd")) W_FUNC(drand48(), ST_SCALAR_FLT); 1567 if (!strcmp (op, "lrnd")) W_FUNC(lrand48(), ST_SCALAR_INT); 1568 if (!strcmp (op, "mrnd")) W_FUNC(mrand48(), ST_SCALAR_INT); 1569 1570 // these are also valid for string values 1571 if (!strcmp (op, "isword")) W_FUNC(FALSE, ST_SCALAR_INT); 1572 if (!strcmp (op, "isnum")) W_FUNC(TRUE, ST_SCALAR_INT); 1573 if (!strcmp (op, "isint")) W_FUNC((V1->type == ST_SCALAR_INT), ST_SCALAR_INT); 1574 if (!strcmp (op, "isflt")) W_FUNC((V1->type == ST_SCALAR_FLT), ST_SCALAR_INT); 1575 1547 1576 # undef S_FUNC 1548 1549 clear_stack (V1); 1550 1551 char line[512]; // this is only used to report an error 1552 snprintf (line, 512, "error: op %s not defined as unary scalar op!", op); 1577 # undef W_FUNC 1578 1579 clear_stack (V1); 1580 1581 char line[512]; // this is only used to report an error 1582 snprintf (line, 512, "error: op %s not defined as unary scalar op for a numerical value!", op); 1583 push_error (line); 1584 return (FALSE); 1585 } 1586 1587 int W_unary (StackVar *OUT, StackVar *V1, char *op) { 1588 1589 # define W_FUNC(VALUE) { \ 1590 OUT[0].type = ST_SCALAR_INT; \ 1591 OUT[0].IntValue = VALUE; \ 1592 clear_stack (V1); \ 1593 return (TRUE); \ 1594 } 1595 1596 // string unary functions (all result in int output values) 1597 if (!strcmp (op, "isword")) W_FUNC(TRUE); 1598 if (!strcmp (op, "isnum")) W_FUNC(FALSE); 1599 if (!strcmp (op, "isint")) W_FUNC(FALSE); 1600 if (!strcmp (op, "isflt")) W_FUNC(FALSE); 1601 if (!strcmp (op, "length")) W_FUNC(strlen(V1[0].name)); 1602 1603 # undef W_FUNC 1604 1605 clear_stack (V1); 1606 1607 char line[512]; // this is only used to report an error 1608 snprintf (line, 512, "error: op %s not defined as unary scalar op for a string value!", op); 1553 1609 push_error (line); 1554 1610 return (FALSE);
Note:
See TracChangeset
for help on using the changeset viewer.
