hush: cosmetics. no code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-10-19 13:13:06 +02:00
parent e8405619fa
commit c0836530f1

View File

@ -2689,9 +2689,9 @@ static void re_execute_shell(char ***to_free, const char *s,
char param_buf[sizeof("-$%x:%x:%x:%x:%x") + sizeof(unsigned) * 2]; char param_buf[sizeof("-$%x:%x:%x:%x:%x") + sizeof(unsigned) * 2];
char *heredoc_argv[4]; char *heredoc_argv[4];
struct variable *cur; struct variable *cur;
#if ENABLE_HUSH_FUNCTIONS # if ENABLE_HUSH_FUNCTIONS
struct function *funcp; struct function *funcp;
#endif # endif
char **argv, **pp; char **argv, **pp;
unsigned cnt; unsigned cnt;
@ -2726,10 +2726,10 @@ static void re_execute_shell(char ***to_free, const char *s,
if (!cur->flg_export || cur->flg_read_only) if (!cur->flg_export || cur->flg_read_only)
cnt += 2; cnt += 2;
} }
#if ENABLE_HUSH_FUNCTIONS # if ENABLE_HUSH_FUNCTIONS
for (funcp = G.top_func; funcp; funcp = funcp->next) for (funcp = G.top_func; funcp; funcp = funcp->next)
cnt += 3; cnt += 3;
#endif # endif
pp = g_argv; pp = g_argv;
while (*pp++) while (*pp++)
cnt++; cnt++;
@ -2747,13 +2747,13 @@ static void re_execute_shell(char ***to_free, const char *s,
*pp++ = cur->varstr; *pp++ = cur->varstr;
} }
} }
#if ENABLE_HUSH_FUNCTIONS # if ENABLE_HUSH_FUNCTIONS
for (funcp = G.top_func; funcp; funcp = funcp->next) { for (funcp = G.top_func; funcp; funcp = funcp->next) {
*pp++ = (char *) "-F"; *pp++ = (char *) "-F";
*pp++ = funcp->name; *pp++ = funcp->name;
*pp++ = funcp->body_as_string; *pp++ = funcp->body_as_string;
} }
#endif # endif
/* We can pass activated traps here. Say, -Tnn:trap_string /* We can pass activated traps here. Say, -Tnn:trap_string
* *
* However, POSIX says that subshells reset signals with traps * However, POSIX says that subshells reset signals with traps
@ -3242,9 +3242,9 @@ static int run_function(const struct function *funcp, char **argv)
/* "we are in function, ok to use return" */ /* "we are in function, ok to use return" */
sv_flg = G.flag_return_in_progress; sv_flg = G.flag_return_in_progress;
G.flag_return_in_progress = -1; G.flag_return_in_progress = -1;
#if ENABLE_HUSH_LOCAL # if ENABLE_HUSH_LOCAL
G.func_nest_level++; G.func_nest_level++;
#endif # endif
/* On MMU, funcp->body is always non-NULL */ /* On MMU, funcp->body is always non-NULL */
# if !BB_MMU # if !BB_MMU
@ -3258,7 +3258,7 @@ static int run_function(const struct function *funcp, char **argv)
rc = run_list(funcp->body); rc = run_list(funcp->body);
} }
#if ENABLE_HUSH_LOCAL # if ENABLE_HUSH_LOCAL
{ {
struct variable *var; struct variable *var;
struct variable **var_pp; struct variable **var_pp;
@ -3281,7 +3281,7 @@ static int run_function(const struct function *funcp, char **argv)
} }
G.func_nest_level--; G.func_nest_level--;
} }
#endif # endif
G.flag_return_in_progress = sv_flg; G.flag_return_in_progress = sv_flg;
restore_G_args(&sv, argv); restore_G_args(&sv, argv);
@ -3291,13 +3291,13 @@ static int run_function(const struct function *funcp, char **argv)
#endif /* ENABLE_HUSH_FUNCTIONS */ #endif /* ENABLE_HUSH_FUNCTIONS */
# if BB_MMU #if BB_MMU
#define exec_builtin(to_free, x, argv) \ #define exec_builtin(to_free, x, argv) \
exec_builtin(x, argv) exec_builtin(x, argv)
# else #else
#define exec_builtin(to_free, x, argv) \ #define exec_builtin(to_free, x, argv) \
exec_builtin(to_free, argv) exec_builtin(to_free, argv)
# endif #endif
static void exec_builtin(char ***to_free, static void exec_builtin(char ***to_free,
const struct built_in_command *x, const struct built_in_command *x,
char **argv) NORETURN; char **argv) NORETURN;
@ -3305,11 +3305,11 @@ static void exec_builtin(char ***to_free,
const struct built_in_command *x, const struct built_in_command *x,
char **argv) char **argv)
{ {
# if BB_MMU #if BB_MMU
int rcode = x->function(argv); int rcode = x->function(argv);
fflush(NULL); fflush(NULL);
_exit(rcode); _exit(rcode);
# else #else
/* On NOMMU, we must never block! /* On NOMMU, we must never block!
* Example: { sleep 99 | read line; } & echo Ok * Example: { sleep 99 | read line; } & echo Ok
*/ */
@ -3318,7 +3318,7 @@ static void exec_builtin(char ***to_free,
G.global_argv[0], G.global_argv[0],
G.global_argv + 1, G.global_argv + 1,
argv); argv);
# endif #endif
} }
@ -4115,30 +4115,30 @@ static void debug_print_tree(struct pipe *pi, int lvl)
}; };
static const char *RES[] = { static const char *RES[] = {
[RES_NONE ] = "NONE" , [RES_NONE ] = "NONE" ,
#if ENABLE_HUSH_IF # if ENABLE_HUSH_IF
[RES_IF ] = "IF" , [RES_IF ] = "IF" ,
[RES_THEN ] = "THEN" , [RES_THEN ] = "THEN" ,
[RES_ELIF ] = "ELIF" , [RES_ELIF ] = "ELIF" ,
[RES_ELSE ] = "ELSE" , [RES_ELSE ] = "ELSE" ,
[RES_FI ] = "FI" , [RES_FI ] = "FI" ,
#endif # endif
#if ENABLE_HUSH_LOOPS # if ENABLE_HUSH_LOOPS
[RES_FOR ] = "FOR" , [RES_FOR ] = "FOR" ,
[RES_WHILE] = "WHILE", [RES_WHILE] = "WHILE",
[RES_UNTIL] = "UNTIL", [RES_UNTIL] = "UNTIL",
[RES_DO ] = "DO" , [RES_DO ] = "DO" ,
[RES_DONE ] = "DONE" , [RES_DONE ] = "DONE" ,
#endif # endif
#if ENABLE_HUSH_LOOPS || ENABLE_HUSH_CASE # if ENABLE_HUSH_LOOPS || ENABLE_HUSH_CASE
[RES_IN ] = "IN" , [RES_IN ] = "IN" ,
#endif # endif
#if ENABLE_HUSH_CASE # if ENABLE_HUSH_CASE
[RES_CASE ] = "CASE" , [RES_CASE ] = "CASE" ,
[RES_CASE_IN ] = "CASE_IN" , [RES_CASE_IN ] = "CASE_IN" ,
[RES_MATCH] = "MATCH", [RES_MATCH] = "MATCH",
[RES_CASE_BODY] = "CASE_BODY", [RES_CASE_BODY] = "CASE_BODY",
[RES_ESAC ] = "ESAC" , [RES_ESAC ] = "ESAC" ,
#endif # endif
[RES_XXXX ] = "XXXX" , [RES_XXXX ] = "XXXX" ,
[RES_SNTX ] = "SNTX" , [RES_SNTX ] = "SNTX" ,
}; };
@ -4146,9 +4146,9 @@ static void debug_print_tree(struct pipe *pi, int lvl)
"{}", "{}",
"()", "()",
"[noglob]", "[noglob]",
#if ENABLE_HUSH_FUNCTIONS # if ENABLE_HUSH_FUNCTIONS
"func()", "func()",
#endif # endif
}; };
int pin, prn; int pin, prn;
@ -4184,7 +4184,7 @@ static void debug_print_tree(struct pipe *pi, int lvl)
pin++; pin++;
} }
} }
#endif #endif /* debug_print_tree */
/* NB: called by pseudo_exec, and therefore must not modify any /* NB: called by pseudo_exec, and therefore must not modify any
* global data until exec/_exit (we can be a child after vfork!) */ * global data until exec/_exit (we can be a child after vfork!) */
@ -4658,25 +4658,25 @@ struct reserved_combo {
}; };
enum { enum {
FLAG_END = (1 << RES_NONE ), FLAG_END = (1 << RES_NONE ),
#if ENABLE_HUSH_IF # if ENABLE_HUSH_IF
FLAG_IF = (1 << RES_IF ), FLAG_IF = (1 << RES_IF ),
FLAG_THEN = (1 << RES_THEN ), FLAG_THEN = (1 << RES_THEN ),
FLAG_ELIF = (1 << RES_ELIF ), FLAG_ELIF = (1 << RES_ELIF ),
FLAG_ELSE = (1 << RES_ELSE ), FLAG_ELSE = (1 << RES_ELSE ),
FLAG_FI = (1 << RES_FI ), FLAG_FI = (1 << RES_FI ),
#endif # endif
#if ENABLE_HUSH_LOOPS # if ENABLE_HUSH_LOOPS
FLAG_FOR = (1 << RES_FOR ), FLAG_FOR = (1 << RES_FOR ),
FLAG_WHILE = (1 << RES_WHILE), FLAG_WHILE = (1 << RES_WHILE),
FLAG_UNTIL = (1 << RES_UNTIL), FLAG_UNTIL = (1 << RES_UNTIL),
FLAG_DO = (1 << RES_DO ), FLAG_DO = (1 << RES_DO ),
FLAG_DONE = (1 << RES_DONE ), FLAG_DONE = (1 << RES_DONE ),
FLAG_IN = (1 << RES_IN ), FLAG_IN = (1 << RES_IN ),
#endif # endif
#if ENABLE_HUSH_CASE # if ENABLE_HUSH_CASE
FLAG_MATCH = (1 << RES_MATCH), FLAG_MATCH = (1 << RES_MATCH),
FLAG_ESAC = (1 << RES_ESAC ), FLAG_ESAC = (1 << RES_ESAC ),
#endif # endif
FLAG_START = (1 << RES_XXXX ), FLAG_START = (1 << RES_XXXX ),
}; };
@ -4688,26 +4688,26 @@ static const struct reserved_combo* match_reserved_word(o_string *word)
* FLAG_START means the word must start a new compound list. * FLAG_START means the word must start a new compound list.
*/ */
static const struct reserved_combo reserved_list[] = { static const struct reserved_combo reserved_list[] = {
#if ENABLE_HUSH_IF # if ENABLE_HUSH_IF
{ "!", RES_NONE, NOT_ASSIGNMENT , 0 }, { "!", RES_NONE, NOT_ASSIGNMENT , 0 },
{ "if", RES_IF, WORD_IS_KEYWORD, FLAG_THEN | FLAG_START }, { "if", RES_IF, WORD_IS_KEYWORD, FLAG_THEN | FLAG_START },
{ "then", RES_THEN, WORD_IS_KEYWORD, FLAG_ELIF | FLAG_ELSE | FLAG_FI }, { "then", RES_THEN, WORD_IS_KEYWORD, FLAG_ELIF | FLAG_ELSE | FLAG_FI },
{ "elif", RES_ELIF, WORD_IS_KEYWORD, FLAG_THEN }, { "elif", RES_ELIF, WORD_IS_KEYWORD, FLAG_THEN },
{ "else", RES_ELSE, WORD_IS_KEYWORD, FLAG_FI }, { "else", RES_ELSE, WORD_IS_KEYWORD, FLAG_FI },
{ "fi", RES_FI, NOT_ASSIGNMENT , FLAG_END }, { "fi", RES_FI, NOT_ASSIGNMENT , FLAG_END },
#endif # endif
#if ENABLE_HUSH_LOOPS # if ENABLE_HUSH_LOOPS
{ "for", RES_FOR, NOT_ASSIGNMENT , FLAG_IN | FLAG_DO | FLAG_START }, { "for", RES_FOR, NOT_ASSIGNMENT , FLAG_IN | FLAG_DO | FLAG_START },
{ "while", RES_WHILE, WORD_IS_KEYWORD, FLAG_DO | FLAG_START }, { "while", RES_WHILE, WORD_IS_KEYWORD, FLAG_DO | FLAG_START },
{ "until", RES_UNTIL, WORD_IS_KEYWORD, FLAG_DO | FLAG_START }, { "until", RES_UNTIL, WORD_IS_KEYWORD, FLAG_DO | FLAG_START },
{ "in", RES_IN, NOT_ASSIGNMENT , FLAG_DO }, { "in", RES_IN, NOT_ASSIGNMENT , FLAG_DO },
{ "do", RES_DO, WORD_IS_KEYWORD, FLAG_DONE }, { "do", RES_DO, WORD_IS_KEYWORD, FLAG_DONE },
{ "done", RES_DONE, NOT_ASSIGNMENT , FLAG_END }, { "done", RES_DONE, NOT_ASSIGNMENT , FLAG_END },
#endif # endif
#if ENABLE_HUSH_CASE # if ENABLE_HUSH_CASE
{ "case", RES_CASE, NOT_ASSIGNMENT , FLAG_MATCH | FLAG_START }, { "case", RES_CASE, NOT_ASSIGNMENT , FLAG_MATCH | FLAG_START },
{ "esac", RES_ESAC, NOT_ASSIGNMENT , FLAG_END }, { "esac", RES_ESAC, NOT_ASSIGNMENT , FLAG_END },
#endif # endif
}; };
const struct reserved_combo *r; const struct reserved_combo *r;
@ -4721,11 +4721,11 @@ static const struct reserved_combo* match_reserved_word(o_string *word)
*/ */
static int reserved_word(o_string *word, struct parse_context *ctx) static int reserved_word(o_string *word, struct parse_context *ctx)
{ {
#if ENABLE_HUSH_CASE # if ENABLE_HUSH_CASE
static const struct reserved_combo reserved_match = { static const struct reserved_combo reserved_match = {
"", RES_MATCH, NOT_ASSIGNMENT , FLAG_MATCH | FLAG_ESAC "", RES_MATCH, NOT_ASSIGNMENT , FLAG_MATCH | FLAG_ESAC
}; };
#endif # endif
const struct reserved_combo *r; const struct reserved_combo *r;
if (word->o_quoted) if (word->o_quoted)
@ -4735,12 +4735,12 @@ static int reserved_word(o_string *word, struct parse_context *ctx)
return 0; return 0;
debug_printf("found reserved word %s, res %d\n", r->literal, r->res); debug_printf("found reserved word %s, res %d\n", r->literal, r->res);
#if ENABLE_HUSH_CASE # if ENABLE_HUSH_CASE
if (r->res == RES_IN && ctx->ctx_res_w == RES_CASE_IN) { if (r->res == RES_IN && ctx->ctx_res_w == RES_CASE_IN) {
/* "case word IN ..." - IN part starts first MATCH part */ /* "case word IN ..." - IN part starts first MATCH part */
r = &reserved_match; r = &reserved_match;
} else } else
#endif # endif
if (r->flag == 0) { /* '!' */ if (r->flag == 0) { /* '!' */
if (ctx->ctx_inverted) { /* bash doesn't accept '! ! true' */ if (ctx->ctx_inverted) { /* bash doesn't accept '! ! true' */
syntax_error("! ! command"); syntax_error("! ! command");
@ -4781,19 +4781,19 @@ static int reserved_word(o_string *word, struct parse_context *ctx)
old = ctx->stack; old = ctx->stack;
old->command->group = ctx->list_head; old->command->group = ctx->list_head;
old->command->cmd_type = CMD_NORMAL; old->command->cmd_type = CMD_NORMAL;
#if !BB_MMU # if !BB_MMU
o_addstr(&old->as_string, ctx->as_string.data); o_addstr(&old->as_string, ctx->as_string.data);
o_free_unsafe(&ctx->as_string); o_free_unsafe(&ctx->as_string);
old->command->group_as_string = xstrdup(old->as_string.data); old->command->group_as_string = xstrdup(old->as_string.data);
debug_printf_parse("pop, remembering as:'%s'\n", debug_printf_parse("pop, remembering as:'%s'\n",
old->command->group_as_string); old->command->group_as_string);
#endif # endif
*ctx = *old; /* physical copy */ *ctx = *old; /* physical copy */
free(old); free(old);
} }
return 1; return 1;
} }
#endif #endif /* HAS_KEYWORDS */
/* Word is complete, look at it and update parsing context. /* Word is complete, look at it and update parsing context.
* Normal return is 0. Syntax errors return 1. * Normal return is 0. Syntax errors return 1.
@ -5200,9 +5200,9 @@ static FILE *generate_stream_from_string(const char *s)
{ {
FILE *pf; FILE *pf;
int pid, channel[2]; int pid, channel[2];
#if !BB_MMU # if !BB_MMU
char **to_free; char **to_free;
#endif # endif
xpipe(channel); xpipe(channel);
pid = BB_MMU ? fork() : vfork(); pid = BB_MMU ? fork() : vfork();
@ -5266,11 +5266,11 @@ static FILE *generate_stream_from_string(const char *s)
builtin_trap((char**)argv); builtin_trap((char**)argv);
exit(0); /* not _exit() - we need to fflush */ exit(0); /* not _exit() - we need to fflush */
} }
#if BB_MMU # if BB_MMU
reset_traps_to_defaults(); reset_traps_to_defaults();
parse_and_run_string(s); parse_and_run_string(s);
_exit(G.last_exitcode); _exit(G.last_exitcode);
#else # else
/* We re-execute after vfork on NOMMU. This makes this script safe: /* We re-execute after vfork on NOMMU. This makes this script safe:
* yes "0123456789012345678901234567890" | dd bs=32 count=64k >BIG * yes "0123456789012345678901234567890" | dd bs=32 count=64k >BIG
* huge=`cat BIG` # was blocking here forever * huge=`cat BIG` # was blocking here forever
@ -5281,18 +5281,18 @@ static FILE *generate_stream_from_string(const char *s)
G.global_argv[0], G.global_argv[0],
G.global_argv + 1, G.global_argv + 1,
NULL); NULL);
#endif # endif
} }
/* parent */ /* parent */
#if ENABLE_HUSH_FAST # if ENABLE_HUSH_FAST
G.count_SIGCHLD++; G.count_SIGCHLD++;
//bb_error_msg("[%d] fork in generate_stream_from_string: G.count_SIGCHLD:%d G.handled_SIGCHLD:%d", getpid(), G.count_SIGCHLD, G.handled_SIGCHLD); //bb_error_msg("[%d] fork in generate_stream_from_string: G.count_SIGCHLD:%d G.handled_SIGCHLD:%d", getpid(), G.count_SIGCHLD, G.handled_SIGCHLD);
#endif # endif
enable_restore_tty_pgrp_on_exit(); enable_restore_tty_pgrp_on_exit();
#if !BB_MMU # if !BB_MMU
free(to_free); free(to_free);
#endif # endif
close(channel[1]); close(channel[1]);
pf = fdopen(channel[0], "r"); pf = fdopen(channel[0], "r");
return pf; return pf;
@ -5336,7 +5336,7 @@ static int process_command_subs(o_string *dest, const char *s)
debug_printf("closed FILE from child. return 0\n"); debug_printf("closed FILE from child. return 0\n");
return 0; return 0;
} }
#endif #endif /* ENABLE_HUSH_TICK */
static int parse_group(o_string *dest, struct parse_context *ctx, static int parse_group(o_string *dest, struct parse_context *ctx,
struct in_str *input, int ch) struct in_str *input, int ch)
@ -5704,7 +5704,7 @@ static int handle_dollar(o_string *as_string,
o_addchr(dest, SPECIAL_VAR_SYMBOL); o_addchr(dest, SPECIAL_VAR_SYMBOL);
break; break;
} }
#if (ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_TICK) #if ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_TICK
case '(': { case '(': {
# if !BB_MMU # if !BB_MMU
int pos; int pos;
@ -6169,8 +6169,9 @@ static struct pipe *parse_stream(char **pstring,
/* Example: echo Hello \2>file /* Example: echo Hello \2>file
* we need to know that word 2 is quoted */ * we need to know that word 2 is quoted */
dest.o_quoted = 1; dest.o_quoted = 1;
} else { }
#if !BB_MMU #if !BB_MMU
else {
/* It's "\<newline>". Remove trailing '\' from ctx.as_string */ /* It's "\<newline>". Remove trailing '\' from ctx.as_string */
ctx.as_string.data[--ctx.as_string.length] = '\0'; ctx.as_string.data[--ctx.as_string.length] = '\0';
#endif #endif
@ -6914,30 +6915,30 @@ static int FAST_FUNC builtin_true(char **argv UNUSED_PARAM)
return 0; return 0;
} }
static int FAST_FUNC _builtin_applet(char **argv, int (applet)(int argc, char **argv)) static int FAST_FUNC run_applet_main(char **argv, int (*applet_main)(int argc, char **argv))
{ {
int argc = 0; int argc = 0;
while (*argv) { while (*argv) {
argc++; argc++;
argv++; argv++;
} }
return applet(argc, argv - argc); return applet_main(argc, argv - argc);
} }
static int FAST_FUNC builtin_test(char **argv) static int FAST_FUNC builtin_test(char **argv)
{ {
return _builtin_applet(argv, test_main); return run_applet_main(argv, test_main);
} }
static int FAST_FUNC builtin_echo(char **argv) static int FAST_FUNC builtin_echo(char **argv)
{ {
return _builtin_applet(argv, echo_main); return run_applet_main(argv, echo_main);
} }
#if ENABLE_PRINTF #if ENABLE_PRINTF
static int FAST_FUNC builtin_printf(char **argv) static int FAST_FUNC builtin_printf(char **argv)
{ {
return _builtin_applet(argv, printf_main); return run_applet_main(argv, printf_main);
} }
#endif #endif
@ -7395,10 +7396,10 @@ static int FAST_FUNC builtin_memleak(char **argv UNUSED_PARAM)
void *p; void *p;
unsigned long l; unsigned long l;
#ifdef M_TRIM_THRESHOLD # ifdef M_TRIM_THRESHOLD
/* Optional. Reduces probability of false positives */ /* Optional. Reduces probability of false positives */
malloc_trim(0); malloc_trim(0);
#endif # endif
/* Crude attempt to find where "free memory" starts, /* Crude attempt to find where "free memory" starts,
* sans fragmentation. */ * sans fragmentation. */
p = malloc(240); p = malloc(240);