hush: style fixes

This commit is contained in:
Denis Vlasenko 2007-01-30 22:32:09 +00:00
parent c72c1ed932
commit bb81c5831a

View File

@ -583,7 +583,8 @@ static int builtin_fg_bg(struct child_prog *child)
for (i = 0; i < pi->num_progs; i++)
pi->progs[i].is_stopped = 0;
if ( (i=kill(- pi->pgrp, SIGCONT)) < 0) {
i = kill(- pi->pgrp, SIGCONT);
if (i < 0) {
if (i == ESRCH) {
remove_bg_job(pi);
} else {
@ -2072,7 +2073,8 @@ static int done_word(o_string *dest, struct p_context *ctx)
}
if (!child->argv && (ctx->type & FLAG_PARSE_SEMICOLON)) {
debug_printf("checking %s for reserved-ness\n",dest->data);
if (reserved_word(dest,ctx)) return ctx->w==RES_SNTX;
if (reserved_word(dest,ctx))
return (ctx->w == RES_SNTX);
}
glob_target = &child->glob_result;
if (child->argv) flags |= GLOB_APPEND;
@ -2195,7 +2197,8 @@ static int redirect_opt_num(o_string *o)
{
int num;
if (o->length==0) return -1;
if (o->length == 0)
return -1;
for (num = 0; num < o->length; num++) {
if (!isdigit(*(o->data + num))) {
return -1;
@ -2262,7 +2265,8 @@ static int process_command_subs(o_string *dest, struct p_context *ctx, struct in
/* XXX In case of a syntax error, should we try to kill the child?
* That would be tough to do right, so just read until EOF. */
if (retcode == 1) {
while (b_getch(&pipe_str)!=EOF) { /* discard */ };
while (b_getch(&pipe_str) != EOF)
/* discard */;
}
debug_printf("done reading from pipe, pclose()ing\n");
@ -2291,9 +2295,15 @@ static int parse_group(o_string *dest, struct p_context *ctx,
}
initialize_context(&sub);
switch (ch) {
case '(': endch=')'; child->subshell=1; break;
case '{': endch='}'; break;
default: syntax(); /* really logic error */
case '(':
endch = ')';
child->subshell = 1;
break;
case '{':
endch = '}';
break;
default:
syntax(); /* really logic error */
}
rcode = parse_stream(dest,&sub,input,endch);
done_word(dest,&sub); /* finish off the final word in the subcontext */
@ -2359,7 +2369,10 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *i
ctx->child->sp++;
b_getch(input);
/* XXX maybe someone will try to escape the '}' */
while (ch=b_getch(input),ch!=EOF && ch!='}') {
while (1) {
ch = b_getch(input);
if (ch == EOF || ch == '}')
break;
b_addchr(dest,ch);
}
if (ch != '}') {
@ -2376,7 +2389,8 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *i
sep[0] = ifs[0];
for (i = 1; i < global_argc; i++) {
parse_string(dest, ctx, global_argv[i]);
if (i+1 < global_argc) parse_string(dest, ctx, sep);
if (i+1 < global_argc)
parse_string(dest, ctx, sep);
}
break;
case '@':
@ -2426,7 +2440,8 @@ int parse_stream(o_string *dest, struct p_context *ctx,
ch, ch, m, dest->quote);
if (m == 0 || ((m == 1 || m == 2) && dest->quote)) {
b_addqchr(dest, ch, dest->quote);
} else {
continue;
}
if (m == 2) { /* unquoted IFS */
if (done_word(dest, ctx)) {
return 1;
@ -2440,7 +2455,9 @@ int parse_stream(o_string *dest, struct p_context *ctx,
debug_printf("leaving parse_stream (triggered)\n");
return 0;
}
if (m!=2) switch (ch) {
if (m == 2)
continue;
switch (ch) {
case '#':
if (dest->length == 0 && !dest->quote) {
while (1) {
@ -2540,19 +2557,18 @@ int parse_stream(o_string *dest, struct p_context *ctx,
break;
case '(':
case '{':
if (parse_group(dest, ctx, input, ch)!=0) return 1;
if (parse_group(dest, ctx, input, ch) != 0)
return 1;
break;
case ')':
case '}':
syntax(); /* Proper use of this character caught by end_trigger */
return 1;
break;
default:
syntax(); /* this is really an internal logic error */
return 1;
}
}
}
/* complain if quote? No, maybe we just finished a command substitution
* that was quoted. Example:
* $ echo "`cat foo` plus more"
@ -2712,7 +2728,6 @@ int hush_main(int argc, char **argv)
last_return_code = EXIT_SUCCESS;
if (argv[0] && argv[0][0] == '-') {
debug_printf("\nsourcing /etc/profile\n");
if ((input = fopen("/etc/profile", "r")) != NULL) {
@ -2757,8 +2772,9 @@ int hush_main(int argc, char **argv)
* standard input is a terminal
* standard output is a terminal
* Refer to Posix.2, the description of the `sh' utility. */
if (argv[optind]==NULL && input==stdin &&
isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
if (argv[optind] == NULL && input == stdin
&& isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)
) {
interactive++;
}