mirror of
https://github.com/sheumann/hush.git
synced 2024-11-05 21:04:56 +00:00
hush: int->smallint for flag vars; make some names more "greppable"
This commit is contained in:
parent
8412d7959a
commit
ff0976248a
60
shell/hush.c
60
shell/hush.c
@ -246,7 +246,7 @@ struct redir_struct {
|
|||||||
redir_type type; /* type of redirection */
|
redir_type type; /* type of redirection */
|
||||||
int fd; /* file descriptor being redirected */
|
int fd; /* file descriptor being redirected */
|
||||||
int dup; /* -1, or file descriptor being duplicated */
|
int dup; /* -1, or file descriptor being duplicated */
|
||||||
glob_t word; /* *word.gl_pathv is the filename */
|
glob_t glob_word; /* *word.gl_pathv is the filename */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct child_prog {
|
struct child_prog {
|
||||||
@ -304,8 +304,8 @@ typedef struct {
|
|||||||
char *data;
|
char *data;
|
||||||
int length;
|
int length;
|
||||||
int maxlen;
|
int maxlen;
|
||||||
int quote;
|
smallint o_quote;
|
||||||
int nonnull;
|
smallint nonnull;
|
||||||
} o_string;
|
} o_string;
|
||||||
#define NULL_O_STRING {NULL,0,0,0,0}
|
#define NULL_O_STRING {NULL,0,0,0,0}
|
||||||
/* used for initialization: o_string foo = NULL_O_STRING; */
|
/* used for initialization: o_string foo = NULL_O_STRING; */
|
||||||
@ -1256,13 +1256,13 @@ static int setup_redirects(struct child_prog *prog, int squirrel[])
|
|||||||
struct redir_struct *redir;
|
struct redir_struct *redir;
|
||||||
|
|
||||||
for (redir = prog->redirects; redir; redir = redir->next) {
|
for (redir = prog->redirects; redir; redir = redir->next) {
|
||||||
if (redir->dup == -1 && redir->word.gl_pathv == NULL) {
|
if (redir->dup == -1 && redir->glob_word.gl_pathv == NULL) {
|
||||||
/* something went wrong in the parse. Pretend it didn't happen */
|
/* something went wrong in the parse. Pretend it didn't happen */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (redir->dup == -1) {
|
if (redir->dup == -1) {
|
||||||
mode = redir_table[redir->type].mode;
|
mode = redir_table[redir->type].mode;
|
||||||
openfd = open_or_warn(redir->word.gl_pathv[0], mode);
|
openfd = open_or_warn(redir->glob_word.gl_pathv[0], mode);
|
||||||
if (openfd < 0) {
|
if (openfd < 0) {
|
||||||
/* this could get lost if stderr has been redirected, but
|
/* this could get lost if stderr has been redirected, but
|
||||||
bash and ash both lose it as well (though zsh doesn't!) */
|
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)
|
|||||||
debug_printf_clean("%s redirect %d%s", indenter(indent), r->fd, redir_table[r->type].descrip);
|
debug_printf_clean("%s redirect %d%s", indenter(indent), r->fd, redir_table[r->type].descrip);
|
||||||
if (r->dup == -1) {
|
if (r->dup == -1) {
|
||||||
/* guard against the case >$FOO, where foo is unset or blank */
|
/* guard against the case >$FOO, where foo is unset or blank */
|
||||||
if (r->word.gl_pathv) {
|
if (r->glob_word.gl_pathv) {
|
||||||
debug_printf_clean(" %s\n", *r->word.gl_pathv);
|
debug_printf_clean(" %s\n", r->glob_word.gl_pathv[0]);
|
||||||
globfree(&r->word);
|
globfree(&r->glob_word);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug_printf_clean("&%d\n", r->dup);
|
debug_printf_clean("&%d\n", r->dup);
|
||||||
@ -2216,6 +2216,10 @@ static int run_list(struct pipe *pi)
|
|||||||
return rcode;
|
return rcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Whoever decided to muck with glob internal data is AN IDIOT! */
|
||||||
|
/* uclibc happily changed the way it works (and it has rights to do so!),
|
||||||
|
all hell broke loose (SEGVs) */
|
||||||
|
|
||||||
/* The API for glob is arguably broken. This routine pushes a non-matching
|
/* The API for glob is arguably broken. This routine pushes a non-matching
|
||||||
* string into the output structure, removing non-backslashed backslashes.
|
* string into the output structure, removing non-backslashed backslashes.
|
||||||
* If someone can prove me wrong, by performing this function within the
|
* 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,
|
|||||||
last_redir = redir;
|
last_redir = redir;
|
||||||
redir = redir->next;
|
redir = redir->next;
|
||||||
}
|
}
|
||||||
redir = xmalloc(sizeof(struct redir_struct));
|
redir = xzalloc(sizeof(struct redir_struct));
|
||||||
redir->next = NULL;
|
/* redir->next = NULL; */
|
||||||
redir->word.gl_pathv = NULL;
|
/* redir->glob_word.gl_pathv = NULL; */
|
||||||
if (last_redir) {
|
if (last_redir) {
|
||||||
last_redir->next = redir;
|
last_redir->next = redir;
|
||||||
} else {
|
} else {
|
||||||
@ -2924,7 +2928,7 @@ static int done_word(o_string *dest, struct p_context *ctx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (ctx->pending_redirect) {
|
if (ctx->pending_redirect) {
|
||||||
glob_target = &ctx->pending_redirect->word;
|
glob_target = &ctx->pending_redirect->glob_word;
|
||||||
} else {
|
} else {
|
||||||
if (child->group) {
|
if (child->group) {
|
||||||
syntax(NULL);
|
syntax(NULL);
|
||||||
@ -3160,10 +3164,10 @@ static int process_command_subs(o_string *dest, struct p_context *ctx,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
while (eol_cnt) {
|
while (eol_cnt) {
|
||||||
b_addqchr(dest, '\n', dest->quote);
|
b_addqchr(dest, '\n', dest->o_quote);
|
||||||
eol_cnt--;
|
eol_cnt--;
|
||||||
}
|
}
|
||||||
b_addqchr(dest, ch, dest->quote);
|
b_addqchr(dest, ch, dest->o_quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_printf("done reading from pipe, pclose()ing\n");
|
debug_printf("done reading from pipe, pclose()ing\n");
|
||||||
@ -3224,7 +3228,7 @@ static const char *lookup_param(const char *src)
|
|||||||
static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *input)
|
static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *input)
|
||||||
{
|
{
|
||||||
int ch = b_peek(input); /* first character after the $ */
|
int ch = b_peek(input); /* first character after the $ */
|
||||||
unsigned char quote_mask = dest->quote ? 0x80 : 0;
|
unsigned char quote_mask = dest->o_quote ? 0x80 : 0;
|
||||||
|
|
||||||
debug_printf_parse("handle_dollar entered: ch='%c'\n", ch);
|
debug_printf_parse("handle_dollar entered: ch='%c'\n", ch);
|
||||||
if (isalpha(ch)) {
|
if (isalpha(ch)) {
|
||||||
@ -3289,7 +3293,7 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *i
|
|||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
b_addqchr(dest, '$', dest->quote);
|
b_addqchr(dest, '$', dest->o_quote);
|
||||||
}
|
}
|
||||||
debug_printf_parse("handle_dollar return 0\n");
|
debug_printf_parse("handle_dollar return 0\n");
|
||||||
return 0;
|
return 0;
|
||||||
@ -3304,9 +3308,9 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
|
|||||||
redir_type redir_style;
|
redir_type redir_style;
|
||||||
int next;
|
int next;
|
||||||
|
|
||||||
/* Only double-quote state is handled in the state variable dest->quote.
|
/* Only double-quote state is handled in the state variable dest->o_quote.
|
||||||
* A single-quote triggers a bypass of the main loop until its mate is
|
* A single-quote triggers a bypass of the main loop until its mate is
|
||||||
* found. When recursing, quote state is passed in via dest->quote. */
|
* found. When recursing, quote state is passed in via dest->o_quote. */
|
||||||
|
|
||||||
debug_printf_parse("parse_stream entered, end_trigger='%s'\n", end_trigger);
|
debug_printf_parse("parse_stream entered, end_trigger='%s'\n", end_trigger);
|
||||||
|
|
||||||
@ -3320,16 +3324,16 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
|
|||||||
next = b_peek(input);
|
next = b_peek(input);
|
||||||
}
|
}
|
||||||
debug_printf_parse(": ch=%c (%d) m=%d quote=%d\n",
|
debug_printf_parse(": ch=%c (%d) m=%d quote=%d\n",
|
||||||
ch, ch, m, dest->quote);
|
ch, ch, m, dest->o_quote);
|
||||||
if (m == CHAR_ORDINARY
|
if (m == CHAR_ORDINARY
|
||||||
|| (m != CHAR_SPECIAL && dest->quote)
|
|| (m != CHAR_SPECIAL && dest->o_quote)
|
||||||
) {
|
) {
|
||||||
if (ch == EOF) {
|
if (ch == EOF) {
|
||||||
syntax("unterminated \"");
|
syntax("unterminated \"");
|
||||||
debug_printf_parse("parse_stream return 1: unterminated \"\n");
|
debug_printf_parse("parse_stream return 1: unterminated \"\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
b_addqchr(dest, ch, dest->quote);
|
b_addqchr(dest, ch, dest->o_quote);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (m == CHAR_IFS) {
|
if (m == CHAR_IFS) {
|
||||||
@ -3347,7 +3351,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((end_trigger && strchr(end_trigger, ch))
|
if ((end_trigger && strchr(end_trigger, ch))
|
||||||
&& !dest->quote && ctx->res_w == RES_NONE
|
&& !dest->o_quote && ctx->res_w == RES_NONE
|
||||||
) {
|
) {
|
||||||
debug_printf_parse("parse_stream return 0: end_trigger char found\n");
|
debug_printf_parse("parse_stream return 0: end_trigger char found\n");
|
||||||
return 0;
|
return 0;
|
||||||
@ -3356,7 +3360,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
|
|||||||
continue;
|
continue;
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '#':
|
case '#':
|
||||||
if (dest->length == 0 && !dest->quote) {
|
if (dest->length == 0 && !dest->o_quote) {
|
||||||
while (1) {
|
while (1) {
|
||||||
ch = b_peek(input);
|
ch = b_peek(input);
|
||||||
if (ch == EOF || ch == '\n')
|
if (ch == EOF || ch == '\n')
|
||||||
@ -3364,7 +3368,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
|
|||||||
b_getch(input);
|
b_getch(input);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
b_addqchr(dest, ch, dest->quote);
|
b_addqchr(dest, ch, dest->o_quote);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\\':
|
case '\\':
|
||||||
@ -3373,8 +3377,8 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
|
|||||||
debug_printf_parse("parse_stream return 1: \\<eof>\n");
|
debug_printf_parse("parse_stream return 1: \\<eof>\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
b_addqchr(dest, '\\', dest->quote);
|
b_addqchr(dest, '\\', dest->o_quote);
|
||||||
b_addqchr(dest, b_getch(input), dest->quote);
|
b_addqchr(dest, b_getch(input), dest->o_quote);
|
||||||
break;
|
break;
|
||||||
case '$':
|
case '$':
|
||||||
if (handle_dollar(dest, ctx, input) != 0) {
|
if (handle_dollar(dest, ctx, input) != 0) {
|
||||||
@ -3398,7 +3402,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
|
|||||||
break;
|
break;
|
||||||
case '"':
|
case '"':
|
||||||
dest->nonnull = 1;
|
dest->nonnull = 1;
|
||||||
dest->quote = !dest->quote;
|
dest->o_quote ^= 1; /* invert */
|
||||||
break;
|
break;
|
||||||
#if ENABLE_HUSH_TICK
|
#if ENABLE_HUSH_TICK
|
||||||
case '`':
|
case '`':
|
||||||
@ -3561,7 +3565,7 @@ static int parse_and_run_stream(struct in_str *inp, int parse_flag)
|
|||||||
b_reset(&temp);
|
b_reset(&temp);
|
||||||
}
|
}
|
||||||
temp.nonnull = 0;
|
temp.nonnull = 0;
|
||||||
temp.quote = 0;
|
temp.o_quote = 0;
|
||||||
inp->p = NULL;
|
inp->p = NULL;
|
||||||
free_pipe_list(ctx.list_head, 0);
|
free_pipe_list(ctx.list_head, 0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user