diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-01 10:00:45 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-01 10:00:45 +0000 |
commit | ff0976248ac8759af1f1de32677887c4c9866865 (patch) | |
tree | e691e1366c7b3456ccbb8b0c1d22afb8696401d9 | |
parent | 8412d7959a26bf697faf15aee4df8f91df444022 (diff) | |
download | busybox-w32-ff0976248ac8759af1f1de32677887c4c9866865.tar.gz busybox-w32-ff0976248ac8759af1f1de32677887c4c9866865.tar.bz2 busybox-w32-ff0976248ac8759af1f1de32677887c4c9866865.zip |
hush: int->smallint for flag vars; make some names more "greppable"
-rw-r--r-- | shell/hush.c | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/shell/hush.c b/shell/hush.c index 19d516dff..e73432a89 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -246,7 +246,7 @@ struct redir_struct { | |||
246 | redir_type type; /* type of redirection */ | 246 | redir_type type; /* type of redirection */ |
247 | int fd; /* file descriptor being redirected */ | 247 | int fd; /* file descriptor being redirected */ |
248 | int dup; /* -1, or file descriptor being duplicated */ | 248 | int dup; /* -1, or file descriptor being duplicated */ |
249 | glob_t word; /* *word.gl_pathv is the filename */ | 249 | glob_t glob_word; /* *word.gl_pathv is the filename */ |
250 | }; | 250 | }; |
251 | 251 | ||
252 | struct child_prog { | 252 | struct child_prog { |
@@ -304,8 +304,8 @@ typedef struct { | |||
304 | char *data; | 304 | char *data; |
305 | int length; | 305 | int length; |
306 | int maxlen; | 306 | int maxlen; |
307 | int quote; | 307 | smallint o_quote; |
308 | int nonnull; | 308 | smallint nonnull; |
309 | } o_string; | 309 | } o_string; |
310 | #define NULL_O_STRING {NULL,0,0,0,0} | 310 | #define NULL_O_STRING {NULL,0,0,0,0} |
311 | /* used for initialization: o_string foo = NULL_O_STRING; */ | 311 | /* used for initialization: o_string foo = NULL_O_STRING; */ |
@@ -1256,13 +1256,13 @@ static int setup_redirects(struct child_prog *prog, int squirrel[]) | |||
1256 | struct redir_struct *redir; | 1256 | struct redir_struct *redir; |
1257 | 1257 | ||
1258 | for (redir = prog->redirects; redir; redir = redir->next) { | 1258 | for (redir = prog->redirects; redir; redir = redir->next) { |
1259 | if (redir->dup == -1 && redir->word.gl_pathv == NULL) { | 1259 | if (redir->dup == -1 && redir->glob_word.gl_pathv == NULL) { |
1260 | /* something went wrong in the parse. Pretend it didn't happen */ | 1260 | /* something went wrong in the parse. Pretend it didn't happen */ |
1261 | continue; | 1261 | continue; |
1262 | } | 1262 | } |
1263 | if (redir->dup == -1) { | 1263 | if (redir->dup == -1) { |
1264 | mode = redir_table[redir->type].mode; | 1264 | mode = redir_table[redir->type].mode; |
1265 | openfd = open_or_warn(redir->word.gl_pathv[0], mode); | 1265 | openfd = open_or_warn(redir->glob_word.gl_pathv[0], mode); |
1266 | if (openfd < 0) { | 1266 | if (openfd < 0) { |
1267 | /* this could get lost if stderr has been redirected, but | 1267 | /* this could get lost if stderr has been redirected, but |
1268 | bash and ash both lose it as well (though zsh doesn't!) */ | 1268 | bash and ash both lose it as well (though zsh doesn't!) */ |
@@ -2162,9 +2162,9 @@ static int free_pipe(struct pipe *pi, int indent) | |||
2162 | debug_printf_clean("%s redirect %d%s", indenter(indent), r->fd, redir_table[r->type].descrip); | 2162 | debug_printf_clean("%s redirect %d%s", indenter(indent), r->fd, redir_table[r->type].descrip); |
2163 | if (r->dup == -1) { | 2163 | if (r->dup == -1) { |
2164 | /* guard against the case >$FOO, where foo is unset or blank */ | 2164 | /* guard against the case >$FOO, where foo is unset or blank */ |
2165 | if (r->word.gl_pathv) { | 2165 | if (r->glob_word.gl_pathv) { |
2166 | debug_printf_clean(" %s\n", *r->word.gl_pathv); | 2166 | debug_printf_clean(" %s\n", r->glob_word.gl_pathv[0]); |
2167 | globfree(&r->word); | 2167 | globfree(&r->glob_word); |
2168 | } | 2168 | } |
2169 | } else { | 2169 | } else { |
2170 | debug_printf_clean("&%d\n", r->dup); | 2170 | debug_printf_clean("&%d\n", r->dup); |
@@ -2216,6 +2216,10 @@ static int run_list(struct pipe *pi) | |||
2216 | return rcode; | 2216 | return rcode; |
2217 | } | 2217 | } |
2218 | 2218 | ||
2219 | /* Whoever decided to muck with glob internal data is AN IDIOT! */ | ||
2220 | /* uclibc happily changed the way it works (and it has rights to do so!), | ||
2221 | all hell broke loose (SEGVs) */ | ||
2222 | |||
2219 | /* The API for glob is arguably broken. This routine pushes a non-matching | 2223 | /* The API for glob is arguably broken. This routine pushes a non-matching |
2220 | * string into the output structure, removing non-backslashed backslashes. | 2224 | * string into the output structure, removing non-backslashed backslashes. |
2221 | * If someone can prove me wrong, by performing this function within the | 2225 | * If someone can prove me wrong, by performing this function within the |
@@ -2769,9 +2773,9 @@ static int setup_redirect(struct p_context *ctx, int fd, redir_type style, | |||
2769 | last_redir = redir; | 2773 | last_redir = redir; |
2770 | redir = redir->next; | 2774 | redir = redir->next; |
2771 | } | 2775 | } |
2772 | redir = xmalloc(sizeof(struct redir_struct)); | 2776 | redir = xzalloc(sizeof(struct redir_struct)); |
2773 | redir->next = NULL; | 2777 | /* redir->next = NULL; */ |
2774 | redir->word.gl_pathv = NULL; | 2778 | /* redir->glob_word.gl_pathv = NULL; */ |
2775 | if (last_redir) { | 2779 | if (last_redir) { |
2776 | last_redir->next = redir; | 2780 | last_redir->next = redir; |
2777 | } else { | 2781 | } else { |
@@ -2924,7 +2928,7 @@ static int done_word(o_string *dest, struct p_context *ctx) | |||
2924 | return 0; | 2928 | return 0; |
2925 | } | 2929 | } |
2926 | if (ctx->pending_redirect) { | 2930 | if (ctx->pending_redirect) { |
2927 | glob_target = &ctx->pending_redirect->word; | 2931 | glob_target = &ctx->pending_redirect->glob_word; |
2928 | } else { | 2932 | } else { |
2929 | if (child->group) { | 2933 | if (child->group) { |
2930 | syntax(NULL); | 2934 | syntax(NULL); |
@@ -3160,10 +3164,10 @@ static int process_command_subs(o_string *dest, struct p_context *ctx, | |||
3160 | continue; | 3164 | continue; |
3161 | } | 3165 | } |
3162 | while (eol_cnt) { | 3166 | while (eol_cnt) { |
3163 | b_addqchr(dest, '\n', dest->quote); | 3167 | b_addqchr(dest, '\n', dest->o_quote); |
3164 | eol_cnt--; | 3168 | eol_cnt--; |
3165 | } | 3169 | } |
3166 | b_addqchr(dest, ch, dest->quote); | 3170 | b_addqchr(dest, ch, dest->o_quote); |
3167 | } | 3171 | } |
3168 | 3172 | ||
3169 | debug_printf("done reading from pipe, pclose()ing\n"); | 3173 | debug_printf("done reading from pipe, pclose()ing\n"); |
@@ -3224,7 +3228,7 @@ static const char *lookup_param(const char *src) | |||
3224 | static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *input) | 3228 | static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *input) |
3225 | { | 3229 | { |
3226 | int ch = b_peek(input); /* first character after the $ */ | 3230 | int ch = b_peek(input); /* first character after the $ */ |
3227 | unsigned char quote_mask = dest->quote ? 0x80 : 0; | 3231 | unsigned char quote_mask = dest->o_quote ? 0x80 : 0; |
3228 | 3232 | ||
3229 | debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); | 3233 | debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); |
3230 | if (isalpha(ch)) { | 3234 | if (isalpha(ch)) { |
@@ -3289,7 +3293,7 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *i | |||
3289 | return 1; | 3293 | return 1; |
3290 | break; | 3294 | break; |
3291 | default: | 3295 | default: |
3292 | b_addqchr(dest, '$', dest->quote); | 3296 | b_addqchr(dest, '$', dest->o_quote); |
3293 | } | 3297 | } |
3294 | debug_printf_parse("handle_dollar return 0\n"); | 3298 | debug_printf_parse("handle_dollar return 0\n"); |
3295 | return 0; | 3299 | return 0; |
@@ -3304,9 +3308,9 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3304 | redir_type redir_style; | 3308 | redir_type redir_style; |
3305 | int next; | 3309 | int next; |
3306 | 3310 | ||
3307 | /* Only double-quote state is handled in the state variable dest->quote. | 3311 | /* Only double-quote state is handled in the state variable dest->o_quote. |
3308 | * A single-quote triggers a bypass of the main loop until its mate is | 3312 | * A single-quote triggers a bypass of the main loop until its mate is |
3309 | * found. When recursing, quote state is passed in via dest->quote. */ | 3313 | * found. When recursing, quote state is passed in via dest->o_quote. */ |
3310 | 3314 | ||
3311 | debug_printf_parse("parse_stream entered, end_trigger='%s'\n", end_trigger); | 3315 | debug_printf_parse("parse_stream entered, end_trigger='%s'\n", end_trigger); |
3312 | 3316 | ||
@@ -3320,16 +3324,16 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3320 | next = b_peek(input); | 3324 | next = b_peek(input); |
3321 | } | 3325 | } |
3322 | debug_printf_parse(": ch=%c (%d) m=%d quote=%d\n", | 3326 | debug_printf_parse(": ch=%c (%d) m=%d quote=%d\n", |
3323 | ch, ch, m, dest->quote); | 3327 | ch, ch, m, dest->o_quote); |
3324 | if (m == CHAR_ORDINARY | 3328 | if (m == CHAR_ORDINARY |
3325 | || (m != CHAR_SPECIAL && dest->quote) | 3329 | || (m != CHAR_SPECIAL && dest->o_quote) |
3326 | ) { | 3330 | ) { |
3327 | if (ch == EOF) { | 3331 | if (ch == EOF) { |
3328 | syntax("unterminated \""); | 3332 | syntax("unterminated \""); |
3329 | debug_printf_parse("parse_stream return 1: unterminated \"\n"); | 3333 | debug_printf_parse("parse_stream return 1: unterminated \"\n"); |
3330 | return 1; | 3334 | return 1; |
3331 | } | 3335 | } |
3332 | b_addqchr(dest, ch, dest->quote); | 3336 | b_addqchr(dest, ch, dest->o_quote); |
3333 | continue; | 3337 | continue; |
3334 | } | 3338 | } |
3335 | if (m == CHAR_IFS) { | 3339 | if (m == CHAR_IFS) { |
@@ -3347,7 +3351,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3347 | } | 3351 | } |
3348 | } | 3352 | } |
3349 | if ((end_trigger && strchr(end_trigger, ch)) | 3353 | if ((end_trigger && strchr(end_trigger, ch)) |
3350 | && !dest->quote && ctx->res_w == RES_NONE | 3354 | && !dest->o_quote && ctx->res_w == RES_NONE |
3351 | ) { | 3355 | ) { |
3352 | debug_printf_parse("parse_stream return 0: end_trigger char found\n"); | 3356 | debug_printf_parse("parse_stream return 0: end_trigger char found\n"); |
3353 | return 0; | 3357 | return 0; |
@@ -3356,7 +3360,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3356 | continue; | 3360 | continue; |
3357 | switch (ch) { | 3361 | switch (ch) { |
3358 | case '#': | 3362 | case '#': |
3359 | if (dest->length == 0 && !dest->quote) { | 3363 | if (dest->length == 0 && !dest->o_quote) { |
3360 | while (1) { | 3364 | while (1) { |
3361 | ch = b_peek(input); | 3365 | ch = b_peek(input); |
3362 | if (ch == EOF || ch == '\n') | 3366 | if (ch == EOF || ch == '\n') |
@@ -3364,7 +3368,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3364 | b_getch(input); | 3368 | b_getch(input); |
3365 | } | 3369 | } |
3366 | } else { | 3370 | } else { |
3367 | b_addqchr(dest, ch, dest->quote); | 3371 | b_addqchr(dest, ch, dest->o_quote); |
3368 | } | 3372 | } |
3369 | break; | 3373 | break; |
3370 | case '\\': | 3374 | case '\\': |
@@ -3373,8 +3377,8 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3373 | debug_printf_parse("parse_stream return 1: \\<eof>\n"); | 3377 | debug_printf_parse("parse_stream return 1: \\<eof>\n"); |
3374 | return 1; | 3378 | return 1; |
3375 | } | 3379 | } |
3376 | b_addqchr(dest, '\\', dest->quote); | 3380 | b_addqchr(dest, '\\', dest->o_quote); |
3377 | b_addqchr(dest, b_getch(input), dest->quote); | 3381 | b_addqchr(dest, b_getch(input), dest->o_quote); |
3378 | break; | 3382 | break; |
3379 | case '$': | 3383 | case '$': |
3380 | if (handle_dollar(dest, ctx, input) != 0) { | 3384 | if (handle_dollar(dest, ctx, input) != 0) { |
@@ -3398,7 +3402,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3398 | break; | 3402 | break; |
3399 | case '"': | 3403 | case '"': |
3400 | dest->nonnull = 1; | 3404 | dest->nonnull = 1; |
3401 | dest->quote = !dest->quote; | 3405 | dest->o_quote ^= 1; /* invert */ |
3402 | break; | 3406 | break; |
3403 | #if ENABLE_HUSH_TICK | 3407 | #if ENABLE_HUSH_TICK |
3404 | case '`': | 3408 | case '`': |
@@ -3561,7 +3565,7 @@ static int parse_and_run_stream(struct in_str *inp, int parse_flag) | |||
3561 | b_reset(&temp); | 3565 | b_reset(&temp); |
3562 | } | 3566 | } |
3563 | temp.nonnull = 0; | 3567 | temp.nonnull = 0; |
3564 | temp.quote = 0; | 3568 | temp.o_quote = 0; |
3565 | inp->p = NULL; | 3569 | inp->p = NULL; |
3566 | free_pipe_list(ctx.list_head, 0); | 3570 | free_pipe_list(ctx.list_head, 0); |
3567 | } | 3571 | } |