- Timestamp:
- Mar 29, 2019, 5:05:27 AM (7 years ago)
- Location:
- trunk/Ohana/src/opihi/lib.shell
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/ListOps.c
r39333 r40652 213 213 if (!strcmp (temp, "-x")) goto escape; 214 214 if (!strcmp (temp, "-glob")) goto escape; 215 if (!strcmp (temp, "-file")) goto escape; 215 216 if (!strcmp (temp, "-split")) goto escape; 216 217 if (!strcmp (temp, "-join")) goto escape; -
trunk/Ohana/src/opihi/lib.shell/expand_vars.c
r30614 r40652 23 23 24 24 /* look for form $a$b..$n and expand only the last ones */ 25 26 // expand from line (L) into newline (N) 25 27 for (L = line, N = newline; *L != 0; N++, L++) { /* loop until end of line */ 28 29 // look for end of line or start of variable ($) 26 30 for (done = FALSE; !done;) { 27 31 if (*L == 0) done = TRUE; 32 33 // look for the last $var 28 34 if (*L == '$') { 29 35 V1 = aftervar(L); … … 31 37 if (V1 == NULL) done = TRUE; 32 38 } 39 40 // copy into newline 33 41 if (!done) { 34 42 *N = *L; … … 44 52 } 45 53 54 // end of the line 46 55 if (*L == 0) break; 47 56 … … 50 59 /* note: V1 points to a fraction of L, it does not need to be freed */ 51 60 52 /* no variable name */61 /* no variable name, e.g., word$ or $$. keep the $ intact */ 53 62 if (V0 == NULL) { 54 63 *N = *L; … … 62 71 } 63 72 64 /* variable assignment ( skip these variables)*/73 /* variable assignment ($ at start of the line) : skip these variables */ 65 74 if ((L == line) && (V1 != NULL)) { 66 75 int isAssignment; … … 86 95 } 87 96 97 // V0 is the name of a variable. 98 // $tree_$branch_$twig should work (e.g,. $foo_bar_baz exists, $twig = baz, $foo_bar_$twig ) 99 // $ref = name; echo $$ref:n word need to expand $ref to get value of $name:n 100 101 // examples of valid nested variables, given $name = value, $ref = name, $name:n = 1, $name:0 = a, $i = 0 102 // $$ref -> value 103 // $$ref:n -> $name:n 104 // $$ref:$i -> $$ref:0 $name:9 105 106 // is there a $ in the previous character? 107 // do not include ':' in the variable name 108 int isRef = FALSE; 109 if ((L != line) && (L[-1] == '$')) { 110 free (V0); 111 V0 = thisref(L); 112 isRef = TRUE; 113 } 114 115 // check for macro-arguments ($1, $2) 88 116 found = TRUE; 89 117 for (c = V0; isdigit(*c); c++); /* test if this is a macro argument variable (ie, $1.2) */ … … 100 128 } 101 129 } 130 131 // we have something of the form $word, where V0 now is word. expand it out: 102 132 103 133 Val = get_variable_ptr (V0); … … 117 147 N--; /* we overshoot on last loop */ 118 148 119 /* skip past the variable in the source line */149 /* skip past the variable (or reference) in the source line */ 120 150 /* L currently points at $ */ 121 151 L++; 122 152 if (*L == '?') L++; /* skip past ? in $?name */ 123 153 124 while (ISVAR(*L)) L++; 154 if (isRef) { 155 while (ISREF(*L)) L++; 156 } else { 157 while (ISVAR(*L)) L++; 158 } 125 159 L--; /* we overshoot */ 126 160 -
trunk/Ohana/src/opihi/lib.shell/opihi.c
r34088 r40652 8 8 pid_t ppid; 9 9 10 general_init (&argc, argv); 11 program_init (&argc, argv); 12 startup (&argc, argv); 10 general_init (&argc, argv); // in startup.c : init drand48, signals, gprint, opihi_error 11 program_init (&argc, argv); // in mana.c.in, dvo.c.in, etc 12 startup (&argc, argv); // in startup.c : set global variables, load history, --norc, --only 13 13 prompt = get_variable("PROMPT"); 14 14 history = get_variable("HISTORY"); -
trunk/Ohana/src/opihi/lib.shell/string.c
r37049 r40652 114 114 } 115 115 116 /* take a pointer to the beginning of a variable (ie $foo) 117 and extract only the variable name (eg, foo) */ 118 119 char *thisref (char *string) { 120 121 int i, start; 122 char *word; 123 124 if (string == (char *) NULL) return ((char *) NULL); 125 if (string[0] != '$') return ((char *) NULL); 126 127 /* special case $?name : check that name is valid */ 128 start = 1; 129 if (string[1] == '?') start = 2; 130 131 for (i = start; ISREF(string[i]); i++); 132 if (i == start) return ((char *) NULL); 133 134 /* the ? is part of the variable */ 135 word = strncreate (&string[1], i - 1); 136 return (word); 137 138 } 116 139 117 140 /**********************************************************************/
Note:
See TracChangeset
for help on using the changeset viewer.
