hush: style fixes
This commit is contained in:
parent
15d78fb724
commit
0c886c65de
196
shell/hush.c
196
shell/hush.c
@ -79,21 +79,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
#include <ctype.h> /* isalpha, isdigit */
|
|
||||||
#include <unistd.h> /* getpid */
|
|
||||||
#include <stdlib.h> /* getenv, atoi */
|
|
||||||
#include <string.h> /* strchr */
|
|
||||||
#include <stdio.h> /* popen etc. */
|
|
||||||
#include <glob.h> /* glob, of course */
|
#include <glob.h> /* glob, of course */
|
||||||
#include <stdarg.h> /* va_list */
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <getopt.h> /* should be pretty obvious */
|
#include <getopt.h> /* should be pretty obvious */
|
||||||
|
|
||||||
#include <sys/stat.h> /* ulimit */
|
//#include <sys/wait.h>
|
||||||
#include <sys/types.h>
|
//#include <signal.h>
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
/* #include <dmalloc.h> */
|
/* #include <dmalloc.h> */
|
||||||
/* #define DEBUG_SHELL */
|
/* #define DEBUG_SHELL */
|
||||||
@ -238,9 +228,9 @@ static int interactive;
|
|||||||
static struct close_me *close_me_head;
|
static struct close_me *close_me_head;
|
||||||
static const char *cwd;
|
static const char *cwd;
|
||||||
static struct pipe *job_list;
|
static struct pipe *job_list;
|
||||||
static unsigned int last_bg_pid;
|
static unsigned last_bg_pid;
|
||||||
static int last_jobid;
|
static int last_jobid;
|
||||||
static unsigned int shell_terminal;
|
static unsigned shell_terminal;
|
||||||
static char *PS1;
|
static char *PS1;
|
||||||
static char *PS2;
|
static char *PS2;
|
||||||
static struct variables shell_ver = { "HUSH_VERSION", "0.01", 1, 1, 0 };
|
static struct variables shell_ver = { "HUSH_VERSION", "0.01", 1, 1, 0 };
|
||||||
@ -340,7 +330,7 @@ static int b_check_space(o_string *o, int len);
|
|||||||
static int b_addchr(o_string *o, int ch);
|
static int b_addchr(o_string *o, int ch);
|
||||||
static void b_reset(o_string *o);
|
static void b_reset(o_string *o);
|
||||||
static int b_addqchr(o_string *o, int ch, int quote);
|
static int b_addqchr(o_string *o, int ch, int quote);
|
||||||
static int b_adduint(o_string *o, unsigned int i);
|
static int b_adduint(o_string *o, unsigned i);
|
||||||
/* in_str manipulations: */
|
/* in_str manipulations: */
|
||||||
static int static_get(struct in_str *i);
|
static int static_get(struct in_str *i);
|
||||||
static int static_peek(struct in_str *i);
|
static int static_peek(struct in_str *i);
|
||||||
@ -477,8 +467,8 @@ static int builtin_env(struct child_prog *dummy ATTRIBUTE_UNUSED)
|
|||||||
{
|
{
|
||||||
char **e = environ;
|
char **e = environ;
|
||||||
if (e == NULL) return EXIT_FAILURE;
|
if (e == NULL) return EXIT_FAILURE;
|
||||||
for (; *e; e++) {
|
for (*e) {
|
||||||
puts(*e);
|
puts(*e++);
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -624,7 +614,7 @@ static int builtin_help(struct child_prog *dummy ATTRIBUTE_UNUSED)
|
|||||||
static int builtin_jobs(struct child_prog *child ATTRIBUTE_UNUSED)
|
static int builtin_jobs(struct child_prog *child ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
struct pipe *job;
|
struct pipe *job;
|
||||||
char *status_string;
|
const char *status_string;
|
||||||
|
|
||||||
for (job = job_list; job; job = job->next) {
|
for (job = job_list; job; job = job->next) {
|
||||||
if (job->running_progs == job->stopped_progs)
|
if (job->running_progs == job->stopped_progs)
|
||||||
@ -652,9 +642,9 @@ static int builtin_read(struct child_prog *child)
|
|||||||
|
|
||||||
if (child->argv[1]) {
|
if (child->argv[1]) {
|
||||||
char string[BUFSIZ];
|
char string[BUFSIZ];
|
||||||
char *var = 0;
|
char *var = NULL;
|
||||||
|
|
||||||
string[0] = 0; /* In case stdin has only EOF */
|
string[0] = '\0'; /* In case stdin has only EOF */
|
||||||
/* read string */
|
/* read string */
|
||||||
fgets(string, sizeof(string), stdin);
|
fgets(string, sizeof(string), stdin);
|
||||||
chomp(string);
|
chomp(string);
|
||||||
@ -668,11 +658,10 @@ static int builtin_read(struct child_prog *child)
|
|||||||
bb_perror_msg("read");
|
bb_perror_msg("read");
|
||||||
free(var); /* So not move up to avoid breaking errno */
|
free(var); /* So not move up to avoid breaking errno */
|
||||||
return res;
|
return res;
|
||||||
} else {
|
}
|
||||||
do res = getchar(); while (res != '\n' && res != EOF);
|
do res = getchar(); while (res != '\n' && res != EOF);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* built-in 'set VAR=value' handler */
|
/* built-in 'set VAR=value' handler */
|
||||||
static int builtin_set(struct child_prog *child)
|
static int builtin_set(struct child_prog *child)
|
||||||
@ -745,7 +734,8 @@ static int builtin_umask(struct child_prog *child)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("%.3o\n", (unsigned int) (new_umask=umask(0)));
|
new_umask = umask(0);
|
||||||
|
printf("%.3o\n", (unsigned) new_umask);
|
||||||
}
|
}
|
||||||
umask(new_umask);
|
umask(new_umask);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
@ -784,7 +774,8 @@ static int b_check_space(o_string *o, int len)
|
|||||||
static int b_addchr(o_string *o, int ch)
|
static int b_addchr(o_string *o, int ch)
|
||||||
{
|
{
|
||||||
debug_printf("b_addchr: %c %d %p\n", ch, o->length, o);
|
debug_printf("b_addchr: %c %d %p\n", ch, o->length, o);
|
||||||
if (b_check_space(o, 1)) return B_NOSPAC;
|
if (b_check_space(o, 1))
|
||||||
|
return B_NOSPAC;
|
||||||
o->data[o->length] = ch;
|
o->data[o->length] = ch;
|
||||||
o->length++;
|
o->length++;
|
||||||
o->data[o->length] = '\0';
|
o->data[o->length] = '\0';
|
||||||
@ -795,7 +786,8 @@ static void b_reset(o_string *o)
|
|||||||
{
|
{
|
||||||
o->length = 0;
|
o->length = 0;
|
||||||
o->nonnull = 0;
|
o->nonnull = 0;
|
||||||
if (o->data != NULL) *o->data = '\0';
|
if (o->data != NULL)
|
||||||
|
*o->data = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void b_free(o_string *o)
|
static void b_free(o_string *o)
|
||||||
@ -814,17 +806,17 @@ static int b_addqchr(o_string *o, int ch, int quote)
|
|||||||
if (quote && strchr("*?[\\",ch)) {
|
if (quote && strchr("*?[\\",ch)) {
|
||||||
int rc;
|
int rc;
|
||||||
rc = b_addchr(o, '\\');
|
rc = b_addchr(o, '\\');
|
||||||
if (rc) return rc;
|
if (rc)
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
return b_addchr(o, ch);
|
return b_addchr(o, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* belongs in utility.c */
|
/* belongs in utility.c */
|
||||||
static char *simple_itoa(unsigned int i)
|
static char *simple_itoa(unsigned i)
|
||||||
{
|
{
|
||||||
/* 21 digits plus null terminator, good for 64-bit or smaller ints */
|
static char local[sizeof(int)*3 + 2];
|
||||||
static char local[22];
|
char *p = &local[sizeof(int)*3 + 2 - 1];
|
||||||
char *p = &local[21];
|
|
||||||
*p-- = '\0';
|
*p-- = '\0';
|
||||||
do {
|
do {
|
||||||
*p-- = '0' + i % 10;
|
*p-- = '0' + i % 10;
|
||||||
@ -833,7 +825,7 @@ static char *simple_itoa(unsigned int i)
|
|||||||
return p + 1;
|
return p + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int b_adduint(o_string *o, unsigned int i)
|
static int b_adduint(o_string *o, unsigned i)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
char *p = simple_itoa(i);
|
char *p = simple_itoa(i);
|
||||||
@ -860,7 +852,7 @@ static void cmdedit_set_initial_prompt(void)
|
|||||||
PS1 = NULL;
|
PS1 = NULL;
|
||||||
#else
|
#else
|
||||||
PS1 = getenv("PS1");
|
PS1 = getenv("PS1");
|
||||||
if(PS1==0)
|
if (PS1 == NULL)
|
||||||
PS1 = "\\w \\$ ";
|
PS1 = "\\w \\$ ";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -926,7 +918,7 @@ static int file_get(struct in_str *i)
|
|||||||
/* need to double check i->file because we might be doing something
|
/* need to double check i->file because we might be doing something
|
||||||
* more complicated by now, like sourcing or substituting. */
|
* more complicated by now, like sourcing or substituting. */
|
||||||
if (i->__promptme && interactive && i->file == stdin) {
|
if (i->__promptme && interactive && i->file == stdin) {
|
||||||
while(! i->p || (interactive && strlen(i->p)==0) ) {
|
while (!i->p || !(interactive && strlen(i->p))) {
|
||||||
get_user_input(i);
|
get_user_input(i);
|
||||||
}
|
}
|
||||||
i->promptmode = 2;
|
i->promptmode = 2;
|
||||||
@ -940,7 +932,8 @@ static int file_get(struct in_str *i)
|
|||||||
|
|
||||||
debug_printf("b_getch: got a %d\n", ch);
|
debug_printf("b_getch: got a %d\n", ch);
|
||||||
}
|
}
|
||||||
if (ch == '\n') i->__promptme=1;
|
if (ch == '\n')
|
||||||
|
i->__promptme = 1;
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1072,10 +1065,12 @@ static void pseudo_exec(struct child_prog *child)
|
|||||||
const struct built_in_command *x;
|
const struct built_in_command *x;
|
||||||
if (child->argv) {
|
if (child->argv) {
|
||||||
for (i = 0; is_assignment(child->argv[i]); i++) {
|
for (i = 0; is_assignment(child->argv[i]); i++) {
|
||||||
debug_printf("pid %d environment modification: %s\n",getpid(),child->argv[i]);
|
debug_printf("pid %d environment modification: %s\n",
|
||||||
|
getpid(), child->argv[i]);
|
||||||
p = insert_var_value(child->argv[i]);
|
p = insert_var_value(child->argv[i]);
|
||||||
putenv(strdup(p));
|
putenv(strdup(p));
|
||||||
if (p != child->argv[i]) free(p);
|
if (p != child->argv[i])
|
||||||
|
free(p);
|
||||||
}
|
}
|
||||||
child->argv += i; /* XXX this hack isn't so horrible, since we are about
|
child->argv += i; /* XXX this hack isn't so horrible, since we are about
|
||||||
to exit, and therefore don't need to keep data
|
to exit, and therefore don't need to keep data
|
||||||
@ -1118,7 +1113,8 @@ static void pseudo_exec(struct child_prog *child)
|
|||||||
char *name = child->argv[0];
|
char *name = child->argv[0];
|
||||||
|
|
||||||
/* Count argc for use in a second... */
|
/* Count argc for use in a second... */
|
||||||
for(argc_l=0;*argv_l!=NULL; argv_l++, argc_l++);
|
for (argc_l = 0; *argv_l; argv_l++, argc_l++)
|
||||||
|
/**/;
|
||||||
optind = 1;
|
optind = 1;
|
||||||
debug_printf("running applet %s\n", name);
|
debug_printf("running applet %s\n", name);
|
||||||
run_applet_by_name(name, argc_l, child->argv);
|
run_applet_by_name(name, argc_l, child->argv);
|
||||||
@ -1156,7 +1152,8 @@ static void insert_bg_job(struct pipe *pi)
|
|||||||
if (!job_list) {
|
if (!job_list) {
|
||||||
thejob = job_list = xmalloc(sizeof(*thejob));
|
thejob = job_list = xmalloc(sizeof(*thejob));
|
||||||
} else {
|
} else {
|
||||||
for (thejob = job_list; thejob->next; thejob = thejob->next) /* nothing */;
|
for (thejob = job_list; thejob->next; thejob = thejob->next)
|
||||||
|
/* nothing */;
|
||||||
thejob->next = xmalloc(sizeof(*thejob));
|
thejob->next = xmalloc(sizeof(*thejob));
|
||||||
thejob = thejob->next;
|
thejob = thejob->next;
|
||||||
}
|
}
|
||||||
@ -1172,10 +1169,10 @@ static void insert_bg_job(struct pipe *pi)
|
|||||||
{
|
{
|
||||||
char *bar = thejob->text;
|
char *bar = thejob->text;
|
||||||
char **foo = pi->progs[0].argv;
|
char **foo = pi->progs[0].argv;
|
||||||
while(foo && *foo) {
|
if (foo)
|
||||||
|
while (*foo)
|
||||||
bar += sprintf(bar, "%s ", *foo++);
|
bar += sprintf(bar, "%s ", *foo++);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* we don't wait for background thejobs to return -- append it
|
/* we don't wait for background thejobs to return -- append it
|
||||||
to the list of backgrounded thejobs and leave it alone */
|
to the list of backgrounded thejobs and leave it alone */
|
||||||
@ -1229,7 +1226,7 @@ static int checkjobs(struct pipe* fg_pipe)
|
|||||||
if (fg_pipe->progs[i].pid == childpid) {
|
if (fg_pipe->progs[i].pid == childpid) {
|
||||||
if (i == fg_pipe->num_progs-1)
|
if (i == fg_pipe->num_progs-1)
|
||||||
rcode = WEXITSTATUS(status);
|
rcode = WEXITSTATUS(status);
|
||||||
(fg_pipe->num_progs)--;
|
fg_pipe->num_progs--;
|
||||||
return rcode;
|
return rcode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1245,7 +1242,8 @@ static int checkjobs(struct pipe* fg_pipe)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pi == NULL) {
|
if (pi == NULL) {
|
||||||
debug_printf("checkjobs: pid %d was not in our list!\n", childpid);
|
debug_printf("checkjobs: pid %d was not in our list!\n",
|
||||||
|
childpid);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1255,7 +1253,8 @@ static int checkjobs(struct pipe* fg_pipe)
|
|||||||
pi->progs[prognum].pid = 0;
|
pi->progs[prognum].pid = 0;
|
||||||
|
|
||||||
if (!pi->running_progs) {
|
if (!pi->running_progs) {
|
||||||
printf(JOB_STATUS_FORMAT, pi->jobid, "Done", pi->text);
|
printf(JOB_STATUS_FORMAT, pi->jobid,
|
||||||
|
"Done", pi->text);
|
||||||
remove_bg_job(pi);
|
remove_bg_job(pi);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1318,11 +1317,11 @@ static int run_pipe_real(struct pipe *pi)
|
|||||||
restore_redirects(squirrel);
|
restore_redirects(squirrel);
|
||||||
return rcode;
|
return rcode;
|
||||||
} else if (pi->num_progs == 1 && pi->progs[0].argv != NULL) {
|
} else if (pi->num_progs == 1 && pi->progs[0].argv != NULL) {
|
||||||
for (i=0; is_assignment(child->argv[i]); i++) { /* nothing */ }
|
for (i = 0; is_assignment(child->argv[i]); i++)
|
||||||
|
/* nothing */;
|
||||||
if (i != 0 && child->argv[i] == NULL) {
|
if (i != 0 && child->argv[i] == NULL) {
|
||||||
/* assignments, but no command: set the local environment */
|
/* assignments, but no command: set the local environment */
|
||||||
for (i = 0; child->argv[i] != NULL; i++) {
|
for (i = 0; child->argv[i] != NULL; i++) {
|
||||||
|
|
||||||
/* Ok, this case is tricky. We have to decide if this is a
|
/* Ok, this case is tricky. We have to decide if this is a
|
||||||
* local variable, or an already exported variable. If it is
|
* local variable, or an already exported variable. If it is
|
||||||
* already exported, we have to export the new value. If it is
|
* already exported, we have to export the new value. If it is
|
||||||
@ -1342,7 +1341,8 @@ static int run_pipe_real(struct pipe *pi)
|
|||||||
free(name);
|
free(name);
|
||||||
p = insert_var_value(child->argv[i]);
|
p = insert_var_value(child->argv[i]);
|
||||||
set_local_var(p, export_me);
|
set_local_var(p, export_me);
|
||||||
if (p != child->argv[i]) free(p);
|
if (p != child->argv[i])
|
||||||
|
free(p);
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS; /* don't worry about errors in set_local_var() yet */
|
return EXIT_SUCCESS; /* don't worry about errors in set_local_var() yet */
|
||||||
}
|
}
|
||||||
@ -1391,7 +1391,8 @@ static int run_pipe_real(struct pipe *pi)
|
|||||||
|
|
||||||
/* pipes are inserted between pairs of commands */
|
/* pipes are inserted between pairs of commands */
|
||||||
if ((i + 1) < pi->num_progs) {
|
if ((i + 1) < pi->num_progs) {
|
||||||
if (pipe(pipefds)<0) bb_perror_msg_and_die("pipe");
|
if (pipe(pipefds) < 0)
|
||||||
|
bb_perror_msg_and_die("pipe");
|
||||||
nextout = pipefds[1];
|
nextout = pipefds[1];
|
||||||
} else {
|
} else {
|
||||||
nextout = 1;
|
nextout = 1;
|
||||||
@ -1400,11 +1401,11 @@ static int run_pipe_real(struct pipe *pi)
|
|||||||
|
|
||||||
/* XXX test for failed fork()? */
|
/* XXX test for failed fork()? */
|
||||||
#if !defined(__UCLIBC__) || defined(__ARCH_HAS_MMU__)
|
#if !defined(__UCLIBC__) || defined(__ARCH_HAS_MMU__)
|
||||||
if (!(child->pid = fork()))
|
child->pid = fork();
|
||||||
#else
|
#else
|
||||||
if (!(child->pid = vfork()))
|
child->pid = vfork();
|
||||||
#endif
|
#endif
|
||||||
{
|
if (!child->pid) {
|
||||||
/* Set the handling for job control signals back to the default. */
|
/* Set the handling for job control signals back to the default. */
|
||||||
signal(SIGINT, SIG_DFL);
|
signal(SIGINT, SIG_DFL);
|
||||||
signal(SIGQUIT, SIG_DFL);
|
signal(SIGQUIT, SIG_DFL);
|
||||||
@ -1446,7 +1447,6 @@ static int run_pipe_real(struct pipe *pi)
|
|||||||
pseudo_exec(child);
|
pseudo_exec(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* put our child in the process group whose leader is the
|
/* put our child in the process group whose leader is the
|
||||||
first process in this pipe */
|
first process in this pipe */
|
||||||
if (pi->pgrp < 0) {
|
if (pi->pgrp < 0) {
|
||||||
@ -1482,24 +1482,23 @@ static int run_list_real(struct pipe *pi)
|
|||||||
reserved_style rmode, skip_more_in_this_rmode = RES_XXXX;
|
reserved_style rmode, skip_more_in_this_rmode = RES_XXXX;
|
||||||
/* check syntax for "for" */
|
/* check syntax for "for" */
|
||||||
for (rpipe = pi; rpipe; rpipe = rpipe->next) {
|
for (rpipe = pi; rpipe; rpipe = rpipe->next) {
|
||||||
if ((rpipe->r_mode == RES_IN ||
|
if ((rpipe->r_mode == RES_IN || rpipe->r_mode == RES_FOR)
|
||||||
rpipe->r_mode == RES_FOR) &&
|
&& (rpipe->next == NULL)
|
||||||
(rpipe->next == NULL)) {
|
) {
|
||||||
syntax();
|
syntax();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if ((rpipe->r_mode == RES_IN &&
|
if ((rpipe->r_mode == RES_IN && rpipe->next->r_mode == RES_IN && rpipe->next->progs->argv != NULL)
|
||||||
(rpipe->next->r_mode == RES_IN &&
|
|| (rpipe->r_mode == RES_FOR && rpipe->next->r_mode != RES_IN)
|
||||||
rpipe->next->progs->argv != NULL))||
|
) {
|
||||||
(rpipe->r_mode == RES_FOR &&
|
|
||||||
rpipe->next->r_mode != RES_IN)) {
|
|
||||||
syntax();
|
syntax();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (; pi; pi = (flag_restore != 0) ? rpipe : pi->next) {
|
for (; pi; pi = (flag_restore != 0) ? rpipe : pi->next) {
|
||||||
if (pi->r_mode == RES_WHILE || pi->r_mode == RES_UNTIL ||
|
if (pi->r_mode == RES_WHILE || pi->r_mode == RES_UNTIL
|
||||||
pi->r_mode == RES_FOR) {
|
|| pi->r_mode == RES_FOR
|
||||||
|
) {
|
||||||
flag_restore = 0;
|
flag_restore = 0;
|
||||||
if (!rpipe) {
|
if (!rpipe) {
|
||||||
flag_rep = 0;
|
flag_rep = 0;
|
||||||
@ -1507,21 +1506,28 @@ static int run_list_real(struct pipe *pi)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
rmode = pi->r_mode;
|
rmode = pi->r_mode;
|
||||||
debug_printf("rmode=%d if_code=%d next_if_code=%d skip_more=%d\n", rmode, if_code, next_if_code, skip_more_in_this_rmode);
|
debug_printf("rmode=%d if_code=%d next_if_code=%d skip_more=%d\n",
|
||||||
|
rmode, if_code, next_if_code, skip_more_in_this_rmode);
|
||||||
if (rmode == skip_more_in_this_rmode && flag_skip) {
|
if (rmode == skip_more_in_this_rmode && flag_skip) {
|
||||||
if (pi->followup == PIPE_SEQ) flag_skip=0;
|
if (pi->followup == PIPE_SEQ)
|
||||||
|
flag_skip = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
flag_skip = 1;
|
flag_skip = 1;
|
||||||
skip_more_in_this_rmode = RES_XXXX;
|
skip_more_in_this_rmode = RES_XXXX;
|
||||||
if (rmode == RES_THEN || rmode == RES_ELSE) if_code = next_if_code;
|
if (rmode == RES_THEN || rmode == RES_ELSE)
|
||||||
if (rmode == RES_THEN && if_code) continue;
|
if_code = next_if_code;
|
||||||
if (rmode == RES_ELSE && !if_code) continue;
|
if (rmode == RES_THEN && if_code)
|
||||||
if (rmode == RES_ELIF && !if_code) break;
|
continue;
|
||||||
|
if (rmode == RES_ELSE && !if_code)
|
||||||
|
continue;
|
||||||
|
if (rmode == RES_ELIF && !if_code)
|
||||||
|
break;
|
||||||
if (rmode == RES_FOR && pi->num_progs) {
|
if (rmode == RES_FOR && pi->num_progs) {
|
||||||
if (!list) {
|
if (!list) {
|
||||||
/* if no variable values after "in" we skip "for" */
|
/* if no variable values after "in" we skip "for" */
|
||||||
if (!pi->next->progs->argv) continue;
|
if (!pi->next->progs->argv)
|
||||||
|
continue;
|
||||||
/* create list of variable values */
|
/* create list of variable values */
|
||||||
list = make_list_in(pi->next->progs->argv,
|
list = make_list_in(pi->next->progs->argv,
|
||||||
pi->progs->argv[0]);
|
pi->progs->argv[0]);
|
||||||
@ -1530,27 +1536,27 @@ static int run_list_real(struct pipe *pi)
|
|||||||
pi->progs->argv[0] = NULL;
|
pi->progs->argv[0] = NULL;
|
||||||
flag_rep = 1;
|
flag_rep = 1;
|
||||||
}
|
}
|
||||||
if (!(*list)) {
|
if (!*list) {
|
||||||
free(pi->progs->argv[0]);
|
free(pi->progs->argv[0]);
|
||||||
free(save_list);
|
free(save_list);
|
||||||
list = NULL;
|
list = NULL;
|
||||||
flag_rep = 0;
|
flag_rep = 0;
|
||||||
pi->progs->argv[0] = save_name;
|
pi->progs->argv[0] = save_name;
|
||||||
pi->progs->glob_result.gl_pathv[0] =
|
pi->progs->glob_result.gl_pathv[0] = pi->progs->argv[0];
|
||||||
pi->progs->argv[0];
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
/* insert new value from list for variable */
|
/* insert new value from list for variable */
|
||||||
if (pi->progs->argv[0])
|
if (pi->progs->argv[0])
|
||||||
free(pi->progs->argv[0]);
|
free(pi->progs->argv[0]);
|
||||||
pi->progs->argv[0] = *list++;
|
pi->progs->argv[0] = *list++;
|
||||||
pi->progs->glob_result.gl_pathv[0] =
|
pi->progs->glob_result.gl_pathv[0] = pi->progs->argv[0];
|
||||||
pi->progs->argv[0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rmode == RES_IN) continue;
|
if (rmode == RES_IN)
|
||||||
|
continue;
|
||||||
if (rmode == RES_DO) {
|
if (rmode == RES_DO) {
|
||||||
if (!flag_rep) continue;
|
if (!flag_rep)
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if ((rmode == RES_DONE)) {
|
if ((rmode == RES_DONE)) {
|
||||||
if (flag_rep) {
|
if (flag_rep) {
|
||||||
@ -1559,7 +1565,8 @@ static int run_list_real(struct pipe *pi)
|
|||||||
rpipe = NULL;
|
rpipe = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pi->num_progs == 0) continue;
|
if (pi->num_progs == 0)
|
||||||
|
continue;
|
||||||
save_num_progs = pi->num_progs; /* save number of programs */
|
save_num_progs = pi->num_progs; /* save number of programs */
|
||||||
rcode = run_pipe_real(pi);
|
rcode = run_pipe_real(pi);
|
||||||
debug_printf("run_pipe_real returned %d\n",rcode);
|
debug_printf("run_pipe_real returned %d\n",rcode);
|
||||||
@ -1594,9 +1601,11 @@ static int run_list_real(struct pipe *pi)
|
|||||||
flag_rep = !last_return_code;
|
flag_rep = !last_return_code;
|
||||||
if (rmode == RES_UNTIL)
|
if (rmode == RES_UNTIL)
|
||||||
flag_rep = last_return_code;
|
flag_rep = last_return_code;
|
||||||
if ( (rcode==EXIT_SUCCESS && pi->followup==PIPE_OR) ||
|
if ((rcode == EXIT_SUCCESS && pi->followup == PIPE_OR)
|
||||||
(rcode!=EXIT_SUCCESS && pi->followup==PIPE_AND) )
|
|| (rcode != EXIT_SUCCESS && pi->followup == PIPE_AND)
|
||||||
|
) {
|
||||||
skip_more_in_this_rmode = rmode;
|
skip_more_in_this_rmode = rmode;
|
||||||
|
}
|
||||||
checkjobs(NULL);
|
checkjobs(NULL);
|
||||||
}
|
}
|
||||||
return rcode;
|
return rcode;
|
||||||
@ -1825,7 +1834,7 @@ static int set_local_var(const char *s, int flg_export)
|
|||||||
result = -1;
|
result = -1;
|
||||||
} else {
|
} else {
|
||||||
cur->name = strdup(name);
|
cur->name = strdup(name);
|
||||||
if(cur->name == 0) {
|
if (cur->name) {
|
||||||
free(cur);
|
free(cur);
|
||||||
result = -1;
|
result = -1;
|
||||||
} else {
|
} else {
|
||||||
@ -1834,7 +1843,8 @@ static int set_local_var(const char *s, int flg_export)
|
|||||||
cur->next = 0;
|
cur->next = 0;
|
||||||
cur->flg_export = flg_export;
|
cur->flg_export = flg_export;
|
||||||
cur->flg_read_only = 0;
|
cur->flg_read_only = 0;
|
||||||
while(bottom->next) bottom=bottom->next;
|
while (bottom->next)
|
||||||
|
bottom = bottom->next;
|
||||||
bottom->next = cur;
|
bottom->next = cur;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1865,7 +1875,7 @@ static void unset_local_var(const char *name)
|
|||||||
if (cur->flg_read_only) {
|
if (cur->flg_read_only) {
|
||||||
bb_error_msg("%s: readonly variable", name);
|
bb_error_msg("%s: readonly variable", name);
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
if (cur->flg_export)
|
if (cur->flg_export)
|
||||||
unsetenv(cur->name);
|
unsetenv(cur->name);
|
||||||
free((char*)cur->name);
|
free((char*)cur->name);
|
||||||
@ -1873,7 +1883,6 @@ static void unset_local_var(const char *name)
|
|||||||
while (next->next != cur)
|
while (next->next != cur)
|
||||||
next = next->next;
|
next = next->next;
|
||||||
next->next = cur->next;
|
next->next = cur->next;
|
||||||
}
|
|
||||||
free(cur);
|
free(cur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1881,9 +1890,11 @@ static void unset_local_var(const char *name)
|
|||||||
|
|
||||||
static int is_assignment(const char *s)
|
static int is_assignment(const char *s)
|
||||||
{
|
{
|
||||||
if (s==NULL || !isalpha(*s)) return 0;
|
if (!s || !isalpha(*s))
|
||||||
++s;
|
return 0;
|
||||||
while(isalnum(*s) || *s=='_') ++s;
|
s++;
|
||||||
|
while (isalnum(*s) || *s == '_')
|
||||||
|
s++;
|
||||||
return *s == '=';
|
return *s == '=';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1991,9 +2002,8 @@ static int reserved_word(o_string *dest, struct p_context *ctx)
|
|||||||
{ "done", RES_DONE, FLAG_END }
|
{ "done", RES_DONE, FLAG_END }
|
||||||
};
|
};
|
||||||
struct reserved_combo *r;
|
struct reserved_combo *r;
|
||||||
for (r=reserved_list;
|
|
||||||
#define NRES sizeof(reserved_list)/sizeof(struct reserved_combo)
|
#define NRES sizeof(reserved_list)/sizeof(struct reserved_combo)
|
||||||
r<reserved_list+NRES; r++) {
|
for (r = reserved_list; r < reserved_list+NRES; r++) {
|
||||||
if (strcmp(dest->data, r->literal) == 0) {
|
if (strcmp(dest->data, r->literal) == 0) {
|
||||||
debug_printf("found reserved word %s, code %d\n",r->literal,r->code);
|
debug_printf("found reserved word %s, code %d\n",r->literal,r->code);
|
||||||
if (r->flag & FLAG_START) {
|
if (r->flag & FLAG_START) {
|
||||||
@ -2427,7 +2437,12 @@ int parse_stream(o_string *dest, struct p_context *ctx,
|
|||||||
if (m!=2) switch (ch) {
|
if (m!=2) switch (ch) {
|
||||||
case '#':
|
case '#':
|
||||||
if (dest->length == 0 && !dest->quote) {
|
if (dest->length == 0 && !dest->quote) {
|
||||||
while(ch=b_peek(input),ch!=EOF && ch!='\n') { b_getch(input); }
|
while (1) {
|
||||||
|
ch = b_peek(input);
|
||||||
|
if (ch == EOF || ch == '\n')
|
||||||
|
break;
|
||||||
|
b_getch(input);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
b_addqchr(dest, ch, dest->quote);
|
b_addqchr(dest, ch, dest->quote);
|
||||||
}
|
}
|
||||||
@ -2445,7 +2460,10 @@ int parse_stream(o_string *dest, struct p_context *ctx,
|
|||||||
break;
|
break;
|
||||||
case '\'':
|
case '\'':
|
||||||
dest->nonnull = 1;
|
dest->nonnull = 1;
|
||||||
while(ch=b_getch(input),ch!=EOF && ch!='\'') {
|
while (1) {
|
||||||
|
ch = b_getch(input);
|
||||||
|
if (ch == EOF || ch == '\'')
|
||||||
|
break;
|
||||||
b_addchr(dest,ch);
|
b_addchr(dest,ch);
|
||||||
}
|
}
|
||||||
if (ch == EOF) {
|
if (ch == EOF) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user