diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-10 18:05:12 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-10 18:05:12 +0000 |
commit | 46ccdcb96eab18739509078638a0a7b2ae393684 (patch) | |
tree | c6d6877ecae7711228120afa6065f7862f019666 /shell | |
parent | 7b4f3f13d305d0b610f232699fac9f54cc74ec3c (diff) | |
download | busybox-w32-46ccdcb96eab18739509078638a0a7b2ae393684.tar.gz busybox-w32-46ccdcb96eab18739509078638a0a7b2ae393684.tar.bz2 busybox-w32-46ccdcb96eab18739509078638a0a7b2ae393684.zip |
hush: search/and/replace style cleanups, no code changes
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 261 |
1 files changed, 123 insertions, 138 deletions
diff --git a/shell/hush.c b/shell/hush.c index 58100d4d1..ca854c2eb 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -20,7 +20,7 @@ | |||
20 | * rewrites. | 20 | * rewrites. |
21 | * | 21 | * |
22 | * Other credits: | 22 | * Other credits: |
23 | * b_addchr() derived from similar w_addchar function in glibc-2.2 | 23 | * o_addchr() derived from similar w_addchar function in glibc-2.2 |
24 | * setup_redirect(), redirect_opt_num(), and big chunks of main() | 24 | * setup_redirect(), redirect_opt_num(), and big chunks of main() |
25 | * and many builtins derived from contributions by Erik Andersen | 25 | * and many builtins derived from contributions by Erik Andersen |
26 | * miscellaneous bugfixes from Matt Kraai | 26 | * miscellaneous bugfixes from Matt Kraai |
@@ -293,10 +293,6 @@ struct child_prog { | |||
293 | smallint is_stopped; /* is the program currently running? */ | 293 | smallint is_stopped; /* is the program currently running? */ |
294 | struct redir_struct *redirects; /* I/O redirections */ | 294 | struct redir_struct *redirects; /* I/O redirections */ |
295 | struct pipe *family; /* pointer back to the child's parent pipe */ | 295 | struct pipe *family; /* pointer back to the child's parent pipe */ |
296 | //sp counting seems to be broken... so commented out, grep for '//sp:' | ||
297 | //sp: int sp; /* number of SPECIAL_VAR_SYMBOL */ | ||
298 | //seems to be unused, grep for '//pt:' | ||
299 | //pt: int parse_type; | ||
300 | }; | 296 | }; |
301 | /* argv vector may contain variable references (^Cvar^C, ^C0^C etc) | 297 | /* argv vector may contain variable references (^Cvar^C, ^C0^C etc) |
302 | * and on execution these are substituted with their values. | 298 | * and on execution these are substituted with their values. |
@@ -361,8 +357,8 @@ struct in_str { | |||
361 | int (*get) (struct in_str *); | 357 | int (*get) (struct in_str *); |
362 | int (*peek) (struct in_str *); | 358 | int (*peek) (struct in_str *); |
363 | }; | 359 | }; |
364 | #define b_getch(input) ((input)->get(input)) | 360 | #define i_getch(input) ((input)->get(input)) |
365 | #define b_peek(input) ((input)->peek(input)) | 361 | #define i_peek(input) ((input)->peek(input)) |
366 | 362 | ||
367 | enum { | 363 | enum { |
368 | CHAR_ORDINARY = 0, | 364 | CHAR_ORDINARY = 0, |
@@ -533,12 +529,12 @@ static int done_pipe(struct p_context *ctx, pipe_style type); | |||
533 | static int redirect_dup_num(struct in_str *input); | 529 | static int redirect_dup_num(struct in_str *input); |
534 | static int redirect_opt_num(o_string *o); | 530 | static int redirect_opt_num(o_string *o); |
535 | #if ENABLE_HUSH_TICK | 531 | #if ENABLE_HUSH_TICK |
536 | static int process_command_subs(o_string *dest, /*struct p_context *ctx,*/ | 532 | static int process_command_subs(o_string *dest, |
537 | struct in_str *input, const char *subst_end); | 533 | struct in_str *input, const char *subst_end); |
538 | #endif | 534 | #endif |
539 | static int parse_group(o_string *dest, struct p_context *ctx, struct in_str *input, int ch); | 535 | static int parse_group(o_string *dest, struct p_context *ctx, struct in_str *input, int ch); |
540 | static const char *lookup_param(const char *src); | 536 | static const char *lookup_param(const char *src); |
541 | static int handle_dollar(o_string *dest, /*struct p_context *ctx,*/ | 537 | static int handle_dollar(o_string *dest, |
542 | struct in_str *input); | 538 | struct in_str *input); |
543 | static int parse_stream(o_string *dest, struct p_context *ctx, struct in_str *input0, const char *end_trigger); | 539 | static int parse_stream(o_string *dest, struct p_context *ctx, struct in_str *input0, const char *end_trigger); |
544 | /* setup: */ | 540 | /* setup: */ |
@@ -1175,7 +1171,7 @@ static int builtin_unset(char **argv) | |||
1175 | */ | 1171 | */ |
1176 | #define B_CHUNK (32 * sizeof(char*)) | 1172 | #define B_CHUNK (32 * sizeof(char*)) |
1177 | 1173 | ||
1178 | static void b_reset(o_string *o) | 1174 | static void o_reset(o_string *o) |
1179 | { | 1175 | { |
1180 | o->length = 0; | 1176 | o->length = 0; |
1181 | o->nonnull = 0; | 1177 | o->nonnull = 0; |
@@ -1183,13 +1179,13 @@ static void b_reset(o_string *o) | |||
1183 | o->data[0] = '\0'; | 1179 | o->data[0] = '\0'; |
1184 | } | 1180 | } |
1185 | 1181 | ||
1186 | static void b_free(o_string *o) | 1182 | static void o_free(o_string *o) |
1187 | { | 1183 | { |
1188 | free(o->data); | 1184 | free(o->data); |
1189 | memset(o, 0, sizeof(*o)); | 1185 | memset(o, 0, sizeof(*o)); |
1190 | } | 1186 | } |
1191 | 1187 | ||
1192 | static void b_grow_by(o_string *o, int len) | 1188 | static void o_grow_by(o_string *o, int len) |
1193 | { | 1189 | { |
1194 | if (o->length + len > o->maxlen) { | 1190 | if (o->length + len > o->maxlen) { |
1195 | o->maxlen += (2*len > B_CHUNK ? 2*len : B_CHUNK); | 1191 | o->maxlen += (2*len > B_CHUNK ? 2*len : B_CHUNK); |
@@ -1197,18 +1193,18 @@ static void b_grow_by(o_string *o, int len) | |||
1197 | } | 1193 | } |
1198 | } | 1194 | } |
1199 | 1195 | ||
1200 | static void b_addchr(o_string *o, int ch) | 1196 | static void o_addchr(o_string *o, int ch) |
1201 | { | 1197 | { |
1202 | debug_printf("b_addchr: '%c' o->length=%d o=%p\n", ch, o->length, o); | 1198 | debug_printf("o_addchr: '%c' o->length=%d o=%p\n", ch, o->length, o); |
1203 | b_grow_by(o, 1); | 1199 | o_grow_by(o, 1); |
1204 | o->data[o->length] = ch; | 1200 | o->data[o->length] = ch; |
1205 | o->length++; | 1201 | o->length++; |
1206 | o->data[o->length] = '\0'; | 1202 | o->data[o->length] = '\0'; |
1207 | } | 1203 | } |
1208 | 1204 | ||
1209 | static void b_addstr(o_string *o, const char *str, int len) | 1205 | static void o_addstr(o_string *o, const char *str, int len) |
1210 | { | 1206 | { |
1211 | b_grow_by(o, len); | 1207 | o_grow_by(o, len); |
1212 | memcpy(&o->data[o->length], str, len); | 1208 | memcpy(&o->data[o->length], str, len); |
1213 | o->length += len; | 1209 | o->length += len; |
1214 | o->data[o->length] = '\0'; | 1210 | o->data[o->length] = '\0'; |
@@ -1217,12 +1213,12 @@ static void b_addstr(o_string *o, const char *str, int len) | |||
1217 | /* My analysis of quoting semantics tells me that state information | 1213 | /* My analysis of quoting semantics tells me that state information |
1218 | * is associated with a destination, not a source. | 1214 | * is associated with a destination, not a source. |
1219 | */ | 1215 | */ |
1220 | static void b_addqchr(o_string *o, int ch, int quote) | 1216 | static void o_addqchr(o_string *o, int ch, int quote) |
1221 | { | 1217 | { |
1222 | if (quote && strchr("*?[\\", ch)) { | 1218 | if (quote && strchr("*?[\\", ch)) { |
1223 | b_addchr(o, '\\'); | 1219 | o_addchr(o, '\\'); |
1224 | } | 1220 | } |
1225 | b_addchr(o, ch); | 1221 | o_addchr(o, ch); |
1226 | } | 1222 | } |
1227 | 1223 | ||
1228 | /* A special kind of o_string for $VAR and `cmd` expansion. | 1224 | /* A special kind of o_string for $VAR and `cmd` expansion. |
@@ -1232,10 +1228,10 @@ static void b_addqchr(o_string *o, int ch, int quote) | |||
1232 | * It means that if list[] needs to grow, data needs to be moved higher up | 1228 | * It means that if list[] needs to grow, data needs to be moved higher up |
1233 | * but list[i]'s need not be modified. | 1229 | * but list[i]'s need not be modified. |
1234 | * NB: remembering how many list[i]'s you have there is crucial. | 1230 | * NB: remembering how many list[i]'s you have there is crucial. |
1235 | * b_finalize_list() operation post-processes this structure - calculates | 1231 | * o_finalize_list() operation post-processes this structure - calculates |
1236 | * and stores actual char* ptrs in list[]. Oh, it NULL terminates it as well. | 1232 | * and stores actual char* ptrs in list[]. Oh, it NULL terminates it as well. |
1237 | */ | 1233 | */ |
1238 | static int b_addptr(o_string *o, int n) | 1234 | static int o_save_ptr(o_string *o, int n) |
1239 | { | 1235 | { |
1240 | char **list = (char**)o->data; | 1236 | char **list = (char**)o->data; |
1241 | int string_start = ((n + 0xf) & ~0xf) * sizeof(list[0]); | 1237 | int string_start = ((n + 0xf) & ~0xf) * sizeof(list[0]); |
@@ -1258,7 +1254,7 @@ static int b_addptr(o_string *o, int n) | |||
1258 | return n + 1; | 1254 | return n + 1; |
1259 | } | 1255 | } |
1260 | 1256 | ||
1261 | static int b_get_last_ptr(o_string *o, int n) | 1257 | static int o_get_last_ptr(o_string *o, int n) |
1262 | { | 1258 | { |
1263 | char **list = (char**)o->data; | 1259 | char **list = (char**)o->data; |
1264 | int string_start = ((n + 0xf) & ~0xf) * sizeof(list[0]); | 1260 | int string_start = ((n + 0xf) & ~0xf) * sizeof(list[0]); |
@@ -1266,12 +1262,12 @@ static int b_get_last_ptr(o_string *o, int n) | |||
1266 | return ((int)list[n-1]) + string_start; | 1262 | return ((int)list[n-1]) + string_start; |
1267 | } | 1263 | } |
1268 | 1264 | ||
1269 | static char **b_finalize_list(o_string *o, int n) | 1265 | static char **o_finalize_list(o_string *o, int n) |
1270 | { | 1266 | { |
1271 | char **list = (char**)o->data; | 1267 | char **list = (char**)o->data; |
1272 | int string_start; | 1268 | int string_start; |
1273 | 1269 | ||
1274 | b_addptr(o, n); /* force growth for list[n] if necessary */ | 1270 | o_save_ptr(o, n); /* force growth for list[n] if necessary */ |
1275 | string_start = ((n+1 + 0xf) & ~0xf) * sizeof(list[0]); | 1271 | string_start = ((n+1 + 0xf) & ~0xf) * sizeof(list[0]); |
1276 | list[n] = NULL; | 1272 | list[n] = NULL; |
1277 | while (n) { | 1273 | while (n) { |
@@ -1282,7 +1278,7 @@ static char **b_finalize_list(o_string *o, int n) | |||
1282 | } | 1278 | } |
1283 | 1279 | ||
1284 | #ifdef DEBUG_EXPAND | 1280 | #ifdef DEBUG_EXPAND |
1285 | static void b_debug_list(const char *prefix, o_string *o, int n) | 1281 | static void o_debug_list(const char *prefix, o_string *o, int n) |
1286 | { | 1282 | { |
1287 | char **list = (char**)o->data; | 1283 | char **list = (char**)o->data; |
1288 | int string_start = ((n + 0xf) & ~0xf) * sizeof(list[0]); | 1284 | int string_start = ((n + 0xf) & ~0xf) * sizeof(list[0]); |
@@ -1300,7 +1296,7 @@ static void b_debug_list(const char *prefix, o_string *o, int n) | |||
1300 | } | 1296 | } |
1301 | } | 1297 | } |
1302 | #else | 1298 | #else |
1303 | #define b_debug_list(prefix, o, n) ((void)0) | 1299 | #define o_debug_list(prefix, o, n) ((void)0) |
1304 | #endif | 1300 | #endif |
1305 | 1301 | ||
1306 | 1302 | ||
@@ -1931,7 +1927,6 @@ static int run_pipe(struct pipe *pi) | |||
1931 | } | 1927 | } |
1932 | for (i = 0; is_assignment(argv[i]); i++) { | 1928 | for (i = 0; is_assignment(argv[i]); i++) { |
1933 | p = expand_string_to_string(argv[i]); | 1929 | p = expand_string_to_string(argv[i]); |
1934 | //sp: child->sp--; | ||
1935 | putenv(p); | 1930 | putenv(p); |
1936 | } | 1931 | } |
1937 | for (x = bltins; x->cmd; x++) { | 1932 | for (x = bltins; x->cmd; x++) { |
@@ -1948,7 +1943,6 @@ static int run_pipe(struct pipe *pi) | |||
1948 | * things seem to work with glibc. */ | 1943 | * things seem to work with glibc. */ |
1949 | setup_redirects(child, squirrel); | 1944 | setup_redirects(child, squirrel); |
1950 | debug_printf_exec(": builtin '%s' '%s'...\n", x->cmd, argv[i+1]); | 1945 | debug_printf_exec(": builtin '%s' '%s'...\n", x->cmd, argv[i+1]); |
1951 | //sp: if (child->sp) /* btw we can do it unconditionally... */ | ||
1952 | argv_expanded = expand_strvec_to_strvec(argv + i); | 1946 | argv_expanded = expand_strvec_to_strvec(argv + i); |
1953 | rcode = x->function(argv_expanded) & 0xff; | 1947 | rcode = x->function(argv_expanded) & 0xff; |
1954 | free(argv_expanded); | 1948 | free(argv_expanded); |
@@ -1964,7 +1958,6 @@ static int run_pipe(struct pipe *pi) | |||
1964 | setup_redirects(child, squirrel); | 1958 | setup_redirects(child, squirrel); |
1965 | save_nofork_data(&nofork_save); | 1959 | save_nofork_data(&nofork_save); |
1966 | argv_expanded = argv + i; | 1960 | argv_expanded = argv + i; |
1967 | //sp: if (child->sp) | ||
1968 | argv_expanded = expand_strvec_to_strvec(argv + i); | 1961 | argv_expanded = expand_strvec_to_strvec(argv + i); |
1969 | debug_printf_exec(": run_nofork_applet '%s' '%s'...\n", argv_expanded[0], argv_expanded[1]); | 1962 | debug_printf_exec(": run_nofork_applet '%s' '%s'...\n", argv_expanded[0], argv_expanded[1]); |
1970 | rcode = run_nofork_applet_prime(&nofork_save, a, argv_expanded); | 1963 | rcode = run_nofork_applet_prime(&nofork_save, a, argv_expanded); |
@@ -2549,17 +2542,17 @@ static int expand_on_ifs(o_string *output, int n, const char *str) | |||
2549 | while (1) { | 2542 | while (1) { |
2550 | int word_len = strcspn(str, ifs); | 2543 | int word_len = strcspn(str, ifs); |
2551 | if (word_len) { | 2544 | if (word_len) { |
2552 | b_addstr(output, str, word_len); /* store non-ifs chars */ | 2545 | o_addstr(output, str, word_len); /* store non-ifs chars */ |
2553 | str += word_len; | 2546 | str += word_len; |
2554 | } | 2547 | } |
2555 | if (!*str) /* EOL - do not finalize word */ | 2548 | if (!*str) /* EOL - do not finalize word */ |
2556 | break; | 2549 | break; |
2557 | b_addchr(output, '\0'); | 2550 | o_addchr(output, '\0'); |
2558 | b_debug_list("expand_on_ifs", output, n); | 2551 | o_debug_list("expand_on_ifs", output, n); |
2559 | n = b_addptr(output, n); | 2552 | n = o_save_ptr(output, n); |
2560 | str += strspn(str, ifs); /* skip ifs chars */ | 2553 | str += strspn(str, ifs); /* skip ifs chars */ |
2561 | } | 2554 | } |
2562 | b_debug_list("expand_on_ifs[1]", output, n); | 2555 | o_debug_list("expand_on_ifs[1]", output, n); |
2563 | return n; | 2556 | return n; |
2564 | } | 2557 | } |
2565 | 2558 | ||
@@ -2583,15 +2576,15 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask) | |||
2583 | ored_ch = 0; | 2576 | ored_ch = 0; |
2584 | 2577 | ||
2585 | debug_printf_expand("expand_vars_to_list: arg '%s'\n", arg); | 2578 | debug_printf_expand("expand_vars_to_list: arg '%s'\n", arg); |
2586 | b_debug_list("expand_vars_to_list", output, n); | 2579 | o_debug_list("expand_vars_to_list", output, n); |
2587 | n = b_addptr(output, n); | 2580 | n = o_save_ptr(output, n); |
2588 | b_debug_list("expand_vars_to_list[0]", output, n); | 2581 | o_debug_list("expand_vars_to_list[0]", output, n); |
2589 | 2582 | ||
2590 | while ((p = strchr(arg, SPECIAL_VAR_SYMBOL)) != NULL) { | 2583 | while ((p = strchr(arg, SPECIAL_VAR_SYMBOL)) != NULL) { |
2591 | o_string subst_result = NULL_O_STRING; | 2584 | o_string subst_result = NULL_O_STRING; |
2592 | 2585 | ||
2593 | b_addstr(output, arg, p - arg); | 2586 | o_addstr(output, arg, p - arg); |
2594 | b_debug_list("expand_vars_to_list[1]", output, n); | 2587 | o_debug_list("expand_vars_to_list[1]", output, n); |
2595 | arg = ++p; | 2588 | arg = ++p; |
2596 | p = strchr(p, SPECIAL_VAR_SYMBOL); | 2589 | p = strchr(p, SPECIAL_VAR_SYMBOL); |
2597 | 2590 | ||
@@ -2625,10 +2618,10 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask) | |||
2625 | if (global_argv[i++][0] && global_argv[i]) { | 2618 | if (global_argv[i++][0] && global_argv[i]) { |
2626 | /* this argv[] is not empty and not last: | 2619 | /* this argv[] is not empty and not last: |
2627 | * put terminating NUL, start new word */ | 2620 | * put terminating NUL, start new word */ |
2628 | b_addchr(output, '\0'); | 2621 | o_addchr(output, '\0'); |
2629 | b_debug_list("expand_vars_to_list[2]", output, n); | 2622 | o_debug_list("expand_vars_to_list[2]", output, n); |
2630 | n = b_addptr(output, n); | 2623 | n = o_save_ptr(output, n); |
2631 | b_debug_list("expand_vars_to_list[3]", output, n); | 2624 | o_debug_list("expand_vars_to_list[3]", output, n); |
2632 | } | 2625 | } |
2633 | } | 2626 | } |
2634 | } else | 2627 | } else |
@@ -2636,20 +2629,20 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask) | |||
2636 | * and in this case should treat it like '$*' - see 'else...' below */ | 2629 | * and in this case should treat it like '$*' - see 'else...' below */ |
2637 | if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */ | 2630 | if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */ |
2638 | while (1) { | 2631 | while (1) { |
2639 | b_addstr(output, global_argv[i], strlen(global_argv[i])); | 2632 | o_addstr(output, global_argv[i], strlen(global_argv[i])); |
2640 | if (++i >= global_argc) | 2633 | if (++i >= global_argc) |
2641 | break; | 2634 | break; |
2642 | b_addchr(output, '\0'); | 2635 | o_addchr(output, '\0'); |
2643 | b_debug_list("expand_vars_to_list[4]", output, n); | 2636 | o_debug_list("expand_vars_to_list[4]", output, n); |
2644 | n = b_addptr(output, n); | 2637 | n = o_save_ptr(output, n); |
2645 | } | 2638 | } |
2646 | } else { /* quoted $*: add as one word */ | 2639 | } else { /* quoted $*: add as one word */ |
2647 | while (1) { | 2640 | while (1) { |
2648 | b_addstr(output, global_argv[i], strlen(global_argv[i])); | 2641 | o_addstr(output, global_argv[i], strlen(global_argv[i])); |
2649 | if (!global_argv[++i]) | 2642 | if (!global_argv[++i]) |
2650 | break; | 2643 | break; |
2651 | if (ifs[0]) | 2644 | if (ifs[0]) |
2652 | b_addchr(output, ifs[0]); | 2645 | o_addchr(output, ifs[0]); |
2653 | } | 2646 | } |
2654 | } | 2647 | } |
2655 | break; | 2648 | break; |
@@ -2685,17 +2678,17 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask) | |||
2685 | } /* else: quoted $VAR, val will be appended below */ | 2678 | } /* else: quoted $VAR, val will be appended below */ |
2686 | } | 2679 | } |
2687 | if (val) | 2680 | if (val) |
2688 | b_addstr(output, val, strlen(val)); | 2681 | o_addstr(output, val, strlen(val)); |
2689 | 2682 | ||
2690 | b_free(&subst_result); | 2683 | o_free(&subst_result); |
2691 | arg = ++p; | 2684 | arg = ++p; |
2692 | } /* end of "while (SPECIAL_VAR_SYMBOL is found) ..." */ | 2685 | } /* end of "while (SPECIAL_VAR_SYMBOL is found) ..." */ |
2693 | 2686 | ||
2694 | b_debug_list("expand_vars_to_list[a]", output, n); | 2687 | o_debug_list("expand_vars_to_list[a]", output, n); |
2695 | b_addstr(output, arg, strlen(arg) + 1); | 2688 | o_addstr(output, arg, strlen(arg) + 1); |
2696 | b_debug_list("expand_vars_to_list[b]", output, n); | 2689 | o_debug_list("expand_vars_to_list[b]", output, n); |
2697 | //TESTME | 2690 | //TESTME |
2698 | if (output->length - 1 == b_get_last_ptr(output, n)) { /* expansion is empty */ | 2691 | if (output->length - 1 == o_get_last_ptr(output, n)) { /* expansion is empty */ |
2699 | if (!(ored_ch & 0x80)) { /* all vars were not quoted... */ | 2692 | if (!(ored_ch & 0x80)) { /* all vars were not quoted... */ |
2700 | n--; | 2693 | n--; |
2701 | /* allow to reuse list[n] later without re-growth */ | 2694 | /* allow to reuse list[n] later without re-growth */ |
@@ -2717,10 +2710,10 @@ static char **expand_variables(char **argv, char or_mask) | |||
2717 | v = argv; | 2710 | v = argv; |
2718 | while (*v) | 2711 | while (*v) |
2719 | n = expand_vars_to_list(&output, n, *v++, or_mask); | 2712 | n = expand_vars_to_list(&output, n, *v++, or_mask); |
2720 | b_debug_list("expand_variables", &output, n); | 2713 | o_debug_list("expand_variables", &output, n); |
2721 | 2714 | ||
2722 | /* output.data (malloced) gets returned in "list" */ | 2715 | /* output.data (malloced) gets returned in "list" */ |
2723 | list = b_finalize_list(&output, n); | 2716 | list = o_finalize_list(&output, n); |
2724 | 2717 | ||
2725 | #ifdef DEBUG_EXPAND | 2718 | #ifdef DEBUG_EXPAND |
2726 | { | 2719 | { |
@@ -3021,7 +3014,7 @@ static int reserved_word(o_string *dest, struct p_context *ctx) | |||
3021 | if (ctx->res_w == RES_IN || ctx->res_w == RES_FOR) { | 3014 | if (ctx->res_w == RES_IN || ctx->res_w == RES_FOR) { |
3022 | syntax("malformed for"); /* example: 'for if' */ | 3015 | syntax("malformed for"); /* example: 'for if' */ |
3023 | ctx->res_w = RES_SNTX; | 3016 | ctx->res_w = RES_SNTX; |
3024 | b_reset(dest); | 3017 | o_reset(dest); |
3025 | return 1; | 3018 | return 1; |
3026 | } | 3019 | } |
3027 | #endif | 3020 | #endif |
@@ -3032,7 +3025,7 @@ static int reserved_word(o_string *dest, struct p_context *ctx) | |||
3032 | } else if (ctx->res_w == RES_NONE || !(ctx->old_flag & (1 << r->code))) { | 3025 | } else if (ctx->res_w == RES_NONE || !(ctx->old_flag & (1 << r->code))) { |
3033 | syntax(NULL); | 3026 | syntax(NULL); |
3034 | ctx->res_w = RES_SNTX; | 3027 | ctx->res_w = RES_SNTX; |
3035 | b_reset(dest); | 3028 | o_reset(dest); |
3036 | return 1; | 3029 | return 1; |
3037 | } | 3030 | } |
3038 | ctx->res_w = r->code; | 3031 | ctx->res_w = r->code; |
@@ -3047,7 +3040,7 @@ static int reserved_word(o_string *dest, struct p_context *ctx) | |||
3047 | *ctx = *old; /* physical copy */ | 3040 | *ctx = *old; /* physical copy */ |
3048 | free(old); | 3041 | free(old); |
3049 | } | 3042 | } |
3050 | b_reset(dest); | 3043 | o_reset(dest); |
3051 | return 1; | 3044 | return 1; |
3052 | } | 3045 | } |
3053 | return 0; | 3046 | return 0; |
@@ -3092,7 +3085,7 @@ static int done_word(o_string *dest, struct p_context *ctx) | |||
3092 | return 1; | 3085 | return 1; |
3093 | } | 3086 | } |
3094 | 3087 | ||
3095 | b_reset(dest); | 3088 | o_reset(dest); |
3096 | if (ctx->pending_redirect) { | 3089 | if (ctx->pending_redirect) { |
3097 | /* NB: don't free_strings(ctx->pending_redirect->glob_word) here */ | 3090 | /* NB: don't free_strings(ctx->pending_redirect->glob_word) here */ |
3098 | if (ctx->pending_redirect->glob_word | 3091 | if (ctx->pending_redirect->glob_word |
@@ -3151,8 +3144,6 @@ static int done_command(struct p_context *ctx) | |||
3151 | /*child->is_stopped = 0;*/ | 3144 | /*child->is_stopped = 0;*/ |
3152 | /*child->group = NULL;*/ | 3145 | /*child->group = NULL;*/ |
3153 | child->family = pi; | 3146 | child->family = pi; |
3154 | //sp: /*child->sp = 0;*/ | ||
3155 | //pt: child->parse_type = ctx->parse_type; | ||
3156 | 3147 | ||
3157 | ctx->child = child; | 3148 | ctx->child = child; |
3158 | /* but ctx->pipe and ctx->list_head remain unchanged */ | 3149 | /* but ctx->pipe and ctx->list_head remain unchanged */ |
@@ -3190,20 +3181,20 @@ static int done_pipe(struct p_context *ctx, pipe_style type) | |||
3190 | static int redirect_dup_num(struct in_str *input) | 3181 | static int redirect_dup_num(struct in_str *input) |
3191 | { | 3182 | { |
3192 | int ch, d = 0, ok = 0; | 3183 | int ch, d = 0, ok = 0; |
3193 | ch = b_peek(input); | 3184 | ch = i_peek(input); |
3194 | if (ch != '&') return -1; | 3185 | if (ch != '&') return -1; |
3195 | 3186 | ||
3196 | b_getch(input); /* get the & */ | 3187 | i_getch(input); /* get the & */ |
3197 | ch = b_peek(input); | 3188 | ch = i_peek(input); |
3198 | if (ch == '-') { | 3189 | if (ch == '-') { |
3199 | b_getch(input); | 3190 | i_getch(input); |
3200 | return -3; /* "-" represents "close me" */ | 3191 | return -3; /* "-" represents "close me" */ |
3201 | } | 3192 | } |
3202 | while (isdigit(ch)) { | 3193 | while (isdigit(ch)) { |
3203 | d = d*10 + (ch-'0'); | 3194 | d = d*10 + (ch-'0'); |
3204 | ok = 1; | 3195 | ok = 1; |
3205 | b_getch(input); | 3196 | i_getch(input); |
3206 | ch = b_peek(input); | 3197 | ch = i_peek(input); |
3207 | } | 3198 | } |
3208 | if (ok) return d; | 3199 | if (ok) return d; |
3209 | 3200 | ||
@@ -3235,7 +3226,7 @@ static int redirect_opt_num(o_string *o) | |||
3235 | } | 3226 | } |
3236 | /* reuse num (and save an int) */ | 3227 | /* reuse num (and save an int) */ |
3237 | num = atoi(o->data); | 3228 | num = atoi(o->data); |
3238 | b_reset(o); | 3229 | o_reset(o); |
3239 | return num; | 3230 | return num; |
3240 | } | 3231 | } |
3241 | 3232 | ||
@@ -3285,7 +3276,6 @@ static FILE *generate_stream_from_list(struct pipe *head) | |||
3285 | 3276 | ||
3286 | /* Return code is exit status of the process that is run. */ | 3277 | /* Return code is exit status of the process that is run. */ |
3287 | static int process_command_subs(o_string *dest, | 3278 | static int process_command_subs(o_string *dest, |
3288 | /*struct p_context *ctx,*/ | ||
3289 | struct in_str *input, | 3279 | struct in_str *input, |
3290 | const char *subst_end) | 3280 | const char *subst_end) |
3291 | { | 3281 | { |
@@ -3303,7 +3293,7 @@ static int process_command_subs(o_string *dest, | |||
3303 | return retcode; /* syntax error or EOF */ | 3293 | return retcode; /* syntax error or EOF */ |
3304 | done_word(&result, &inner); | 3294 | done_word(&result, &inner); |
3305 | done_pipe(&inner, PIPE_SEQ); | 3295 | done_pipe(&inner, PIPE_SEQ); |
3306 | b_free(&result); | 3296 | o_free(&result); |
3307 | 3297 | ||
3308 | p = generate_stream_from_list(inner.list_head); | 3298 | p = generate_stream_from_list(inner.list_head); |
3309 | if (p == NULL) | 3299 | if (p == NULL) |
@@ -3313,16 +3303,16 @@ static int process_command_subs(o_string *dest, | |||
3313 | 3303 | ||
3314 | /* now send results of command back into original context */ | 3304 | /* now send results of command back into original context */ |
3315 | eol_cnt = 0; | 3305 | eol_cnt = 0; |
3316 | while ((ch = b_getch(&pipe_str)) != EOF) { | 3306 | while ((ch = i_getch(&pipe_str)) != EOF) { |
3317 | if (ch == '\n') { | 3307 | if (ch == '\n') { |
3318 | eol_cnt++; | 3308 | eol_cnt++; |
3319 | continue; | 3309 | continue; |
3320 | } | 3310 | } |
3321 | while (eol_cnt) { | 3311 | while (eol_cnt) { |
3322 | b_addqchr(dest, '\n', dest->o_quote); | 3312 | o_addqchr(dest, '\n', dest->o_quote); |
3323 | eol_cnt--; | 3313 | eol_cnt--; |
3324 | } | 3314 | } |
3325 | b_addqchr(dest, ch, dest->o_quote); | 3315 | o_addqchr(dest, ch, dest->o_quote); |
3326 | } | 3316 | } |
3327 | 3317 | ||
3328 | debug_printf("done reading from pipe, pclose()ing\n"); | 3318 | debug_printf("done reading from pipe, pclose()ing\n"); |
@@ -3386,31 +3376,31 @@ static void add_till_backquote(o_string *dest, struct in_str *input); | |||
3386 | static void add_till_single_quote(o_string *dest, struct in_str *input) | 3376 | static void add_till_single_quote(o_string *dest, struct in_str *input) |
3387 | { | 3377 | { |
3388 | while (1) { | 3378 | while (1) { |
3389 | int ch = b_getch(input); | 3379 | int ch = i_getch(input); |
3390 | if (ch == EOF) | 3380 | if (ch == EOF) |
3391 | break; | 3381 | break; |
3392 | if (ch == '\'') | 3382 | if (ch == '\'') |
3393 | break; | 3383 | break; |
3394 | b_addchr(dest, ch); | 3384 | o_addchr(dest, ch); |
3395 | } | 3385 | } |
3396 | } | 3386 | } |
3397 | /* "...\"...`..`...." - do we need to handle "...$(..)..." too? */ | 3387 | /* "...\"...`..`...." - do we need to handle "...$(..)..." too? */ |
3398 | static void add_till_double_quote(o_string *dest, struct in_str *input) | 3388 | static void add_till_double_quote(o_string *dest, struct in_str *input) |
3399 | { | 3389 | { |
3400 | while (1) { | 3390 | while (1) { |
3401 | int ch = b_getch(input); | 3391 | int ch = i_getch(input); |
3402 | if (ch == '"') | 3392 | if (ch == '"') |
3403 | break; | 3393 | break; |
3404 | if (ch == '\\') { /* \x. Copy both chars. */ | 3394 | if (ch == '\\') { /* \x. Copy both chars. */ |
3405 | b_addchr(dest, ch); | 3395 | o_addchr(dest, ch); |
3406 | ch = b_getch(input); | 3396 | ch = i_getch(input); |
3407 | } | 3397 | } |
3408 | if (ch == EOF) | 3398 | if (ch == EOF) |
3409 | break; | 3399 | break; |
3410 | b_addchr(dest, ch); | 3400 | o_addchr(dest, ch); |
3411 | if (ch == '`') { | 3401 | if (ch == '`') { |
3412 | add_till_backquote(dest, input); | 3402 | add_till_backquote(dest, input); |
3413 | b_addchr(dest, ch); | 3403 | o_addchr(dest, ch); |
3414 | continue; | 3404 | continue; |
3415 | } | 3405 | } |
3416 | // if (ch == '$') ... | 3406 | // if (ch == '$') ... |
@@ -3433,19 +3423,19 @@ static void add_till_double_quote(o_string *dest, struct in_str *input) | |||
3433 | static void add_till_backquote(o_string *dest, struct in_str *input) | 3423 | static void add_till_backquote(o_string *dest, struct in_str *input) |
3434 | { | 3424 | { |
3435 | while (1) { | 3425 | while (1) { |
3436 | int ch = b_getch(input); | 3426 | int ch = i_getch(input); |
3437 | //bb_error_msg("ADD '%c'", ch); | 3427 | //bb_error_msg("ADD '%c'", ch); |
3438 | if (ch == '`') | 3428 | if (ch == '`') |
3439 | break; | 3429 | break; |
3440 | if (ch == '\\') { /* \x. Copy both chars unless it is \` */ | 3430 | if (ch == '\\') { /* \x. Copy both chars unless it is \` */ |
3441 | int ch2 = b_getch(input); | 3431 | int ch2 = i_getch(input); |
3442 | if (ch2 != '`' && ch2 != '$' && ch2 != '\\') | 3432 | if (ch2 != '`' && ch2 != '$' && ch2 != '\\') |
3443 | b_addchr(dest, ch); | 3433 | o_addchr(dest, ch); |
3444 | ch = ch2; | 3434 | ch = ch2; |
3445 | } | 3435 | } |
3446 | if (ch == EOF) | 3436 | if (ch == EOF) |
3447 | break; | 3437 | break; |
3448 | b_addchr(dest, ch); | 3438 | o_addchr(dest, ch); |
3449 | } | 3439 | } |
3450 | } | 3440 | } |
3451 | /* Process $(cmd) - copy contents until ")" is seen. Complicated by | 3441 | /* Process $(cmd) - copy contents until ")" is seen. Complicated by |
@@ -3464,7 +3454,7 @@ static void add_till_closing_curly_brace(o_string *dest, struct in_str *input) | |||
3464 | { | 3454 | { |
3465 | int count = 0; | 3455 | int count = 0; |
3466 | while (1) { | 3456 | while (1) { |
3467 | int ch = b_getch(input); | 3457 | int ch = i_getch(input); |
3468 | if (ch == EOF) | 3458 | if (ch == EOF) |
3469 | break; | 3459 | break; |
3470 | if (ch == '(') | 3460 | if (ch == '(') |
@@ -3472,51 +3462,47 @@ static void add_till_closing_curly_brace(o_string *dest, struct in_str *input) | |||
3472 | if (ch == ')') | 3462 | if (ch == ')') |
3473 | if (--count < 0) | 3463 | if (--count < 0) |
3474 | break; | 3464 | break; |
3475 | b_addchr(dest, ch); | 3465 | o_addchr(dest, ch); |
3476 | if (ch == '\'') { | 3466 | if (ch == '\'') { |
3477 | add_till_single_quote(dest, input); | 3467 | add_till_single_quote(dest, input); |
3478 | b_addchr(dest, ch); | 3468 | o_addchr(dest, ch); |
3479 | continue; | 3469 | continue; |
3480 | } | 3470 | } |
3481 | if (ch == '"') { | 3471 | if (ch == '"') { |
3482 | add_till_double_quote(dest, input); | 3472 | add_till_double_quote(dest, input); |
3483 | b_addchr(dest, ch); | 3473 | o_addchr(dest, ch); |
3484 | continue; | 3474 | continue; |
3485 | } | 3475 | } |
3486 | } | 3476 | } |
3487 | } | 3477 | } |
3488 | #endif /* ENABLE_HUSH_TICK */ | 3478 | #endif /* ENABLE_HUSH_TICK */ |
3489 | 3479 | ||
3490 | //FIXME: remove ctx and sp | ||
3491 | |||
3492 | /* return code: 0 for OK, 1 for syntax error */ | 3480 | /* return code: 0 for OK, 1 for syntax error */ |
3493 | static int handle_dollar(o_string *dest, /*struct p_context *ctx,*/ struct in_str *input) | 3481 | static int handle_dollar(o_string *dest, struct in_str *input) |
3494 | { | 3482 | { |
3495 | int ch = b_peek(input); /* first character after the $ */ | 3483 | int ch = i_peek(input); /* first character after the $ */ |
3496 | unsigned char quote_mask = dest->o_quote ? 0x80 : 0; | 3484 | unsigned char quote_mask = dest->o_quote ? 0x80 : 0; |
3497 | 3485 | ||
3498 | debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); | 3486 | debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); |
3499 | if (isalpha(ch)) { | 3487 | if (isalpha(ch)) { |
3500 | b_addchr(dest, SPECIAL_VAR_SYMBOL); | 3488 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3501 | //sp: ctx->child->sp++; | ||
3502 | while (1) { | 3489 | while (1) { |
3503 | debug_printf_parse(": '%c'\n", ch); | 3490 | debug_printf_parse(": '%c'\n", ch); |
3504 | b_getch(input); | 3491 | i_getch(input); |
3505 | b_addchr(dest, ch | quote_mask); | 3492 | o_addchr(dest, ch | quote_mask); |
3506 | quote_mask = 0; | 3493 | quote_mask = 0; |
3507 | ch = b_peek(input); | 3494 | ch = i_peek(input); |
3508 | if (!isalnum(ch) && ch != '_') | 3495 | if (!isalnum(ch) && ch != '_') |
3509 | break; | 3496 | break; |
3510 | } | 3497 | } |
3511 | b_addchr(dest, SPECIAL_VAR_SYMBOL); | 3498 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3512 | } else if (isdigit(ch)) { | 3499 | } else if (isdigit(ch)) { |
3513 | make_one_char_var: | 3500 | make_one_char_var: |
3514 | b_addchr(dest, SPECIAL_VAR_SYMBOL); | 3501 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3515 | //sp: ctx->child->sp++; | ||
3516 | debug_printf_parse(": '%c'\n", ch); | 3502 | debug_printf_parse(": '%c'\n", ch); |
3517 | b_getch(input); | 3503 | i_getch(input); |
3518 | b_addchr(dest, ch | quote_mask); | 3504 | o_addchr(dest, ch | quote_mask); |
3519 | b_addchr(dest, SPECIAL_VAR_SYMBOL); | 3505 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3520 | } else switch (ch) { | 3506 | } else switch (ch) { |
3521 | case '$': /* pid */ | 3507 | case '$': /* pid */ |
3522 | case '!': /* last bg pid */ | 3508 | case '!': /* last bg pid */ |
@@ -3526,12 +3512,11 @@ static int handle_dollar(o_string *dest, /*struct p_context *ctx,*/ struct in_st | |||
3526 | case '@': /* args */ | 3512 | case '@': /* args */ |
3527 | goto make_one_char_var; | 3513 | goto make_one_char_var; |
3528 | case '{': | 3514 | case '{': |
3529 | b_addchr(dest, SPECIAL_VAR_SYMBOL); | 3515 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3530 | //sp: ctx->child->sp++; | 3516 | i_getch(input); |
3531 | b_getch(input); | ||
3532 | /* XXX maybe someone will try to escape the '}' */ | 3517 | /* XXX maybe someone will try to escape the '}' */ |
3533 | while (1) { | 3518 | while (1) { |
3534 | ch = b_getch(input); | 3519 | ch = i_getch(input); |
3535 | if (ch == '}') | 3520 | if (ch == '}') |
3536 | break; | 3521 | break; |
3537 | if (!isalnum(ch) && ch != '_') { | 3522 | if (!isalnum(ch) && ch != '_') { |
@@ -3540,18 +3525,18 @@ static int handle_dollar(o_string *dest, /*struct p_context *ctx,*/ struct in_st | |||
3540 | return 1; | 3525 | return 1; |
3541 | } | 3526 | } |
3542 | debug_printf_parse(": '%c'\n", ch); | 3527 | debug_printf_parse(": '%c'\n", ch); |
3543 | b_addchr(dest, ch | quote_mask); | 3528 | o_addchr(dest, ch | quote_mask); |
3544 | quote_mask = 0; | 3529 | quote_mask = 0; |
3545 | } | 3530 | } |
3546 | b_addchr(dest, SPECIAL_VAR_SYMBOL); | 3531 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3547 | break; | 3532 | break; |
3548 | #if ENABLE_HUSH_TICK | 3533 | #if ENABLE_HUSH_TICK |
3549 | case '(': | 3534 | case '(': |
3550 | b_getch(input); | 3535 | i_getch(input); |
3551 | b_addchr(dest, SPECIAL_VAR_SYMBOL); | 3536 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3552 | b_addchr(dest, quote_mask | '`'); | 3537 | o_addchr(dest, quote_mask | '`'); |
3553 | add_till_closing_curly_brace(dest, input); | 3538 | add_till_closing_curly_brace(dest, input); |
3554 | b_addchr(dest, SPECIAL_VAR_SYMBOL); | 3539 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3555 | break; | 3540 | break; |
3556 | #endif | 3541 | #endif |
3557 | case '-': | 3542 | case '-': |
@@ -3561,7 +3546,7 @@ static int handle_dollar(o_string *dest, /*struct p_context *ctx,*/ struct in_st | |||
3561 | return 1; | 3546 | return 1; |
3562 | break; | 3547 | break; |
3563 | default: | 3548 | default: |
3564 | b_addqchr(dest, '$', dest->o_quote); | 3549 | o_addqchr(dest, '$', dest->o_quote); |
3565 | } | 3550 | } |
3566 | debug_printf_parse("handle_dollar return 0\n"); | 3551 | debug_printf_parse("handle_dollar return 0\n"); |
3567 | return 0; | 3552 | return 0; |
@@ -3585,11 +3570,11 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3585 | while (1) { | 3570 | while (1) { |
3586 | m = CHAR_IFS; | 3571 | m = CHAR_IFS; |
3587 | next = '\0'; | 3572 | next = '\0'; |
3588 | ch = b_getch(input); | 3573 | ch = i_getch(input); |
3589 | if (ch != EOF) { | 3574 | if (ch != EOF) { |
3590 | m = charmap[ch]; | 3575 | m = charmap[ch]; |
3591 | if (ch != '\n') | 3576 | if (ch != '\n') |
3592 | next = b_peek(input); | 3577 | next = i_peek(input); |
3593 | } | 3578 | } |
3594 | debug_printf_parse(": ch=%c (%d) m=%d quote=%d\n", | 3579 | debug_printf_parse(": ch=%c (%d) m=%d quote=%d\n", |
3595 | ch, ch, m, dest->o_quote); | 3580 | ch, ch, m, dest->o_quote); |
@@ -3601,7 +3586,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3601 | debug_printf_parse("parse_stream return 1: unterminated \"\n"); | 3586 | debug_printf_parse("parse_stream return 1: unterminated \"\n"); |
3602 | return 1; | 3587 | return 1; |
3603 | } | 3588 | } |
3604 | b_addqchr(dest, ch, dest->o_quote); | 3589 | o_addqchr(dest, ch, dest->o_quote); |
3605 | continue; | 3590 | continue; |
3606 | } | 3591 | } |
3607 | if (m == CHAR_IFS) { | 3592 | if (m == CHAR_IFS) { |
@@ -3630,13 +3615,13 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3630 | case '#': | 3615 | case '#': |
3631 | if (dest->length == 0 && !dest->o_quote) { | 3616 | if (dest->length == 0 && !dest->o_quote) { |
3632 | while (1) { | 3617 | while (1) { |
3633 | ch = b_peek(input); | 3618 | ch = i_peek(input); |
3634 | if (ch == EOF || ch == '\n') | 3619 | if (ch == EOF || ch == '\n') |
3635 | break; | 3620 | break; |
3636 | b_getch(input); | 3621 | i_getch(input); |
3637 | } | 3622 | } |
3638 | } else { | 3623 | } else { |
3639 | b_addqchr(dest, ch, dest->o_quote); | 3624 | o_addqchr(dest, ch, dest->o_quote); |
3640 | } | 3625 | } |
3641 | break; | 3626 | break; |
3642 | case '\\': | 3627 | case '\\': |
@@ -3645,11 +3630,11 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3645 | debug_printf_parse("parse_stream return 1: \\<eof>\n"); | 3630 | debug_printf_parse("parse_stream return 1: \\<eof>\n"); |
3646 | return 1; | 3631 | return 1; |
3647 | } | 3632 | } |
3648 | b_addqchr(dest, '\\', dest->o_quote); | 3633 | o_addqchr(dest, '\\', dest->o_quote); |
3649 | b_addqchr(dest, b_getch(input), dest->o_quote); | 3634 | o_addqchr(dest, i_getch(input), dest->o_quote); |
3650 | break; | 3635 | break; |
3651 | case '$': | 3636 | case '$': |
3652 | if (handle_dollar(dest, /*ctx,*/ input) != 0) { | 3637 | if (handle_dollar(dest, input) != 0) { |
3653 | debug_printf_parse("parse_stream return 1: handle_dollar returned non-0\n"); | 3638 | debug_printf_parse("parse_stream return 1: handle_dollar returned non-0\n"); |
3654 | return 1; | 3639 | return 1; |
3655 | } | 3640 | } |
@@ -3657,10 +3642,10 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3657 | case '\'': | 3642 | case '\'': |
3658 | dest->nonnull = 1; | 3643 | dest->nonnull = 1; |
3659 | while (1) { | 3644 | while (1) { |
3660 | ch = b_getch(input); | 3645 | ch = i_getch(input); |
3661 | if (ch == EOF || ch == '\'') | 3646 | if (ch == EOF || ch == '\'') |
3662 | break; | 3647 | break; |
3663 | b_addchr(dest, ch); | 3648 | o_addchr(dest, ch); |
3664 | } | 3649 | } |
3665 | if (ch == EOF) { | 3650 | if (ch == EOF) { |
3666 | syntax("unterminated '"); | 3651 | syntax("unterminated '"); |
@@ -3675,10 +3660,10 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3675 | #if ENABLE_HUSH_TICK | 3660 | #if ENABLE_HUSH_TICK |
3676 | case '`': { | 3661 | case '`': { |
3677 | //int pos = dest->length; | 3662 | //int pos = dest->length; |
3678 | b_addchr(dest, SPECIAL_VAR_SYMBOL); | 3663 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3679 | b_addchr(dest, dest->o_quote ? 0x80 | '`' : '`'); | 3664 | o_addchr(dest, dest->o_quote ? 0x80 | '`' : '`'); |
3680 | add_till_backquote(dest, input); | 3665 | add_till_backquote(dest, input); |
3681 | b_addchr(dest, SPECIAL_VAR_SYMBOL); | 3666 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3682 | //bb_error_msg("RES '%s'", dest->data + pos); | 3667 | //bb_error_msg("RES '%s'", dest->data + pos); |
3683 | break; | 3668 | break; |
3684 | } | 3669 | } |
@@ -3689,7 +3674,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3689 | redir_style = REDIRECT_OVERWRITE; | 3674 | redir_style = REDIRECT_OVERWRITE; |
3690 | if (next == '>') { | 3675 | if (next == '>') { |
3691 | redir_style = REDIRECT_APPEND; | 3676 | redir_style = REDIRECT_APPEND; |
3692 | b_getch(input); | 3677 | i_getch(input); |
3693 | } | 3678 | } |
3694 | #if 0 | 3679 | #if 0 |
3695 | else if (next == '(') { | 3680 | else if (next == '(') { |
@@ -3706,10 +3691,10 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3706 | redir_style = REDIRECT_INPUT; | 3691 | redir_style = REDIRECT_INPUT; |
3707 | if (next == '<') { | 3692 | if (next == '<') { |
3708 | redir_style = REDIRECT_HEREIS; | 3693 | redir_style = REDIRECT_HEREIS; |
3709 | b_getch(input); | 3694 | i_getch(input); |
3710 | } else if (next == '>') { | 3695 | } else if (next == '>') { |
3711 | redir_style = REDIRECT_IO; | 3696 | redir_style = REDIRECT_IO; |
3712 | b_getch(input); | 3697 | i_getch(input); |
3713 | } | 3698 | } |
3714 | #if 0 | 3699 | #if 0 |
3715 | else if (next == '(') { | 3700 | else if (next == '(') { |
@@ -3727,7 +3712,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3727 | case '&': | 3712 | case '&': |
3728 | done_word(dest, ctx); | 3713 | done_word(dest, ctx); |
3729 | if (next == '&') { | 3714 | if (next == '&') { |
3730 | b_getch(input); | 3715 | i_getch(input); |
3731 | done_pipe(ctx, PIPE_AND); | 3716 | done_pipe(ctx, PIPE_AND); |
3732 | } else { | 3717 | } else { |
3733 | done_pipe(ctx, PIPE_BG); | 3718 | done_pipe(ctx, PIPE_BG); |
@@ -3736,7 +3721,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3736 | case '|': | 3721 | case '|': |
3737 | done_word(dest, ctx); | 3722 | done_word(dest, ctx); |
3738 | if (next == '|') { | 3723 | if (next == '|') { |
3739 | b_getch(input); | 3724 | i_getch(input); |
3740 | done_pipe(ctx, PIPE_OR); | 3725 | done_pipe(ctx, PIPE_OR); |
3741 | } else { | 3726 | } else { |
3742 | /* we could pick up a file descriptor choice here | 3727 | /* we could pick up a file descriptor choice here |
@@ -3836,14 +3821,14 @@ static int parse_and_run_stream(struct in_str *inp, int parse_flag) | |||
3836 | } else { | 3821 | } else { |
3837 | if (ctx.old_flag != 0) { | 3822 | if (ctx.old_flag != 0) { |
3838 | free(ctx.stack); | 3823 | free(ctx.stack); |
3839 | b_reset(&temp); | 3824 | o_reset(&temp); |
3840 | } | 3825 | } |
3841 | temp.nonnull = 0; | 3826 | temp.nonnull = 0; |
3842 | temp.o_quote = 0; | 3827 | temp.o_quote = 0; |
3843 | inp->p = NULL; | 3828 | inp->p = NULL; |
3844 | free_pipe_list(ctx.list_head, /* indent: */ 0); | 3829 | free_pipe_list(ctx.list_head, /* indent: */ 0); |
3845 | } | 3830 | } |
3846 | b_free(&temp); | 3831 | o_free(&temp); |
3847 | } while (rcode != -1 && !(parse_flag & PARSEFLAG_EXIT_FROM_LOOP)); /* loop on syntax errors, return on EOF */ | 3832 | } while (rcode != -1 && !(parse_flag & PARSEFLAG_EXIT_FROM_LOOP)); /* loop on syntax errors, return on EOF */ |
3848 | return 0; | 3833 | return 0; |
3849 | } | 3834 | } |