*/
/* Syntax classes */
-#define CWORD 0 /* character is nothing special */
-#define CNL 1 /* newline character */
-#define CBACK 2 /* a backslash character */
-#define CSQUOTE 3 /* single quote */
-#define CDQUOTE 4 /* double quote */
-#define CENDQUOTE 5 /* a terminating quote */
-#define CBQUOTE 6 /* backwards single quote */
-#define CVAR 7 /* a dollar sign */
-#define CENDVAR 8 /* a '}' character */
-#define CLP 9 /* a left paren in arithmetic */
-#define CRP 10 /* a right paren in arithmetic */
-#define CENDFILE 11 /* end of file */
-#define CCTL 12 /* like CWORD, except it must be escaped */
-#define CSPCL 13 /* these terminate a word */
-#define CIGN 14 /* character should be ignored */
+#define CWORD 0 /* character is nothing special */
+#define CNL 1 /* newline character */
+#define CBACK 2 /* a backslash character */
+#define CSQUOTE 3 /* single quote */
+#define CDQUOTE 4 /* double quote */
+#define CENDQUOTE 5 /* a terminating quote */
+#define CBQUOTE 6 /* backwards single quote */
+#define CVAR 7 /* a dollar sign */
+#define CENDVAR 8 /* a '}' character */
+#define CLP 9 /* a left paren in arithmetic */
+#define CRP 10 /* a right paren in arithmetic */
+#define CENDFILE 11 /* end of file */
+#define CCTL 12 /* like CWORD, except it must be escaped */
+#define CSPCL 13 /* these terminate a word */
+#define CIGN 14 /* character should be ignored */
#define SYNBASE 130
#define PEOF -130
#define CTLVAR '\202'
#define CTLENDVAR '\203'
#define CTLBACKQ '\204'
-#define CTLQUOTE 01 /* ored with CTLBACKQ code if in quotes */
+#define CTLQUOTE 01 /* ored with CTLBACKQ code if in quotes */
/* CTLBACKQ | CTLQUOTE == '\205' */
#define CTLARI '\206'
#define CTLENDARI '\207'
#define digit_val(c) ((c) - '0')
-#define S_DFL 1 /* default signal handling (SIG_DFL) */
-#define S_CATCH 2 /* signal is caught */
-#define S_IGN 3 /* signal is ignored (SIG_IGN) */
-#define S_HARD_IGN 4 /* signal is ignored permenantly */
-#define S_RESET 5 /* temporary - to reset a hard ignored sig */
+#define S_DFL 1 /* default signal handling (SIG_DFL) */
+#define S_CATCH 2 /* signal is caught */
+#define S_IGN 3 /* signal is ignored (SIG_IGN) */
+#define S_HARD_IGN 4 /* signal is ignored permenantly */
+#define S_RESET 5 /* temporary - to reset a hard ignored sig */
/* variable substitution byte (follows CTLVAR) */
-#define VSTYPE 0x0f /* type of variable substitution */
-#define VSNUL 0x10 /* colon--treat the empty string as unset */
-#define VSQUOTE 0x80 /* inside double quotes--suppress splitting */
+#define VSTYPE 0x0f /* type of variable substitution */
+#define VSNUL 0x10 /* colon--treat the empty string as unset */
+#define VSQUOTE 0x80 /* inside double quotes--suppress splitting */
/* values of VSTYPE field */
-#define VSNORMAL 0x1 /* normal variable: $var or ${var} */
-#define VSMINUS 0x2 /* ${var-text} */
-#define VSPLUS 0x3 /* ${var+text} */
-#define VSQUESTION 0x4 /* ${var?message} */
-#define VSASSIGN 0x5 /* ${var=text} */
-#define VSTRIMLEFT 0x6 /* ${var#pattern} */
-#define VSTRIMLEFTMAX 0x7 /* ${var##pattern} */
-#define VSTRIMRIGHT 0x8 /* ${var%pattern} */
-#define VSTRIMRIGHTMAX 0x9 /* ${var%%pattern} */
-#define VSLENGTH 0xa /* ${#var} */
+#define VSNORMAL 0x1 /* normal variable: $var or ${var} */
+#define VSMINUS 0x2 /* ${var-text} */
+#define VSPLUS 0x3 /* ${var+text} */
+#define VSQUESTION 0x4 /* ${var?message} */
+#define VSASSIGN 0x5 /* ${var=text} */
+#define VSTRIMLEFT 0x6 /* ${var#pattern} */
+#define VSTRIMLEFTMAX 0x7 /* ${var##pattern} */
+#define VSTRIMRIGHT 0x8 /* ${var%pattern} */
+#define VSTRIMRIGHTMAX 0x9 /* ${var%%pattern} */
+#define VSLENGTH 0xa /* ${#var} */
/* flags passed to redirect */
-#define REDIR_PUSH 01 /* save previous values of file descriptors */
-#define REDIR_BACKQ 02 /* save the command output to pipe */
+#define REDIR_PUSH 01 /* save previous values of file descriptors */
+#define REDIR_BACKQ 02 /* save the command output to pipe */
/*
* BSD setjmp saves the signal mask, which violates ANSI C and takes time,
* more fun than worrying about efficiency and portability. :-))
*/
-static void onint (void);
+static void onint(void);
static volatile int suppressint;
static volatile int intpending;
#define INTON { if (--suppressint == 0 && intpending) onint(); }
#define FORCEINTON {suppressint = 0; if (intpending) onint();}
#else
-static void __inton (void);
-static void forceinton (void);
+static void __inton(void);
+static void forceinton(void);
+
#define INTON __inton()
#define FORCEINTON forceinton()
#endif
typedef void *pointer;
+
#ifndef NULL
#define NULL (void *)0
#endif
-static pointer stalloc (int);
-static void stunalloc (pointer);
-static void ungrabstackstr (char *, char *);
-static char * growstackstr(void);
-static char * makestrspace(size_t newlen);
-static char *sstrdup (const char *);
+static pointer stalloc(int);
+static void stunalloc(pointer);
+static void ungrabstackstr(char *, char *);
+static char *growstackstr(void);
+static char *makestrspace(size_t newlen);
+static char *sstrdup(const char *);
/*
* Parse trees for commands are allocated in lifo order, so we use a stack
* well.
*/
-#define MINSIZE 504 /* minimum size of a block */
+#define MINSIZE 504 /* minimum size of a block */
struct stack_block {
#ifdef DEBUG
#define TRACE(param) trace param
typedef union node unode;
-static void trace (const char *, ...);
-static void trargs (char **);
-static void showtree (unode *);
-static void trputc (int);
-static void trputs (const char *);
-static void opentrace (void);
+static void trace(const char *, ...);
+static void trargs(char **);
+static void showtree(unode *);
+static void trputc(int);
+static void trputs(const char *);
+static void opentrace(void);
#else
#define TRACE(param)
#endif
/*
* expandarg() flags
*/
-#define EXP_FULL 0x1 /* perform word splitting & file globbing */
-#define EXP_TILDE 0x2 /* do normal tilde expansion */
-#define EXP_VARTILDE 0x4 /* expand tildes in an assignment */
-#define EXP_REDIR 0x8 /* file glob for a redirection (1 match only) */
-#define EXP_CASE 0x10 /* keeps quotes around for CASE pattern */
-#define EXP_RECORD 0x20 /* need to record arguments for ifs breakup */
+#define EXP_FULL 0x1 /* perform word splitting & file globbing */
+#define EXP_TILDE 0x2 /* do normal tilde expansion */
+#define EXP_VARTILDE 0x4 /* expand tildes in an assignment */
+#define EXP_REDIR 0x8 /* file glob for a redirection (1 match only) */
+#define EXP_CASE 0x10 /* keeps quotes around for CASE pattern */
+#define EXP_RECORD 0x20 /* need to record arguments for ifs breakup */
#define NOPTS 16
static char optet_vals[NOPTS];
-static const char * const optlist[NOPTS] = {
+static const char *const optlist[NOPTS] = {
"e" "errexit",
"f" "noglob",
"I" "ignoreeof",
struct nbinary {
- int type;
- union node *ch1;
- union node *ch2;
+ int type;
+ union node *ch1;
+ union node *ch2;
};
struct ncmd {
- int type;
- int backgnd;
- union node *assign;
- union node *args;
- union node *redirect;
+ int type;
+ int backgnd;
+ union node *assign;
+ union node *args;
+ union node *redirect;
};
struct npipe {
- int type;
- int backgnd;
- struct nodelist *cmdlist;
+ int type;
+ int backgnd;
+ struct nodelist *cmdlist;
};
struct nredir {
- int type;
- union node *n;
- union node *redirect;
+ int type;
+ union node *n;
+ union node *redirect;
};
struct nif {
- int type;
- union node *test;
- union node *ifpart;
- union node *elsepart;
+ int type;
+ union node *test;
+ union node *ifpart;
+ union node *elsepart;
};
struct nfor {
- int type;
- union node *args;
- union node *body;
- char *var;
+ int type;
+ union node *args;
+ union node *body;
+ char *var;
};
struct ncase {
- int type;
- union node *expr;
- union node *cases;
+ int type;
+ union node *expr;
+ union node *cases;
};
struct nclist {
- int type;
- union node *next;
- union node *pattern;
- union node *body;
+ int type;
+ union node *next;
+ union node *pattern;
+ union node *body;
};
struct narg {
- int type;
- union node *next;
- char *text;
- struct nodelist *backquote;
+ int type;
+ union node *next;
+ char *text;
+ struct nodelist *backquote;
};
struct nfile {
- int type;
- union node *next;
- int fd;
- union node *fname;
- char *expfname;
+ int type;
+ union node *next;
+ int fd;
+ union node *fname;
+ char *expfname;
};
struct ndup {
- int type;
- union node *next;
- int fd;
- int dupfd;
- union node *vname;
+ int type;
+ union node *next;
+ int fd;
+ int dupfd;
+ union node *vname;
};
struct nhere {
- int type;
- union node *next;
- int fd;
- union node *doc;
+ int type;
+ union node *next;
+ int fd;
+ union node *doc;
};
struct nnot {
- int type;
- union node *com;
+ int type;
+ union node *com;
};
union node {
- int type;
- struct nbinary nbinary;
- struct ncmd ncmd;
- struct npipe npipe;
- struct nredir nredir;
- struct nif nif;
- struct nfor nfor;
- struct ncase ncase;
- struct nclist nclist;
- struct narg narg;
- struct nfile nfile;
- struct ndup ndup;
- struct nhere nhere;
- struct nnot nnot;
+ int type;
+ struct nbinary nbinary;
+ struct ncmd ncmd;
+ struct npipe npipe;
+ struct nredir nredir;
+ struct nif nif;
+ struct nfor nfor;
+ struct ncase ncase;
+ struct nclist nclist;
+ struct narg narg;
+ struct nfile nfile;
+ struct ndup ndup;
+ struct nhere nhere;
+ struct nnot nnot;
};
union node *n;
};
-struct backcmd { /* result of evalbackcmd */
- int fd; /* file descriptor to read from */
- char *buf; /* buffer */
- int nleft; /* number of chars in buffer */
- struct job *jp; /* job structure for command */
+struct backcmd { /* result of evalbackcmd */
+ int fd; /* file descriptor to read from */
+ char *buf; /* buffer */
+ int nleft; /* number of chars in buffer */
+ struct job *jp; /* job structure for command */
};
struct cmdentry {
};
struct strpush {
- struct strpush *prev; /* preceding string on stack */
+ struct strpush *prev; /* preceding string on stack */
char *prevstring;
int prevnleft;
#ifdef CONFIG_ASH_ALIAS
- struct alias *ap; /* if push was associated with an alias */
+ struct alias *ap; /* if push was associated with an alias */
#endif
- char *string; /* remember the string since it may change */
+ char *string; /* remember the string since it may change */
};
struct parsefile {
- struct parsefile *prev; /* preceding file on stack */
- int linno; /* current line */
- int fd; /* file descriptor (or -1 if string) */
- int nleft; /* number of chars left in this line */
- int lleft; /* number of chars left in this buffer */
- char *nextc; /* next char in buffer */
- char *buf; /* input buffer */
- struct strpush *strpush; /* for pushing strings at this level */
- struct strpush basestrpush; /* so pushing one is fast */
+ struct parsefile *prev; /* preceding file on stack */
+ int linno; /* current line */
+ int fd; /* file descriptor (or -1 if string) */
+ int nleft; /* number of chars left in this line */
+ int lleft; /* number of chars left in this buffer */
+ char *nextc; /* next char in buffer */
+ char *buf; /* input buffer */
+ struct strpush *strpush; /* for pushing strings at this level */
+ struct strpush basestrpush; /* so pushing one is fast */
};
struct stackmark {
};
struct shparam {
- int nparam; /* # of positional parameters (without $0) */
- unsigned char malloc; /* if parameter list dynamically allocated */
- char **p; /* parameter list */
- int optind; /* next parameter to be processed by getopts */
- int optoff; /* used by getopts */
+ int nparam; /* # of positional parameters (without $0) */
+ unsigned char malloc; /* if parameter list dynamically allocated */
+ char **p; /* parameter list */
+ int optind; /* next parameter to be processed by getopts */
+ int optoff; /* used by getopts */
};
/*
* We should investigate converting to a linear search, even though that
* would make the command name "hash" a misnomer.
*/
-#define CMDTABLESIZE 31 /* should be prime */
-#define ARB 1 /* actual size determined at run time */
+#define CMDTABLESIZE 31 /* should be prime */
+#define ARB 1 /* actual size determined at run time */
struct tblentry {
- struct tblentry *next; /* next entry in hash chain */
- union param param; /* definition of builtin function */
- short cmdtype; /* index identifying command */
- char rehash; /* if set, cd done since entry created */
- char cmdname[ARB]; /* name of command */
+ struct tblentry *next; /* next entry in hash chain */
+ union param param; /* definition of builtin function */
+ short cmdtype; /* index identifying command */
+ char rehash; /* if set, cd done since entry created */
+ char cmdname[ARB]; /* name of command */
};
static struct tblentry *cmdtable[CMDTABLESIZE];
-static int builtinloc = -1; /* index in path of %builtin, or -1 */
-static int exerrno = 0; /* Last exec error */
+static int builtinloc = -1; /* index in path of %builtin, or -1 */
+static int exerrno = 0; /* Last exec error */
-static void tryexec (char *, char **, char **);
-static void printentry (struct tblentry *, int);
-static void clearcmdentry (int);
-static struct tblentry *cmdlookup (const char *, int);
-static void delete_cmd_entry (void);
-static int path_change (const char *, int *);
+static void tryexec(char *, char **, char **);
+static void printentry(struct tblentry *, int);
+static void clearcmdentry(int);
+static struct tblentry *cmdlookup(const char *, int);
+static void delete_cmd_entry(void);
+static int path_change(const char *, int *);
-static void flushall (void);
-static void out2fmt (const char *, ...)
- __attribute__((__format__(__printf__,1,2)));
-static int xwrite (int, const char *, int);
+static void flushall(void);
+static void out2fmt(const char *, ...)
+ __attribute__ ((__format__(__printf__, 1, 2)));
+static int xwrite(int, const char *, int);
-static inline void outstr (const char *p, FILE *file) { fputs(p, file); }
-static void out1str(const char *p) { outstr(p, stdout); }
-static void out2str(const char *p) { outstr(p, stderr); }
+static inline void outstr(const char *p, FILE * file)
+{
+ fputs(p, file);
+}
+static void out1str(const char *p)
+{
+ outstr(p, stdout);
+}
+static void out2str(const char *p)
+{
+ outstr(p, stderr);
+}
#ifndef CONFIG_ASH_OPTIMIZE_FOR_SIZE
#define out2c(c) putc((c), stderr)
#else
-static void out2c(int c) { putc(c, stderr); }
+static void out2c(int c)
+{
+ putc(c, stderr);
+}
#endif
#endif
/* number syntax index */
-#define BASESYNTAX 0 /* not in quotes */
-#define DQSYNTAX 1 /* in double quotes */
-#define SQSYNTAX 2 /* in single quotes */
-#define ARISYNTAX 3 /* in arithmetic */
+#define BASESYNTAX 0 /* not in quotes */
+#define DQSYNTAX 1 /* in double quotes */
+#define SQSYNTAX 2 /* in single quotes */
+#define ARISYNTAX 3 /* in arithmetic */
static const char S_I_T[][4] = {
- /* 0 */ { CSPCL, CIGN, CIGN, CIGN }, /* PEOA */
- /* 1 */ { CSPCL, CWORD, CWORD, CWORD }, /* ' ' */
- /* 2 */ { CNL, CNL, CNL, CNL }, /* \n */
- /* 3 */ { CWORD, CCTL, CCTL, CWORD }, /* !*-/:=?[]~ */
- /* 4 */ { CDQUOTE, CENDQUOTE, CWORD, CDQUOTE }, /* '"' */
- /* 5 */ { CVAR, CVAR, CWORD, CVAR }, /* $ */
- /* 6 */ { CSQUOTE, CWORD, CENDQUOTE, CSQUOTE }, /* "'" */
- /* 7 */ { CSPCL, CWORD, CWORD, CLP }, /* ( */
- /* 8 */ { CSPCL, CWORD, CWORD, CRP }, /* ) */
- /* 9 */ { CBACK, CBACK, CCTL, CBACK }, /* \ */
- /* 10 */ { CBQUOTE, CBQUOTE, CWORD, CBQUOTE }, /* ` */
- /* 11 */ { CENDVAR, CENDVAR, CWORD, CENDVAR }, /* } */
+ /* 0 */ {CSPCL, CIGN, CIGN, CIGN},
+ /* PEOA */
+ /* 1 */ {CSPCL, CWORD, CWORD, CWORD},
+ /* ' ' */
+ /* 2 */ {CNL, CNL, CNL, CNL},
+ /* \n */
+ /* 3 */ {CWORD, CCTL, CCTL, CWORD},
+ /* !*-/:=?[]~ */
+ /* 4 */ {CDQUOTE, CENDQUOTE, CWORD, CDQUOTE},
+ /* '"' */
+ /* 5 */ {CVAR, CVAR, CWORD, CVAR},
+ /* $ */
+ /* 6 */ {CSQUOTE, CWORD, CENDQUOTE, CSQUOTE},
+ /* "'" */
+ /* 7 */ {CSPCL, CWORD, CWORD, CLP},
+ /* ( */
+ /* 8 */ {CSPCL, CWORD, CWORD, CRP},
+ /* ) */
+ /* 9 */ {CBACK, CBACK, CCTL, CBACK},
+ /* \ */
+ /* 10 */ {CBQUOTE, CBQUOTE, CWORD, CBQUOTE},
+ /* ` */
+ /* 11 */ {CENDVAR, CENDVAR, CWORD, CENDVAR},
+ /* } */
#ifndef USE_SIT_FUNCTION
- /* 12 */ { CENDFILE, CENDFILE, CENDFILE, CENDFILE }, /* PEOF */
- /* 13 */ { CWORD, CWORD, CWORD, CWORD }, /* 0-9A-Za-z */
- /* 14 */ { CCTL, CCTL, CCTL, CCTL } /* CTLESC ... */
+ /* 12 */ {CENDFILE, CENDFILE, CENDFILE, CENDFILE},
+ /* PEOF */
+ /* 13 */ {CWORD, CWORD, CWORD, CWORD},
+ /* 0-9A-Za-z */
+ /* 14 */ {CCTL, CCTL, CCTL, CCTL}
+ /* CTLESC ... */
#endif
};
static int SIT(int c, int syntax)
{
- static const char spec_symbls[]="\t\n !\"$&'()*-/:;<=>?[\\]`|}~";
- static const char syntax_index_table [] = {
- 1, 2, 1, 3, 4, 5, 1, 6, /* "\t\n !\"$&'" */
- 7, 8, 3, 3, 3, 3, 1, 1, /* "()*-/:;<" */
- 3, 1, 3, 3, 9, 3,10, 1, /* "=>?[\\]`|" */
- 11,3 }; /* "}~" */
+ static const char spec_symbls[] = "\t\n !\"$&'()*-/:;<=>?[\\]`|}~";
+ static const char syntax_index_table[] = {
+ 1, 2, 1, 3, 4, 5, 1, 6, /* "\t\n !\"$&'" */
+ 7, 8, 3, 3, 3, 3, 1, 1, /* "()*-/:;<" */
+ 3, 1, 3, 3, 9, 3, 10, 1, /* "=>?[\\]`|" */
+ 11, 3
+ }; /* "}~" */
const char *s;
int indx;
- if(c==PEOF) /* 2^8+2 */
+ if (c == PEOF) /* 2^8+2 */
return CENDFILE;
- if(c==PEOA) /* 2^8+1 */
+ if (c == PEOA) /* 2^8+1 */
indx = 0;
- else if(U_C(c)>=U_C(CTLESC) && U_C(c)<=U_C(CTLQUOTEMARK))
+ else if (U_C(c) >= U_C(CTLESC) && U_C(c) <= U_C(CTLQUOTEMARK))
return CCTL;
- else {
+ else {
s = strchr(spec_symbls, c);
- if(s==0)
+ if (s == 0)
return CWORD;
- indx = syntax_index_table[(s-spec_symbls)];
+ indx = syntax_index_table[(s - spec_symbls)];
}
return S_I_T[indx][syntax];
}
-#else /* USE_SIT_FUNCTION */
+#else /* USE_SIT_FUNCTION */
#define SIT(c, syntax) S_I_T[(int)syntax_index_table[((int)c)+SYNBASE]][syntax]
#define CCTL_CCTL_CCTL_CCTL 14
static const char syntax_index_table[258] = {
- /* BASESYNTAX_DQSYNTAX_SQSYNTAX_ARISYNTAX */
- /* 0 -130 PEOF */ CENDFILE_CENDFILE_CENDFILE_CENDFILE,
- /* 1 -129 PEOA */ CSPCL_CIGN_CIGN_CIGN,
- /* 2 -128 0xff */ CWORD_CWORD_CWORD_CWORD,
- /* 3 -127 */ CCTL_CCTL_CCTL_CCTL, /* CTLQUOTEMARK */
- /* 4 -126 */ CCTL_CCTL_CCTL_CCTL,
- /* 5 -125 */ CCTL_CCTL_CCTL_CCTL,
- /* 6 -124 */ CCTL_CCTL_CCTL_CCTL,
- /* 7 -123 */ CCTL_CCTL_CCTL_CCTL,
- /* 8 -122 */ CCTL_CCTL_CCTL_CCTL,
- /* 9 -121 */ CCTL_CCTL_CCTL_CCTL,
- /* 10 -120 */ CCTL_CCTL_CCTL_CCTL, /* CTLESC */
- /* 11 -119 */ CWORD_CWORD_CWORD_CWORD,
- /* 12 -118 */ CWORD_CWORD_CWORD_CWORD,
- /* 13 -117 */ CWORD_CWORD_CWORD_CWORD,
- /* 14 -116 */ CWORD_CWORD_CWORD_CWORD,
- /* 15 -115 */ CWORD_CWORD_CWORD_CWORD,
- /* 16 -114 */ CWORD_CWORD_CWORD_CWORD,
- /* 17 -113 */ CWORD_CWORD_CWORD_CWORD,
- /* 18 -112 */ CWORD_CWORD_CWORD_CWORD,
- /* 19 -111 */ CWORD_CWORD_CWORD_CWORD,
- /* 20 -110 */ CWORD_CWORD_CWORD_CWORD,
- /* 21 -109 */ CWORD_CWORD_CWORD_CWORD,
- /* 22 -108 */ CWORD_CWORD_CWORD_CWORD,
- /* 23 -107 */ CWORD_CWORD_CWORD_CWORD,
- /* 24 -106 */ CWORD_CWORD_CWORD_CWORD,
- /* 25 -105 */ CWORD_CWORD_CWORD_CWORD,
- /* 26 -104 */ CWORD_CWORD_CWORD_CWORD,
- /* 27 -103 */ CWORD_CWORD_CWORD_CWORD,
- /* 28 -102 */ CWORD_CWORD_CWORD_CWORD,
- /* 29 -101 */ CWORD_CWORD_CWORD_CWORD,
- /* 30 -100 */ CWORD_CWORD_CWORD_CWORD,
- /* 31 -99 */ CWORD_CWORD_CWORD_CWORD,
- /* 32 -98 */ CWORD_CWORD_CWORD_CWORD,
- /* 33 -97 */ CWORD_CWORD_CWORD_CWORD,
- /* 34 -96 */ CWORD_CWORD_CWORD_CWORD,
- /* 35 -95 */ CWORD_CWORD_CWORD_CWORD,
- /* 36 -94 */ CWORD_CWORD_CWORD_CWORD,
- /* 37 -93 */ CWORD_CWORD_CWORD_CWORD,
- /* 38 -92 */ CWORD_CWORD_CWORD_CWORD,
- /* 39 -91 */ CWORD_CWORD_CWORD_CWORD,
- /* 40 -90 */ CWORD_CWORD_CWORD_CWORD,
- /* 41 -89 */ CWORD_CWORD_CWORD_CWORD,
- /* 42 -88 */ CWORD_CWORD_CWORD_CWORD,
- /* 43 -87 */ CWORD_CWORD_CWORD_CWORD,
- /* 44 -86 */ CWORD_CWORD_CWORD_CWORD,
- /* 45 -85 */ CWORD_CWORD_CWORD_CWORD,
- /* 46 -84 */ CWORD_CWORD_CWORD_CWORD,
- /* 47 -83 */ CWORD_CWORD_CWORD_CWORD,
- /* 48 -82 */ CWORD_CWORD_CWORD_CWORD,
- /* 49 -81 */ CWORD_CWORD_CWORD_CWORD,
- /* 50 -80 */ CWORD_CWORD_CWORD_CWORD,
- /* 51 -79 */ CWORD_CWORD_CWORD_CWORD,
- /* 52 -78 */ CWORD_CWORD_CWORD_CWORD,
- /* 53 -77 */ CWORD_CWORD_CWORD_CWORD,
- /* 54 -76 */ CWORD_CWORD_CWORD_CWORD,
- /* 55 -75 */ CWORD_CWORD_CWORD_CWORD,
- /* 56 -74 */ CWORD_CWORD_CWORD_CWORD,
- /* 57 -73 */ CWORD_CWORD_CWORD_CWORD,
- /* 58 -72 */ CWORD_CWORD_CWORD_CWORD,
- /* 59 -71 */ CWORD_CWORD_CWORD_CWORD,
- /* 60 -70 */ CWORD_CWORD_CWORD_CWORD,
- /* 61 -69 */ CWORD_CWORD_CWORD_CWORD,
- /* 62 -68 */ CWORD_CWORD_CWORD_CWORD,
- /* 63 -67 */ CWORD_CWORD_CWORD_CWORD,
- /* 64 -66 */ CWORD_CWORD_CWORD_CWORD,
- /* 65 -65 */ CWORD_CWORD_CWORD_CWORD,
- /* 66 -64 */ CWORD_CWORD_CWORD_CWORD,
- /* 67 -63 */ CWORD_CWORD_CWORD_CWORD,
- /* 68 -62 */ CWORD_CWORD_CWORD_CWORD,
- /* 69 -61 */ CWORD_CWORD_CWORD_CWORD,
- /* 70 -60 */ CWORD_CWORD_CWORD_CWORD,
- /* 71 -59 */ CWORD_CWORD_CWORD_CWORD,
- /* 72 -58 */ CWORD_CWORD_CWORD_CWORD,
- /* 73 -57 */ CWORD_CWORD_CWORD_CWORD,
- /* 74 -56 */ CWORD_CWORD_CWORD_CWORD,
- /* 75 -55 */ CWORD_CWORD_CWORD_CWORD,
- /* 76 -54 */ CWORD_CWORD_CWORD_CWORD,
- /* 77 -53 */ CWORD_CWORD_CWORD_CWORD,
- /* 78 -52 */ CWORD_CWORD_CWORD_CWORD,
- /* 79 -51 */ CWORD_CWORD_CWORD_CWORD,
- /* 80 -50 */ CWORD_CWORD_CWORD_CWORD,
- /* 81 -49 */ CWORD_CWORD_CWORD_CWORD,
- /* 82 -48 */ CWORD_CWORD_CWORD_CWORD,
- /* 83 -47 */ CWORD_CWORD_CWORD_CWORD,
- /* 84 -46 */ CWORD_CWORD_CWORD_CWORD,
- /* 85 -45 */ CWORD_CWORD_CWORD_CWORD,
- /* 86 -44 */ CWORD_CWORD_CWORD_CWORD,
- /* 87 -43 */ CWORD_CWORD_CWORD_CWORD,
- /* 88 -42 */ CWORD_CWORD_CWORD_CWORD,
- /* 89 -41 */ CWORD_CWORD_CWORD_CWORD,
- /* 90 -40 */ CWORD_CWORD_CWORD_CWORD,
- /* 91 -39 */ CWORD_CWORD_CWORD_CWORD,
- /* 92 -38 */ CWORD_CWORD_CWORD_CWORD,
- /* 93 -37 */ CWORD_CWORD_CWORD_CWORD,
- /* 94 -36 */ CWORD_CWORD_CWORD_CWORD,
- /* 95 -35 */ CWORD_CWORD_CWORD_CWORD,
- /* 96 -34 */ CWORD_CWORD_CWORD_CWORD,
- /* 97 -33 */ CWORD_CWORD_CWORD_CWORD,
- /* 98 -32 */ CWORD_CWORD_CWORD_CWORD,
- /* 99 -31 */ CWORD_CWORD_CWORD_CWORD,
- /* 100 -30 */ CWORD_CWORD_CWORD_CWORD,
- /* 101 -29 */ CWORD_CWORD_CWORD_CWORD,
- /* 102 -28 */ CWORD_CWORD_CWORD_CWORD,
- /* 103 -27 */ CWORD_CWORD_CWORD_CWORD,
- /* 104 -26 */ CWORD_CWORD_CWORD_CWORD,
- /* 105 -25 */ CWORD_CWORD_CWORD_CWORD,
- /* 106 -24 */ CWORD_CWORD_CWORD_CWORD,
- /* 107 -23 */ CWORD_CWORD_CWORD_CWORD,
- /* 108 -22 */ CWORD_CWORD_CWORD_CWORD,
- /* 109 -21 */ CWORD_CWORD_CWORD_CWORD,
- /* 110 -20 */ CWORD_CWORD_CWORD_CWORD,
- /* 111 -19 */ CWORD_CWORD_CWORD_CWORD,
- /* 112 -18 */ CWORD_CWORD_CWORD_CWORD,
- /* 113 -17 */ CWORD_CWORD_CWORD_CWORD,
- /* 114 -16 */ CWORD_CWORD_CWORD_CWORD,
- /* 115 -15 */ CWORD_CWORD_CWORD_CWORD,
- /* 116 -14 */ CWORD_CWORD_CWORD_CWORD,
- /* 117 -13 */ CWORD_CWORD_CWORD_CWORD,
- /* 118 -12 */ CWORD_CWORD_CWORD_CWORD,
- /* 119 -11 */ CWORD_CWORD_CWORD_CWORD,
- /* 120 -10 */ CWORD_CWORD_CWORD_CWORD,
- /* 121 -9 */ CWORD_CWORD_CWORD_CWORD,
- /* 122 -8 */ CWORD_CWORD_CWORD_CWORD,
- /* 123 -7 */ CWORD_CWORD_CWORD_CWORD,
- /* 124 -6 */ CWORD_CWORD_CWORD_CWORD,
- /* 125 -5 */ CWORD_CWORD_CWORD_CWORD,
- /* 126 -4 */ CWORD_CWORD_CWORD_CWORD,
- /* 127 -3 */ CWORD_CWORD_CWORD_CWORD,
- /* 128 -2 */ CWORD_CWORD_CWORD_CWORD,
- /* 129 -1 */ CWORD_CWORD_CWORD_CWORD,
- /* 130 0 */ CWORD_CWORD_CWORD_CWORD,
- /* 131 1 */ CWORD_CWORD_CWORD_CWORD,
- /* 132 2 */ CWORD_CWORD_CWORD_CWORD,
- /* 133 3 */ CWORD_CWORD_CWORD_CWORD,
- /* 134 4 */ CWORD_CWORD_CWORD_CWORD,
- /* 135 5 */ CWORD_CWORD_CWORD_CWORD,
- /* 136 6 */ CWORD_CWORD_CWORD_CWORD,
- /* 137 7 */ CWORD_CWORD_CWORD_CWORD,
- /* 138 8 */ CWORD_CWORD_CWORD_CWORD,
- /* 139 9 "\t" */ CSPCL_CWORD_CWORD_CWORD,
- /* 140 10 "\n" */ CNL_CNL_CNL_CNL,
- /* 141 11 */ CWORD_CWORD_CWORD_CWORD,
- /* 142 12 */ CWORD_CWORD_CWORD_CWORD,
- /* 143 13 */ CWORD_CWORD_CWORD_CWORD,
- /* 144 14 */ CWORD_CWORD_CWORD_CWORD,
- /* 145 15 */ CWORD_CWORD_CWORD_CWORD,
- /* 146 16 */ CWORD_CWORD_CWORD_CWORD,
- /* 147 17 */ CWORD_CWORD_CWORD_CWORD,
- /* 148 18 */ CWORD_CWORD_CWORD_CWORD,
- /* 149 19 */ CWORD_CWORD_CWORD_CWORD,
- /* 150 20 */ CWORD_CWORD_CWORD_CWORD,
- /* 151 21 */ CWORD_CWORD_CWORD_CWORD,
- /* 152 22 */ CWORD_CWORD_CWORD_CWORD,
- /* 153 23 */ CWORD_CWORD_CWORD_CWORD,
- /* 154 24 */ CWORD_CWORD_CWORD_CWORD,
- /* 155 25 */ CWORD_CWORD_CWORD_CWORD,
- /* 156 26 */ CWORD_CWORD_CWORD_CWORD,
- /* 157 27 */ CWORD_CWORD_CWORD_CWORD,
- /* 158 28 */ CWORD_CWORD_CWORD_CWORD,
- /* 159 29 */ CWORD_CWORD_CWORD_CWORD,
- /* 160 30 */ CWORD_CWORD_CWORD_CWORD,
- /* 161 31 */ CWORD_CWORD_CWORD_CWORD,
- /* 162 32 " " */ CSPCL_CWORD_CWORD_CWORD,
- /* 163 33 "!" */ CWORD_CCTL_CCTL_CWORD,
- /* 164 34 """ */ CDQUOTE_CENDQUOTE_CWORD_CDQUOTE,
- /* 165 35 "#" */ CWORD_CWORD_CWORD_CWORD,
- /* 166 36 "$" */ CVAR_CVAR_CWORD_CVAR,
- /* 167 37 "%" */ CWORD_CWORD_CWORD_CWORD,
- /* 168 38 "&" */ CSPCL_CWORD_CWORD_CWORD,
- /* 169 39 "'" */ CSQUOTE_CWORD_CENDQUOTE_CSQUOTE,
- /* 170 40 "(" */ CSPCL_CWORD_CWORD_CLP,
- /* 171 41 ")" */ CSPCL_CWORD_CWORD_CRP,
- /* 172 42 "*" */ CWORD_CCTL_CCTL_CWORD,
- /* 173 43 "+" */ CWORD_CWORD_CWORD_CWORD,
- /* 174 44 "," */ CWORD_CWORD_CWORD_CWORD,
- /* 175 45 "-" */ CWORD_CCTL_CCTL_CWORD,
- /* 176 46 "." */ CWORD_CWORD_CWORD_CWORD,
- /* 177 47 "/" */ CWORD_CCTL_CCTL_CWORD,
- /* 178 48 "0" */ CWORD_CWORD_CWORD_CWORD,
- /* 179 49 "1" */ CWORD_CWORD_CWORD_CWORD,
- /* 180 50 "2" */ CWORD_CWORD_CWORD_CWORD,
- /* 181 51 "3" */ CWORD_CWORD_CWORD_CWORD,
- /* 182 52 "4" */ CWORD_CWORD_CWORD_CWORD,
- /* 183 53 "5" */ CWORD_CWORD_CWORD_CWORD,
- /* 184 54 "6" */ CWORD_CWORD_CWORD_CWORD,
- /* 185 55 "7" */ CWORD_CWORD_CWORD_CWORD,
- /* 186 56 "8" */ CWORD_CWORD_CWORD_CWORD,
- /* 187 57 "9" */ CWORD_CWORD_CWORD_CWORD,
- /* 188 58 ":" */ CWORD_CCTL_CCTL_CWORD,
- /* 189 59 ";" */ CSPCL_CWORD_CWORD_CWORD,
- /* 190 60 "<" */ CSPCL_CWORD_CWORD_CWORD,
- /* 191 61 "=" */ CWORD_CCTL_CCTL_CWORD,
- /* 192 62 ">" */ CSPCL_CWORD_CWORD_CWORD,
- /* 193 63 "?" */ CWORD_CCTL_CCTL_CWORD,
- /* 194 64 "@" */ CWORD_CWORD_CWORD_CWORD,
- /* 195 65 "A" */ CWORD_CWORD_CWORD_CWORD,
- /* 196 66 "B" */ CWORD_CWORD_CWORD_CWORD,
- /* 197 67 "C" */ CWORD_CWORD_CWORD_CWORD,
- /* 198 68 "D" */ CWORD_CWORD_CWORD_CWORD,
- /* 199 69 "E" */ CWORD_CWORD_CWORD_CWORD,
- /* 200 70 "F" */ CWORD_CWORD_CWORD_CWORD,
- /* 201 71 "G" */ CWORD_CWORD_CWORD_CWORD,
- /* 202 72 "H" */ CWORD_CWORD_CWORD_CWORD,
- /* 203 73 "I" */ CWORD_CWORD_CWORD_CWORD,
- /* 204 74 "J" */ CWORD_CWORD_CWORD_CWORD,
- /* 205 75 "K" */ CWORD_CWORD_CWORD_CWORD,
- /* 206 76 "L" */ CWORD_CWORD_CWORD_CWORD,
- /* 207 77 "M" */ CWORD_CWORD_CWORD_CWORD,
- /* 208 78 "N" */ CWORD_CWORD_CWORD_CWORD,
- /* 209 79 "O" */ CWORD_CWORD_CWORD_CWORD,
- /* 210 80 "P" */ CWORD_CWORD_CWORD_CWORD,
- /* 211 81 "Q" */ CWORD_CWORD_CWORD_CWORD,
- /* 212 82 "R" */ CWORD_CWORD_CWORD_CWORD,
- /* 213 83 "S" */ CWORD_CWORD_CWORD_CWORD,
- /* 214 84 "T" */ CWORD_CWORD_CWORD_CWORD,
- /* 215 85 "U" */ CWORD_CWORD_CWORD_CWORD,
- /* 216 86 "V" */ CWORD_CWORD_CWORD_CWORD,
- /* 217 87 "W" */ CWORD_CWORD_CWORD_CWORD,
- /* 218 88 "X" */ CWORD_CWORD_CWORD_CWORD,
- /* 219 89 "Y" */ CWORD_CWORD_CWORD_CWORD,
- /* 220 90 "Z" */ CWORD_CWORD_CWORD_CWORD,
- /* 221 91 "[" */ CWORD_CCTL_CCTL_CWORD,
- /* 222 92 "\" */ CBACK_CBACK_CCTL_CBACK,
- /* 223 93 "]" */ CWORD_CCTL_CCTL_CWORD,
- /* 224 94 "^" */ CWORD_CWORD_CWORD_CWORD,
- /* 225 95 "_" */ CWORD_CWORD_CWORD_CWORD,
- /* 226 96 "`" */ CBQUOTE_CBQUOTE_CWORD_CBQUOTE,
- /* 227 97 "a" */ CWORD_CWORD_CWORD_CWORD,
- /* 228 98 "b" */ CWORD_CWORD_CWORD_CWORD,
- /* 229 99 "c" */ CWORD_CWORD_CWORD_CWORD,
- /* 230 100 "d" */ CWORD_CWORD_CWORD_CWORD,
- /* 231 101 "e" */ CWORD_CWORD_CWORD_CWORD,
- /* 232 102 "f" */ CWORD_CWORD_CWORD_CWORD,
- /* 233 103 "g" */ CWORD_CWORD_CWORD_CWORD,
- /* 234 104 "h" */ CWORD_CWORD_CWORD_CWORD,
- /* 235 105 "i" */ CWORD_CWORD_CWORD_CWORD,
- /* 236 106 "j" */ CWORD_CWORD_CWORD_CWORD,
- /* 237 107 "k" */ CWORD_CWORD_CWORD_CWORD,
- /* 238 108 "l" */ CWORD_CWORD_CWORD_CWORD,
- /* 239 109 "m" */ CWORD_CWORD_CWORD_CWORD,
- /* 240 110 "n" */ CWORD_CWORD_CWORD_CWORD,
- /* 241 111 "o" */ CWORD_CWORD_CWORD_CWORD,
- /* 242 112 "p" */ CWORD_CWORD_CWORD_CWORD,
- /* 243 113 "q" */ CWORD_CWORD_CWORD_CWORD,
- /* 244 114 "r" */ CWORD_CWORD_CWORD_CWORD,
- /* 245 115 "s" */ CWORD_CWORD_CWORD_CWORD,
- /* 246 116 "t" */ CWORD_CWORD_CWORD_CWORD,
- /* 247 117 "u" */ CWORD_CWORD_CWORD_CWORD,
- /* 248 118 "v" */ CWORD_CWORD_CWORD_CWORD,
- /* 249 119 "w" */ CWORD_CWORD_CWORD_CWORD,
- /* 250 120 "x" */ CWORD_CWORD_CWORD_CWORD,
- /* 251 121 "y" */ CWORD_CWORD_CWORD_CWORD,
- /* 252 122 "z" */ CWORD_CWORD_CWORD_CWORD,
- /* 253 123 "{" */ CWORD_CWORD_CWORD_CWORD,
- /* 254 124 "|" */ CSPCL_CWORD_CWORD_CWORD,
- /* 255 125 "}" */ CENDVAR_CENDVAR_CWORD_CENDVAR,
- /* 256 126 "~" */ CWORD_CCTL_CCTL_CWORD,
- /* 257 127 */ CWORD_CWORD_CWORD_CWORD,
+ /* BASESYNTAX_DQSYNTAX_SQSYNTAX_ARISYNTAX */
+ /* 0 -130 PEOF */ CENDFILE_CENDFILE_CENDFILE_CENDFILE,
+ /* 1 -129 PEOA */ CSPCL_CIGN_CIGN_CIGN,
+ /* 2 -128 0xff */ CWORD_CWORD_CWORD_CWORD,
+ /* 3 -127 */ CCTL_CCTL_CCTL_CCTL,
+ /* CTLQUOTEMARK */
+ /* 4 -126 */ CCTL_CCTL_CCTL_CCTL,
+ /* 5 -125 */ CCTL_CCTL_CCTL_CCTL,
+ /* 6 -124 */ CCTL_CCTL_CCTL_CCTL,
+ /* 7 -123 */ CCTL_CCTL_CCTL_CCTL,
+ /* 8 -122 */ CCTL_CCTL_CCTL_CCTL,
+ /* 9 -121 */ CCTL_CCTL_CCTL_CCTL,
+ /* 10 -120 */ CCTL_CCTL_CCTL_CCTL,
+ /* CTLESC */
+ /* 11 -119 */ CWORD_CWORD_CWORD_CWORD,
+ /* 12 -118 */ CWORD_CWORD_CWORD_CWORD,
+ /* 13 -117 */ CWORD_CWORD_CWORD_CWORD,
+ /* 14 -116 */ CWORD_CWORD_CWORD_CWORD,
+ /* 15 -115 */ CWORD_CWORD_CWORD_CWORD,
+ /* 16 -114 */ CWORD_CWORD_CWORD_CWORD,
+ /* 17 -113 */ CWORD_CWORD_CWORD_CWORD,
+ /* 18 -112 */ CWORD_CWORD_CWORD_CWORD,
+ /* 19 -111 */ CWORD_CWORD_CWORD_CWORD,
+ /* 20 -110 */ CWORD_CWORD_CWORD_CWORD,
+ /* 21 -109 */ CWORD_CWORD_CWORD_CWORD,
+ /* 22 -108 */ CWORD_CWORD_CWORD_CWORD,
+ /* 23 -107 */ CWORD_CWORD_CWORD_CWORD,
+ /* 24 -106 */ CWORD_CWORD_CWORD_CWORD,
+ /* 25 -105 */ CWORD_CWORD_CWORD_CWORD,
+ /* 26 -104 */ CWORD_CWORD_CWORD_CWORD,
+ /* 27 -103 */ CWORD_CWORD_CWORD_CWORD,
+ /* 28 -102 */ CWORD_CWORD_CWORD_CWORD,
+ /* 29 -101 */ CWORD_CWORD_CWORD_CWORD,
+ /* 30 -100 */ CWORD_CWORD_CWORD_CWORD,
+ /* 31 -99 */ CWORD_CWORD_CWORD_CWORD,
+ /* 32 -98 */ CWORD_CWORD_CWORD_CWORD,
+ /* 33 -97 */ CWORD_CWORD_CWORD_CWORD,
+ /* 34 -96 */ CWORD_CWORD_CWORD_CWORD,
+ /* 35 -95 */ CWORD_CWORD_CWORD_CWORD,
+ /* 36 -94 */ CWORD_CWORD_CWORD_CWORD,
+ /* 37 -93 */ CWORD_CWORD_CWORD_CWORD,
+ /* 38 -92 */ CWORD_CWORD_CWORD_CWORD,
+ /* 39 -91 */ CWORD_CWORD_CWORD_CWORD,
+ /* 40 -90 */ CWORD_CWORD_CWORD_CWORD,
+ /* 41 -89 */ CWORD_CWORD_CWORD_CWORD,
+ /* 42 -88 */ CWORD_CWORD_CWORD_CWORD,
+ /* 43 -87 */ CWORD_CWORD_CWORD_CWORD,
+ /* 44 -86 */ CWORD_CWORD_CWORD_CWORD,
+ /* 45 -85 */ CWORD_CWORD_CWORD_CWORD,
+ /* 46 -84 */ CWORD_CWORD_CWORD_CWORD,
+ /* 47 -83 */ CWORD_CWORD_CWORD_CWORD,
+ /* 48 -82 */ CWORD_CWORD_CWORD_CWORD,
+ /* 49 -81 */ CWORD_CWORD_CWORD_CWORD,
+ /* 50 -80 */ CWORD_CWORD_CWORD_CWORD,
+ /* 51 -79 */ CWORD_CWORD_CWORD_CWORD,
+ /* 52 -78 */ CWORD_CWORD_CWORD_CWORD,
+ /* 53 -77 */ CWORD_CWORD_CWORD_CWORD,
+ /* 54 -76 */ CWORD_CWORD_CWORD_CWORD,
+ /* 55 -75 */ CWORD_CWORD_CWORD_CWORD,
+ /* 56 -74 */ CWORD_CWORD_CWORD_CWORD,
+ /* 57 -73 */ CWORD_CWORD_CWORD_CWORD,
+ /* 58 -72 */ CWORD_CWORD_CWORD_CWORD,
+ /* 59 -71 */ CWORD_CWORD_CWORD_CWORD,
+ /* 60 -70 */ CWORD_CWORD_CWORD_CWORD,
+ /* 61 -69 */ CWORD_CWORD_CWORD_CWORD,
+ /* 62 -68 */ CWORD_CWORD_CWORD_CWORD,
+ /* 63 -67 */ CWORD_CWORD_CWORD_CWORD,
+ /* 64 -66 */ CWORD_CWORD_CWORD_CWORD,
+ /* 65 -65 */ CWORD_CWORD_CWORD_CWORD,
+ /* 66 -64 */ CWORD_CWORD_CWORD_CWORD,
+ /* 67 -63 */ CWORD_CWORD_CWORD_CWORD,
+ /* 68 -62 */ CWORD_CWORD_CWORD_CWORD,
+ /* 69 -61 */ CWORD_CWORD_CWORD_CWORD,
+ /* 70 -60 */ CWORD_CWORD_CWORD_CWORD,
+ /* 71 -59 */ CWORD_CWORD_CWORD_CWORD,
+ /* 72 -58 */ CWORD_CWORD_CWORD_CWORD,
+ /* 73 -57 */ CWORD_CWORD_CWORD_CWORD,
+ /* 74 -56 */ CWORD_CWORD_CWORD_CWORD,
+ /* 75 -55 */ CWORD_CWORD_CWORD_CWORD,
+ /* 76 -54 */ CWORD_CWORD_CWORD_CWORD,
+ /* 77 -53 */ CWORD_CWORD_CWORD_CWORD,
+ /* 78 -52 */ CWORD_CWORD_CWORD_CWORD,
+ /* 79 -51 */ CWORD_CWORD_CWORD_CWORD,
+ /* 80 -50 */ CWORD_CWORD_CWORD_CWORD,
+ /* 81 -49 */ CWORD_CWORD_CWORD_CWORD,
+ /* 82 -48 */ CWORD_CWORD_CWORD_CWORD,
+ /* 83 -47 */ CWORD_CWORD_CWORD_CWORD,
+ /* 84 -46 */ CWORD_CWORD_CWORD_CWORD,
+ /* 85 -45 */ CWORD_CWORD_CWORD_CWORD,
+ /* 86 -44 */ CWORD_CWORD_CWORD_CWORD,
+ /* 87 -43 */ CWORD_CWORD_CWORD_CWORD,
+ /* 88 -42 */ CWORD_CWORD_CWORD_CWORD,
+ /* 89 -41 */ CWORD_CWORD_CWORD_CWORD,
+ /* 90 -40 */ CWORD_CWORD_CWORD_CWORD,
+ /* 91 -39 */ CWORD_CWORD_CWORD_CWORD,
+ /* 92 -38 */ CWORD_CWORD_CWORD_CWORD,
+ /* 93 -37 */ CWORD_CWORD_CWORD_CWORD,
+ /* 94 -36 */ CWORD_CWORD_CWORD_CWORD,
+ /* 95 -35 */ CWORD_CWORD_CWORD_CWORD,
+ /* 96 -34 */ CWORD_CWORD_CWORD_CWORD,
+ /* 97 -33 */ CWORD_CWORD_CWORD_CWORD,
+ /* 98 -32 */ CWORD_CWORD_CWORD_CWORD,
+ /* 99 -31 */ CWORD_CWORD_CWORD_CWORD,
+ /* 100 -30 */ CWORD_CWORD_CWORD_CWORD,
+ /* 101 -29 */ CWORD_CWORD_CWORD_CWORD,
+ /* 102 -28 */ CWORD_CWORD_CWORD_CWORD,
+ /* 103 -27 */ CWORD_CWORD_CWORD_CWORD,
+ /* 104 -26 */ CWORD_CWORD_CWORD_CWORD,
+ /* 105 -25 */ CWORD_CWORD_CWORD_CWORD,
+ /* 106 -24 */ CWORD_CWORD_CWORD_CWORD,
+ /* 107 -23 */ CWORD_CWORD_CWORD_CWORD,
+ /* 108 -22 */ CWORD_CWORD_CWORD_CWORD,
+ /* 109 -21 */ CWORD_CWORD_CWORD_CWORD,
+ /* 110 -20 */ CWORD_CWORD_CWORD_CWORD,
+ /* 111 -19 */ CWORD_CWORD_CWORD_CWORD,
+ /* 112 -18 */ CWORD_CWORD_CWORD_CWORD,
+ /* 113 -17 */ CWORD_CWORD_CWORD_CWORD,
+ /* 114 -16 */ CWORD_CWORD_CWORD_CWORD,
+ /* 115 -15 */ CWORD_CWORD_CWORD_CWORD,
+ /* 116 -14 */ CWORD_CWORD_CWORD_CWORD,
+ /* 117 -13 */ CWORD_CWORD_CWORD_CWORD,
+ /* 118 -12 */ CWORD_CWORD_CWORD_CWORD,
+ /* 119 -11 */ CWORD_CWORD_CWORD_CWORD,
+ /* 120 -10 */ CWORD_CWORD_CWORD_CWORD,
+ /* 121 -9 */ CWORD_CWORD_CWORD_CWORD,
+ /* 122 -8 */ CWORD_CWORD_CWORD_CWORD,
+ /* 123 -7 */ CWORD_CWORD_CWORD_CWORD,
+ /* 124 -6 */ CWORD_CWORD_CWORD_CWORD,
+ /* 125 -5 */ CWORD_CWORD_CWORD_CWORD,
+ /* 126 -4 */ CWORD_CWORD_CWORD_CWORD,
+ /* 127 -3 */ CWORD_CWORD_CWORD_CWORD,
+ /* 128 -2 */ CWORD_CWORD_CWORD_CWORD,
+ /* 129 -1 */ CWORD_CWORD_CWORD_CWORD,
+ /* 130 0 */ CWORD_CWORD_CWORD_CWORD,
+ /* 131 1 */ CWORD_CWORD_CWORD_CWORD,
+ /* 132 2 */ CWORD_CWORD_CWORD_CWORD,
+ /* 133 3 */ CWORD_CWORD_CWORD_CWORD,
+ /* 134 4 */ CWORD_CWORD_CWORD_CWORD,
+ /* 135 5 */ CWORD_CWORD_CWORD_CWORD,
+ /* 136 6 */ CWORD_CWORD_CWORD_CWORD,
+ /* 137 7 */ CWORD_CWORD_CWORD_CWORD,
+ /* 138 8 */ CWORD_CWORD_CWORD_CWORD,
+ /* 139 9 "\t" */ CSPCL_CWORD_CWORD_CWORD,
+ /* 140 10 "\n" */ CNL_CNL_CNL_CNL,
+ /* 141 11 */ CWORD_CWORD_CWORD_CWORD,
+ /* 142 12 */ CWORD_CWORD_CWORD_CWORD,
+ /* 143 13 */ CWORD_CWORD_CWORD_CWORD,
+ /* 144 14 */ CWORD_CWORD_CWORD_CWORD,
+ /* 145 15 */ CWORD_CWORD_CWORD_CWORD,
+ /* 146 16 */ CWORD_CWORD_CWORD_CWORD,
+ /* 147 17 */ CWORD_CWORD_CWORD_CWORD,
+ /* 148 18 */ CWORD_CWORD_CWORD_CWORD,
+ /* 149 19 */ CWORD_CWORD_CWORD_CWORD,
+ /* 150 20 */ CWORD_CWORD_CWORD_CWORD,
+ /* 151 21 */ CWORD_CWORD_CWORD_CWORD,
+ /* 152 22 */ CWORD_CWORD_CWORD_CWORD,
+ /* 153 23 */ CWORD_CWORD_CWORD_CWORD,
+ /* 154 24 */ CWORD_CWORD_CWORD_CWORD,
+ /* 155 25 */ CWORD_CWORD_CWORD_CWORD,
+ /* 156 26 */ CWORD_CWORD_CWORD_CWORD,
+ /* 157 27 */ CWORD_CWORD_CWORD_CWORD,
+ /* 158 28 */ CWORD_CWORD_CWORD_CWORD,
+ /* 159 29 */ CWORD_CWORD_CWORD_CWORD,
+ /* 160 30 */ CWORD_CWORD_CWORD_CWORD,
+ /* 161 31 */ CWORD_CWORD_CWORD_CWORD,
+ /* 162 32 " " */ CSPCL_CWORD_CWORD_CWORD,
+ /* 163 33 "!" */ CWORD_CCTL_CCTL_CWORD,
+ /* 164 34 """ */ CDQUOTE_CENDQUOTE_CWORD_CDQUOTE,
+ /* 165 35 "#" */ CWORD_CWORD_CWORD_CWORD,
+ /* 166 36 "$" */ CVAR_CVAR_CWORD_CVAR,
+ /* 167 37 "%" */ CWORD_CWORD_CWORD_CWORD,
+ /* 168 38 "&" */ CSPCL_CWORD_CWORD_CWORD,
+ /* 169 39 "'" */ CSQUOTE_CWORD_CENDQUOTE_CSQUOTE,
+ /* 170 40 "(" */ CSPCL_CWORD_CWORD_CLP,
+ /* 171 41 ")" */ CSPCL_CWORD_CWORD_CRP,
+ /* 172 42 "*" */ CWORD_CCTL_CCTL_CWORD,
+ /* 173 43 "+" */ CWORD_CWORD_CWORD_CWORD,
+ /* 174 44 "," */ CWORD_CWORD_CWORD_CWORD,
+ /* 175 45 "-" */ CWORD_CCTL_CCTL_CWORD,
+ /* 176 46 "." */ CWORD_CWORD_CWORD_CWORD,
+ /* 177 47 "/" */ CWORD_CCTL_CCTL_CWORD,
+ /* 178 48 "0" */ CWORD_CWORD_CWORD_CWORD,
+ /* 179 49 "1" */ CWORD_CWORD_CWORD_CWORD,
+ /* 180 50 "2" */ CWORD_CWORD_CWORD_CWORD,
+ /* 181 51 "3" */ CWORD_CWORD_CWORD_CWORD,
+ /* 182 52 "4" */ CWORD_CWORD_CWORD_CWORD,
+ /* 183 53 "5" */ CWORD_CWORD_CWORD_CWORD,
+ /* 184 54 "6" */ CWORD_CWORD_CWORD_CWORD,
+ /* 185 55 "7" */ CWORD_CWORD_CWORD_CWORD,
+ /* 186 56 "8" */ CWORD_CWORD_CWORD_CWORD,
+ /* 187 57 "9" */ CWORD_CWORD_CWORD_CWORD,
+ /* 188 58 ":" */ CWORD_CCTL_CCTL_CWORD,
+ /* 189 59 ";" */ CSPCL_CWORD_CWORD_CWORD,
+ /* 190 60 "<" */ CSPCL_CWORD_CWORD_CWORD,
+ /* 191 61 "=" */ CWORD_CCTL_CCTL_CWORD,
+ /* 192 62 ">" */ CSPCL_CWORD_CWORD_CWORD,
+ /* 193 63 "?" */ CWORD_CCTL_CCTL_CWORD,
+ /* 194 64 "@" */ CWORD_CWORD_CWORD_CWORD,
+ /* 195 65 "A" */ CWORD_CWORD_CWORD_CWORD,
+ /* 196 66 "B" */ CWORD_CWORD_CWORD_CWORD,
+ /* 197 67 "C" */ CWORD_CWORD_CWORD_CWORD,
+ /* 198 68 "D" */ CWORD_CWORD_CWORD_CWORD,
+ /* 199 69 "E" */ CWORD_CWORD_CWORD_CWORD,
+ /* 200 70 "F" */ CWORD_CWORD_CWORD_CWORD,
+ /* 201 71 "G" */ CWORD_CWORD_CWORD_CWORD,
+ /* 202 72 "H" */ CWORD_CWORD_CWORD_CWORD,
+ /* 203 73 "I" */ CWORD_CWORD_CWORD_CWORD,
+ /* 204 74 "J" */ CWORD_CWORD_CWORD_CWORD,
+ /* 205 75 "K" */ CWORD_CWORD_CWORD_CWORD,
+ /* 206 76 "L" */ CWORD_CWORD_CWORD_CWORD,
+ /* 207 77 "M" */ CWORD_CWORD_CWORD_CWORD,
+ /* 208 78 "N" */ CWORD_CWORD_CWORD_CWORD,
+ /* 209 79 "O" */ CWORD_CWORD_CWORD_CWORD,
+ /* 210 80 "P" */ CWORD_CWORD_CWORD_CWORD,
+ /* 211 81 "Q" */ CWORD_CWORD_CWORD_CWORD,
+ /* 212 82 "R" */ CWORD_CWORD_CWORD_CWORD,
+ /* 213 83 "S" */ CWORD_CWORD_CWORD_CWORD,
+ /* 214 84 "T" */ CWORD_CWORD_CWORD_CWORD,
+ /* 215 85 "U" */ CWORD_CWORD_CWORD_CWORD,
+ /* 216 86 "V" */ CWORD_CWORD_CWORD_CWORD,
+ /* 217 87 "W" */ CWORD_CWORD_CWORD_CWORD,
+ /* 218 88 "X" */ CWORD_CWORD_CWORD_CWORD,
+ /* 219 89 "Y" */ CWORD_CWORD_CWORD_CWORD,
+ /* 220 90 "Z" */ CWORD_CWORD_CWORD_CWORD,
+ /* 221 91 "[" */ CWORD_CCTL_CCTL_CWORD,
+ /* 222 92 "\" */ CBACK_CBACK_CCTL_CBACK,
+ /* 223 93 "]" */ CWORD_CCTL_CCTL_CWORD,
+ /* 224 94 "^" */ CWORD_CWORD_CWORD_CWORD,
+ /* 225 95 "_" */ CWORD_CWORD_CWORD_CWORD,
+ /* 226 96 "`" */ CBQUOTE_CBQUOTE_CWORD_CBQUOTE,
+ /* 227 97 "a" */ CWORD_CWORD_CWORD_CWORD,
+ /* 228 98 "b" */ CWORD_CWORD_CWORD_CWORD,
+ /* 229 99 "c" */ CWORD_CWORD_CWORD_CWORD,
+ /* 230 100 "d" */ CWORD_CWORD_CWORD_CWORD,
+ /* 231 101 "e" */ CWORD_CWORD_CWORD_CWORD,
+ /* 232 102 "f" */ CWORD_CWORD_CWORD_CWORD,
+ /* 233 103 "g" */ CWORD_CWORD_CWORD_CWORD,
+ /* 234 104 "h" */ CWORD_CWORD_CWORD_CWORD,
+ /* 235 105 "i" */ CWORD_CWORD_CWORD_CWORD,
+ /* 236 106 "j" */ CWORD_CWORD_CWORD_CWORD,
+ /* 237 107 "k" */ CWORD_CWORD_CWORD_CWORD,
+ /* 238 108 "l" */ CWORD_CWORD_CWORD_CWORD,
+ /* 239 109 "m" */ CWORD_CWORD_CWORD_CWORD,
+ /* 240 110 "n" */ CWORD_CWORD_CWORD_CWORD,
+ /* 241 111 "o" */ CWORD_CWORD_CWORD_CWORD,
+ /* 242 112 "p" */ CWORD_CWORD_CWORD_CWORD,
+ /* 243 113 "q" */ CWORD_CWORD_CWORD_CWORD,
+ /* 244 114 "r" */ CWORD_CWORD_CWORD_CWORD,
+ /* 245 115 "s" */ CWORD_CWORD_CWORD_CWORD,
+ /* 246 116 "t" */ CWORD_CWORD_CWORD_CWORD,
+ /* 247 117 "u" */ CWORD_CWORD_CWORD_CWORD,
+ /* 248 118 "v" */ CWORD_CWORD_CWORD_CWORD,
+ /* 249 119 "w" */ CWORD_CWORD_CWORD_CWORD,
+ /* 250 120 "x" */ CWORD_CWORD_CWORD_CWORD,
+ /* 251 121 "y" */ CWORD_CWORD_CWORD_CWORD,
+ /* 252 122 "z" */ CWORD_CWORD_CWORD_CWORD,
+ /* 253 123 "{" */ CWORD_CWORD_CWORD_CWORD,
+ /* 254 124 "|" */ CSPCL_CWORD_CWORD_CWORD,
+ /* 255 125 "}" */ CENDVAR_CENDVAR_CWORD_CENDVAR,
+ /* 256 126 "~" */ CWORD_CCTL_CCTL_CWORD,
+ /* 257 127 */ CWORD_CWORD_CWORD_CWORD,
};
-#endif /* USE_SIT_FUNCTION */
+#endif /* USE_SIT_FUNCTION */
/* first char is indicating which tokens mark the end of a list */
{
static char buf[16];
- if(tok>=TSEMI)
+ if (tok >= TSEMI)
buf[0] = '"';
- sprintf(buf+(tok>=TSEMI), "%s%c",
- tokname_array[tok]+1, (tok>=TSEMI ? '"' : 0));
+ sprintf(buf + (tok >= TSEMI), "%s%c",
+ tokname_array[tok] + 1, (tok >= TSEMI ? '"' : 0));
return buf;
}
-static int plinno = 1; /* input line number */
+static int plinno = 1; /* input line number */
-static int parselleft; /* copy of parsefile->lleft */
+static int parselleft; /* copy of parsefile->lleft */
-static struct parsefile basepf; /* top level input file */
-static char basebuf[BUFSIZ]; /* buffer for top level input file */
-static struct parsefile *parsefile = &basepf; /* current input file */
+static struct parsefile basepf; /* top level input file */
+static char basebuf[BUFSIZ]; /* buffer for top level input file */
+static struct parsefile *parsefile = &basepf; /* current input file */
/*
* NEOF is returned by parsecmd when it encounters an end of file. It
* happens to be handy.
*/
-static int tokpushback; /* last token pushed back */
+static int tokpushback; /* last token pushed back */
+
#define NEOF ((union node *)&tokpushback)
-static int checkkwd; /* 1 == check for kwds, 2 == also eat newlines */
+static int checkkwd; /* 1 == check for kwds, 2 == also eat newlines */
-static void error (const char *, ...) __attribute__((__noreturn__));
-static void exerror (int, const char *, ...) __attribute__((__noreturn__));
-static void shellexec (char **, char **, const char *, int)
- __attribute__((noreturn));
-static void exitshell (int) __attribute__((noreturn));
+static void error(const char *, ...) __attribute__ ((__noreturn__));
+static void exerror(int, const char *, ...) __attribute__ ((__noreturn__));
+static void shellexec(char **, char **, const char *, int)
+ __attribute__ ((noreturn));
+static void exitshell(int) __attribute__ ((noreturn));
-static int goodname(const char *);
-static void ignoresig (int);
-static void onsig (int);
-static void dotrap (void);
-static int decode_signal (const char *, int);
+static int goodname(const char *);
+static void ignoresig(int);
+static void onsig(int);
+static void dotrap(void);
+static int decode_signal(const char *, int);
static void shprocvar(void);
static void deletefuncs(void);
-static void setparam (char **);
-static void freeparam (volatile struct shparam *);
+static void setparam(char **);
+static void freeparam(volatile struct shparam *);
-static void find_command (const char *, struct cmdentry *, int, const char *);
+static void find_command(const char *, struct cmdentry *, int, const char *);
-static inline void hashcd (void);
+static inline void hashcd(void);
/* reasons for skipping commands (see comment on breakcmd routine) */
#define SKIPBREAK 1
#define SKIPFILE 4
/* values of cmdtype */
-#define CMDUNKNOWN -1 /* no entry in table for command */
-#define CMDNORMAL 0 /* command is an executable program */
-#define CMDBUILTIN 1 /* command is a shell builtin */
-#define CMDFUNCTION 2 /* command is a shell function */
+#define CMDUNKNOWN -1 /* no entry in table for command */
+#define CMDNORMAL 0 /* command is an executable program */
+#define CMDBUILTIN 1 /* command is a shell builtin */
+#define CMDFUNCTION 2 /* command is a shell function */
-#define DO_ERR 1 /* find_command prints errors */
-#define DO_ABS 2 /* find_command checks absolute paths */
-#define DO_NOFUN 4 /* find_command ignores functions */
-#define DO_BRUTE 8 /* find_command ignores hash table */
+#define DO_ERR 1 /* find_command prints errors */
+#define DO_ABS 2 /* find_command checks absolute paths */
+#define DO_NOFUN 4 /* find_command ignores functions */
+#define DO_BRUTE 8 /* find_command ignores hash table */
/*
* Shell variables.
*/
/* flags */
-#define VEXPORT 0x01 /* variable is exported */
-#define VREADONLY 0x02 /* variable cannot be modified */
-#define VSTRFIXED 0x04 /* variable struct is staticly allocated */
-#define VTEXTFIXED 0x08 /* text is staticly allocated */
-#define VSTACK 0x10 /* text is allocated on the stack */
-#define VUNSET 0x20 /* the variable is not set */
-#define VNOFUNC 0x40 /* don't call the callback function */
+#define VEXPORT 0x01 /* variable is exported */
+#define VREADONLY 0x02 /* variable cannot be modified */
+#define VSTRFIXED 0x04 /* variable struct is staticly allocated */
+#define VTEXTFIXED 0x08 /* text is staticly allocated */
+#define VSTACK 0x10 /* text is allocated on the stack */
+#define VUNSET 0x20 /* the variable is not set */
+#define VNOFUNC 0x40 /* don't call the callback function */
struct var {
- struct var *next; /* next entry in hash list */
- int flags; /* flags are defined above */
- char *text; /* name=value */
+ struct var *next; /* next entry in hash list */
+ int flags; /* flags are defined above */
+ char *text; /* name=value */
void (*func) (const char *);
- /* function to be called when */
- /* the variable gets set/unset */
+ /* function to be called when */
+ /* the variable gets set/unset */
};
struct localvar {
- struct localvar *next; /* next local variable in list */
- struct var *vp; /* the variable that was made local */
- int flags; /* saved flags */
- char *text; /* saved text */
+ struct localvar *next; /* next local variable in list */
+ struct var *vp; /* the variable that was made local */
+ int flags; /* saved flags */
+ char *text; /* saved text */
};
#if defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN)
#define rmescapes(p) _rmescapes((p), 0)
-static char *_rmescapes (char *, int);
+static char *_rmescapes(char *, int);
#else
-static void rmescapes (char *);
+static void rmescapes(char *);
#endif
-static int casematch (union node *, const char *);
+static int casematch(union node *, const char *);
static void clearredir(void);
static void popstring(void);
-static void readcmdfile (const char *);
+static void readcmdfile(const char *);
-static int number (const char *);
-static int is_number (const char *, int *num);
-static char *single_quote (const char *);
-static int nextopt (const char *);
+static int number(const char *);
+static int is_number(const char *, int *num);
+static char *single_quote(const char *);
+static int nextopt(const char *);
-static void redirect (union node *, int);
-static void popredir (void);
-static int dup_as_newfd (int, int);
+static void redirect(union node *, int);
+static void popredir(void);
+static int dup_as_newfd(int, int);
static void changepath(const char *newval);
static void getoptsreset(const char *value);
-static int parsenleft; /* copy of parsefile->nleft */
-static char *parsenextc; /* copy of parsefile->nextc */
-static int rootpid; /* pid of main shell */
-static int rootshell; /* true if we aren't a child of the main shell */
+static int parsenleft; /* copy of parsefile->nleft */
+static char *parsenextc; /* copy of parsefile->nextc */
+static int rootpid; /* pid of main shell */
+static int rootshell; /* true if we aren't a child of the main shell */
static const char spcstr[] = " ";
static const char snlfmt[] = "%s\n";
static struct var vps1;
static struct var vps2;
static struct var voptind;
+
#ifdef CONFIG_LOCALE_SUPPORT
static struct var vlc_all;
static struct var vlc_ctype;
#ifdef IFS_BROKEN
static const char defifsvar[] = "IFS= \t\n";
+
#define defifs (defifsvar + 4)
#else
static const char defifs[] = " \t\n";
static const struct varinit varinit[] = {
#ifdef IFS_BROKEN
- { &vifs, VSTRFIXED|VTEXTFIXED, defifsvar,
+ {&vifs, VSTRFIXED | VTEXTFIXED, defifsvar,
#else
- { &vifs, VSTRFIXED|VTEXTFIXED|VUNSET, "IFS=",
-#endif
- NULL },
- { &vmail, VSTRFIXED|VTEXTFIXED|VUNSET, "MAIL=",
- NULL },
- { &vmpath, VSTRFIXED|VTEXTFIXED|VUNSET, "MAILPATH=",
- NULL },
- { &vpath, VSTRFIXED|VTEXTFIXED, defpathvar,
- changepath },
+ {&vifs, VSTRFIXED | VTEXTFIXED | VUNSET, "IFS=",
+#endif
+ NULL},
+ {&vmail, VSTRFIXED | VTEXTFIXED | VUNSET, "MAIL=",
+ NULL},
+ {&vmpath, VSTRFIXED | VTEXTFIXED | VUNSET, "MAILPATH=",
+ NULL},
+ {&vpath, VSTRFIXED | VTEXTFIXED, defpathvar,
+ changepath},
#if defined(CONFIG_FEATURE_COMMAND_EDITING) && defined(CONFIG_FEATURE_SH_FANCY_PROMPT)
- { &vps1, VSTRFIXED|VTEXTFIXED, "PS1=\\w \\$ ",
- NULL },
-#endif /* else vps1 depends on uid */
- { &vps2, VSTRFIXED|VTEXTFIXED, "PS2=> ",
- NULL },
- { &voptind, VSTRFIXED|VTEXTFIXED, "OPTIND=1",
- getoptsreset },
+ {&vps1, VSTRFIXED | VTEXTFIXED, "PS1=\\w \\$ ",
+ NULL},
+#endif /* else vps1 depends on uid */
+ {&vps2, VSTRFIXED | VTEXTFIXED, "PS2=> ",
+ NULL},
+ {&voptind, VSTRFIXED | VTEXTFIXED, "OPTIND=1",
+ getoptsreset},
#ifdef CONFIG_LOCALE_SUPPORT
- { &vlc_all, VSTRFIXED|VTEXTFIXED|VUNSET, "LC_ALL=",
- change_lc_all },
- { &vlc_ctype, VSTRFIXED|VTEXTFIXED|VUNSET, "LC_CTYPE=",
- change_lc_ctype },
+ {&vlc_all, VSTRFIXED | VTEXTFIXED | VUNSET, "LC_ALL=",
+ change_lc_all},
+ {&vlc_ctype, VSTRFIXED | VTEXTFIXED | VUNSET, "LC_CTYPE=",
+ change_lc_ctype},
#endif
- { NULL, 0, NULL,
- NULL }
+ {NULL, 0, NULL,
+ NULL}
};
#define VTABSIZE 39
#define mpathset() ((vmpath.flags & VUNSET) == 0)
-static void initvar (void);
-static void setvar (const char *, const char *, int);
-static void setvareq (char *, int);
-static void listsetvar (struct strlist *);
-static const char *lookupvar (const char *);
-static const char *bltinlookup (const char *);
-static char **environment (void);
-static int showvarscmd (int, char **);
-static void mklocal (char *);
-static void poplocalvars (void);
-static int unsetvar (const char *);
-static int varequal (const char *, const char *);
+static void initvar(void);
+static void setvar(const char *, const char *, int);
+static void setvareq(char *, int);
+static void listsetvar(struct strlist *);
+static const char *lookupvar(const char *);
+static const char *bltinlookup(const char *);
+static char **environment(void);
+static int showvarscmd(int, char **);
+static void mklocal(char *);
+static void poplocalvars(void);
+static int unsetvar(const char *);
+static int varequal(const char *, const char *);
-static char *arg0; /* value of $0 */
-static struct shparam shellparam; /* current positional parameters */
-static char **argptr; /* argument list for builtin commands */
-static char *optionarg; /* set by nextopt (like getopt) */
-static char *optptr; /* used by nextopt */
-static char *minusc; /* argument to -c option */
+static char *arg0; /* value of $0 */
+static struct shparam shellparam; /* current positional parameters */
+static char **argptr; /* argument list for builtin commands */
+static char *optionarg; /* set by nextopt (like getopt) */
+static char *optptr; /* used by nextopt */
+static char *minusc; /* argument to -c option */
#ifdef CONFIG_ASH_ALIAS
static struct alias *atab[ATABSIZE];
-static void setalias (char *, char *);
-static struct alias **hashalias (const char *);
-static struct alias *freealias (struct alias *);
-static struct alias **__lookupalias (const char *);
+static void setalias(char *, char *);
+static struct alias **hashalias(const char *);
+static struct alias *freealias(struct alias *);
+static struct alias **__lookupalias(const char *);
-static void
-setalias(char *name, char *val)
+static void setalias(char *name, char *val)
{
struct alias *ap, **app;
ap->flag &= ~ALIASDEAD;
} else {
/* not found */
- ap = xmalloc(sizeof (struct alias));
+ ap = xmalloc(sizeof(struct alias));
ap->name = xstrdup(name);
ap->val = xstrdup(val);
ap->flag = 0;
INTON;
}
-static int
-unalias(char *name)
+static int unalias(char *name)
{
struct alias **app;
return (1);
}
-static void
-rmaliases(void)
+static void rmaliases(void)
{
struct alias *ap, **app;
int i;
INTON;
}
-static void
-printalias(const struct alias *ap) {
+static void printalias(const struct alias *ap)
+{
char *p;
p = single_quote(ap->val);
/*
* TODO - sort output
*/
-static int
-aliascmd(int argc, char **argv)
+static int aliascmd(int argc, char **argv)
{
char *n, *v;
int ret = 0;
return (0);
}
while ((n = *++argv) != NULL) {
- if ((v = strchr(n+1, '=')) == NULL) { /* n+1: funny ksh stuff */
+ if ((v = strchr(n + 1, '=')) == NULL) { /* n+1: funny ksh stuff */
if ((ap = *__lookupalias(n)) == NULL) {
out2fmt("%s: %s not found\n", "alias", n);
ret = 1;
} else
printalias(ap);
- }
- else {
+ } else {
*v++ = '\0';
setalias(n, v);
}
return (ret);
}
-static int
-unaliascmd(int argc, char **argv)
+static int unaliascmd(int argc, char **argv)
{
int i;
return (i);
}
-static struct alias **
-hashalias(const char *p)
+static struct alias **hashalias(const char *p)
{
unsigned int hashval;
hashval = *p << 4;
while (*p)
- hashval+= *p++;
+ hashval += *p++;
return &atab[hashval % ATABSIZE];
}
-static struct alias *
-freealias(struct alias *ap)
+static struct alias *freealias(struct alias *ap)
{
struct alias *next;
}
-static struct alias **
-__lookupalias(const char *name)
+static struct alias **__lookupalias(const char *name)
{
struct alias **app = hashalias(name);
* written implementation written by Aaron Lehmann <aaronl@vitelus.com>.
* This is now part of libbb, so that it can be used by all the shells
* in busybox. */
-static void expari (int);
+static void expari(int);
#endif
-static char *trap[NSIG]; /* trap handler commands */
-static char sigmode[NSIG - 1]; /* current value of signal */
-static char gotsig[NSIG - 1]; /* indicates specified signal received */
-static int pendingsigs; /* indicates some signal received */
+static char *trap[NSIG]; /* trap handler commands */
+static char sigmode[NSIG - 1]; /* current value of signal */
+static char gotsig[NSIG - 1]; /* indicates specified signal received */
+static int pendingsigs; /* indicates some signal received */
/*
* This file was generated by the mkbuiltins program.
*/
#ifdef CONFIG_ASH_JOB_CONTROL
-static int bgcmd (int, char **);
-static int fgcmd (int, char **);
-static int killcmd (int, char **);
+static int bgcmd(int, char **);
+static int fgcmd(int, char **);
+static int killcmd(int, char **);
#endif
-static int bltincmd (int, char **);
-static int cdcmd (int, char **);
-static int breakcmd (int, char **);
+static int bltincmd(int, char **);
+static int cdcmd(int, char **);
+static int breakcmd(int, char **);
+
#ifdef CONFIG_ASH_CMDCMD
-static int commandcmd (int, char **);
-#endif
-static int dotcmd (int, char **);
-static int evalcmd (int, char **);
-static int execcmd (int, char **);
-static int exitcmd (int, char **);
-static int exportcmd (int, char **);
-static int histcmd (int, char **);
-static int hashcmd (int, char **);
-static int helpcmd (int, char **);
-static int jobscmd (int, char **);
-static int localcmd (int, char **);
-static int pwdcmd (int, char **);
-static int readcmd (int, char **);
-static int returncmd (int, char **);
-static int setcmd (int, char **);
-static int setvarcmd (int, char **);
-static int shiftcmd (int, char **);
-static int trapcmd (int, char **);
-static int umaskcmd (int, char **);
+static int commandcmd(int, char **);
+#endif
+static int dotcmd(int, char **);
+static int evalcmd(int, char **);
+static int execcmd(int, char **);
+static int exitcmd(int, char **);
+static int exportcmd(int, char **);
+static int histcmd(int, char **);
+static int hashcmd(int, char **);
+static int helpcmd(int, char **);
+static int jobscmd(int, char **);
+static int localcmd(int, char **);
+static int pwdcmd(int, char **);
+static int readcmd(int, char **);
+static int returncmd(int, char **);
+static int setcmd(int, char **);
+static int setvarcmd(int, char **);
+static int shiftcmd(int, char **);
+static int trapcmd(int, char **);
+static int umaskcmd(int, char **);
+
#ifdef CONFIG_ASH_ALIAS
-static int aliascmd (int, char **);
-static int unaliascmd (int, char **);
+static int aliascmd(int, char **);
+static int unaliascmd(int, char **);
#endif
-static int unsetcmd (int, char **);
-static int waitcmd (int, char **);
-static int ulimitcmd (int, char **);
-static int timescmd (int, char **);
+static int unsetcmd(int, char **);
+static int waitcmd(int, char **);
+static int ulimitcmd(int, char **);
+static int timescmd(int, char **);
+
#ifdef CONFIG_ASH_MATH_SUPPORT
-static int letcmd (int, char **);
+static int letcmd(int, char **);
#endif
-static int typecmd (int, char **);
+static int typecmd(int, char **);
+
#ifdef CONFIG_ASH_GETOPTS
-static int getoptscmd (int, char **);
+static int getoptscmd(int, char **);
#endif
#ifndef CONFIG_TRUE
-static int true_main (int, char **);
+static int true_main(int, char **);
#endif
#ifndef CONFIG_FALSE
-static int false_main (int, char **);
+static int false_main(int, char **);
#endif
-static void setpwd (const char *, int);
+static void setpwd(const char *, int);
#define BUILTIN_NOSPEC "0"
struct builtincmd {
const char *name;
int (*const builtinfunc) (int, char **);
- //unsigned flags;
+ /* unsigned flags; */
};
* have been warned.
*/
static const struct builtincmd builtincmds[] = {
- { BUILTIN_SPECIAL ".", dotcmd }, /* first, see declare DOTCMD */
- { BUILTIN_SPECIAL ":", true_main },
+ {BUILTIN_SPECIAL ".", dotcmd}, /* first, see declare DOTCMD */
+ {BUILTIN_SPECIAL ":", true_main},
#ifdef CONFIG_ASH_ALIAS
- { BUILTIN_REG_ASSG "alias", aliascmd },
+ {BUILTIN_REG_ASSG "alias", aliascmd},
#endif
#ifdef CONFIG_ASH_JOB_CONTROL
- { BUILTIN_REGULAR "bg", bgcmd },
+ {BUILTIN_REGULAR "bg", bgcmd},
#endif
- { BUILTIN_SPECIAL "break", breakcmd },
- { BUILTIN_SPECIAL "builtin", bltincmd },
- { BUILTIN_REGULAR "cd", cdcmd },
- { BUILTIN_NOSPEC "chdir", cdcmd },
+ {BUILTIN_SPECIAL "break", breakcmd},
+ {BUILTIN_SPECIAL "builtin", bltincmd},
+ {BUILTIN_REGULAR "cd", cdcmd},
+ {BUILTIN_NOSPEC "chdir", cdcmd},
#ifdef CONFIG_ASH_CMDCMD
- { BUILTIN_REGULAR "command", commandcmd },
-#endif
- { BUILTIN_SPECIAL "continue", breakcmd },
- { BUILTIN_SPECIAL "eval", evalcmd },
- { BUILTIN_SPECIAL "exec", execcmd },
- { BUILTIN_SPECIAL "exit", exitcmd },
- { BUILTIN_SPEC_ASSG "export", exportcmd },
- { BUILTIN_REGULAR "false", false_main },
- { BUILTIN_REGULAR "fc", histcmd },
+ {BUILTIN_REGULAR "command", commandcmd},
+#endif
+ {BUILTIN_SPECIAL "continue", breakcmd},
+ {BUILTIN_SPECIAL "eval", evalcmd},
+ {BUILTIN_SPECIAL "exec", execcmd},
+ {BUILTIN_SPECIAL "exit", exitcmd},
+ {BUILTIN_SPEC_ASSG "export", exportcmd},
+ {BUILTIN_REGULAR "false", false_main},
+ {BUILTIN_REGULAR "fc", histcmd},
#ifdef CONFIG_ASH_JOB_CONTROL
- { BUILTIN_REGULAR "fg", fgcmd },
+ {BUILTIN_REGULAR "fg", fgcmd},
#endif
#ifdef CONFIG_ASH_GETOPTS
- { BUILTIN_REGULAR "getopts", getoptscmd },
+ {BUILTIN_REGULAR "getopts", getoptscmd},
#endif
- { BUILTIN_NOSPEC "hash", hashcmd },
- { BUILTIN_NOSPEC "help", helpcmd },
- { BUILTIN_REGULAR "jobs", jobscmd },
+ {BUILTIN_NOSPEC "hash", hashcmd},
+ {BUILTIN_NOSPEC "help", helpcmd},
+ {BUILTIN_REGULAR "jobs", jobscmd},
#ifdef CONFIG_ASH_JOB_CONTROL
- { BUILTIN_REGULAR "kill", killcmd },
+ {BUILTIN_REGULAR "kill", killcmd},
#endif
#ifdef CONFIG_ASH_MATH_SUPPORT
- { BUILTIN_REGULAR "let", letcmd },
-#endif
- { BUILTIN_ASSIGN "local", localcmd },
- { BUILTIN_NOSPEC "pwd", pwdcmd },
- { BUILTIN_REGULAR "read", readcmd },
- { BUILTIN_SPEC_ASSG "readonly", exportcmd },
- { BUILTIN_SPECIAL "return", returncmd },
- { BUILTIN_SPECIAL "set", setcmd },
- { BUILTIN_NOSPEC "setvar", setvarcmd },
- { BUILTIN_SPECIAL "shift", shiftcmd },
- { BUILTIN_SPECIAL "times", timescmd },
- { BUILTIN_SPECIAL "trap", trapcmd },
- { BUILTIN_REGULAR "true", true_main },
- { BUILTIN_NOSPEC "type", typecmd },
- { BUILTIN_NOSPEC "ulimit", ulimitcmd },
- { BUILTIN_REGULAR "umask", umaskcmd },
+ {BUILTIN_REGULAR "let", letcmd},
+#endif
+ {BUILTIN_ASSIGN "local", localcmd},
+ {BUILTIN_NOSPEC "pwd", pwdcmd},
+ {BUILTIN_REGULAR "read", readcmd},
+ {BUILTIN_SPEC_ASSG "readonly", exportcmd},
+ {BUILTIN_SPECIAL "return", returncmd},
+ {BUILTIN_SPECIAL "set", setcmd},
+ {BUILTIN_NOSPEC "setvar", setvarcmd},
+ {BUILTIN_SPECIAL "shift", shiftcmd},
+ {BUILTIN_SPECIAL "times", timescmd},
+ {BUILTIN_SPECIAL "trap", trapcmd},
+ {BUILTIN_REGULAR "true", true_main},
+ {BUILTIN_NOSPEC "type", typecmd},
+ {BUILTIN_NOSPEC "ulimit", ulimitcmd},
+ {BUILTIN_REGULAR "umask", umaskcmd},
#ifdef CONFIG_ASH_ALIAS
- { BUILTIN_REGULAR "unalias", unaliascmd },
+ {BUILTIN_REGULAR "unalias", unaliascmd},
#endif
- { BUILTIN_SPECIAL "unset", unsetcmd },
- { BUILTIN_REGULAR "wait", waitcmd },
+ {BUILTIN_SPECIAL "unset", unsetcmd},
+ {BUILTIN_REGULAR "wait", waitcmd},
};
+
#define NUMBUILTINS (sizeof (builtincmds) / sizeof (struct builtincmd) )
#define DOTCMD &builtincmds[0]
static struct builtincmd *EVALCMD;
/* states */
-#define CONFIG_ASH_JOB_CONTROLTOPPED 1 /* all procs are stopped */
-#define JOBDONE 2 /* all procs are completed */
+#define CONFIG_ASH_JOB_CONTROLTOPPED 1 /* all procs are stopped */
+#define JOBDONE 2 /* all procs are completed */
/*
* A job structure contains information about a job. A job is either a
*/
struct procstat {
- pid_t pid; /* process id */
- int status; /* status flags (defined above) */
- char *cmd; /* text of command being run */
+ pid_t pid; /* process id */
+ int status; /* status flags (defined above) */
+ char *cmd; /* text of command being run */
};
-static int job_warning; /* user was warned about stopped jobs */
+static int job_warning; /* user was warned about stopped jobs */
#ifdef CONFIG_ASH_JOB_CONTROL
static void setjobctl(int enable);
#else
-#define setjobctl(on) /* do nothing */
+#define setjobctl(on) /* do nothing */
#endif
struct job {
- struct procstat ps0; /* status of process */
- struct procstat *ps; /* status or processes when more than one */
- short nprocs; /* number of processes */
- short pgrp; /* process group of this job */
- char state; /* true if job is finished */
- char used; /* true if this entry is in used */
- char changed; /* true if status has changed */
+ struct procstat ps0; /* status of process */
+ struct procstat *ps; /* status or processes when more than one */
+ short nprocs; /* number of processes */
+ short pgrp; /* process group of this job */
+ char state; /* true if job is finished */
+ char used; /* true if this entry is in used */
+ char changed; /* true if status has changed */
#ifdef CONFIG_ASH_JOB_CONTROL
- char jobctl; /* job running under job control */
+ char jobctl; /* job running under job control */
#endif
};
-static struct job *jobtab; /* array of jobs */
-static int njobs; /* size of array */
-static int backgndpid = -1; /* pid of last background process */
+static struct job *jobtab; /* array of jobs */
+static int njobs; /* size of array */
+static int backgndpid = -1; /* pid of last background process */
+
#ifdef CONFIG_ASH_JOB_CONTROL
-static int initialpgrp; /* pgrp of shell on invocation */
-static int curjob; /* current job */
+static int initialpgrp; /* pgrp of shell on invocation */
+static int curjob; /* current job */
static int jobctl;
#endif
static int intreceived;
-static struct job *makejob (const union node *, int);
-static int forkshell (struct job *, const union node *, int);
-static int waitforjob (struct job *);
+static struct job *makejob(const union node *, int);
+static int forkshell(struct job *, const union node *, int);
+static int waitforjob(struct job *);
-static int docd (char *, int);
-static void getpwd (void);
+static int docd(char *, int);
+static void getpwd(void);
-static char *padvance (const char **, const char *);
+static char *padvance(const char **, const char *);
-static char nullstr[1]; /* zero length string */
-static char *curdir = nullstr; /* current working directory */
+static char nullstr[1]; /* zero length string */
+static char *curdir = nullstr; /* current working directory */
-static int
-cdcmd(int argc, char **argv)
+static int cdcmd(int argc, char **argv)
{
const char *dest;
const char *path;
* directory name if "print" is nonzero.
*/
-static int
-docd(char *dest, int print)
+static int docd(char *dest, int print)
{
TRACE(("docd(\"%s\", %d) called\n", dest, print));
INTOFF;
}
-static int
-pwdcmd(int argc, char **argv)
+static int pwdcmd(int argc, char **argv)
{
puts(curdir);
return 0;
}
/* Ask system the current directory */
-static void
-getpwd(void)
+static void getpwd(void)
{
curdir = xgetcwd(0);
- if(curdir==0)
+ if (curdir == 0)
curdir = nullstr;
}
-static void
-setpwd(const char *val, int setold)
+static void setpwd(const char *val, int setold)
{
char *cated = NULL;
}
INTOFF;
if (curdir != nullstr) {
- if(val!=NULL && *val != '/')
+ if (val != NULL && *val != '/')
val = cated = concat_path_file(curdir, val);
free(curdir);
}
if (!val)
getpwd();
- else
+ else
curdir = simplify_path(val);
free(cated);
INTON;
};
/* exceptions */
-#define EXINT 0 /* SIGINT received */
-#define EXERROR 1 /* a generic error */
-#define EXSHELLPROC 2 /* execute a shell procedure */
-#define EXEXEC 3 /* command execution failed */
+#define EXINT 0 /* SIGINT received */
+#define EXERROR 1 /* a generic error */
+#define EXSHELLPROC 2 /* execute a shell procedure */
+#define EXEXEC 3 /* command execution failed */
static struct jmploc *handler;
static int exception;
-static void exverror (int, const char *, va_list)
- __attribute__((__noreturn__));
+static void exverror(int, const char *, va_list)
+ __attribute__ ((__noreturn__));
/*
* Called to raise an exception. Since C doesn't include exceptions, we
* stored in the global variable "exception".
*/
-static void exraise (int) __attribute__((__noreturn__));
+static void exraise(int) __attribute__ ((__noreturn__));
-static void
-exraise(int e)
+static void exraise(int e)
{
#ifdef DEBUG
if (handler == NULL)
* just defensive programming.)
*/
-static void
-onint(void) {
+static void onint(void)
+{
sigset_t mysigset;
if (suppressint) {
}
-static char *commandname; /* currently executing command */
+static char *commandname; /* currently executing command */
/*
* Exverror is called to raise the error exception. If the first argument
* is not NULL then error prints an error message using printf style
* formatting. It then raises the error exception.
*/
-static void
-exverror(int cond, const char *msg, va_list ap)
+static void exverror(int cond, const char *msg, va_list ap)
{
CLEAR_PENDING_INT;
INTOFF;
}
-static void
-error(const char *msg, ...)
+static void error(const char *msg, ...)
{
va_list ap;
+
va_start(ap, msg);
exverror(EXERROR, msg, ap);
/* NOTREACHED */
}
-static void
-exerror(int cond, const char *msg, ...)
+static void exerror(int cond, const char *msg, ...)
{
va_list ap;
+
va_start(ap, msg);
exverror(cond, msg, ap);
/* NOTREACHED */
*/
struct errname {
- short errcode; /* error number */
- short action; /* operation which encountered the error */
+ short errcode; /* error number */
+ short action; /* operation which encountered the error */
};
/*
* Types of operations (passed to the errmsg routine).
*/
-#define E_OPEN 01 /* opening a file */
-#define E_CREAT 02 /* creating a file */
-#define E_EXEC 04 /* executing a program */
+#define E_OPEN 01 /* opening a file */
+#define E_CREAT 02 /* creating a file */
+#define E_EXEC 04 /* executing a program */
#define ALL (E_OPEN|E_CREAT|E_EXEC)
static const struct errname errormsg[] = {
- { EINTR, ALL },
- { EACCES, ALL },
- { EIO, ALL },
- { ENOENT, E_OPEN },
- { ENOENT, E_CREAT },
- { ENOENT, E_EXEC },
- { ENOTDIR, E_OPEN },
- { ENOTDIR, E_CREAT },
- { ENOTDIR, E_EXEC },
- { EISDIR, ALL },
- { EEXIST, E_CREAT },
+ {EINTR, ALL},
+ {EACCES, ALL},
+ {EIO, ALL},
+ {ENOENT, E_OPEN},
+ {ENOENT, E_CREAT},
+ {ENOENT, E_EXEC},
+ {ENOTDIR, E_OPEN},
+ {ENOTDIR, E_CREAT},
+ {ENOTDIR, E_EXEC},
+ {EISDIR, ALL},
+ {EEXIST, E_CREAT},
#ifdef EMFILE
- { EMFILE, ALL },
+ {EMFILE, ALL},
#endif
- { ENFILE, ALL },
- { ENOSPC, ALL },
+ {ENFILE, ALL},
+ {ENOSPC, ALL},
#ifdef EDQUOT
- { EDQUOT, ALL },
+ {EDQUOT, ALL},
#endif
#ifdef ENOSR
- { ENOSR, ALL },
+ {ENOSR, ALL},
#endif
- { ENXIO, ALL },
- { EROFS, ALL },
- { ETXTBSY, ALL },
+ {ENXIO, ALL},
+ {EROFS, ALL},
+ {ETXTBSY, ALL},
#ifdef EAGAIN
- { EAGAIN, E_EXEC },
+ {EAGAIN, E_EXEC},
#endif
- { ENOMEM, ALL },
+ {ENOMEM, ALL},
#ifdef ENOLINK
- { ENOLINK, ALL },
+ {ENOLINK, ALL},
#endif
#ifdef EMULTIHOP
- { EMULTIHOP, ALL },
+ {EMULTIHOP, ALL},
#endif
#ifdef ECOMM
- { ECOMM, ALL },
+ {ECOMM, ALL},
#endif
#ifdef ESTALE
- { ESTALE, ALL },
+ {ESTALE, ALL},
#endif
#ifdef ETIMEDOUT
- { ETIMEDOUT, ALL },
+ {ETIMEDOUT, ALL},
#endif
#ifdef ELOOP
- { ELOOP, ALL },
+ {ELOOP, ALL},
#endif
- { E2BIG, E_EXEC },
+ {E2BIG, E_EXEC},
#ifdef ELIBACC
- { ELIBACC, E_EXEC },
+ {ELIBACC, E_EXEC},
#endif
};
* Action describes the operation that got the error.
*/
-static const char *
-errmsg(int e, int action)
+static const char *errmsg(int e, int action)
{
struct errname const *ep;
static char buf[12];
- for (ep = errormsg ; ep < errormsg+ERRNAME_SIZE; ep++) {
+ for (ep = errormsg; ep < errormsg + ERRNAME_SIZE; ep++) {
if (ep->errcode == e && (ep->action & action) != 0)
return strerror(e);
}
#ifdef CONFIG_ASH_OPTIMIZE_FOR_SIZE
-static void
-__inton() {
+static void __inton()
+{
if (--suppressint == 0 && intpending) {
onint();
}
}
-static void forceinton (void) {
+static void forceinton(void)
+{
suppressint = 0;
if (intpending)
onint();
#endif
/* flags in argument to evaltree */
-#define EV_EXIT 01 /* exit after evaluating tree */
-#define EV_TESTED 02 /* exit status is checked; ignore -e flag */
-#define EV_BACKCMD 04 /* command executing within back quotes */
+#define EV_EXIT 01 /* exit after evaluating tree */
+#define EV_TESTED 02 /* exit status is checked; ignore -e flag */
+#define EV_BACKCMD 04 /* command executing within back quotes */
-static int evalskip; /* set if we are skipping commands */
-static int skipcount; /* number of levels to skip */
-static int loopnest; /* current loop nesting level */
-static int funcnest; /* depth of function calls */
+static int evalskip; /* set if we are skipping commands */
+static int skipcount; /* number of levels to skip */
+static int loopnest; /* current loop nesting level */
+static int funcnest; /* depth of function calls */
-static struct strlist *cmdenviron; /* environment for builtin command */
-static int exitstatus; /* exit status of last command */
-static int oexitstatus; /* saved exit status */
+static struct strlist *cmdenviron; /* environment for builtin command */
+static int exitstatus; /* exit status of last command */
+static int oexitstatus; /* saved exit status */
-static void evalsubshell (const union node *, int);
-static void expredir (union node *);
-static void eprintlist (struct strlist *);
+static void evalsubshell(const union node *, int);
+static void expredir(union node *);
+static void eprintlist(struct strlist *);
static union node *parsecmd(int);
+
/*
* Called to reset things after an exception.
*/
/*
* The eval commmand.
*/
-static void evalstring (char *, int);
+static void evalstring(char *, int);
-static int
-evalcmd(int argc, char **argv)
+static int evalcmd(int argc, char **argv)
{
char *p;
char *concat;
* Execute a command or commands contained in a string.
*/
-static void evaltree (union node *, int);
-static void setinputstring (char *);
-static void popfile (void);
+static void evaltree(union node *, int);
+static void setinputstring(char *);
+static void popfile(void);
static void setstackmark(struct stackmark *mark);
static void popstackmark(struct stackmark *mark);
-static void
-evalstring(char *s, int flag)
+static void evalstring(char *s, int flag)
{
union node *n;
struct stackmark smark;
popstackmark(&smark);
}
-static struct builtincmd *find_builtin (const char *);
-static void expandarg (union node *, struct arglist *, int);
-static void calcsize (const union node *);
-static union node *copynode (const union node *);
+static struct builtincmd *find_builtin(const char *);
+static void expandarg(union node *, struct arglist *, int);
+static void calcsize(const union node *);
+static union node *copynode(const union node *);
/*
* Make a copy of a parse tree.
*/
-static int funcblocksize; /* size of structures in function */
-static int funcstringsize; /* size of strings in node */
-static pointer funcblock; /* block to allocate function from */
-static char *funcstring; /* block to allocate strings from */
+static int funcblocksize; /* size of structures in function */
+static int funcstringsize; /* size of strings in node */
+static pointer funcblock; /* block to allocate function from */
+static char *funcstring; /* block to allocate strings from */
-static inline union node *
-copyfunc(union node *n)
+static inline union node *copyfunc(union node *n)
{
if (n == NULL)
return NULL;
* the same name.
*/
-static inline void
-addcmdentry(char *name, struct cmdentry *entry)
+static inline void addcmdentry(char *name, struct cmdentry *entry)
{
struct tblentry *cmdp;
INTON;
}
-static inline void
-evalloop(const union node *n, int flags)
+static inline void evalloop(const union node *n, int flags)
{
int status;
for (;;) {
evaltree(n->nbinary.ch1, EV_TESTED);
if (evalskip) {
-skipping: if (evalskip == SKIPCONT && --skipcount <= 0) {
+ skipping:if (evalskip == SKIPCONT && --skipcount <= 0) {
evalskip = 0;
continue;
}
exitstatus = status;
}
-static void
-evalfor(const union node *n, int flags)
+static void evalfor(const union node *n, int flags)
{
struct arglist arglist;
union node *argp;
setstackmark(&smark);
arglist.lastp = &arglist.list;
- for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
+ for (argp = n->nfor.args; argp; argp = argp->narg.next) {
oexitstatus = exitstatus;
expandarg(argp, &arglist, EXP_FULL | EXP_TILDE | EXP_RECORD);
if (evalskip)
exitstatus = 0;
loopnest++;
- for (sp = arglist.list ; sp ; sp = sp->next) {
+ for (sp = arglist.list; sp; sp = sp->next) {
setvar(n->nfor.var, sp->text, 0);
evaltree(n->nfor.body, flags & EV_TESTED);
if (evalskip) {
}
}
loopnest--;
-out:
+ out:
popstackmark(&smark);
}
-static inline void
-evalcase(const union node *n, int flags)
+static inline void evalcase(const union node *n, int flags)
{
union node *cp;
union node *patp;
arglist.lastp = &arglist.list;
oexitstatus = exitstatus;
expandarg(n->ncase.expr, &arglist, EXP_TILDE);
- for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) {
- for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
+ for (cp = n->ncase.cases; cp && evalskip == 0; cp = cp->nclist.next) {
+ for (patp = cp->nclist.pattern; patp; patp = patp->narg.next) {
if (casematch(patp, arglist.list->text)) {
if (evalskip == 0) {
evaltree(cp->nclist.body, flags);
}
}
}
-out:
+ out:
popstackmark(&smark);
}
int prevfd;
int pip[2];
- TRACE(("evalpipe(0x%lx) called\n", (long)n));
+ TRACE(("evalpipe(0x%lx) called\n", (long) n));
pipelen = 0;
- for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
+ for (lp = n->npipe.cmdlist; lp; lp = lp->next)
pipelen++;
INTOFF;
jp = makejob(n, pipelen);
prevfd = -1;
- for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
+ for (lp = n->npipe.cmdlist; lp; lp = lp->next) {
/*
* Search for a command. This is called before we fork so that the
* location of the command will be available in the parent as well as
struct cmdentry entry;
union node *lpn = lp->n;
- if (lpn->type == NCMD && lpn->ncmd.args && goodname(lpn->ncmd.args->narg.text))
+
+ if (lpn->type == NCMD && lpn->ncmd.args
+ && goodname(lpn->ncmd.args->narg.text))
find_command(lpn->ncmd.args->narg.text, &entry, 0, pathval());
pip[1] = -1;
}
}
-static int
-isassignment(const char *word) {
+static int isassignment(const char *word)
+{
if (!is_name(*word)) {
return 0;
}
}
-static void
-evalcommand(union node *cmd, int flags)
+static void evalcommand(union node *cmd, int flags)
{
struct stackmark smark;
union node *argp;
const struct builtincmd *firstbltin;
struct jmploc *volatile savehandler;
struct jmploc jmploc;
+
#if __GNUC__
/* Avoid longjmp clobbering */
(void) &argv;
#endif
/* First expand the arguments. */
- TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags));
+ TRACE(("evalcommand(0x%lx, %d) called\n", (long) cmd, flags));
setstackmark(&smark);
arglist.lastp = &arglist.list;
varlist.lastp = &varlist.list;
for (argp = cmd->ncmd.assign; argp; argp = argp->narg.next) {
expandarg(argp, &varlist, EXP_VARTILDE);
}
- for (
- argp = cmd->ncmd.args; argp && !arglist.list;
- argp = argp->narg.next
- ) {
+ for (argp = cmd->ncmd.args; argp && !arglist.list; argp = argp->narg.next) {
expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
}
if (argp) {
struct builtincmd *bcmd;
int pseudovarflag;
+
bcmd = find_builtin(arglist.list->text);
pseudovarflag = bcmd && IS_BUILTIN_ASSIGN(bcmd);
for (; argp; argp = argp->narg.next) {
*varlist.lastp = NULL;
expredir(cmd->ncmd.redirect);
argc = 0;
- for (sp = arglist.list ; sp ; sp = sp->next)
+ for (sp = arglist.list; sp; sp = sp->next)
argc++;
- argv = stalloc(sizeof (char *) * (argc + 1));
+ argv = stalloc(sizeof(char *) * (argc + 1));
- for (sp = arglist.list ; sp ; sp = sp->next) {
+ for (sp = arglist.list; sp; sp = sp->next) {
TRACE(("evalcommand arg: %s\n", sp->text));
*argv++ = sp->text;
}
* Modify the command lookup path, if a PATH= assignment
* is present
*/
- for (sp = varlist.list ; sp ; sp = sp->next)
+ for (sp = varlist.list; sp; sp = sp->next)
if (varequal(sp->text, defpathvar)) {
path = sp->text + 5;
findflag |= DO_BRUTE;
oldpath = path;
oldfindflag = findflag;
firstbltin = 0;
- for(;;) {
+ for (;;) {
find_command(argv[0], &cmdentry, findflag, path);
- if (cmdentry.cmdtype == CMDUNKNOWN) { /* command not found */
+ if (cmdentry.cmdtype == CMDUNKNOWN) { /* command not found */
exitstatus = 127;
goto out;
}
firstbltin = cmdentry.u.cmd;
}
if (cmdentry.u.cmd == BLTINCMD) {
- for(;;) {
+ for (;;) {
struct builtincmd *bcmd;
argv++;
findflag |= DO_NOFUN;
continue;
}
-found:
+ found:
break;
}
}
/* Fork off a child process if necessary. */
if (cmd->ncmd.backgnd
- || (cmdentry.cmdtype == CMDNORMAL && (flags & EV_EXIT) == 0)
- ) {
+ || (cmdentry.cmdtype == CMDNORMAL && (flags & EV_EXIT) == 0)
+ ) {
jp = makejob(cmd, 1);
mode = cmd->ncmd.backgnd;
if (forkshell(jp, cmd, mode) != 0)
- goto parent; /* at end of routine */
+ goto parent; /* at end of routine */
flags |= EV_EXIT;
}
/* Execute the command. */
if (cmdentry.cmdtype == CMDFUNCTION) {
#ifdef DEBUG
- trputs("Shell function: "); trargs(argv);
+ trputs("Shell function: ");
+ trargs(argv);
#endif
exitstatus = oexitstatus;
redirect(cmd->ncmd.redirect, REDIR_PUSH);
if (setjmp(jmploc.loc)) {
if (exception == EXSHELLPROC) {
freeparam((volatile struct shparam *)
- &saveparam);
+ &saveparam);
} else {
saveparam.optind = shellparam.optind;
saveparam.optoff = shellparam.optoff;
}
savehandler = handler;
handler = &jmploc;
- for (sp = varlist.list ; sp ; sp = sp->next)
+ for (sp = varlist.list; sp; sp = sp->next)
mklocal(sp->text);
funcnest++;
evaltree(cmdentry.u.func, flags & EV_TESTED);
exitshell(exitstatus);
} else if (cmdentry.cmdtype == CMDBUILTIN) {
#ifdef DEBUG
- trputs("builtin command: "); trargs(argv);
+ trputs("builtin command: ");
+ trargs(argv);
#endif
- mode = (cmdentry.u.cmd == EXECCMD)? 0 : REDIR_PUSH;
+ mode = (cmdentry.u.cmd == EXECCMD) ? 0 : REDIR_PUSH;
redirect(cmd->ncmd.redirect, mode);
savecmdname = commandname;
if (IS_BUILTIN_SPECIAL(firstbltin)) {
e = -1;
if (setjmp(jmploc.loc)) {
e = exception;
- exitstatus = (e == EXINT)? SIGINT+128 : 2;
+ exitstatus = (e == EXINT) ? SIGINT + 128 : 2;
goto cmddone;
}
savehandler = handler;
handler = &jmploc;
commandname = argv[0];
argptr = argv + 1;
- optptr = NULL; /* initialize nextopt */
- exitstatus = (*cmdentry.u.cmd->builtinfunc)(argc, argv);
+ optptr = NULL; /* initialize nextopt */
+ exitstatus = (*cmdentry.u.cmd->builtinfunc) (argc, argv);
flushall();
-cmddone:
+ cmddone:
cmdenviron = NULL;
if (e != EXSHELLPROC) {
commandname = savecmdname;
handler = savehandler;
if (e != -1) {
if ((e != EXERROR && e != EXEXEC)
- || cmdentry.u.cmd == BLTINCMD
- || cmdentry.u.cmd == DOTCMD
- || cmdentry.u.cmd == EVALCMD
- || cmdentry.u.cmd == EXECCMD)
+ || cmdentry.u.cmd == BLTINCMD
+ || cmdentry.u.cmd == DOTCMD
+ || cmdentry.u.cmd == EVALCMD || cmdentry.u.cmd == EXECCMD)
exraise(e);
FORCEINTON;
}
popredir();
} else {
#ifdef DEBUG
- trputs("normal command: "); trargs(argv);
+ trputs("normal command: ");
+ trargs(argv);
#endif
redirect(cmd->ncmd.redirect, 0);
clearredir();
- for (sp = varlist.list ; sp ; sp = sp->next)
- setvareq(sp->text, VEXPORT|VSTACK);
+ for (sp = varlist.list; sp; sp = sp->next)
+ setvareq(sp->text, VEXPORT | VSTACK);
envp = environment();
shellexec(argv, envp, path, cmdentry.u.index);
}
goto out;
-parent: /* parent process gets here (if we forked) */
- if (mode == 0) { /* argument to fork */
+ parent: /* parent process gets here (if we forked) */
+ if (mode == 0) { /* argument to fork */
INTOFF;
exitstatus = waitforjob(jp);
INTON;
}
-out:
+ out:
if (lastarg)
setvar("_", lastarg, 0);
popstackmark(&smark);
* Evaluate a parse tree. The value is left in the global variable
* exitstatus.
*/
-static void
-evaltree(union node *n, int flags)
+static void evaltree(union node *n, int flags)
{
int checkexit = 0;
+
if (n == NULL) {
TRACE(("evaltree(NULL) called\n"));
goto out;
}
- TRACE(("evaltree(0x%lx: %d) called\n", (long)n, n->type));
+ TRACE(("evaltree(0x%lx: %d) called\n", (long) n, n->type));
switch (n->type) {
case NSEMI:
evaltree(n->nbinary.ch1, flags & EV_TESTED);
case NBACKGND:
evalsubshell(n, flags);
break;
- case NIF: {
+ case NIF:{
evaltree(n->nif.test, EV_TESTED);
if (evalskip)
goto out;
case NCASE:
evalcase(n, flags);
break;
- case NDEFUN: {
+ case NDEFUN:{
struct builtincmd *bcmd;
struct cmdentry entry;
- if (
- (bcmd = find_builtin(n->narg.text)) &&
- IS_BUILTIN_SPECIAL(bcmd)
- ) {
+
+ if ((bcmd = find_builtin(n->narg.text)) && IS_BUILTIN_SPECIAL(bcmd)
+ ) {
out2fmt("%s is a special built-in\n", n->narg.text);
exitstatus = 1;
break;
break;
#endif
}
-out:
+ out:
if (pendingsigs)
dotrap();
- if (
- flags & EV_EXIT ||
+ if (flags & EV_EXIT ||
(checkexit && eflag && exitstatus && !(flags & EV_TESTED))
- )
+ )
exitshell(exitstatus);
}
* Kick off a subshell to evaluate a tree.
*/
-static void
-evalsubshell(const union node *n, int flags)
+static void evalsubshell(const union node *n, int flags)
{
struct job *jp;
int backgnd = (n->type == NBACKGND);
jp = makejob(n, 1);
if (forkshell(jp, n, backgnd) == 0) {
if (backgnd)
- flags &=~ EV_TESTED;
+ flags &= ~EV_TESTED;
redirect(n->nredir.redirect, 0);
- evaltree(n->nredir.n, flags | EV_EXIT); /* never returns */
+ evaltree(n->nredir.n, flags | EV_EXIT); /* never returns */
}
- if (! backgnd) {
+ if (!backgnd) {
INTOFF;
exitstatus = waitforjob(jp);
INTON;
static void fixredir(union node *n, const char *text, int err);
-static void
-expredir(union node *n)
+static void expredir(union node *n)
{
union node *redir;
- for (redir = n ; redir ; redir = redir->nfile.next) {
+ for (redir = n; redir; redir = redir->nfile.next) {
struct arglist fn;
+
fn.lastp = &fn.list;
oexitstatus = exitstatus;
switch (redir->type) {
* Should be called with interrupts off.
*/
-static void
-evalbackcmd(union node *n, struct backcmd *result)
+static void evalbackcmd(union node *n, struct backcmd *result)
{
int pip[2];
struct job *jp;
- struct stackmark smark; /* unnecessary */
+ struct stackmark smark; /* unnecessary */
setstackmark(&smark);
result->fd = -1;
close(pip[1]);
result->fd = pip[0];
result->jp = jp;
-out:
+ out:
popstackmark(&smark);
TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n",
- result->fd, result->buf, result->nleft, result->jp));
+ result->fd, result->buf, result->nleft, result->jp));
}
* specified variables.
*/
-int
-bltincmd(int argc, char **argv)
+int bltincmd(int argc, char **argv)
{
/*
* Preserve exitstatus of a previous possible redirection
* in the standard shell so we don't make it one here.
*/
-static int
-breakcmd(int argc, char **argv)
+static int breakcmd(int argc, char **argv)
{
int n = argc > 1 ? number(argv[1]) : 1;
if (n > loopnest)
n = loopnest;
if (n > 0) {
- evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK;
+ evalskip = (**argv == 'c') ? SKIPCONT : SKIPBREAK;
skipcount = n;
}
return 0;
* The return command.
*/
-static int
-returncmd(int argc, char **argv)
+static int returncmd(int argc, char **argv)
{
int ret = argc > 1 ? number(argv[1]) : oexitstatus;
evalskip = SKIPFUNC;
skipcount = 1;
return ret;
- }
- else {
+ } else {
/* Do what ksh does; skip the rest of the file */
evalskip = SKIPFILE;
skipcount = 1;
#ifndef CONFIG_FALSE
-static int
-false_main(int argc, char **argv)
+static int false_main(int argc, char **argv)
{
return 1;
}
#endif
#ifndef CONFIG_TRUE
-static int
-true_main(int argc, char **argv)
+static int true_main(int argc, char **argv)
{
return 0;
}
static void chkmail(int silent);
#endif
-static void
-setinteractive(int on)
+static void setinteractive(int on)
{
static int is_interactive;
- static int do_banner=0;
+ static int do_banner = 0;
if (on == is_interactive)
return;
chkmail(1);
#endif
is_interactive = on;
- if (do_banner==0 && is_interactive) {
+ if (do_banner == 0 && is_interactive) {
/* Looks like they want an interactive shell */
-#ifndef CONFIG_FEATURE_SH_EXTRA_QUIET
- printf( "\n\n" BB_BANNER " Built-in shell (ash)\n");
- printf( "Enter 'help' for a list of built-in commands.\n\n");
+#ifndef CONFIG_FEATURE_SH_EXTRA_QUIET
+ printf("\n\n" BB_BANNER " Built-in shell (ash)\n");
+ printf("Enter 'help' for a list of built-in commands.\n\n");
#endif
- do_banner=1;
+ do_banner = 1;
}
}
-static void
-optschanged(void)
+static void optschanged(void)
{
setinteractive(iflag);
setjobctl(mflag);
}
-static int
-execcmd(int argc, char **argv)
+static int execcmd(int argc, char **argv)
{
if (argc > 1) {
struct strlist *sp;
- iflag = 0; /* exit on error */
+ iflag = 0; /* exit on error */
mflag = 0;
optschanged();
- for (sp = cmdenviron; sp ; sp = sp->next)
- setvareq(sp->text, VEXPORT|VSTACK);
+ for (sp = cmdenviron; sp; sp = sp->next)
+ setvareq(sp->text, VEXPORT | VSTACK);
shellexec(argv + 1, environment(), pathval(), 0);
}
return 0;
}
-static void
-eprintlist(struct strlist *sp)
+static void eprintlist(struct strlist *sp)
{
for (; sp; sp = sp->next) {
- out2fmt(" %s",sp->text);
+ out2fmt(" %s", sp->text);
}
}
* have to change the find_command routine as well.
*/
-static const char *pathopt; /* set by padvance */
+static const char *pathopt; /* set by padvance */
-static void
-shellexec(char **argv, char **envp, const char *path, int idx)
+static void shellexec(char **argv, char **envp, const char *path, int idx)
{
char *cmdname;
int e;
/*
* Clear traps on a fork.
*/
-static void
-clear_traps(void)
+static void clear_traps(void)
{
char **tp;
- for (tp = trap ; tp < &trap[NSIG] ; tp++) {
- if (*tp && **tp) { /* trap not NULL or SIG_IGN */
+ for (tp = trap; tp < &trap[NSIG]; tp++) {
+ if (*tp && **tp) { /* trap not NULL or SIG_IGN */
INTOFF;
free(*tp);
*tp = NULL;
}
-static void
-initshellproc(void)
+static void initshellproc(void)
{
#ifdef CONFIG_ASH_ALIAS
- /* from alias.c: */
- {
- rmaliases();
- }
-#endif
- /* from eval.c: */
- {
- exitstatus = 0;
- }
-
- /* from exec.c: */
- {
- deletefuncs();
- }
-
- /* from jobs.c: */
- {
- backgndpid = -1;
+ /* from alias.c: */
+ {
+ rmaliases();
+ }
+#endif
+ /* from eval.c: */
+ {
+ exitstatus = 0;
+ }
+
+ /* from exec.c: */
+ {
+ deletefuncs();
+ }
+
+ /* from jobs.c: */
+ {
+ backgndpid = -1;
#ifdef CONFIG_ASH_JOB_CONTROL
- jobctl = 0;
+ jobctl = 0;
#endif
- }
+ }
- /* from options.c: */
- {
- int i;
+ /* from options.c: */
+ {
+ int i;
- for (i = 0; i < NOPTS; i++)
- optent_val(i) = 0;
- optschanged();
+ for (i = 0; i < NOPTS; i++)
+ optent_val(i) = 0;
+ optschanged();
- }
+ }
- /* from redir.c: */
- {
- clearredir();
- }
+ /* from redir.c: */
+ {
+ clearredir();
+ }
- /* from trap.c: */
- {
- char *sm;
+ /* from trap.c: */
+ {
+ char *sm;
- clear_traps();
- for (sm = sigmode ; sm < sigmode + NSIG - 1; sm++) {
- if (*sm == S_IGN)
- *sm = S_HARD_IGN;
- }
- }
+ clear_traps();
+ for (sm = sigmode; sm < sigmode + NSIG - 1; sm++) {
+ if (*sm == S_IGN)
+ *sm = S_HARD_IGN;
+ }
+ }
- /* from var.c: */
- {
- shprocvar();
- }
+ /* from var.c: */
+ {
+ shprocvar();
+ }
}
static int preadbuffer(void);
-static void pushfile (void);
+static void pushfile(void);
/*
* Read a character from the script, returning PEOF on end of file.
#ifndef CONFIG_ASH_OPTIMIZE_FOR_SIZE
#define pgetc_macro() (--parsenleft >= 0? *parsenextc++ : preadbuffer())
-static int
-pgetc(void)
+static int pgetc(void)
{
return pgetc_macro();
}
#else
-static int
-pgetc_macro(void)
+static int pgetc_macro(void)
{
- return --parsenleft >= 0? *parsenextc++ : preadbuffer();
+ return --parsenleft >= 0 ? *parsenextc++ : preadbuffer();
}
-static inline int
-pgetc(void)
+static inline int pgetc(void)
{
return pgetc_macro();
}
* PEOF may be pushed back.
*/
-static void pungetc(void)
+static void pungetc(void)
{
parsenleft++;
parsenextc--;
}
-static void
-popfile(void)
+static void popfile(void)
{
struct parsefile *pf = parsefile;
* Return to top level.
*/
-static void
-popallfiles(void)
+static void popallfiles(void)
{
while (parsefile != &basepf)
popfile();
* after a fork is done.
*/
-static void closescript(void)
+static void closescript(void)
{
popallfiles();
if (parsefile->fd > 0) {
* old input onto the stack first.
*/
-static void
-setinputfile(const char *fname, int push)
+static void setinputfile(const char *fname, int push)
{
int fd;
int myfileno2;
}
-static void
-tryexec(char *cmd, char **argv, char **envp)
+static void tryexec(char *cmd, char **argv, char **envp)
{
int e;
#ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL
char *name = cmd;
- char** argv_l=argv;
+ char **argv_l = argv;
int argc_l;
+
#ifdef CONFIG_FEATURE_SH_APPLETS_ALWAYS_WIN
name = get_last_path_component(name);
#endif
- argv_l=envp;
- for(argc_l=0;*argv_l!=NULL; argv_l++, argc_l++)
+ argv_l = envp;
+ for (argc_l = 0; *argv_l != NULL; argv_l++, argc_l++)
putenv(*argv_l);
- argv_l=argv;
- for(argc_l=0;*argv_l!=NULL; argv_l++, argc_l++)
- optind = 1;
+ argv_l = argv;
+ for (argc_l = 0; *argv_l != NULL; argv_l++, argc_l++)
+ optind = 1;
run_applet_by_name(name, argc_l, argv);
#endif
execve(cmd, argv, envp);
errno = e;
}
-static char *commandtext (const union node *);
+static char *commandtext(const union node *);
/*
* Do a path search. The variable path (passed by reference) should be
static void growstackblock(void);
-static char *
-padvance(const char **path, const char *name)
+static char *padvance(const char **path, const char *name)
{
const char *p;
char *q;
if (*path == NULL)
return NULL;
start = *path;
- for (p = start ; *p && *p != ':' && *p != '%' ; p++);
- len = p - start + strlen(name) + 2; /* "2" is for '/' and '\0' */
+ for (p = start; *p && *p != ':' && *p != '%'; p++);
+ len = p - start + strlen(name) + 2; /* "2" is for '/' and '\0' */
while (stackblocksize() < len)
growstackblock();
q = stackblock();
pathopt = NULL;
if (*p == '%') {
pathopt = ++p;
- while (*p && *p != ':') p++;
+ while (*p && *p != ':')
+ p++;
}
if (*p == ':')
*path = p + 1;
/*
* Wrapper around strcmp for qsort/bsearch/...
*/
-static int
-pstrcmp(const void *a, const void *b)
+static int pstrcmp(const void *a, const void *b)
{
return strcmp((const char *) a, (*(const char *const *) b) + 1);
}
* Find a keyword is in a sorted array.
*/
-static const char *const *
-findkwd(const char *s)
+static const char *const *findkwd(const char *s)
{
- return bsearch(s, tokname_array + KWDOFFSET,
- (sizeof(tokname_array)/sizeof(const char *)) - KWDOFFSET,
- sizeof(const char *), pstrcmp);
+ return bsearch(s, tokname_array + KWDOFFSET,
+ (sizeof(tokname_array) / sizeof(const char *)) - KWDOFFSET,
+ sizeof(const char *), pstrcmp);
}
/*** Command hashing code ***/
-static int
-hashcmd(int argc, char **argv)
+static int hashcmd(int argc, char **argv)
{
struct tblentry **pp;
struct tblentry *cmdp;
int verbose;
struct cmdentry entry;
char *name;
+
#ifdef CONFIG_ASH_ALIAS
const struct alias *ap;
#endif
}
}
if (*argptr == NULL) {
- for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
- for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
+ for (pp = cmdtable; pp < &cmdtable[CMDTABLESIZE]; pp++) {
+ for (cmdp = *pp; cmdp; cmdp = cmdp->next) {
if (cmdp->cmdtype != CMDBUILTIN) {
printentry(cmdp, verbose);
}
c = 0;
while ((name = *argptr++) != NULL) {
if ((cmdp = cmdlookup(name, 0)) != NULL
- && (cmdp->cmdtype == CMDNORMAL
- || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0)))
+ && (cmdp->cmdtype == CMDNORMAL
+ || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0)))
delete_cmd_entry();
#ifdef CONFIG_ASH_ALIAS
- /* Then look at the aliases */
+ /* Then look at the aliases */
if ((ap = *__lookupalias(name)) != NULL) {
- if (verbose=='v')
+ if (verbose == 'v')
printf("%s is an alias for %s\n", name, ap->val);
else
printalias(ap);
continue;
}
#endif
- /* First look at the keywords */
- if (findkwd(name)!=0) {
- if (verbose=='v')
+ /* First look at the keywords */
+ if (findkwd(name) != 0) {
+ if (verbose == 'v')
printf("%s is a shell keyword\n", name);
else
puts(name);
}
find_command(name, &entry, DO_ERR, pathval());
- if (entry.cmdtype == CMDUNKNOWN) c = 1;
+ if (entry.cmdtype == CMDUNKNOWN)
+ c = 1;
else if (verbose) {
cmdp = cmdlookup(name, 0);
- if (cmdp) printentry(cmdp, verbose=='v');
+ if (cmdp)
+ printentry(cmdp, verbose == 'v');
flushall();
}
}
return c;
}
-static void
-printentry(struct tblentry *cmdp, int verbose)
+static void printentry(struct tblentry *cmdp, int verbose)
{
int idx;
const char *path;
name = padvance(&path, cmdp->cmdname);
stunalloc(name);
} while (--idx >= 0);
- if(verbose)
+ if (verbose)
out1str(name);
} else if (cmdp->cmdtype == CMDBUILTIN) {
- if(verbose)
+ if (verbose)
out1str("a shell builtin");
} else if (cmdp->cmdtype == CMDFUNCTION) {
if (verbose) {
/*** List the available builtins ***/
-static int helpcmd(int argc, char** argv)
+static int helpcmd(int argc, char **argv)
{
int col, i;
printf("\nBuilt-in commands:\n-------------------\n");
- for (col=0, i=0; i < NUMBUILTINS; i++) {
+ for (col = 0, i = 0; i < NUMBUILTINS; i++) {
col += printf("%c%s", ((col == 0) ? '\t' : ' '),
- builtincmds[i].name+1);
+ builtincmds[i].name + 1);
if (col > 60) {
printf("\n");
col = 0;
extern const struct BB_applet applets[];
extern const size_t NUM_APPLETS;
- for (i=0; i < NUM_APPLETS; i++) {
+ for (i = 0; i < NUM_APPLETS; i++) {
- col += printf("%c%s", ((col == 0) ? '\t' : ' '),
- applets[i].name);
+ col += printf("%c%s", ((col == 0) ? '\t' : ' '), applets[i].name);
if (col > 60) {
printf("\n");
col = 0;
* change the shellexec routine as well.
*/
-static int prefix (const char *, const char *);
+static int prefix(const char *, const char *);
static void
-find_command(const char *name, struct cmdentry *entry, int act, const char *path)
+find_command(const char *name, struct cmdentry *entry, int act,
+ const char *path)
{
struct tblentry *cmdp;
int idx;
}
} else if (act & DO_BRUTE) {
if ((cmdp->cmdtype == CMDNORMAL &&
- cmdp->param.index >= firstchange) ||
- (cmdp->cmdtype == CMDBUILTIN &&
- ((builtinloc < 0 && bltin >= 0) ?
- bltin : builtinloc) >= firstchange)) {
+ cmdp->param.index >= firstchange) ||
+ (cmdp->cmdtype == CMDBUILTIN &&
+ ((builtinloc < 0 && bltin >= 0) ?
+ bltin : builtinloc) >= firstchange)) {
/* need to recompute the entry */
} else {
goto success;
/* If %builtin not in path, check for builtin next */
if (regular || (bltin < 0 && bcmd)) {
-builtin:
+ builtin:
if (!updatetbl) {
entry->cmdtype = CMDBUILTIN;
entry->u.cmd = bcmd;
}
/* We have to search path. */
- prev = -1; /* where to start */
- if (cmdp && cmdp->rehash) { /* doing a rehash */
+ prev = -1; /* where to start */
+ if (cmdp && cmdp->rehash) { /* doing a rehash */
if (cmdp->cmdtype == CMDBUILTIN)
prev = builtinloc;
else
e = ENOENT;
idx = -1;
-loop:
+ loop:
while ((fullname = padvance(&path, name)) != NULL) {
stunalloc(fullname);
idx++;
goto builtin;
}
continue;
- } else if (!(act & DO_NOFUN) &&
- prefix("func", pathopt)) {
+ } else if (!(act & DO_NOFUN) && prefix("func", pathopt)) {
/* handled below */
} else {
- continue; /* ignore unimplemented options */
+ continue; /* ignore unimplemented options */
}
}
/* if rehash, don't redo absolute path names */
- if (fullname[0] == '/' && idx <= prev &&
- idx < firstchange) {
+ if (fullname[0] == '/' && idx <= prev && idx < firstchange) {
if (idx < prev)
continue;
TRACE(("searchexec \"%s\": no change\n", name));
e = errno;
goto loop;
}
- e = EACCES; /* if we fail, this will be the error */
+ e = EACCES; /* if we fail, this will be the error */
if (!S_ISREG(statb.st_mode))
continue;
- if (pathopt) { /* this is a %func directory */
+ if (pathopt) { /* this is a %func directory */
stalloc(strlen(fullname) + 1);
readcmdfile(fullname);
- if ((cmdp = cmdlookup(name, 0)) == NULL || cmdp->cmdtype != CMDFUNCTION)
+ if ((cmdp = cmdlookup(name, 0)) == NULL
+ || cmdp->cmdtype != CMDFUNCTION)
error("%s not defined in %s", name, fullname);
stunalloc(fullname);
goto success;
entry->cmdtype = CMDUNKNOWN;
return;
-success:
+ success:
cmdp->rehash = 0;
entry->cmdtype = cmdp->cmdtype;
entry->u = cmdp->param;
* Search the table of builtin commands.
*/
-static int
-bstrcmp(const void *name, const void *b)
+static int bstrcmp(const void *name, const void *b)
{
- return strcmp((const char *)name, (*(const char *const *) b)+1);
+ return strcmp((const char *) name, (*(const char *const *) b) + 1);
}
-static struct builtincmd *
-find_builtin(const char *name)
+static struct builtincmd *find_builtin(const char *name)
{
struct builtincmd *bp;
bp = bsearch(name, builtincmds, NUMBUILTINS, sizeof(struct builtincmd),
- bstrcmp
- );
+ bstrcmp);
return bp;
}
* are executed they will be rehashed.
*/
-static inline void
-hashcd(void)
+static inline void hashcd(void)
{
struct tblentry **pp;
struct tblentry *cmdp;
- for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
- for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
+ for (pp = cmdtable; pp < &cmdtable[CMDTABLESIZE]; pp++) {
+ for (cmdp = *pp; cmdp; cmdp = cmdp->next) {
if (cmdp->cmdtype == CMDNORMAL
- || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0))
+ || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0))
cmdp->rehash = 1;
}
}
* interrupts off.
*/
-static void
-changepath(const char *newval)
+static void changepath(const char *newval)
{
int firstchange;
int bltin;
firstchange = path_change(newval, &bltin);
if (builtinloc < 0 && bltin >= 0)
- builtinloc = bltin; /* zap builtins */
+ builtinloc = bltin; /* zap builtins */
clearcmdentry(firstchange);
builtinloc = bltin;
/* Ensure that getenv("PATH") stays current */
* PATH which has changed.
*/
-static void
-clearcmdentry(int firstchange)
+static void clearcmdentry(int firstchange)
{
struct tblentry **tblp;
struct tblentry **pp;
struct tblentry *cmdp;
INTOFF;
- for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) {
+ for (tblp = cmdtable; tblp < &cmdtable[CMDTABLESIZE]; tblp++) {
pp = tblp;
while ((cmdp = *pp) != NULL) {
if ((cmdp->cmdtype == CMDNORMAL &&
- cmdp->param.index >= firstchange)
- || (cmdp->cmdtype == CMDBUILTIN &&
- builtinloc >= firstchange)) {
+ cmdp->param.index >= firstchange)
+ || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= firstchange)) {
*pp = cmdp->next;
free(cmdp);
} else {
* Delete all functions.
*/
-static void
-deletefuncs(void)
+static void deletefuncs(void)
{
struct tblentry **tblp;
struct tblentry **pp;
struct tblentry *cmdp;
INTOFF;
- for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) {
+ for (tblp = cmdtable; tblp < &cmdtable[CMDTABLESIZE]; tblp++) {
pp = tblp;
while ((cmdp = *pp) != NULL) {
if (cmdp->cmdtype == CMDFUNCTION) {
static struct tblentry **lastcmdentry;
-static struct tblentry *
-cmdlookup(const char *name, int add)
+static struct tblentry *cmdlookup(const char *name, int add)
{
int hashval;
const char *p;
hashval += *p++;
hashval &= 0x7FFF;
pp = &cmdtable[hashval % CMDTABLESIZE];
- for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
+ for (cmdp = *pp; cmdp; cmdp = cmdp->next) {
if (equal(cmdp->cmdname, name))
break;
pp = &cmdp->next;
}
if (add && cmdp == NULL) {
INTOFF;
- cmdp = *pp = xmalloc(sizeof (struct tblentry) - ARB
- + strlen(name) + 1);
+ cmdp = *pp = xmalloc(sizeof(struct tblentry) - ARB
+ + strlen(name) + 1);
cmdp->next = NULL;
cmdp->cmdtype = CMDUNKNOWN;
cmdp->rehash = 0;
* Delete the command entry returned on the last lookup.
*/
-static void
-delete_cmd_entry()
+static void delete_cmd_entry()
{
struct tblentry *cmdp;
static const unsigned char nodesize[26] = {
- ALIGN(sizeof (struct nbinary)),
- ALIGN(sizeof (struct ncmd)),
- ALIGN(sizeof (struct npipe)),
- ALIGN(sizeof (struct nredir)),
- ALIGN(sizeof (struct nredir)),
- ALIGN(sizeof (struct nredir)),
- ALIGN(sizeof (struct nbinary)),
- ALIGN(sizeof (struct nbinary)),
- ALIGN(sizeof (struct nif)),
- ALIGN(sizeof (struct nbinary)),
- ALIGN(sizeof (struct nbinary)),
- ALIGN(sizeof (struct nfor)),
- ALIGN(sizeof (struct ncase)),
- ALIGN(sizeof (struct nclist)),
- ALIGN(sizeof (struct narg)),
- ALIGN(sizeof (struct narg)),
- ALIGN(sizeof (struct nfile)),
- ALIGN(sizeof (struct nfile)),
- ALIGN(sizeof (struct nfile)),
- ALIGN(sizeof (struct nfile)),
- ALIGN(sizeof (struct nfile)),
- ALIGN(sizeof (struct ndup)),
- ALIGN(sizeof (struct ndup)),
- ALIGN(sizeof (struct nhere)),
- ALIGN(sizeof (struct nhere)),
- ALIGN(sizeof (struct nnot)),
+ ALIGN(sizeof(struct nbinary)),
+ ALIGN(sizeof(struct ncmd)),
+ ALIGN(sizeof(struct npipe)),
+ ALIGN(sizeof(struct nredir)),
+ ALIGN(sizeof(struct nredir)),
+ ALIGN(sizeof(struct nredir)),
+ ALIGN(sizeof(struct nbinary)),
+ ALIGN(sizeof(struct nbinary)),
+ ALIGN(sizeof(struct nif)),
+ ALIGN(sizeof(struct nbinary)),
+ ALIGN(sizeof(struct nbinary)),
+ ALIGN(sizeof(struct nfor)),
+ ALIGN(sizeof(struct ncase)),
+ ALIGN(sizeof(struct nclist)),
+ ALIGN(sizeof(struct narg)),
+ ALIGN(sizeof(struct narg)),
+ ALIGN(sizeof(struct nfile)),
+ ALIGN(sizeof(struct nfile)),
+ ALIGN(sizeof(struct nfile)),
+ ALIGN(sizeof(struct nfile)),
+ ALIGN(sizeof(struct nfile)),
+ ALIGN(sizeof(struct ndup)),
+ ALIGN(sizeof(struct ndup)),
+ ALIGN(sizeof(struct nhere)),
+ ALIGN(sizeof(struct nhere)),
+ ALIGN(sizeof(struct nnot)),
};
* Delete a function if it exists.
*/
-static void
-unsetfunc(char *name)
+static void unsetfunc(char *name)
{
struct tblentry *cmdp;
* Locate and print what a word is...
*/
-static int
-typecmd(int argc, char **argv)
+static int typecmd(int argc, char **argv)
{
int i;
int err = 0;
}
#ifdef CONFIG_ASH_CMDCMD
-static int
-commandcmd(int argc, char **argv)
+static int commandcmd(int argc, char **argv)
{
int c;
int default_path = 0;
break;
}
- if (default_path + verify_only + verbose_verify_only > 1 ||
- !*argptr) {
- out2str(
- "command [-p] command [arg ...]\n"
+ if (default_path + verify_only + verbose_verify_only > 1 || !*argptr) {
+ out2str("command [-p] command [arg ...]\n"
"command {-v|-V} command\n");
- return EX_USAGE;
+ return EX_USAGE;
}
if (verify_only || verbose_verify_only) {
argv_a[1] = 0;
argv_a[0] = *argptr;
argptr = argv_a;
- optptr = verbose_verify_only ? "v" : "V"; /* reverse special */
+ optptr = verbose_verify_only ? "v" : "V"; /* reverse special */
return hashcmd(argc, argv);
}
}
#endif
-static int
-path_change(const char *newval, int *bltin)
+static int path_change(const char *newval, int *bltin)
{
const char *old, *new;
int idx;
old = pathval();
new = newval;
- firstchange = 9999; /* assume no change */
+ firstchange = 9999; /* assume no change */
idx = 0;
*bltin = -1;
for (;;) {
if (*old != *new) {
firstchange = idx;
if ((*old == '\0' && *new == ':')
- || (*old == ':' && *new == '\0'))
+ || (*old == ':' && *new == '\0'))
firstchange++;
- old = new; /* ignore subsequent differences */
+ old = new; /* ignore subsequent differences */
}
if (*new == '\0')
break;
firstchange = 0;
return firstchange;
}
+
/*
* Routines to expand arguments to commands. We have to deal with
* backquotes, shell variables, and file metacharacters.
/*
* _rmescape() flags
*/
-#define RMESCAPE_ALLOC 0x1 /* Allocate a new string */
-#define RMESCAPE_GLOB 0x2 /* Add backslashes for glob */
+#define RMESCAPE_ALLOC 0x1 /* Allocate a new string */
+#define RMESCAPE_GLOB 0x2 /* Add backslashes for glob */
/*
* Structure specifying which parts of the string should be searched
*/
struct ifsregion {
- struct ifsregion *next; /* next region in list */
- int begoff; /* offset of start of region */
- int endoff; /* offset of end of region */
- int nulonly; /* search for nul bytes only */
+ struct ifsregion *next; /* next region in list */
+ int begoff; /* offset of start of region */
+ int endoff; /* offset of end of region */
+ int nulonly; /* search for nul bytes only */
};
-static char *expdest; /* output of current string */
-static struct nodelist *argbackq; /* list of back quote expressions */
-static struct ifsregion ifsfirst; /* first struct in list of ifs regions */
-static struct ifsregion *ifslastp; /* last struct in list */
-static struct arglist exparg; /* holds expanded arg list */
-
-static void argstr (char *, int);
-static char *exptilde (char *, int);
-static void expbackq (union node *, int, int);
-static int subevalvar (char *, char *, int, int, int, int, int);
-static int varisset (char *, int);
-static void strtodest (const char *, int, int);
-static inline void varvalue (char *, int, int);
-static void recordregion (int, int, int);
-static void removerecordregions (int);
-static void ifsbreakup (char *, struct arglist *);
-static void ifsfree (void);
-static void expandmeta (struct strlist *, int);
+static char *expdest; /* output of current string */
+static struct nodelist *argbackq; /* list of back quote expressions */
+static struct ifsregion ifsfirst; /* first struct in list of ifs regions */
+static struct ifsregion *ifslastp; /* last struct in list */
+static struct arglist exparg; /* holds expanded arg list */
+
+static void argstr(char *, int);
+static char *exptilde(char *, int);
+static void expbackq(union node *, int, int);
+static int subevalvar(char *, char *, int, int, int, int, int);
+static int varisset(char *, int);
+static void strtodest(const char *, int, int);
+static inline void varvalue(char *, int, int);
+static void recordregion(int, int, int);
+static void removerecordregions(int);
+static void ifsbreakup(char *, struct arglist *);
+static void ifsfree(void);
+static void expandmeta(struct strlist *, int);
+
#if defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN)
#define preglob(p) _rmescapes((p), RMESCAPE_ALLOC | RMESCAPE_GLOB)
#if !defined(GLOB_BROKEN)
-static inline void addglob (const glob_t *);
+static inline void addglob(const glob_t *);
#endif
#endif
#if !(defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN))
-static void expmeta (char *, char *);
+static void expmeta(char *, char *);
#endif
#if !(defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN))
-static struct strlist *expsort (struct strlist *);
-static struct strlist *msort (struct strlist *, int);
+static struct strlist *expsort(struct strlist *);
+static struct strlist *msort(struct strlist *, int);
#endif
-static int patmatch (char *, char *, int);
+static int patmatch(char *, char *, int);
+
#if defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN)
-static int patmatch2 (char *, char *, int);
+static int patmatch2(char *, char *, int);
#else
-static int pmatch (char *, char *, int);
+static int pmatch(char *, char *, int);
+
#define patmatch2 patmatch
#endif
-static char *cvtnum (int, char *);
+static char *cvtnum(int, char *);
/*
* Expand shell variables and backquotes inside a here document.
*/
/* arg: the document, fd: where to write the expanded version */
-static inline void
-expandhere(union node *arg, int fd)
+static inline void expandhere(union node *arg, int fd)
{
herefd = fd;
- expandarg(arg, (struct arglist *)NULL, 0);
+ expandarg(arg, (struct arglist *) NULL, 0);
xwrite(fd, stackblock(), expdest - stackblock());
}
* here document expansion.
*/
-static void
-expandarg(union node *arg, struct arglist *arglist, int flag)
+static void expandarg(union node *arg, struct arglist *arglist, int flag)
{
struct strlist *sp;
char *p;
ifslastp = NULL;
argstr(arg->narg.text, flag);
if (arglist == NULL) {
- return; /* here document expanded */
+ return; /* here document expanded */
}
STPUTC('\0', expdest);
p = grabstackstr(expdest);
exparg.lastp = &exparg.list;
expandmeta(exparg.list, flag);
} else {
- if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */
+ if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */
rmescapes(p);
- sp = (struct strlist *)stalloc(sizeof (struct strlist));
+ sp = (struct strlist *) stalloc(sizeof(struct strlist));
sp->text = p;
*exparg.lastp = sp;
exparg.lastp = &sp->next;
* input string.
*/
-static inline char * evalvar(char *p, int flag)
+static inline char *evalvar(char *p, int flag)
{
int subtype;
int varflags;
subtype = varflags & VSTYPE;
var = p;
special = 0;
- if (! is_name(*p))
+ if (!is_name(*p))
special = 1;
p = strchr(p, '=') + 1;
-again: /* jump here after setting a variable with ${var=text} */
+ again: /* jump here after setting a variable with ${var=text} */
if (special) {
set = varisset(var, varflags & VSNUL);
val = NULL;
if (subtype == VSLENGTH) {
varlen = strlen(val);
} else {
- strtodest(
- val,
- varflags & VSQUOTE ?
- DQSYNTAX : BASESYNTAX,
- quotes
- );
+ strtodest(val,
+ varflags & VSQUOTE ? DQSYNTAX : BASESYNTAX, quotes);
}
}
}
if (subtype == VSPLUS)
- set = ! set;
+ set = !set;
easy = ((varflags & VSQUOTE) == 0 ||
- (*var == '@' && shellparam.nparam != 1));
+ (*var == '@' && shellparam.nparam != 1));
switch (subtype) {
case VSNORMAL:
if (!easy)
break;
-record:
- recordregion(startloc, expdest - stackblock(),
- varflags & VSQUOTE);
+ record:
+ recordregion(startloc, expdest - stackblock(), varflags & VSQUOTE);
break;
case VSPLUS:
STPUTC('\0', expdest);
patloc = expdest - stackblock();
if (subevalvar(p, NULL, patloc, subtype,
- startloc, varflags, quotes) == 0) {
+ startloc, varflags, quotes) == 0) {
int amount = (expdest - stackblock() - patloc) + 1;
+
STADJUST(-amount, expdest);
}
/* Remove any recorded regions beyond start of variable */
case VSASSIGN:
case VSQUESTION:
if (!set) {
- if (subevalvar(p, var, 0, subtype, startloc,
- varflags, quotes)) {
+ if (subevalvar(p, var, 0, subtype, startloc, varflags, quotes)) {
varflags &= ~VSNUL;
/*
* Remove any recorded regions beyond
#endif
}
- if (subtype != VSNORMAL) { /* skip to end of alternative */
+ if (subtype != VSNORMAL) { /* skip to end of alternative */
int nesting = 1;
+
for (;;) {
if ((c = *p++) == CTLESC)
p++;
- else if (c == CTLBACKQ || c == (CTLBACKQ|CTLQUOTE)) {
+ else if (c == CTLBACKQ || c == (CTLBACKQ | CTLQUOTE)) {
if (set)
argbackq = argbackq->next;
} else if (c == CTLVAR) {
* $@ like $* since no splitting will be performed.
*/
-static void
-argstr(char *p, int flag)
+static void argstr(char *p, int flag)
{
char c;
- int quotes = flag & (EXP_FULL | EXP_CASE); /* do CTLESC */
+ int quotes = flag & (EXP_FULL | EXP_CASE); /* do CTLESC */
int firsteq = 1;
if (*p == '~' && (flag & (EXP_TILDE | EXP_VARTILDE)))
for (;;) {
switch (c = *p++) {
case '\0':
- case CTLENDVAR: /* ??? */
+ case CTLENDVAR: /* ??? */
return;
case CTLQUOTEMARK:
/* "$@" syntax adherence hack */
p = evalvar(p, flag);
break;
case CTLBACKQ:
- case CTLBACKQ|CTLQUOTE:
+ case CTLBACKQ | CTLQUOTE:
expbackq(argbackq->n, c & CTLQUOTE, flag);
argbackq = argbackq->next;
break;
return;
}
-static char *
-exptilde(char *p, int flag)
+static char *exptilde(char *p, int flag)
{
char c, *startp = p;
struct passwd *pw;
int quotes = flag & (EXP_FULL | EXP_CASE);
while ((c = *p) != '\0') {
- switch(c) {
+ switch (c) {
case CTLESC:
return (startp);
case CTLQUOTEMARK:
}
p++;
}
-done:
+ done:
*p = '\0';
- if (*(startp+1) == '\0') {
+ if (*(startp + 1) == '\0') {
if ((home = lookupvar("HOME")) == NULL)
goto lose;
} else {
- if ((pw = getpwnam(startp+1)) == NULL)
+ if ((pw = getpwnam(startp + 1)) == NULL)
goto lose;
home = pw->pw_dir;
}
*p = c;
strtodest(home, SQSYNTAX, quotes);
return (p);
-lose:
+ lose:
*p = c;
return (startp);
}
-static void
-removerecordregions(int endoff)
+static void removerecordregions(int endoff)
{
if (ifslastp == NULL)
return;
if (ifsfirst.endoff > endoff) {
while (ifsfirst.next != NULL) {
struct ifsregion *ifsp;
+
INTOFF;
ifsp = ifsfirst.next->next;
free(ifsfirst.next);
ifslastp = &ifsfirst;
while (ifslastp->next && ifslastp->next->begoff < endoff)
- ifslastp=ifslastp->next;
+ ifslastp = ifslastp->next;
while (ifslastp->next != NULL) {
struct ifsregion *ifsp;
+
INTOFF;
ifsp = ifslastp->next->next;
free(ifslastp->next);
* Expand arithmetic expression. Backup to start of expression,
* evaluate, place result in (backed up) result, adjust string position.
*/
-static void
-expari(int flag)
+static void expari(int flag)
{
char *p, *start;
int errcode;
--p;
if (*p != CTLARI)
error("missing CTLARI (shouldn't happen)");
- if (p > start && *(p-1) == CTLESC)
+ if (p > start && *(p - 1) == CTLESC)
for (p = start; *p != CTLARI; p++)
if (*p == CTLESC)
p++;
if (p[1] == '"')
- quoted=1;
+ quoted = 1;
else
- quoted=0;
+ quoted = 0;
begoff = p - start;
removerecordregions(begoff);
if (quotes)
- rmescapes(p+2);
- result = arith(p+2, &errcode);
+ rmescapes(p + 2);
+ result = arith(p + 2, &errcode);
if (errcode < 0) {
- if(errcode == -2)
+ if (errcode == -2)
error("divide by zero");
else
- error("syntax error: \"%s\"\n", p+2);
+ error("syntax error: \"%s\"\n", p + 2);
}
snprintf(p, 12, "%d", result);
- while (*p++)
- ;
+ while (*p++);
if (quoted == 0)
recordregion(begoff, p - 1 - start, 0);
* Expand stuff in backwards quotes.
*/
-static void
-expbackq(union node *cmd, int quoted, int flag)
+static void expbackq(union node *cmd, int quoted, int flag)
{
volatile struct backcmd in;
int i;
p = grabstackstr(dest);
evalbackcmd(cmd, (struct backcmd *) &in);
ungrabstackstr(p, dest);
-err1:
+ err1:
INTOFF;
ifsfirst = saveifs;
ifslastp = savelastp;
for (; dest > stackblock() && dest[-1] == '\n';)
STUNPUTC(dest);
-err2:
+ err2:
if (in.fd >= 0)
close(in.fd);
free(in.buf);
if (quoted == 0)
recordregion(startloc, dest - stackblock(), 0);
TRACE(("evalbackq: size=%d: \"%.*s\"\n",
- (dest - stackblock()) - startloc,
- (dest - stackblock()) - startloc,
- stackblock() + startloc));
+ (dest - stackblock()) - startloc,
+ (dest - stackblock()) - startloc, stackblock() + startloc));
expdest = dest;
INTON;
}
static int
-subevalvar(char *p, char *str, int strloc, int subtype, int startloc, int varflags, int quotes)
+subevalvar(char *p, char *str, int strloc, int subtype, int startloc,
+ int varflags, int quotes)
{
char *startp;
char *loc = NULL;
argbackq = saveargbackq;
startp = stackblock() + startloc;
if (str == NULL)
- str = stackblock() + strloc;
+ str = stackblock() + strloc;
switch (subtype) {
case VSASSIGN:
case VSQUESTION:
if (*p != CTLENDVAR) {
out2fmt(snlfmt, startp);
- error((char *)NULL);
+ error((char *) NULL);
}
error("%.*s: parameter %snot set", p - str - 1,
- str, (varflags & VSNUL) ? "null or "
- : nullstr);
+ str, (varflags & VSNUL) ? "null or " : nullstr);
/* NOTREACHED */
case VSTRIMLEFT:
#endif
}
-recordleft:
+ recordleft:
*loc = c;
amount = ((str - 1) - (loc - startp)) - expdest;
STADJUST(amount, expdest);
*startp++ = *loc++;
return 1;
-recordright:
+ recordright:
amount = loc - expdest;
STADJUST(amount, expdest);
STPUTC('\0', expdest);
* Test whether a specialized variable is set.
*/
-static int
-varisset(char *name, int nulok)
+static int varisset(char *name, int nulok)
{
if (*name == '!')
return backgndpid != -1;
* Put a string on the stack.
*/
-static void
-strtodest(const char *p, int syntax, int quotes)
+static void strtodest(const char *p, int syntax, int quotes)
{
while (*p) {
- if (quotes && SIT(*p,syntax) == CCTL)
+ if (quotes && SIT(*p, syntax) == CCTL)
STPUTC(CTLESC, expdest);
STPUTC(*p++, expdest);
}
* Add the value of a specialized variable to the stack string.
*/
-static inline void
-varvalue(char *name, int quoted, int flags)
+static inline void varvalue(char *name, int quoted, int flags)
{
int num;
char *p;
goto numvar;
case '!':
num = backgndpid;
-numvar:
+ numvar:
expdest = cvtnum(num, expdest);
break;
case '-':
- for (i = 0 ; i < NOPTS ; i++) {
+ for (i = 0; i < NOPTS; i++) {
if (optent_val(i))
STPUTC(optent_letter(optlist[i]), expdest);
}
}
/* fall through */
case '*':
- sep = ifsset() ? ifsval()[0] : ' ';
+ sep = ifsset()? ifsval()[0] : ' ';
if (quotes) {
- sepq = SIT(sep,syntax) == CCTL;
+ sepq = SIT(sep, syntax) == CCTL;
}
-param:
- for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
+ param:
+ for (ap = shellparam.p; (p = *ap++) != NULL;) {
strtodest(p, syntax, quotes);
if (*ap && sep) {
if (sepq)
* string for IFS characters.
*/
-static void
-recordregion(int start, int end, int nulonly)
+static void recordregion(int start, int end, int nulonly)
{
struct ifsregion *ifsp;
ifsp = &ifsfirst;
} else {
INTOFF;
- ifsp = (struct ifsregion *)xmalloc(sizeof (struct ifsregion));
+ ifsp = (struct ifsregion *) xmalloc(sizeof(struct ifsregion));
ifsp->next = NULL;
ifslastp->next = ifsp;
INTON;
* strings to the argument list. The regions of the string to be
* searched for IFS characters have been stored by recordregion.
*/
-static void
-ifsbreakup(char *string, struct arglist *arglist)
+static void ifsbreakup(char *string, struct arglist *arglist)
{
struct ifsregion *ifsp;
struct strlist *sp;
start = string;
ifsspc = 0;
nulonly = 0;
- realifs = ifsset() ? ifsval() : defifs;
+ realifs = ifsset()? ifsval() : defifs;
if (ifslastp != NULL) {
ifsp = &ifsfirst;
do {
continue;
}
*q = '\0';
- sp = (struct strlist *)stalloc(sizeof *sp);
+ sp = (struct strlist *) stalloc(sizeof *sp);
sp->text = start;
*arglist->lastp = sp;
arglist->lastp = &sp->next;
q = p;
if (*p == CTLESC)
p++;
- if (strchr(ifs, *p) == NULL ) {
+ if (strchr(ifs, *p) == NULL) {
p = q;
break;
} else if (strchr(defifs, *p) == NULL) {
}
}
- sp = (struct strlist *)stalloc(sizeof *sp);
+ sp = (struct strlist *) stalloc(sizeof *sp);
sp->text = start;
*arglist->lastp = sp;
arglist->lastp = &sp->next;
}
-static void
-ifsfree(void)
+static void ifsfree(void)
{
while (ifsfirst.next != NULL) {
struct ifsregion *ifsp;
+
INTOFF;
ifsp = ifsfirst.next->next;
free(ifsfirst.next);
* Add a file name to the list.
*/
-static void
-addfname(const char *name)
+static void addfname(const char *name)
{
struct strlist *sp;
- sp = (struct strlist *)stalloc(sizeof *sp);
+ sp = (struct strlist *) stalloc(sizeof *sp);
sp->text = sstrdup(name);
*exparg.lastp = sp;
exparg.lastp = &sp->next;
*/
#if defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN)
-static void
-expandmeta(struct strlist *str, int flag)
+static void expandmeta(struct strlist *str, int flag)
{
const char *p;
glob_t pglob;
+
/* TODO - EXP_REDIR */
while (str) {
INTOFF;
switch (glob(p, 0, 0, &pglob)) {
case 0:
- if(pglob.gl_pathv[1]==0 && !strcmp(p, pglob.gl_pathv[0]))
+ if (pglob.gl_pathv[1] == 0 && !strcmp(p, pglob.gl_pathv[0]))
goto nometa2;
addglob(&pglob);
globfree(&pglob);
INTON;
break;
case GLOB_NOMATCH:
-nometa2:
+ nometa2:
globfree(&pglob);
INTON;
-nometa:
+ nometa:
*exparg.lastp = str;
rmescapes(str->text);
exparg.lastp = &str->next;
break;
- default: /* GLOB_NOSPACE */
+ default: /* GLOB_NOSPACE */
error("Out of space");
}
str = str->next;
* Add the result of glob(3) to the list.
*/
-static inline void
-addglob(const glob_t *pglob)
+static inline void addglob(const glob_t * pglob)
{
char **p = pglob->gl_pathv;
}
-#else /* defined(__GLIBC__) && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN) */
+#else /* defined(__GLIBC__) && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN) */
static char *expdir;
-static void
-expandmeta(struct strlist *str, int flag)
+static void expandmeta(struct strlist *str, int flag)
{
char *p;
struct strlist **savelastp;
struct strlist *sp;
char c;
+
/* TODO - EXP_REDIR */
while (str) {
if (fflag)
goto nometa;
p = str->text;
- for (;;) { /* fast check for meta chars */
+ for (;;) { /* fast check for meta chars */
if ((c = *p++) == '\0')
goto nometa;
if (c == '*' || c == '?' || c == '[' || c == '!')
INTOFF;
if (expdir == NULL) {
int i = strlen(str->text);
- expdir = xmalloc(i < 2048 ? 2048 : i); /* XXX */
+
+ expdir = xmalloc(i < 2048 ? 2048 : i); /* XXX */
}
expmeta(expdir, str->text);
/*
* no matches
*/
-nometa:
+ nometa:
*exparg.lastp = str;
rmescapes(str->text);
exparg.lastp = &str->next;
* Do metacharacter (i.e. *, ?, [...]) expansion.
*/
-static void
-expmeta(char *enddir, char *name)
+static void expmeta(char *enddir, char *name)
{
char *p;
const char *cp;
metaflag = 0;
start = name;
- for (p = name ; ; p++) {
+ for (p = name;; p++) {
if (*p == '*' || *p == '?')
metaflag = 1;
else if (*p == '[') {
start = p + 1;
}
}
- if (metaflag == 0) { /* we've reached the end of the file name */
+ if (metaflag == 0) { /* we've reached the end of the file name */
if (enddir != expdir)
metaflag++;
- for (p = name ; ; p++) {
+ for (p = name;; p++) {
if (*p == CTLQUOTEMARK)
continue;
if (*p == CTLESC)
p++;
if (*p == '.')
matchdot++;
- while (! int_pending() && (dp = readdir(dirp)) != NULL) {
- if (dp->d_name[0] == '.' && ! matchdot)
+ while (!int_pending() && (dp = readdir(dirp)) != NULL) {
+ if (dp->d_name[0] == '.' && !matchdot)
continue;
if (patmatch(start, dp->d_name, 0)) {
if (atend) {
strcpy(enddir, dp->d_name);
addfname(expdir);
} else {
- for (p = enddir, cp = dp->d_name;
- (*p++ = *cp++) != '\0';)
+ for (p = enddir, cp = dp->d_name; (*p++ = *cp++) != '\0';)
continue;
p[-1] = '/';
expmeta(p, endname);
}
}
closedir(dirp);
- if (! atend)
+ if (!atend)
endname[-1] = '/';
}
-#endif /* defined(__GLIBC__) && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN) */
+#endif /* defined(__GLIBC__) && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN) */
* work.
*/
-static struct strlist *
-expsort(struct strlist *str)
+static struct strlist *expsort(struct strlist *str)
{
int len;
struct strlist *sp;
len = 0;
- for (sp = str ; sp ; sp = sp->next)
+ for (sp = str; sp; sp = sp->next)
len++;
return msort(str, len);
}
-static struct strlist *
-msort(struct strlist *list, int len)
+static struct strlist *msort(struct strlist *list, int len)
{
struct strlist *p, *q = NULL;
struct strlist **lpp;
return list;
half = len >> 1;
p = list;
- for (n = half ; --n >= 0 ; ) {
+ for (n = half; --n >= 0;) {
q = p;
p = p->next;
}
- q->next = NULL; /* terminate first half of list */
- q = msort(list, half); /* sort first half of list */
- p = msort(p, len - half); /* sort second half */
+ q->next = NULL; /* terminate first half of list */
+ q = msort(list, half); /* sort first half of list */
+ p = msort(p, len - half); /* sort second half */
lpp = &list;
for (;;) {
if (strcmp(p->text, q->text) < 0) {
#if defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN)
/* squoted: string might have quote chars */
-static int
-patmatch(char *pattern, char *string, int squoted)
+static int patmatch(char *pattern, char *string, int squoted)
{
const char *p;
char *q;
}
-static int
-patmatch2(char *pattern, char *string, int squoted)
+static int patmatch2(char *pattern, char *string, int squoted)
{
char *p;
int res;
return res;
}
#else
-static int
-patmatch(char *pattern, char *string, int squoted) {
+static int patmatch(char *pattern, char *string, int squoted)
+{
return pmatch(pattern, string, squoted);
}
-static int
-pmatch(char *pattern, char *string, int squoted)
+static int pmatch(char *pattern, char *string, int squoted)
{
char *p, *q;
char c;
c = *p;
while (c == CTLQUOTEMARK || c == '*')
c = *++p;
- if (c != CTLESC && c != CTLQUOTEMARK &&
- c != '?' && c != '*' && c != '[') {
+ if (c != CTLESC && c != CTLQUOTEMARK &&
+ c != '?' && c != '*' && c != '[') {
while (*q != c) {
- if (squoted && *q == CTLESC &&
- q[1] == c)
+ if (squoted && *q == CTLESC && q[1] == c)
break;
if (*q == '\0')
return 0;
q++;
} while (*q++ != '\0');
return 0;
- case '[': {
+ case '[':{
char *endp;
int invert, found;
char chr;
while (*endp == CTLQUOTEMARK)
endp++;
if (*endp == '\0')
- goto dft; /* no matching ] */
+ goto dft; /* no matching ] */
if (*endp == CTLESC)
endp++;
if (*++endp == ']')
return 0;
break;
}
-dft: default:
+ dft: default:
if (squoted && *q == CTLESC)
q++;
if (*q++ != c)
break;
}
}
-breakloop:
+ breakloop:
if (*q != '\0')
return 0;
return 1;
*/
#if defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN)
-static char *
-_rmescapes(char *str, int flag)
+static char *_rmescapes(char *str, int flag)
{
char *p, *q, *r;
static const char qchars[] = { CTLESC, CTLQUOTEMARK, 0 };
r = str;
if (flag & RMESCAPE_ALLOC) {
size_t len = p - str;
+
q = r = stalloc(strlen(p) + len + 1);
if (len > 0) {
memcpy(q, str, len);
return r;
}
#else
-static void
-rmescapes(char *str)
+static void rmescapes(char *str)
{
char *p, *q;
* See if a pattern matches in a case statement.
*/
-static int
-casematch(union node *pattern, const char *val)
+static int casematch(union node *pattern, const char *val)
{
struct stackmark smark;
int result;
argstr(pattern->narg.text, EXP_TILDE | EXP_CASE);
STPUTC('\0', expdest);
p = grabstackstr(expdest);
- result = patmatch(p, (char *)val, 0);
+ result = patmatch(p, (char *) val, 0);
popstackmark(&smark);
return result;
}
* Our own itoa().
*/
-static char *
-cvtnum(int num, char *buf)
+static char *cvtnum(int num, char *buf)
{
int len;
STADJUST(len, buf);
return buf;
}
+
/*
* Editline and history functions (and glue).
*/
struct redirtab {
struct redirtab *next;
- short renamed[10]; /* Current ash support only 0-9 descriptors */
+ short renamed[10]; /* Current ash support only 0-9 descriptors */
/* char on arm (and others) can't be negative */
};
* Initialization code.
*/
-static void
-init(void) {
+static void init(void)
+{
- /* from cd.c: */
- {
- curdir = nullstr;
- setpwd(0, 0);
- }
+ /* from cd.c: */
+ {
+ curdir = nullstr;
+ setpwd(0, 0);
+ }
- /* from input.c: */
- {
- basepf.nextc = basepf.buf = basebuf;
- }
+ /* from input.c: */
+ {
+ basepf.nextc = basepf.buf = basebuf;
+ }
- /* from var.c: */
- {
- char **envp;
- char ppid[32];
+ /* from var.c: */
+ {
+ char **envp;
+ char ppid[32];
- initvar();
- for (envp = environ ; *envp ; envp++) {
- if (strchr(*envp, '=')) {
- setvareq(*envp, VEXPORT|VTEXTFIXED);
- }
- }
+ initvar();
+ for (envp = environ; *envp; envp++) {
+ if (strchr(*envp, '=')) {
+ setvareq(*envp, VEXPORT | VTEXTFIXED);
+ }
+ }
- snprintf(ppid, sizeof(ppid), "%d", (int) getppid());
- setvar("PPID", ppid, 0);
- }
+ snprintf(ppid, sizeof(ppid), "%d", (int) getppid());
+ setvar("PPID", ppid, 0);
+ }
}
*/
/* 1 == check for aliases, 2 == also check for assignments */
-static int checkalias; /* also used in no alias mode for check assignments */
+static int checkalias; /* also used in no alias mode for check assignments */
-static void
-reset(void) {
+static void reset(void)
+{
- /* from eval.c: */
- {
- evalskip = 0;
- loopnest = 0;
- funcnest = 0;
- }
+ /* from eval.c: */
+ {
+ evalskip = 0;
+ loopnest = 0;
+ funcnest = 0;
+ }
- /* from input.c: */
- {
- if (exception != EXSHELLPROC)
- parselleft = parsenleft = 0; /* clear input buffer */
- popallfiles();
- }
+ /* from input.c: */
+ {
+ if (exception != EXSHELLPROC)
+ parselleft = parsenleft = 0; /* clear input buffer */
+ popallfiles();
+ }
- /* from parser.c: */
- {
- tokpushback = 0;
- checkkwd = 0;
- checkalias = 0;
- }
+ /* from parser.c: */
+ {
+ tokpushback = 0;
+ checkkwd = 0;
+ checkalias = 0;
+ }
- /* from redir.c: */
- {
- while (redirlist)
- popredir();
- }
+ /* from redir.c: */
+ {
+ while (redirlist)
+ popredir();
+ }
}
*/
#ifdef CONFIG_FEATURE_COMMAND_EDITING
-static const char * cmdedit_prompt;
-static inline void putprompt(const char *s) {
- cmdedit_prompt = s;
+static const char *cmdedit_prompt;
+static inline void putprompt(const char *s)
+{
+ cmdedit_prompt = s;
}
#else
-static inline void putprompt(const char *s) {
- out2str(s);
+static inline void putprompt(const char *s)
+{
+ out2str(s);
}
#endif
-#define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */
+#define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */
*/
#ifdef CONFIG_ASH_ALIAS
-static int
-pgetc2(void)
+static int pgetc2(void)
{
int c;
+
do {
c = pgetc_macro();
} while (c == PEOA);
return c;
}
#else
-static inline int pgetc2(void) { return pgetc_macro(); }
+static inline int pgetc2(void)
+{
+ return pgetc_macro();
+}
#endif
/*
* Read a line from the script.
*/
-static inline char *
-pfgets(char *line, int len)
+static inline char *pfgets(char *line, int len)
{
char *p = line;
int nleft = len;
return line;
}
-static inline int
-preadfd(void)
+static inline int preadfd(void)
{
- int nr;
- char *buf = parsefile->buf;
- parsenextc = buf;
+ int nr;
+ char *buf = parsefile->buf;
+
+ parsenextc = buf;
-retry:
+ retry:
#ifdef CONFIG_FEATURE_COMMAND_EDITING
{
- if (!iflag || parsefile->fd)
- nr = safe_read(parsefile->fd, buf, BUFSIZ - 1);
- else {
- nr = cmdedit_read_input((char*)cmdedit_prompt, buf);
- }
+ if (!iflag || parsefile->fd)
+ nr = safe_read(parsefile->fd, buf, BUFSIZ - 1);
+ else {
+ nr = cmdedit_read_input((char *) cmdedit_prompt, buf);
+ }
}
#else
nr = safe_read(parsefile->fd, buf, BUFSIZ - 1);
if (nr < 0) {
if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
int flags = fcntl(0, F_GETFL, 0);
+
if (flags >= 0 && flags & O_NONBLOCK) {
- flags &=~ O_NONBLOCK;
+ flags &= ~O_NONBLOCK;
if (fcntl(0, F_SETFL, flags) >= 0) {
out2str("sh: turning off NDELAY mode\n");
goto retry;
return nr;
}
-static void
-popstring(void)
+static void popstring(void)
{
struct strpush *sp = parsefile->strpush;
* 4) Process input up to the next newline, deleting nul characters.
*/
-static int
-preadbuffer(void)
+static int preadbuffer(void)
{
char *p, *q;
int more;
return PEOF;
flushall();
-again:
+ again:
if (parselleft <= 0) {
if ((parselleft = preadfd()) <= 0) {
parselleft = parsenleft = EOF_NLEFT;
for (more = 1; more;) {
switch (*p) {
case '\0':
- p++; /* Skip nul */
+ p++; /* Skip nul */
goto check;
case '\n':
parsenleft = q - parsenextc;
- more = 0; /* Stop processing here */
+ more = 0; /* Stop processing here */
break;
}
*q++ = *p++;
-check:
+ check:
if (--parselleft <= 0 && more) {
parsenleft = q - parsenextc - 1;
if (parsenleft < 0)
* Push a string back onto the input at this current parsefile level.
* We handle aliases this way.
*/
-static void
-pushstring(char *s, int len, void *ap)
+static void pushstring(char *s, int len, void *ap)
{
struct strpush *sp;
INTOFF;
/*dprintf("*** calling pushstring: %s, %d\n", s, len);*/
if (parsefile->strpush) {
- sp = xmalloc(sizeof (struct strpush));
+ sp = xmalloc(sizeof(struct strpush));
sp->prev = parsefile->strpush;
parsefile->strpush = sp;
} else
sp->prevstring = parsenextc;
sp->prevnleft = parsenleft;
#ifdef CONFIG_ASH_ALIAS
- sp->ap = (struct alias *)ap;
+ sp->ap = (struct alias *) ap;
if (ap) {
- ((struct alias *)ap)->flag |= ALIASINUSE;
+ ((struct alias *) ap)->flag |= ALIASINUSE;
sp->string = s;
}
#endif
* Like setinputfile, but takes input from a string.
*/
-static void
-setinputstring(char *string)
+static void setinputstring(char *string)
{
INTOFF;
pushfile();
* adds a new entry to the stack and popfile restores the previous level.
*/
-static void
-pushfile(void)
+static void pushfile(void)
{
struct parsefile *pf;
parsefile->lleft = parselleft;
parsefile->nextc = parsenextc;
parsefile->linno = plinno;
- pf = (struct parsefile *)xmalloc(sizeof (struct parsefile));
+ pf = (struct parsefile *) xmalloc(sizeof(struct parsefile));
pf->prev = parsefile;
pf->fd = -1;
pf->strpush = NULL;
}
#ifdef CONFIG_ASH_JOB_CONTROL
-static void restartjob (struct job *);
+static void restartjob(struct job *);
#endif
-static void freejob (struct job *);
-static struct job *getjob (const char *);
-static int dowait (int, struct job *);
+static void freejob(struct job *);
+static struct job *getjob(const char *);
+static int dowait(int, struct job *);
static void waitonint(int);
static int fd0_redirected = 0;
/* Return true if fd 0 has already been redirected at least once. */
-static inline int
-fd0_redirected_p (void)
+static inline int fd0_redirected_p(void)
{
return fd0_redirected != 0;
}
-static void dupredirect (const union node *, int, int fd1dup);
+static void dupredirect(const union node *, int, int fd1dup);
#ifdef CONFIG_ASH_JOB_CONTROL
/*
if (enable == jobctl || rootshell == 0)
return;
if (enable) {
- do { /* while we are in the background */
+ do { /* while we are in the background */
#ifdef OLD_TTY_DRIVER
- if (ioctl(2, TIOCGPGRP, (char *)&initialpgrp) < 0) {
+ if (ioctl(2, TIOCGPGRP, (char *) &initialpgrp) < 0) {
#else
initialpgrp = tcgetpgrp(2);
if (initialpgrp < 0) {
}
} while (0);
#ifdef OLD_TTY_DRIVER
- if (ioctl(2, TIOCGETD, (char *)&ldisc) < 0 || ldisc != NTTYDISC) {
- out2str("sh: need new tty driver to run job control; job control turned off\n");
+ if (ioctl(2, TIOCGETD, (char *) &ldisc) < 0 || ldisc != NTTYDISC) {
+ out2str
+ ("sh: need new tty driver to run job control; job control turned off\n");
mflag = 0;
return;
}
setsignal(SIGTTIN);
setpgid(0, rootpid);
#ifdef OLD_TTY_DRIVER
- ioctl(2, TIOCSPGRP, (char *)&rootpid);
+ ioctl(2, TIOCSPGRP, (char *) &rootpid);
#else
tcsetpgrp(2, rootpid);
#endif
- } else { /* turning job control off */
+ } else { /* turning job control off */
setpgid(0, initialpgrp);
#ifdef OLD_TTY_DRIVER
- ioctl(2, TIOCSPGRP, (char *)&initialpgrp);
+ ioctl(2, TIOCSPGRP, (char *) &initialpgrp);
#else
tcsetpgrp(2, initialpgrp);
#endif
#ifdef CONFIG_ASH_JOB_CONTROL
-static int
-killcmd(int argc, char **argv)
+static int killcmd(int argc, char **argv)
{
int signo = -1;
int list = 0;
struct job *jp;
if (argc <= 1) {
-usage:
- error(
-"Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or\n"
-"kill -l [exitstatus]"
- );
+ usage:
+ error
+ ("Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or\n"
+ "kill -l [exitstatus]");
}
if (*argv[1] == '-') {
case 's':
signo = decode_signal(optionarg, 1);
if (signo < 0) {
- error(
- "invalid signal number or name: %s",
- optionarg
- );
+ error("invalid signal number or name: %s", optionarg);
}
break;
#ifdef DEBUG
default:
- error(
- "nextopt returned character code 0%o", c);
+ error("nextopt returned character code 0%o", c);
#endif
- }
+ }
} else
argptr++;
}
out1str("0\n");
for (i = 1; i < NSIG; i++) {
name = u_signal_names(0, &i, 1);
- if(name)
+ if (name)
puts(name);
}
return 0;
if (name)
puts(name);
else
- error("invalid signal number or exit status: %s",
- *argptr);
+ error("invalid signal number or exit status: %s", *argptr);
return 0;
}
if (**argptr == '%') {
jp = getjob(*argptr);
if (jp->jobctl == 0)
- error("job %s not created under job control",
- *argptr);
+ error("job %s not created under job control", *argptr);
pid = -jp->ps[0].pid;
} else
pid = atoi(*argptr);
return 0;
}
-static int
-fgcmd(int argc, char **argv)
+static int fgcmd(int argc, char **argv)
{
struct job *jp;
int pgrp;
error("job not created under job control");
pgrp = jp->ps[0].pid;
#ifdef OLD_TTY_DRIVER
- ioctl(2, TIOCSPGRP, (char *)&pgrp);
+ ioctl(2, TIOCSPGRP, (char *) &pgrp);
#else
tcsetpgrp(2, pgrp);
#endif
}
-static int
-bgcmd(int argc, char **argv)
+static int bgcmd(int argc, char **argv)
{
struct job *jp;
}
-static void
-restartjob(struct job *jp)
+static void restartjob(struct job *jp)
{
struct procstat *ps;
int i;
return;
INTOFF;
killpg(jp->ps[0].pid, SIGCONT);
- for (ps = jp->ps, i = jp->nprocs ; --i >= 0 ; ps++) {
+ for (ps = jp->ps, i = jp->nprocs; --i >= 0; ps++) {
if (WIFSTOPPED(ps->status)) {
ps->status = -1;
jp->state = 0;
static void showjobs(int change);
-static int
-jobscmd(int argc, char **argv)
+static int jobscmd(int argc, char **argv)
{
showjobs(0);
return 0;
* will be freed here.
*/
-static void
-showjobs(int change)
+static void showjobs(int change)
{
int jobno;
int procno;
char s[64];
TRACE(("showjobs(%d) called\n", change));
- while (dowait(0, (struct job *)NULL) > 0);
- for (jobno = 1, jp = jobtab ; jobno <= njobs ; jobno++, jp++) {
- if (! jp->used)
+ while (dowait(0, (struct job *) NULL) > 0);
+ for (jobno = 1, jp = jobtab; jobno <= njobs; jobno++, jp++) {
+ if (!jp->used)
continue;
if (jp->nprocs == 0) {
freejob(jp);
continue;
}
- if (change && ! jp->changed)
+ if (change && !jp->changed)
continue;
procno = jp->nprocs;
- for (ps = jp->ps ; ; ps++) { /* for each process */
+ for (ps = jp->ps;; ps++) { /* for each process */
if (ps == jp->ps)
- snprintf(s, 64, "[%d] %ld ", jobno,
- (long)ps->pid);
+ snprintf(s, 64, "[%d] %ld ", jobno, (long) ps->pid);
else
- snprintf(s, 64, " %ld ",
- (long)ps->pid);
+ snprintf(s, 64, " %ld ", (long) ps->pid);
out1str(s);
col = strlen(s);
s[0] = '\0';
if (ps->status == -1) {
/* don't print anything */
} else if (WIFEXITED(ps->status)) {
- snprintf(s, 64, "Exit %d",
- WEXITSTATUS(ps->status));
+ snprintf(s, 64, "Exit %d", WEXITSTATUS(ps->status));
} else {
#ifdef CONFIG_ASH_JOB_CONTROL
if (WIFSTOPPED(ps->status))
i = WSTOPSIG(ps->status);
- else /* WIFSIGNALED(ps->status) */
+ else /* WIFSIGNALED(ps->status) */
#endif
i = WTERMSIG(ps->status);
if ((i & 0x7F) < NSIG && sys_siglist[i & 0x7F])
}
out1str(s);
col += strlen(s);
- printf(
- "%*c%s\n", 30 - col >= 0 ? 30 - col : 0, ' ',
- ps->cmd
- );
+ printf("%*c%s\n", 30 - col >= 0 ? 30 - col : 0, ' ', ps->cmd);
if (--procno <= 0)
break;
}
* Mark a job structure as unused.
*/
-static void
-freejob(struct job *jp)
+static void freejob(struct job *jp)
{
const struct procstat *ps;
int i;
INTOFF;
- for (i = jp->nprocs, ps = jp->ps ; --i >= 0 ; ps++) {
+ for (i = jp->nprocs, ps = jp->ps; --i >= 0; ps++) {
if (ps->cmd != nullstr)
free(ps->cmd);
}
-static int
-waitcmd(int argc, char **argv)
+static int waitcmd(int argc, char **argv)
{
struct job *job;
int status, retval;
struct job *jp;
if (--argc > 0) {
-start:
+ start:
job = getjob(*++argv);
} else {
job = NULL;
}
- for (;;) { /* loop until process terminated or stopped */
+ for (;;) { /* loop until process terminated or stopped */
if (job != NULL) {
if (job->state) {
status = job->ps[job->nprocs - 1].status;
- if (! iflag)
+ if (!iflag)
freejob(job);
if (--argc) {
goto start;
return retval;
}
} else {
- for (jp = jobtab ; ; jp++) {
- if (jp >= jobtab + njobs) { /* no running procs */
+ for (jp = jobtab;; jp++) {
+ if (jp >= jobtab + njobs) { /* no running procs */
return 0;
}
if (jp->used && jp->state == 0)
* Convert a job name to a job structure.
*/
-static struct job *
-getjob(const char *name)
+static struct job *getjob(const char *name)
{
int jobno;
struct job *jp;
if (name == NULL) {
#ifdef CONFIG_ASH_JOB_CONTROL
-currentjob:
+ currentjob:
if ((jobno = curjob) == 0 || jobtab[jobno - 1].used == 0)
error("No current job");
return &jobtab[jobno - 1];
} else if (name[0] == '%') {
if (is_digit(name[1])) {
jobno = number(name + 1);
- if (jobno > 0 && jobno <= njobs
- && jobtab[jobno - 1].used != 0)
+ if (jobno > 0 && jobno <= njobs && jobtab[jobno - 1].used != 0)
return &jobtab[jobno - 1];
#ifdef CONFIG_ASH_JOB_CONTROL
} else if (name[1] == '%' && name[2] == '\0') {
#endif
} else {
struct job *found = NULL;
- for (jp = jobtab, i = njobs ; --i >= 0 ; jp++) {
+
+ for (jp = jobtab, i = njobs; --i >= 0; jp++) {
if (jp->used && jp->nprocs > 0
- && prefix(name + 1, jp->ps[0].cmd)) {
+ && prefix(name + 1, jp->ps[0].cmd)) {
if (found)
error("%s: ambiguous", name);
found = jp;
return found;
}
} else if (is_number(name, &pid)) {
- for (jp = jobtab, i = njobs ; --i >= 0 ; jp++) {
+ for (jp = jobtab, i = njobs; --i >= 0; jp++) {
if (jp->used && jp->nprocs > 0
- && jp->ps[jp->nprocs - 1].pid == pid)
+ && jp->ps[jp->nprocs - 1].pid == pid)
return jp;
}
}
* Return a new job structure,
*/
-static struct job *
-makejob(const union node *node, int nprocs)
+static struct job *makejob(const union node *node, int nprocs)
{
int i;
struct job *jp;
- for (i = njobs, jp = jobtab ; ; jp++) {
+ for (i = njobs, jp = jobtab;; jp++) {
if (--i < 0) {
INTOFF;
if (njobs == 0) {
jobtab = jp;
}
jp = jobtab + njobs;
- for (i = 4 ; --i >= 0 ; jobtab[njobs++].used = 0);
+ for (i = 4; --i >= 0; jobtab[njobs++].used = 0);
INTON;
break;
}
jp->jobctl = jobctl;
#endif
if (nprocs > 1) {
- jp->ps = xmalloc(nprocs * sizeof (struct procstat));
+ jp->ps = xmalloc(nprocs * sizeof(struct procstat));
} else {
jp->ps = &jp->ps0;
}
INTON;
- TRACE(("makejob(0x%lx, %d) returns %%%d\n", (long)node, nprocs,
- jp - jobtab + 1));
+ TRACE(("makejob(0x%lx, %d) returns %%%d\n", (long) node, nprocs,
+ jp - jobtab + 1));
return jp;
}
-static int
-forkshell(struct job *jp, const union node *n, int mode)
+static int forkshell(struct job *jp, const union node *n, int mode)
{
int pid;
+
#ifdef CONFIG_ASH_JOB_CONTROL
int pgrp;
#endif
const char *devnull = _PATH_DEVNULL;
const char *nullerr = "Can't open %s";
- TRACE(("forkshell(%%%d, 0x%lx, %d) called\n", jp - jobtab, (long)n,
- mode));
+ TRACE(("forkshell(%%%d, 0x%lx, %d) called\n", jp - jobtab, (long) n,
+ mode));
INTOFF;
#if !defined(__UCLIBC__) || defined(__UCLIBC_HAS_MMU__)
pid = fork();
INTON;
clear_traps();
#ifdef CONFIG_ASH_JOB_CONTROL
- jobctl = 0; /* do job control only in root shell */
+ jobctl = 0; /* do job control only in root shell */
if (wasroot && mode != FORK_NOJOB && mflag) {
if (jp == NULL || jp->nprocs == 0)
pgrp = getpid();
if (mode == FORK_FG) {
/*** this causes superfluous TIOCSPGRPS ***/
#ifdef OLD_TTY_DRIVER
- if (ioctl(2, TIOCSPGRP, (char *)&pgrp) < 0)
+ if (ioctl(2, TIOCSPGRP, (char *) &pgrp) < 0)
error("TIOCSPGRP failed, errno=%d", errno);
#else
if (tcsetpgrp(2, pgrp) < 0)
#endif
ignoresig(SIGINT);
ignoresig(SIGQUIT);
- if ((jp == NULL || jp->nprocs == 0) &&
- ! fd0_redirected_p ()) {
+ if ((jp == NULL || jp->nprocs == 0) && !fd0_redirected_p()) {
close(0);
if (open(devnull, O_RDONLY) != 0)
error(nullerr, devnull);
}
}
- for (i = njobs, p = jobtab ; --i >= 0 ; p++)
+ for (i = njobs, p = jobtab; --i >= 0; p++)
if (p->used)
freejob(p);
if (wasroot && iflag) {
}
#endif
if (mode == FORK_BG)
- backgndpid = pid; /* set $! */
+ backgndpid = pid; /* set $! */
if (jp) {
struct procstat *ps = &jp->ps[jp->nprocs++];
+
ps->pid = pid;
ps->status = -1;
ps->cmd = nullstr;
* confuse this approach.
*/
-static int
-waitforjob(struct job *jp)
+static int waitforjob(struct job *jp)
{
#ifdef CONFIG_ASH_JOB_CONTROL
int mypgrp = getpgrp();
if (!iflag) {
#endif
sigaction(SIGINT, &oact, 0);
- if (intreceived) kill(getpid(), SIGINT);
+ if (intreceived)
+ kill(getpid(), SIGINT);
}
#ifdef CONFIG_ASH_JOB_CONTROL
if (jp->jobctl) {
#ifdef OLD_TTY_DRIVER
- if (ioctl(2, TIOCSPGRP, (char *)&mypgrp) < 0)
+ if (ioctl(2, TIOCSPGRP, (char *) &mypgrp) < 0)
error("TIOCSPGRP failed, errno=%d\n", errno);
#else
if (tcsetpgrp(2, mypgrp) < 0)
raise(SIGINT);
}
if (jp->state == JOBDONE)
-
#endif
freejob(jp);
INTON;
*
*/
-static inline int
-waitproc(int block, int *status)
+static inline int waitproc(int block, int *status)
{
int flags;
#endif
if (block == 0)
flags |= WNOHANG;
- return wait3(status, flags, (struct rusage *)NULL);
+ return wait3(status, flags, (struct rusage *) NULL);
}
-static int
-dowait(int block, struct job *job)
+static int dowait(int block, struct job *job)
{
int pid;
int status;
return pid;
INTOFF;
thisjob = NULL;
- for (jp = jobtab ; jp < jobtab + njobs ; jp++) {
+ for (jp = jobtab; jp < jobtab + njobs; jp++) {
if (jp->used) {
done = 1;
stopped = 1;
- for (sp = jp->ps ; sp < jp->ps + jp->nprocs ; sp++) {
+ for (sp = jp->ps; sp < jp->ps + jp->nprocs; sp++) {
if (sp->pid == -1)
continue;
if (sp->pid == pid) {
- TRACE(("Changing status of proc %d from 0x%x to 0x%x\n", pid, sp->status, status));
+ TRACE(("Changing status of proc %d from 0x%x to 0x%x\n",
+ pid, sp->status, status));
sp->status = status;
thisjob = jp;
}
else if (WIFSTOPPED(sp->status))
done = 0;
}
- if (stopped) { /* stopped or done */
- int state = done? JOBDONE : CONFIG_ASH_JOB_CONTROLTOPPED;
+ if (stopped) { /* stopped or done */
+ int state = done ? JOBDONE : CONFIG_ASH_JOB_CONTROLTOPPED;
+
if (jp->state != state) {
- TRACE(("Job %d: changing state from %d to %d\n", jp - jobtab + 1, jp->state, state));
+ TRACE(("Job %d: changing state from %d to %d\n",
+ jp - jobtab + 1, jp->state, state));
jp->state = state;
#ifdef CONFIG_ASH_JOB_CONTROL
if (done && curjob == jp - jobtab + 1)
- curjob = 0; /* no current job */
+ curjob = 0; /* no current job */
#endif
}
}
}
}
INTON;
- if (! rootshell || ! iflag || (job && thisjob == job)) {
+ if (!rootshell || !iflag || (job && thisjob == job)) {
core = WCOREDUMP(status);
#ifdef CONFIG_ASH_JOB_CONTROL
- if (WIFSTOPPED(status)) sig = WSTOPSIG(status);
+ if (WIFSTOPPED(status))
+ sig = WSTOPSIG(status);
else
#endif
- if (WIFEXITED(status)) sig = 0;
- else sig = WTERMSIG(status);
+ if (WIFEXITED(status))
+ sig = 0;
+ else
+ sig = WTERMSIG(status);
if (sig != 0 && sig != SIGINT && sig != SIGPIPE) {
if (thisjob != job)
out2fmt("%d: ", pid);
#ifdef CONFIG_ASH_JOB_CONTROL
if (sig == SIGTSTP && rootshell && iflag)
- out2fmt("%%%ld ",
- (long)(job - jobtab + 1));
+ out2fmt("%%%ld ", (long) (job - jobtab + 1));
#endif
if (sig < NSIG && sys_siglist[sig])
out2str(sys_siglist[sig]);
out2str(" - core dumped");
out2c('\n');
} else {
- TRACE(("Not printing status: status=%d, sig=%d\n",
- status, sig));
+ TRACE(("Not printing status: status=%d, sig=%d\n", status, sig));
}
} else {
- TRACE(("Not printing status, rootshell=%d, job=0x%x\n", rootshell, job));
+ TRACE(("Not printing status, rootshell=%d, job=0x%x\n", rootshell,
+ job));
if (thisjob)
thisjob->changed = 1;
}
/*
* return 1 if there are stopped jobs, otherwise 0
*/
-static int
-stoppedjobs(void)
+static int stoppedjobs(void)
{
int jobno;
struct job *jp;
static char *cmdnextc;
static int cmdnleft;
+
#define MAXCMDTEXT 200
-static void
-cmdputs(const char *s)
+static void cmdputs(const char *s)
{
const char *p;
char *q;
subtype = 0;
} else if (c == CTLENDVAR) {
*q++ = '}';
- } else if (c == CTLBACKQ || c == CTLBACKQ+CTLQUOTE)
- cmdnleft++; /* ignore it */
+ } else if (c == CTLBACKQ || c == CTLBACKQ + CTLQUOTE)
+ cmdnleft++; /* ignore it */
else
*q++ = c;
if (--cmdnleft <= 0) {
* end-of-instructions flag in bit 0.
*/
-#define CMDTXT_NOMORE 0x01 /* NOTE: no offset should be odd */
+#define CMDTXT_NOMORE 0x01 /* NOTE: no offset should be odd */
#define CMDTXT_CHARPTR 0x40
#define CMDTXT_STRING 0x80
#define CMDTXT_SPECIAL 0xC0
#define CMDTXT_OFFSETMASK 0x3E
-static const char * const cmdtxt_strings[] = {
- /* 0 1 2 3 4 5 6 7 */
+static const char *const cmdtxt_strings[] = {
+ /* 0 1 2 3 4 5 6 7 */
"; ", "(", ")", " && ", " || ", "if ", "; then ", "...",
- /* 8 9 10 11 12 13 */
- "while ", "; do ", "; done", "until ", "for ", " in ...",
- /* 14 15 16 17 */
+ /* 8 9 10 11 12 13 */
+ "while ", "; do ", "; done", "until ", "for ", " in ...",
+ /* 14 15 16 17 */
"case ", "???", "() ...", "<<..."
};
-static const char * const redir_strings[] = {
+static const char *const redir_strings[] = {
">", "<", "<>", ">>", ">|", ">&", "<&"
};
static const unsigned char cmdtxt_ops[] = {
#define CMDTXT_NSEMI 0
offsetof(union node, nbinary.ch1),
- 0|CMDTXT_STRING,
- offsetof(union node, nbinary.ch2)|CMDTXT_NOMORE,
+ 0 | CMDTXT_STRING,
+ offsetof(union node, nbinary.ch2) | CMDTXT_NOMORE,
#define CMDTXT_NCMD (CMDTXT_NSEMI + 3)
#define CMDTXT_NPIPE (CMDTXT_NCMD)
#define CMDTXT_NCASE (CMDTXT_NCMD)
CMDTXT_SPECIAL,
#define CMDTXT_NREDIR (CMDTXT_NPIPE + 1)
#define CMDTXT_NBACKGND (CMDTXT_NREDIR)
- offsetof(union node, nredir.n)|CMDTXT_NOMORE,
+ offsetof(union node, nredir.n) | CMDTXT_NOMORE,
#define CMDTXT_NSUBSHELL (CMDTXT_NBACKGND + 1)
- (1*2)|CMDTXT_STRING,
+ (1 * 2) | CMDTXT_STRING,
offsetof(union node, nredir.n),
- (2*2)|CMDTXT_STRING|CMDTXT_NOMORE,
+ (2 * 2) | CMDTXT_STRING | CMDTXT_NOMORE,
#define CMDTXT_NAND (CMDTXT_NSUBSHELL + 3)
offsetof(union node, nbinary.ch1),
- (3*2)|CMDTXT_STRING,
- offsetof(union node, nbinary.ch2)|CMDTXT_NOMORE,
+ (3 * 2) | CMDTXT_STRING,
+ offsetof(union node, nbinary.ch2) | CMDTXT_NOMORE,
#define CMDTXT_NOR (CMDTXT_NAND + 3)
offsetof(union node, nbinary.ch1),
- (4*2)|CMDTXT_STRING,
- offsetof(union node, nbinary.ch2)|CMDTXT_NOMORE,
+ (4 * 2) | CMDTXT_STRING,
+ offsetof(union node, nbinary.ch2) | CMDTXT_NOMORE,
#define CMDTXT_NIF (CMDTXT_NOR + 3)
- (5*2)|CMDTXT_STRING,
+ (5 * 2) | CMDTXT_STRING,
offsetof(union node, nif.test),
- (6*2)|CMDTXT_STRING,
+ (6 * 2) | CMDTXT_STRING,
offsetof(union node, nif.ifpart),
- (7*2)|CMDTXT_STRING|CMDTXT_NOMORE,
+ (7 * 2) | CMDTXT_STRING | CMDTXT_NOMORE,
#define CMDTXT_NWHILE (CMDTXT_NIF + 5)
- (8*2)|CMDTXT_STRING,
+ (8 * 2) | CMDTXT_STRING,
offsetof(union node, nbinary.ch1),
- (9*2)|CMDTXT_STRING,
+ (9 * 2) | CMDTXT_STRING,
offsetof(union node, nbinary.ch2),
- (10*2)|CMDTXT_STRING|CMDTXT_NOMORE,
+ (10 * 2) | CMDTXT_STRING | CMDTXT_NOMORE,
#define CMDTXT_NUNTIL (CMDTXT_NWHILE + 5)
- (11*2)|CMDTXT_STRING,
+ (11 * 2) | CMDTXT_STRING,
offsetof(union node, nbinary.ch1),
- (9*2)|CMDTXT_STRING,
+ (9 * 2) | CMDTXT_STRING,
offsetof(union node, nbinary.ch2),
- (10*2)|CMDTXT_STRING|CMDTXT_NOMORE,
+ (10 * 2) | CMDTXT_STRING | CMDTXT_NOMORE,
#define CMDTXT_NFOR (CMDTXT_NUNTIL + 5)
- (12*2)|CMDTXT_STRING,
- offsetof(union node, nfor.var)|CMDTXT_CHARPTR,
- (13*2)|CMDTXT_STRING|CMDTXT_NOMORE,
-#define CMDTXT_NCLIST (CMDTXT_NFOR + 3) /* TODO: IS THIS CORRECT??? */
-#define CMDTXT_NNOT (CMDTXT_NCLIST) /* TODO: IS THIS CORRECT??? */
- (15*2)|CMDTXT_STRING|CMDTXT_NOMORE,
+ (12 * 2) | CMDTXT_STRING,
+ offsetof(union node, nfor.var) | CMDTXT_CHARPTR,
+ (13 * 2) | CMDTXT_STRING | CMDTXT_NOMORE,
+#define CMDTXT_NCLIST (CMDTXT_NFOR + 3) /* TODO: IS THIS CORRECT??? */
+#define CMDTXT_NNOT (CMDTXT_NCLIST) /* TODO: IS THIS CORRECT??? */
+ (15 * 2) | CMDTXT_STRING | CMDTXT_NOMORE,
#define CMDTXT_NDEFUN (CMDTXT_NCLIST + 1)
- offsetof(union node, narg.text)|CMDTXT_CHARPTR,
- (16*2)|CMDTXT_STRING|CMDTXT_NOMORE,
+ offsetof(union node, narg.text) | CMDTXT_CHARPTR,
+ (16 * 2) | CMDTXT_STRING | CMDTXT_NOMORE,
#define CMDTXT_NARG (CMDTXT_NDEFUN + 2)
- offsetof(union node, narg.text)|CMDTXT_CHARPTR|CMDTXT_NOMORE,
+ offsetof(union node, narg.text) | CMDTXT_CHARPTR | CMDTXT_NOMORE,
#define CMDTXT_NHERE (CMDTXT_NARG + 1)
#define CMDTXT_NXHERE (CMDTXT_NHERE)
- (17*2)|CMDTXT_STRING|CMDTXT_NOMORE,
+ (17 * 2) | CMDTXT_STRING | CMDTXT_NOMORE,
};
#if CMDTXT_NXHERE != 36
CMDTXT_NNOT,
};
-static void
-cmdtxt(const union node *n)
+static void cmdtxt(const union node *n)
{
const char *p;
return;
p = cmdtxt_ops + (int) cmdtxt_ops_index[n->type];
- if ((*p & CMDTXT_SPECIAL) != CMDTXT_SPECIAL) { /* normal case */
+ if ((*p & CMDTXT_SPECIAL) != CMDTXT_SPECIAL) { /* normal case */
do {
- if (*p & CMDTXT_STRING) { /* output fixed string */
- cmdputs(cmdtxt_strings[((int)(*p & CMDTXT_OFFSETMASK) >> 1)]);
+ if (*p & CMDTXT_STRING) { /* output fixed string */
+ cmdputs(cmdtxt_strings
+ [((int) (*p & CMDTXT_OFFSETMASK) >> 1)]);
} else {
const char *pf = ((const char *) n)
- + ((int)(*p & CMDTXT_OFFSETMASK));
- if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
+ + ((int) (*p & CMDTXT_OFFSETMASK));
+
+ if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
cmdputs(*((const char **) pf));
- } else { /* output field */
+ } else { /* output field */
cmdtxt(*((const union node **) pf));
}
}
} while (!(*p++ & CMDTXT_NOMORE));
} else if (n->type == NCMD) {
union node *np;
- for (np = n->ncmd.args ; np ; np = np->narg.next) {
+
+ for (np = n->ncmd.args; np; np = np->narg.next) {
cmdtxt(np);
if (np->narg.next)
cmdputs(spcstr);
}
- for (np = n->ncmd.redirect ; np ; np = np->nfile.next) {
+ for (np = n->ncmd.redirect; np; np = np->nfile.next) {
cmdputs(spcstr);
cmdtxt(np);
}
} else if (n->type == NPIPE) {
struct nodelist *lp;
- for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
+
+ for (lp = n->npipe.cmdlist; lp; lp = lp->next) {
cmdtxt(lp->n);
if (lp->next)
cmdputs(" | ");
}
}
}
-#else /* CMDTXT_TABLE */
-static void
-cmdtxt(const union node *n)
+#else /* CMDTXT_TABLE */
+static void cmdtxt(const union node *n)
{
union node *np;
struct nodelist *lp;
cmdtxt(n->nbinary.ch2);
break;
case NPIPE:
- for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
+ for (lp = n->npipe.cmdlist; lp; lp = lp->next) {
cmdtxt(lp->n);
if (lp->next)
cmdputs(" | ");
goto until;
case NUNTIL:
cmdputs("until ");
-until:
+ until:
cmdtxt(n->nbinary.ch1);
cmdputs("; do ");
cmdtxt(n->nbinary.ch2);
cmdputs("() ...");
break;
case NCMD:
- for (np = n->ncmd.args ; np ; np = np->narg.next) {
+ for (np = n->ncmd.args; np; np = np->narg.next) {
cmdtxt(np);
if (np->narg.next)
cmdputs(spcstr);
}
- for (np = n->ncmd.redirect ; np ; np = np->nfile.next) {
+ for (np = n->ncmd.redirect; np; np = np->nfile.next) {
cmdputs(spcstr);
cmdtxt(np);
}
cmdputs(n->narg.text);
break;
case NTO:
- p = ">"; i = 1; goto redir;
+ p = ">";
+ i = 1;
+ goto redir;
case NAPPEND:
- p = ">>"; i = 1; goto redir;
+ p = ">>";
+ i = 1;
+ goto redir;
case NTOFD:
- p = ">&"; i = 1; goto redir;
+ p = ">&";
+ i = 1;
+ goto redir;
case NTOOV:
- p = ">|"; i = 1; goto redir;
+ p = ">|";
+ i = 1;
+ goto redir;
case NFROM:
- p = "<"; i = 0; goto redir;
+ p = "<";
+ i = 0;
+ goto redir;
case NFROMFD:
- p = "<&"; i = 0; goto redir;
+ p = "<&";
+ i = 0;
+ goto redir;
case NFROMTO:
- p = "<>"; i = 0; goto redir;
-redir:
+ p = "<>";
+ i = 0;
+ goto redir;
+ redir:
if (n->nfile.fd != i) {
s[0] = n->nfile.fd + '0';
s[1] = '\0';
break;
}
}
-#endif /* CMDTXT_TABLE */
+#endif /* CMDTXT_TABLE */
-static char *
-commandtext(const union node *n)
+static char *commandtext(const union node *n)
{
char *name;
}
-static void waitonint(int sig) {
+static void waitonint(int sig)
+{
intreceived = 1;
}
#define MAXMBOXES 10
-static int nmboxes; /* number of mailboxes */
-static time_t mailtime[MAXMBOXES]; /* times of mailboxes */
+static int nmboxes; /* number of mailboxes */
+static time_t mailtime[MAXMBOXES]; /* times of mailboxes */
* values.
*/
-static void
-chkmail(int silent)
+static void chkmail(int silent)
{
int i;
const char *mpath;
return;
setstackmark(&smark);
mpath = mpathset()? mpathval() : mailval();
- for (i = 0 ; i < nmboxes ; i++) {
+ for (i = 0; i < nmboxes; i++) {
p = padvance(&mpath, nullstr);
if (p == NULL)
break;
if (*p == '\0')
continue;
- for (q = p ; *q ; q++);
+ for (q = p; *q; q++);
#ifdef DEBUG
if (q[-1] != '/')
abort();
#endif
- q[-1] = '\0'; /* delete trailing '/' */
+ q[-1] = '\0'; /* delete trailing '/' */
if (stat(p, &statb) < 0)
statb.st_size = 0;
- if (statb.st_size > mailtime[i] && ! silent) {
- out2fmt(snlfmt,
- pathopt? pathopt : "you have mail");
+ if (statb.st_size > mailtime[i] && !silent) {
+ out2fmt(snlfmt, pathopt ? pathopt : "you have mail");
}
mailtime[i] = statb.st_size;
}
popstackmark(&smark);
}
-#endif /* CONFIG_ASH_MAIL */
+#endif /* CONFIG_ASH_MAIL */
#define PROFILE 0
static int isloginsh = 0;
-static void read_profile (const char *);
-static void cmdloop (int);
-static void options (int);
-static void setoption (int, int);
-static void procargs (int, char **);
+static void read_profile(const char *);
+static void cmdloop(int);
+static void options(int);
+static void setoption(int, int);
+static void procargs(int, char **);
/*
* is used to figure out how far we had gotten.
*/
-int
-ash_main(int argc, char **argv)
+int ash_main(int argc, char **argv)
{
struct jmploc jmploc;
struct stackmark smark;
} else if (exception == EXERROR) {
exitstatus = 2;
}
- if (state == 0 || iflag == 0 || ! rootshell)
- exitshell(exitstatus);
+ if (state == 0 || iflag == 0 || !rootshell)
+ exitshell(exitstatus);
}
reset();
if (exception == EXINT) {
out2c('\n');
}
popstackmark(&smark);
- FORCEINTON; /* enable interrupts */
+ FORCEINTON; /* enable interrupts */
if (state == 1)
goto state1;
else if (state == 2)
handler = &jmploc;
#ifdef DEBUG
opentrace();
- trputs("Shell args: "); trargs(argv);
+ trputs("Shell args: ");
+ trargs(argv);
#endif
rootpid = getpid();
rootshell = 1;
if (isloginsh) {
state = 1;
read_profile("/etc/profile");
-state1:
+ state1:
state = 2;
read_profile(".profile");
}
-state2:
+ state2:
state = 3;
#ifndef linux
if (getuid() == geteuid() && getgid() == getegid()) {
#ifndef linux
}
#endif
-state3:
+ state3:
state = 4;
if (sflag == 0 || minusc) {
- static const char sigs[] = {
- SIGINT, SIGQUIT, SIGHUP,
+ static const char sigs[] = {
+ SIGINT, SIGQUIT, SIGHUP,
#ifdef SIGTSTP
- SIGTSTP,
+ SIGTSTP,
#endif
- SIGPIPE
+ SIGPIPE
};
-#define SIGSSIZE ((sizeof(sigs)/sizeof(sigs[0])) - 1) /* trailing nul */
+
+#define SIGSSIZE ((sizeof(sigs)/sizeof(sigs[0])) - 1) /* trailing nul */
int i;
for (i = 0; i < SIGSSIZE; i++)
- setsignal(sigs[i]);
+ setsignal(sigs[i]);
}
if (minusc)
evalstring(minusc, 0);
if (sflag || minusc == NULL) {
-state4: /* XXX ??? - why isn't this before the "if" statement */
+ state4: /* XXX ??? - why isn't this before the "if" statement */
cmdloop(1);
}
#if PROFILE
* loop; it turns on prompting if the shell is interactive.
*/
-static void
-cmdloop(int top)
+static void cmdloop(int top)
{
union node *n;
struct stackmark smark;
* Read /etc/profile or .profile. Return on error.
*/
-static void
-read_profile(const char *name)
+static void read_profile(const char *name)
{
int fd;
int xflag_save;
/* Note: Might do a little redundant work, but reduces code size. */
xflag_save = xflag;
vflag_save = vflag;
- if (qflag) {
+ if (qflag) {
vflag = xflag = 0;
}
cmdloop(0);
* Read a file containing shell functions.
*/
-static void
-readcmdfile(const char *name)
+static void readcmdfile(const char *name)
{
int fd;
* search for the file, which is necessary to find sub-commands.
*/
-static inline char *
-find_dot_file(char *mybasename)
+static inline char *find_dot_file(char *mybasename)
{
char *fullname;
const char *path = pathval();
/* NOTREACHED */
}
-static int
-dotcmd(int argc, char **argv)
+static int dotcmd(int argc, char **argv)
{
struct strlist *sp;
volatile struct shparam saveparam;
+
exitstatus = 0;
- for (sp = cmdenviron; sp ; sp = sp->next)
- setvareq(xstrdup(sp->text), VSTRFIXED|VTEXTFIXED);
+ for (sp = cmdenviron; sp; sp = sp->next)
+ setvareq(xstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
- if (argc >= 2) { /* That's what SVR2 does */
+ if (argc >= 2) { /* That's what SVR2 does */
char *fullname;
struct stackmark smark;
setstackmark(&smark);
fullname = find_dot_file(argv[1]);
- if (argc>2) {
+ if (argc > 2) {
saveparam = shellparam;
shellparam.malloc = 0;
shellparam.nparam = argc - 2;
cmdloop(0);
popfile();
- if (argc>2) {
+ if (argc > 2) {
freeparam(&shellparam);
shellparam = saveparam;
};
}
-static int
-exitcmd(int argc, char **argv)
+static int exitcmd(int argc, char **argv)
{
if (stoppedjobs())
return 0;
/* NOTREACHED */
}
-static pointer
-stalloc(int nbytes)
+static pointer stalloc(int nbytes)
{
char *p;
}
-static void
-stunalloc(pointer p)
+static void stunalloc(pointer p)
{
#ifdef DEBUG
- if (p == NULL) { /*DEBUG */
+ if (p == NULL) { /*DEBUG */
write(2, "stunalloc\n", 10);
abort();
}
#endif
- if (!(stacknxt >= (char *)p && (char *)p >= stackp->space)) {
+ if (!(stacknxt >= (char *) p && (char *) p >= stackp->space)) {
p = stackp->space;
}
- stacknleft += stacknxt - (char *)p;
+ stacknleft += stacknxt - (char *) p;
stacknxt = p;
}
-static void
-setstackmark(struct stackmark *mark)
+static void setstackmark(struct stackmark *mark)
{
mark->stackp = stackp;
mark->stacknxt = stacknxt;
}
-static void
-popstackmark(struct stackmark *mark)
+static void popstackmark(struct stackmark *mark)
{
struct stack_block *sp;
* part of the block that has been used.
*/
-static void
-growstackblock(void) {
+static void growstackblock(void)
+{
char *p;
int newlen = ALIGN(stacknleft * 2 + 100);
char *oldspace = stacknxt;
oldstackp = stackp;
sp = stackp;
stackp = sp->prev;
- sp = xrealloc((pointer)sp, sizeof(struct stack_block) - MINSIZE + newlen);
+ sp = xrealloc((pointer) sp,
+ sizeof(struct stack_block) - MINSIZE + newlen);
sp->prev = stackp;
stackp = sp;
stacknxt = sp->space;
stacknleft = newlen;
{
- /* Stack marks pointing to the start of the old block
- * must be relocated to point to the new block
- */
- struct stackmark *xmark;
- xmark = markp;
- while (xmark != NULL && xmark->stackp == oldstackp) {
- xmark->stackp = stackp;
- xmark->stacknxt = stacknxt;
- xmark->stacknleft = stacknleft;
- xmark = xmark->marknext;
- }
+ /* Stack marks pointing to the start of the old block
+ * must be relocated to point to the new block
+ */
+ struct stackmark *xmark;
+
+ xmark = markp;
+ while (xmark != NULL && xmark->stackp == oldstackp) {
+ xmark->stackp = stackp;
+ xmark->stacknxt = stacknxt;
+ xmark->stacknleft = stacknleft;
+ xmark = xmark->marknext;
+ }
}
INTON;
} else {
p = stalloc(newlen);
memcpy(p, oldspace, oldlen);
- stacknxt = p; /* free the space */
- stacknleft += newlen; /* we just allocated */
+ stacknxt = p; /* free the space */
+ stacknleft += newlen; /* we just allocated */
}
}
-static inline void
-grabstackblock(int len)
+static inline void grabstackblock(int len)
{
len = ALIGN(len);
stacknxt += len;
*/
-static char *
-growstackstr(void) {
+static char *growstackstr(void)
+{
int len = stackblocksize();
+
if (herefd >= 0 && len >= 1024) {
xwrite(herefd, stackblock(), len);
sstrnleft = len - 1;
* Called from CHECKSTRSPACE.
*/
-static char *
-makestrspace(size_t newlen) {
+static char *makestrspace(size_t newlen)
+{
int len = stackblocksize() - sstrnleft;
+
do {
growstackblock();
sstrnleft = stackblocksize() - len;
-static void
-ungrabstackstr(char *s, char *p)
+static void ungrabstackstr(char *s, char *p)
{
stacknleft += stacknxt - s;
stacknxt = s;
sstrnleft = stacknleft - (p - s);
}
+
/*
* Miscelaneous builtins.
*/
* This uses unbuffered input, which may be avoidable in some cases.
*/
-static int
-readcmd(int argc, char **argv)
+static int readcmd(int argc, char **argv)
{
char **ap;
int backslash;
rflag = 1;
}
if (prompt && isatty(0)) {
- out2str(prompt); /* read without cmdedit */
+ out2str(prompt); /* read without cmdedit */
flushall();
}
if (*(ap = argptr) == NULL)
-static int
-umaskcmd(int argc, char **argv)
+static int umaskcmd(int argc, char **argv)
{
static const char permuser[3] = "ugo";
static const char permmode[3] = "rwx";
if (symbolic_mode) {
char buf[18];
char *p = buf;
- for (i=0 ; i<3 ; i++) {
+
+ for (i = 0; i < 3; i++) {
int j;
+
*p++ = permuser[i];
*p++ = '=';
- for (j=0 ; j<3 ; j++) {
- if ((mask & permmask[3*i+j]) == 0) {
+ for (j = 0; j < 3; j++) {
+ if ((mask & permmask[3 * i + j]) == 0) {
*p++ = permmode[j];
}
}
printf("%.4o\n", mask);
}
} else {
- if (is_digit((unsigned char)*ap)) {
+ if (is_digit((unsigned char) *ap)) {
mask = 0;
do {
if (*ap >= '8' || *ap < '0')
umask(mask);
} else {
mask = ~mask & 0777;
- if (! parse_mode(ap, &mask)) {
+ if (!parse_mode(ap, &mask)) {
error("Illegal mode: %s", ap);
}
umask(~mask & 0777);
struct limits {
const char *name;
- short cmd;
- short factor; /* multiply by to get rlim_{cur,max} values */
+ short cmd;
+ short factor; /* multiply by to get rlim_{cur,max} values */
};
static const struct limits limits[] = {
#ifdef RLIMIT_CPU
- { "time(seconds)", RLIMIT_CPU, 1 },
+ {"time(seconds)", RLIMIT_CPU, 1},
#endif
#ifdef RLIMIT_FSIZE
- { "file(blocks)", RLIMIT_FSIZE, 512 },
+ {"file(blocks)", RLIMIT_FSIZE, 512},
#endif
#ifdef RLIMIT_DATA
- { "data(kbytes)", RLIMIT_DATA, 1024 },
+ {"data(kbytes)", RLIMIT_DATA, 1024},
#endif
#ifdef RLIMIT_STACK
- { "stack(kbytes)", RLIMIT_STACK, 1024 },
+ {"stack(kbytes)", RLIMIT_STACK, 1024},
#endif
#ifdef RLIMIT_CORE
- { "coredump(blocks)", RLIMIT_CORE, 512 },
+ {"coredump(blocks)", RLIMIT_CORE, 512},
#endif
#ifdef RLIMIT_RSS
- { "memory(kbytes)", RLIMIT_RSS, 1024 },
+ {"memory(kbytes)", RLIMIT_RSS, 1024},
#endif
#ifdef RLIMIT_MEMLOCK
- { "locked memory(kbytes)", RLIMIT_MEMLOCK, 1024 },
+ {"locked memory(kbytes)", RLIMIT_MEMLOCK, 1024},
#endif
#ifdef RLIMIT_NPROC
- { "process(processes)", RLIMIT_NPROC, 1 },
+ {"process(processes)", RLIMIT_NPROC, 1},
#endif
#ifdef RLIMIT_NOFILE
- { "nofiles(descriptors)", RLIMIT_NOFILE, 1 },
+ {"nofiles(descriptors)", RLIMIT_NOFILE, 1},
#endif
#ifdef RLIMIT_VMEM
- { "vmemory(kbytes)", RLIMIT_VMEM, 1024 },
+ {"vmemory(kbytes)", RLIMIT_VMEM, 1024},
#endif
#ifdef RLIMIT_SWAP
- { "swap(kbytes)", RLIMIT_SWAP, 1024 },
+ {"swap(kbytes)", RLIMIT_SWAP, 1024},
#endif
- { NULL, 0, 0 }
+ {NULL, 0, 0}
};
-static int
-ulimitcmd(int argc, char **argv)
+static int ulimitcmd(int argc, char **argv)
{
static const char unlimited_string[] = "unlimited";
- int c;
+ int c;
rlim_t val = 0;
- enum { SOFT = 0x1, HARD = 0x2 }
- how = SOFT | HARD;
- const struct limits *l;
- int set, all = 0;
- int optc, what;
- struct rlimit limit;
+ enum { SOFT = 0x1, HARD = 0x2 } how = SOFT | HARD;
+ const struct limits *l;
+ int set, all = 0;
+ int optc, what;
+ struct rlimit limit;
what = 'f';
while ((optc = nextopt("HSa"
#ifdef RLIMIT_CPU
- "t"
+ "t"
#endif
#ifdef RLIMIT_FSIZE
- "f"
+ "f"
#endif
#ifdef RLIMIT_DATA
- "d"
+ "d"
#endif
#ifdef RLIMIT_STACK
- "s"
+ "s"
#endif
#ifdef RLIMIT_CORE
- "c"
+ "c"
#endif
#ifdef RLIMIT_RSS
- "m"
+ "m"
#endif
#ifdef RLIMIT_MEMLOCK
- "l"
+ "l"
#endif
#ifdef RLIMIT_NPROC
- "p"
+ "p"
#endif
#ifdef RLIMIT_NOFILE
- "n"
+ "n"
#endif
#ifdef RLIMIT_VMEM
- "v"
+ "v"
#endif
#ifdef RLIMIT_SWAP
- "w"
+ "w"
#endif
- )) != '\0') {
+ )) != '\0') {
if (optc == 'H') {
how = HARD;
} else if (optc == 'S') {
}
for (l = limits; l->name; l++) {
- if(l->name[0] == what)
+ if (l->name[0] == what)
break;
- if(l->name[1]=='w' && what=='w')
+ if (l->name[1] == 'w' && what == 'w')
break;
}
else {
val = (rlim_t) 0;
- while ((c = *p++) >= '0' && c <= '9')
- {
- val = (val * 10) + (long)(c - '0');
+ while ((c = *p++) >= '0' && c <= '9') {
+ val = (val * 10) + (long) (c - '0');
if (val < (rlim_t) 0)
break;
}
for (l = limits; l->name; l++) {
printf("%-20s ", l->name);
getrlimit(l->cmd, &limit);
- OUTPUT_LIMIT:
+ OUTPUT_LIMIT:
if (how & SOFT)
val = limit.rlim_cur;
else if (how & HARD)
if (val == RLIM_INFINITY)
puts(unlimited_string);
- else
- {
+ else {
val /= l->factor;
printf("%lld\n", (long long) val);
}
error("error setting limit (%m)");
return 0;
}
+
/*
* prefix -- see if pfx is a prefix of string.
*/
-static int
-prefix(char const *pfx, char const *string)
+static int prefix(char const *pfx, char const *string)
{
while (*pfx) {
if (*pfx++ != *string++)
* nagative is bad
*/
-static int
-is_number(const char *p, int *intptr)
+static int is_number(const char *p, int *intptr)
{
int ret = 0;
do {
- if (! is_digit(*p))
+ if (!is_digit(*p))
return 0;
ret *= 10;
ret += digit_val(*p);
* failure.
*/
-static int
-number(const char *s)
+static int number(const char *s)
{
int i;
- if (! is_number(s, &i))
+
+ if (!is_number(s, &i))
error("Illegal number: %s", s);
return i;
}
* The return string is allocated on the stack.
*/
-static char *
-single_quote(const char *s)
+static char *single_quote(const char *s)
{
char *p;
* Like strdup but works with the ash stack.
*/
-static char *
-sstrdup(const char *p)
+static char *sstrdup(const char *p)
{
size_t len = strlen(p) + 1;
+
return memcpy(stalloc(len), p, len);
}
*/
-static void sizenodelist (const struct nodelist *);
-static struct nodelist *copynodelist (const struct nodelist *);
-static char *nodexstrdup (const char *);
+static void sizenodelist(const struct nodelist *);
+static struct nodelist *copynodelist(const struct nodelist *);
+static char *nodexstrdup(const char *);
#define CALCSIZE_TABLE
#define COPYNODE_TABLE
#define NODE_INTEGER 0x40
#define NODE_NODELIST 0x80
#define NODE_CHARPTR 0xC0
-#define NODE_NOMORE 0x01 /* Note: no offset should be odd (aligned)*/
+#define NODE_NOMORE 0x01 /* Note: no offset should be odd (aligned) */
#define NODE_MBRMASK 0xC0
#define NODE_OFFSETMASK 0x3E
static const unsigned char copynode_ops[35] = {
#define COPYNODE_OPS0 0
offsetof(union node, nbinary.ch2),
- offsetof(union node, nbinary.ch1)|NODE_NOMORE,
+ offsetof(union node, nbinary.ch1) | NODE_NOMORE,
#define COPYNODE_OPS1 (COPYNODE_OPS0 + 2)
offsetof(union node, ncmd.redirect),
offsetof(union node, ncmd.args),
offsetof(union node, ncmd.assign),
- offsetof(union node, ncmd.backgnd)|NODE_INTEGER|NODE_NOMORE,
+ offsetof(union node, ncmd.backgnd) | NODE_INTEGER | NODE_NOMORE,
#define COPYNODE_OPS2 (COPYNODE_OPS1 + 4)
- offsetof(union node, npipe.cmdlist)|NODE_NODELIST,
- offsetof(union node, npipe.backgnd)|NODE_INTEGER|NODE_NOMORE,
+ offsetof(union node, npipe.cmdlist) | NODE_NODELIST,
+ offsetof(union node, npipe.backgnd) | NODE_INTEGER | NODE_NOMORE,
#define COPYNODE_OPS3 (COPYNODE_OPS2 + 2)
offsetof(union node, nredir.redirect),
- offsetof(union node, nredir.n)|NODE_NOMORE,
+ offsetof(union node, nredir.n) | NODE_NOMORE,
#define COPYNODE_OPS4 (COPYNODE_OPS3 + 2)
offsetof(union node, nif.elsepart),
offsetof(union node, nif.ifpart),
- offsetof(union node, nif.test)|NODE_NOMORE,
+ offsetof(union node, nif.test) | NODE_NOMORE,
#define COPYNODE_OPS5 (COPYNODE_OPS4 + 3)
- offsetof(union node, nfor.var)|NODE_CHARPTR,
+ offsetof(union node, nfor.var) | NODE_CHARPTR,
offsetof(union node, nfor.body),
- offsetof(union node, nfor.args)|NODE_NOMORE,
+ offsetof(union node, nfor.args) | NODE_NOMORE,
#define COPYNODE_OPS6 (COPYNODE_OPS5 + 3)
offsetof(union node, ncase.cases),
- offsetof(union node, ncase.expr)|NODE_NOMORE,
+ offsetof(union node, ncase.expr) | NODE_NOMORE,
#define COPYNODE_OPS7 (COPYNODE_OPS6 + 2)
offsetof(union node, nclist.body),
offsetof(union node, nclist.pattern),
- offsetof(union node, nclist.next)|NODE_NOMORE,
+ offsetof(union node, nclist.next) | NODE_NOMORE,
#define COPYNODE_OPS8 (COPYNODE_OPS7 + 3)
- offsetof(union node, narg.backquote)|NODE_NODELIST,
- offsetof(union node, narg.text)|NODE_CHARPTR,
- offsetof(union node, narg.next)|NODE_NOMORE,
+ offsetof(union node, narg.backquote) | NODE_NODELIST,
+ offsetof(union node, narg.text) | NODE_CHARPTR,
+ offsetof(union node, narg.next) | NODE_NOMORE,
#define COPYNODE_OPS9 (COPYNODE_OPS8 + 3)
offsetof(union node, nfile.fname),
- offsetof(union node, nfile.fd)|NODE_INTEGER,
- offsetof(union node, nfile.next)|NODE_NOMORE,
+ offsetof(union node, nfile.fd) | NODE_INTEGER,
+ offsetof(union node, nfile.next) | NODE_NOMORE,
#define COPYNODE_OPS10 (COPYNODE_OPS9 + 3)
offsetof(union node, ndup.vname),
- offsetof(union node, ndup.dupfd)|NODE_INTEGER,
- offsetof(union node, ndup.fd)|NODE_INTEGER,
- offsetof(union node, ndup.next)|NODE_NOMORE,
+ offsetof(union node, ndup.dupfd) | NODE_INTEGER,
+ offsetof(union node, ndup.fd) | NODE_INTEGER,
+ offsetof(union node, ndup.next) | NODE_NOMORE,
#define COPYNODE_OPS11 (COPYNODE_OPS10 + 4)
offsetof(union node, nhere.doc),
- offsetof(union node, nhere.fd)|NODE_INTEGER,
- offsetof(union node, nhere.next)|NODE_NOMORE,
+ offsetof(union node, nhere.fd) | NODE_INTEGER,
+ offsetof(union node, nhere.next) | NODE_NOMORE,
#define COPYNODE_OPS12 (COPYNODE_OPS11 + 3)
- offsetof(union node, nnot.com)|NODE_NOMORE,
+ offsetof(union node, nnot.com) | NODE_NOMORE,
};
#if COPYNODE_OPS12 != 34
#endif
static const unsigned char copynode_ops_index[26] = {
- COPYNODE_OPS0, /* NSEMI */
- COPYNODE_OPS1, /* NCMD */
- COPYNODE_OPS2, /* NPIPE */
- COPYNODE_OPS3, /* NREDIR */
- COPYNODE_OPS3, /* NBACKGND */
- COPYNODE_OPS3, /* NSUBSHELL */
- COPYNODE_OPS0, /* NAND */
- COPYNODE_OPS0, /* NOR */
- COPYNODE_OPS4, /* NIF */
- COPYNODE_OPS0, /* NWHILE */
- COPYNODE_OPS0, /* NUNTIL */
- COPYNODE_OPS5, /* NFOR */
- COPYNODE_OPS6, /* NCASE */
- COPYNODE_OPS7, /* NCLIST */
- COPYNODE_OPS8, /* NDEFUN */
- COPYNODE_OPS8, /* NARG */
- COPYNODE_OPS9, /* NTO */
- COPYNODE_OPS9, /* NFROM */
- COPYNODE_OPS9, /* NFROMTO */
- COPYNODE_OPS9, /* NAPPEND */
- COPYNODE_OPS9, /* NTOOV */
- COPYNODE_OPS10, /* NTOFD */
- COPYNODE_OPS10, /* NFROMFD */
- COPYNODE_OPS11, /* NHERE */
- COPYNODE_OPS11, /* NXHERE */
- COPYNODE_OPS12, /* NNOT */
+ COPYNODE_OPS0, /* NSEMI */
+ COPYNODE_OPS1, /* NCMD */
+ COPYNODE_OPS2, /* NPIPE */
+ COPYNODE_OPS3, /* NREDIR */
+ COPYNODE_OPS3, /* NBACKGND */
+ COPYNODE_OPS3, /* NSUBSHELL */
+ COPYNODE_OPS0, /* NAND */
+ COPYNODE_OPS0, /* NOR */
+ COPYNODE_OPS4, /* NIF */
+ COPYNODE_OPS0, /* NWHILE */
+ COPYNODE_OPS0, /* NUNTIL */
+ COPYNODE_OPS5, /* NFOR */
+ COPYNODE_OPS6, /* NCASE */
+ COPYNODE_OPS7, /* NCLIST */
+ COPYNODE_OPS8, /* NDEFUN */
+ COPYNODE_OPS8, /* NARG */
+ COPYNODE_OPS9, /* NTO */
+ COPYNODE_OPS9, /* NFROM */
+ COPYNODE_OPS9, /* NFROMTO */
+ COPYNODE_OPS9, /* NAPPEND */
+ COPYNODE_OPS9, /* NTOOV */
+ COPYNODE_OPS10, /* NTOFD */
+ COPYNODE_OPS10, /* NFROMFD */
+ COPYNODE_OPS11, /* NHERE */
+ COPYNODE_OPS11, /* NXHERE */
+ COPYNODE_OPS12, /* NNOT */
};
#if NODE_CHARPTR != NODE_MBRMASK
#error NODE_CHARPTR != NODE_MBRMASK!!!
#endif
-#endif /* defined(CALCSIZE_TABLE) || defined(COPYNODE_TABLE) */
+#endif /* defined(CALCSIZE_TABLE) || defined(COPYNODE_TABLE) */
#ifdef COPYNODE_TABLE
-static union node *
-copynode(const union node *n)
-{
- union node *new;
- const unsigned char *p;
-
- if (n == NULL) {
- return NULL;
- }
- new = funcblock;
- new->type = n->type;
- funcblock = (char *) funcblock + (int) nodesize[n->type];
- p = copynode_ops + (int) copynode_ops_index[n->type];
- do {
- char *nn = ((char *) new) + ((int)(*p & NODE_OFFSETMASK));
- const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
-
- if (!(*p & NODE_MBRMASK)) { /* standard node */
- *((union node **)nn) = copynode(*((const union node **) no));
- } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
- *((const char **)nn) = nodexstrdup(*((const char **)no));
- } else if (*p & NODE_NODELIST) { /* nodelist */
- *((struct nodelist **)nn)
- = copynodelist(*((const struct nodelist **) no));
- } else { /* integer */
- *((int *) nn) = *((int *) no);
- }
- } while (!(*p++ & NODE_NOMORE));
- return new;
-}
-#else /* COPYNODE_TABLE */
-static union node *
-copynode(const union node *n)
-{
- union node *new;
-
- if (n == NULL)
- return NULL;
- new = funcblock;
- funcblock = (char *) funcblock + nodesize[n->type];
- switch (n->type) {
- case NSEMI:
- case NAND:
- case NOR:
- case NWHILE:
- case NUNTIL:
- new->nbinary.ch2 = copynode(n->nbinary.ch2);
- new->nbinary.ch1 = copynode(n->nbinary.ch1);
- break;
- case NCMD:
- new->ncmd.redirect = copynode(n->ncmd.redirect);
- new->ncmd.args = copynode(n->ncmd.args);
- new->ncmd.assign = copynode(n->ncmd.assign);
- new->ncmd.backgnd = n->ncmd.backgnd;
- break;
- case NPIPE:
- new->npipe.cmdlist = copynodelist(n->npipe.cmdlist);
- new->npipe.backgnd = n->npipe.backgnd;
- break;
- case NREDIR:
- case NBACKGND:
- case NSUBSHELL:
- new->nredir.redirect = copynode(n->nredir.redirect);
- new->nredir.n = copynode(n->nredir.n);
- break;
- case NIF:
- new->nif.elsepart = copynode(n->nif.elsepart);
- new->nif.ifpart = copynode(n->nif.ifpart);
- new->nif.test = copynode(n->nif.test);
- break;
- case NFOR:
- new->nfor.var = nodexstrdup(n->nfor.var);
- new->nfor.body = copynode(n->nfor.body);
- new->nfor.args = copynode(n->nfor.args);
- break;
- case NCASE:
- new->ncase.cases = copynode(n->ncase.cases);
- new->ncase.expr = copynode(n->ncase.expr);
- break;
- case NCLIST:
- new->nclist.body = copynode(n->nclist.body);
- new->nclist.pattern = copynode(n->nclist.pattern);
- new->nclist.next = copynode(n->nclist.next);
- break;
- case NDEFUN:
- case NARG:
- new->narg.backquote = copynodelist(n->narg.backquote);
- new->narg.text = nodexstrdup(n->narg.text);
- new->narg.next = copynode(n->narg.next);
- break;
- case NTO:
- case NFROM:
- case NFROMTO:
- case NAPPEND:
- case NTOOV:
- new->nfile.fname = copynode(n->nfile.fname);
- new->nfile.fd = n->nfile.fd;
- new->nfile.next = copynode(n->nfile.next);
- break;
- case NTOFD:
- case NFROMFD:
- new->ndup.vname = copynode(n->ndup.vname);
- new->ndup.dupfd = n->ndup.dupfd;
- new->ndup.fd = n->ndup.fd;
- new->ndup.next = copynode(n->ndup.next);
- break;
- case NHERE:
- case NXHERE:
- new->nhere.doc = copynode(n->nhere.doc);
- new->nhere.fd = n->nhere.fd;
- new->nhere.next = copynode(n->nhere.next);
- break;
- case NNOT:
- new->nnot.com = copynode(n->nnot.com);
- break;
- };
- new->type = n->type;
- return new;
-}
-#endif /* COPYNODE_TABLE */
+static union node *copynode(const union node *n)
+{
+ union node *new;
+ const unsigned char *p;
+
+ if (n == NULL) {
+ return NULL;
+ }
+ new = funcblock;
+ new->type = n->type;
+ funcblock = (char *) funcblock + (int) nodesize[n->type];
+ p = copynode_ops + (int) copynode_ops_index[n->type];
+ do {
+ char *nn = ((char *) new) + ((int) (*p & NODE_OFFSETMASK));
+ const char *no = ((const char *) n) + ((int) (*p & NODE_OFFSETMASK));
+
+ if (!(*p & NODE_MBRMASK)) { /* standard node */
+ *((union node **) nn) = copynode(*((const union node **) no));
+ } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
+ *((const char **) nn) = nodexstrdup(*((const char **) no));
+ } else if (*p & NODE_NODELIST) { /* nodelist */
+ *((struct nodelist **) nn)
+ = copynodelist(*((const struct nodelist **) no));
+ } else { /* integer */
+ *((int *) nn) = *((int *) no);
+ }
+ } while (!(*p++ & NODE_NOMORE));
+ return new;
+}
+#else /* COPYNODE_TABLE */
+static union node *copynode(const union node *n)
+{
+ union node *new;
+
+ if (n == NULL)
+ return NULL;
+ new = funcblock;
+ funcblock = (char *) funcblock + nodesize[n->type];
+ switch (n->type) {
+ case NSEMI:
+ case NAND:
+ case NOR:
+ case NWHILE:
+ case NUNTIL:
+ new->nbinary.ch2 = copynode(n->nbinary.ch2);
+ new->nbinary.ch1 = copynode(n->nbinary.ch1);
+ break;
+ case NCMD:
+ new->ncmd.redirect = copynode(n->ncmd.redirect);
+ new->ncmd.args = copynode(n->ncmd.args);
+ new->ncmd.assign = copynode(n->ncmd.assign);
+ new->ncmd.backgnd = n->ncmd.backgnd;
+ break;
+ case NPIPE:
+ new->npipe.cmdlist = copynodelist(n->npipe.cmdlist);
+ new->npipe.backgnd = n->npipe.backgnd;
+ break;
+ case NREDIR:
+ case NBACKGND:
+ case NSUBSHELL:
+ new->nredir.redirect = copynode(n->nredir.redirect);
+ new->nredir.n = copynode(n->nredir.n);
+ break;
+ case NIF:
+ new->nif.elsepart = copynode(n->nif.elsepart);
+ new->nif.ifpart = copynode(n->nif.ifpart);
+ new->nif.test = copynode(n->nif.test);
+ break;
+ case NFOR:
+ new->nfor.var = nodexstrdup(n->nfor.var);
+ new->nfor.body = copynode(n->nfor.body);
+ new->nfor.args = copynode(n->nfor.args);
+ break;
+ case NCASE:
+ new->ncase.cases = copynode(n->ncase.cases);
+ new->ncase.expr = copynode(n->ncase.expr);
+ break;
+ case NCLIST:
+ new->nclist.body = copynode(n->nclist.body);
+ new->nclist.pattern = copynode(n->nclist.pattern);
+ new->nclist.next = copynode(n->nclist.next);
+ break;
+ case NDEFUN:
+ case NARG:
+ new->narg.backquote = copynodelist(n->narg.backquote);
+ new->narg.text = nodexstrdup(n->narg.text);
+ new->narg.next = copynode(n->narg.next);
+ break;
+ case NTO:
+ case NFROM:
+ case NFROMTO:
+ case NAPPEND:
+ case NTOOV:
+ new->nfile.fname = copynode(n->nfile.fname);
+ new->nfile.fd = n->nfile.fd;
+ new->nfile.next = copynode(n->nfile.next);
+ break;
+ case NTOFD:
+ case NFROMFD:
+ new->ndup.vname = copynode(n->ndup.vname);
+ new->ndup.dupfd = n->ndup.dupfd;
+ new->ndup.fd = n->ndup.fd;
+ new->ndup.next = copynode(n->ndup.next);
+ break;
+ case NHERE:
+ case NXHERE:
+ new->nhere.doc = copynode(n->nhere.doc);
+ new->nhere.fd = n->nhere.fd;
+ new->nhere.next = copynode(n->nhere.next);
+ break;
+ case NNOT:
+ new->nnot.com = copynode(n->nnot.com);
+ break;
+ };
+ new->type = n->type;
+ return new;
+}
+#endif /* COPYNODE_TABLE */
#ifdef CALCSIZE_TABLE
-static void
-calcsize(const union node *n)
+static void calcsize(const union node *n)
{
- const unsigned char *p;
+ const unsigned char *p;
- if (n == NULL)
- return;
- funcblocksize += (int) nodesize[n->type];
+ if (n == NULL)
+ return;
+ funcblocksize += (int) nodesize[n->type];
- p = copynode_ops + (int) copynode_ops_index[n->type];
- do {
- const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
+ p = copynode_ops + (int) copynode_ops_index[n->type];
+ do {
+ const char *no = ((const char *) n) + ((int) (*p & NODE_OFFSETMASK));
- if (!(*p & NODE_MBRMASK)) { /* standard node */
- calcsize(*((const union node **) no));
- } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
- funcstringsize += strlen(*((const char **)no)) + 1;
- } else if (*p & NODE_NODELIST) { /* nodelist */
- sizenodelist(*((const struct nodelist **) no));
- } /* else integer -- ignore */
- } while (!(*p++ & NODE_NOMORE));
+ if (!(*p & NODE_MBRMASK)) { /* standard node */
+ calcsize(*((const union node **) no));
+ } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
+ funcstringsize += strlen(*((const char **) no)) + 1;
+ } else if (*p & NODE_NODELIST) { /* nodelist */
+ sizenodelist(*((const struct nodelist **) no));
+ } /* else integer -- ignore */
+ } while (!(*p++ & NODE_NOMORE));
}
-#else /* CALCSIZE_TABLE */
-static void
-calcsize(const union node *n)
-{
- if (n == NULL)
- return;
- funcblocksize += nodesize[n->type];
- switch (n->type) {
- case NSEMI:
- case NAND:
- case NOR:
- case NWHILE:
- case NUNTIL:
- calcsize(n->nbinary.ch2);
- calcsize(n->nbinary.ch1);
- break;
- case NCMD:
- calcsize(n->ncmd.redirect);
- calcsize(n->ncmd.args);
- calcsize(n->ncmd.assign);
- break;
- case NPIPE:
- sizenodelist(n->npipe.cmdlist);
- break;
- case NREDIR:
- case NBACKGND:
- case NSUBSHELL:
- calcsize(n->nredir.redirect);
- calcsize(n->nredir.n);
- break;
- case NIF:
- calcsize(n->nif.elsepart);
- calcsize(n->nif.ifpart);
- calcsize(n->nif.test);
- break;
- case NFOR:
- funcstringsize += strlen(n->nfor.var) + 1;
- calcsize(n->nfor.body);
- calcsize(n->nfor.args);
- break;
- case NCASE:
- calcsize(n->ncase.cases);
- calcsize(n->ncase.expr);
- break;
- case NCLIST:
- calcsize(n->nclist.body);
- calcsize(n->nclist.pattern);
- calcsize(n->nclist.next);
- break;
- case NDEFUN:
- case NARG:
- sizenodelist(n->narg.backquote);
- funcstringsize += strlen(n->narg.text) + 1;
- calcsize(n->narg.next);
- break;
- case NTO:
- case NFROM:
- case NFROMTO:
- case NAPPEND:
- case NTOOV:
- calcsize(n->nfile.fname);
- calcsize(n->nfile.next);
- break;
- case NTOFD:
- case NFROMFD:
- calcsize(n->ndup.vname);
- calcsize(n->ndup.next);
- break;
- case NHERE:
- case NXHERE:
- calcsize(n->nhere.doc);
- calcsize(n->nhere.next);
- break;
- case NNOT:
- calcsize(n->nnot.com);
- break;
- };
-}
-#endif /* CALCSIZE_TABLE */
+#else /* CALCSIZE_TABLE */
+static void calcsize(const union node *n)
+{
+ if (n == NULL)
+ return;
+ funcblocksize += nodesize[n->type];
+ switch (n->type) {
+ case NSEMI:
+ case NAND:
+ case NOR:
+ case NWHILE:
+ case NUNTIL:
+ calcsize(n->nbinary.ch2);
+ calcsize(n->nbinary.ch1);
+ break;
+ case NCMD:
+ calcsize(n->ncmd.redirect);
+ calcsize(n->ncmd.args);
+ calcsize(n->ncmd.assign);
+ break;
+ case NPIPE:
+ sizenodelist(n->npipe.cmdlist);
+ break;
+ case NREDIR:
+ case NBACKGND:
+ case NSUBSHELL:
+ calcsize(n->nredir.redirect);
+ calcsize(n->nredir.n);
+ break;
+ case NIF:
+ calcsize(n->nif.elsepart);
+ calcsize(n->nif.ifpart);
+ calcsize(n->nif.test);
+ break;
+ case NFOR:
+ funcstringsize += strlen(n->nfor.var) + 1;
+ calcsize(n->nfor.body);
+ calcsize(n->nfor.args);
+ break;
+ case NCASE:
+ calcsize(n->ncase.cases);
+ calcsize(n->ncase.expr);
+ break;
+ case NCLIST:
+ calcsize(n->nclist.body);
+ calcsize(n->nclist.pattern);
+ calcsize(n->nclist.next);
+ break;
+ case NDEFUN:
+ case NARG:
+ sizenodelist(n->narg.backquote);
+ funcstringsize += strlen(n->narg.text) + 1;
+ calcsize(n->narg.next);
+ break;
+ case NTO:
+ case NFROM:
+ case NFROMTO:
+ case NAPPEND:
+ case NTOOV:
+ calcsize(n->nfile.fname);
+ calcsize(n->nfile.next);
+ break;
+ case NTOFD:
+ case NFROMFD:
+ calcsize(n->ndup.vname);
+ calcsize(n->ndup.next);
+ break;
+ case NHERE:
+ case NXHERE:
+ calcsize(n->nhere.doc);
+ calcsize(n->nhere.next);
+ break;
+ case NNOT:
+ calcsize(n->nnot.com);
+ break;
+ };
+}
+#endif /* CALCSIZE_TABLE */
-static void
-sizenodelist(const struct nodelist *lp)
+static void sizenodelist(const struct nodelist *lp)
{
while (lp) {
funcblocksize += ALIGN(sizeof(struct nodelist));
}
-static struct nodelist *
-copynodelist(const struct nodelist *lp)
+static struct nodelist *copynodelist(const struct nodelist *lp)
{
struct nodelist *start;
struct nodelist **lpp;
}
-static char *
-nodexstrdup(const char *s)
+static char *nodexstrdup(const char *s)
{
const char *p = s;
char *q = funcstring;
- char *rtn = funcstring;
+ char *rtn = funcstring;
while ((*q++ = *p++) != '\0')
continue;
}
#ifdef CONFIG_ASH_GETOPTS
-static int getopts (char *, char *, char **, int *, int *);
+static int getopts(char *, char *, char **, int *, int *);
#endif
/*
* Process the shell command line arguments.
*/
-static void
-procargs(int argc, char **argv)
+static void procargs(int argc, char **argv)
{
int i;
* to the argument list; we advance it past the options.
*/
-static inline void
-minus_o(const char *name, int val)
+static inline void minus_o(const char *name, int val)
{
int i;
out1str("Current option settings\n");
for (i = 0; i < NOPTS; i++)
printf("%-16s%s\n", optent_name(optlist[i]),
- optent_val(i) ? "on" : "off");
+ optent_val(i) ? "on" : "off");
} else {
for (i = 0; i < NOPTS; i++)
if (equal(name, optent_name(optlist[i]))) {
}
-static void
-options(int cmdline)
+static void options(int cmdline)
{
char *p;
int val;
else if (*argptr == NULL)
setparam(argptr);
}
- break; /* "-" or "--" terminates options */
+ break; /* "-" or "--" terminates options */
}
} else if (c == '+') {
val = 0;
while ((c = *p++) != '\0') {
if (c == 'c' && cmdline) {
char *q;
-#ifdef NOHACK /* removing this code allows sh -ce 'foo' for compat */
+
+#ifdef NOHACK /* removing this code allows sh -ce 'foo' for compat */
if (*p == '\0')
#endif
q = *argptr++;
minus_o(*argptr, val);
if (*argptr)
argptr++;
- } else if (cmdline && (c == '-')) { // long options
- if ( strcmp ( p, "login" ) == 0 )
+ } else if (cmdline && (c == '-')) { /* long options */
+ if (strcmp(p, "login") == 0)
isloginsh = 1;
break;
} else {
}
-static void
-setoption(int flag, int val)
+static void setoption(int flag, int val)
{
int i;
* Set the shell parameters.
*/
-static void
-setparam(char **argv)
+static void setparam(char **argv)
{
char **newparam;
char **ap;
int nparam;
- for (nparam = 0 ; argv[nparam] ; nparam++);
+ for (nparam = 0; argv[nparam]; nparam++);
ap = newparam = xmalloc((nparam + 1) * sizeof *ap);
while (*argv) {
*ap++ = xstrdup(*argv++);
* Free the list of positional parameters.
*/
-static void
-freeparam(volatile struct shparam *param)
+static void freeparam(volatile struct shparam *param)
{
char **ap;
if (param->malloc) {
- for (ap = param->p ; *ap ; ap++)
+ for (ap = param->p; *ap; ap++)
free(*ap);
free(param->p);
}
* The shift builtin command.
*/
-static int
-shiftcmd(int argc, char **argv)
+static int shiftcmd(int argc, char **argv)
{
int n;
char **ap1, **ap2;
error("can't shift that many");
INTOFF;
shellparam.nparam -= n;
- for (ap1 = shellparam.p ; --n >= 0 ; ap1++) {
+ for (ap1 = shellparam.p; --n >= 0; ap1++) {
if (shellparam.malloc)
free(*ap1);
}
* The set command builtin.
*/
-static int
-setcmd(int argc, char **argv)
+static int setcmd(int argc, char **argv)
{
if (argc == 1)
return showvarscmd(argc, argv);
}
-static void
-getoptsreset(const char *value)
+static void getoptsreset(const char *value)
{
shellparam.optind = number(value);
shellparam.optoff = -1;
#ifdef CONFIG_LOCALE_SUPPORT
static void change_lc_all(const char *value)
{
- if(value != 0 && *value != 0)
+ if (value != 0 && *value != 0)
setlocale(LC_ALL, value);
}
static void change_lc_ctype(const char *value)
{
- if(value != 0 && *value != 0)
+ if (value != 0 && *value != 0)
setlocale(LC_CTYPE, value);
}
* then it's the first time getopts has been called.
*/
-static int
-getoptscmd(int argc, char **argv)
+static int getoptscmd(int argc, char **argv)
{
char **optbase;
shellparam.optind = 1;
shellparam.optoff = -1;
}
- }
- else {
+ } else {
optbase = &argv[3];
if (shellparam.optind > argc - 2) {
shellparam.optind = 1;
}
return getopts(argv[1], argv[2], optbase, &shellparam.optind,
- &shellparam.optoff);
+ &shellparam.optoff);
}
/*
* Safe version of setvar, returns 1 on success 0 on failure.
*/
-static int
-setvarsafe(const char *name, const char *val, int flags)
+static int setvarsafe(const char *name, const char *val, int flags)
{
struct jmploc jmploc;
struct jmploc *volatile savehandler = handler;
int err = 0;
+
#ifdef __GNUC__
(void) &err;
#endif
}
static int
-getopts(char *optstr, char *optvar, char **optfirst, int *myoptind, int *optoff)
+getopts(char *optstr, char *optvar, char **optfirst, int *myoptind,
+ int *optoff)
{
char *p, *q;
char c = '?';
char **optnext = optfirst + *myoptind - 1;
if (*myoptind <= 1 || *optoff < 0 || !(*(optnext - 1)) ||
- strlen(*(optnext - 1)) < *optoff)
+ strlen(*(optnext - 1)) < *optoff)
p = NULL;
else
p = *(optnext - 1) + *optoff;
return 1;
p = *optnext;
if (p == NULL || *p != '-' || *++p == '\0') {
-atend:
+ atend:
*myoptind = optnext - optfirst + 1;
p = NULL;
done = 1;
goto out;
}
optnext++;
- if (p[0] == '-' && p[1] == '\0') /* check for "--" */
+ if (p[0] == '-' && p[1] == '\0') /* check for "--" */
goto atend;
}
c = *p++;
- for (q = optstr; *q != c; ) {
+ for (q = optstr; *q != c;) {
if (*q == '\0') {
if (optstr[0] == ':') {
s[0] = c;
s[1] = '\0';
err |= setvarsafe("OPTARG", s, 0);
- }
- else {
+ } else {
out2fmt("Illegal option -%c\n", c);
(void) unsetvar("OPTARG");
}
s[1] = '\0';
err |= setvarsafe("OPTARG", s, 0);
c = ':';
- }
- else {
+ } else {
out2fmt("No arg for -%c option\n", c);
(void) unsetvar("OPTARG");
c = '?';
optnext++;
setvarsafe("OPTARG", p, 0);
p = NULL;
- }
- else
+ } else
setvarsafe("OPTARG", "", 0);
*myoptind = optnext - optfirst + 1;
goto out;
-bad:
+ bad:
*myoptind = 1;
p = NULL;
-out:
+ out:
*optoff = p ? p - *(optnext - 1) : -1;
snprintf(s, sizeof(s), "%d", *myoptind);
err |= setvarsafe("OPTIND", s, VNOFUNC);
* end of input.
*/
-static int
-nextopt(const char *optstring)
+static int nextopt(const char *optstring)
{
char *p;
const char *q;
if (p == NULL || *p != '-' || *++p == '\0')
return '\0';
argptr++;
- if (p[0] == '-' && p[1] == '\0') /* check for "--" */
+ if (p[0] == '-' && p[1] == '\0') /* check for "--" */
return '\0';
}
c = *p++;
- for (q = optstring ; *q != c ; ) {
+ for (q = optstring; *q != c;) {
if (*q == '\0')
error("Illegal option -%c", c);
if (*++q == ':')
return c;
}
-static void
-flushall() {
+static void flushall()
+{
INTOFF;
fflush(stdout);
INTON;
}
-static void
-out2fmt(const char *fmt, ...)
+static void out2fmt(const char *fmt, ...)
{
va_list ap;
+
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
* Version of write which resumes after a signal is caught.
*/
-static int
-xwrite(int fd, const char *buf, int nbytes)
+static int xwrite(int fd, const char *buf, int nbytes)
{
int ntry;
int i;
struct heredoc {
- struct heredoc *next; /* next here document in list */
- union node *here; /* redirection node */
- char *eofmark; /* string indicating end of input */
- int striptabs; /* if set, strip leading tabs */
+ struct heredoc *next; /* next here document in list */
+ union node *here; /* redirection node */
+ char *eofmark; /* string indicating end of input */
+ int striptabs; /* if set, strip leading tabs */
};
-static struct heredoc *heredoclist; /* list of here documents to read */
-static int parsebackquote; /* nonzero if we are inside backquotes */
-static int doprompt; /* if set, prompt the user */
-static int needprompt; /* true if interactive and at start of line */
-static int lasttoken; /* last token read */
+static struct heredoc *heredoclist; /* list of here documents to read */
+static int parsebackquote; /* nonzero if we are inside backquotes */
+static int doprompt; /* if set, prompt the user */
+static int needprompt; /* true if interactive and at start of line */
+static int lasttoken; /* last token read */
-static char *wordtext; /* text of last word returned by readtoken */
+static char *wordtext; /* text of last word returned by readtoken */
static struct nodelist *backquotelist;
static union node *redirnode;
static struct heredoc *heredoc;
-static int quoteflag; /* set if (part of) last token was quoted */
-static int startlinno; /* line # where last token started */
+static int quoteflag; /* set if (part of) last token was quoted */
+static int startlinno; /* line # where last token started */
-static union node *list (int);
-static union node *andor (void);
-static union node *pipeline (void);
-static union node *command (void);
+static union node *list(int);
+static union node *andor(void);
+static union node *pipeline(void);
+static union node *command(void);
static union node *simplecmd(union node **rpp, union node *redir);
-static void parsefname (void);
-static void parseheredoc (void);
-static char peektoken (void);
-static int readtoken (void);
-static int xxreadtoken (void);
-static int readtoken1 (int, int, const char *, int);
-static int noexpand (char *);
-static void synexpect (int) __attribute__((noreturn));
-static void synerror (const char *) __attribute__((noreturn));
-static void setprompt (int);
+static void parsefname(void);
+static void parseheredoc(void);
+static char peektoken(void);
+static int readtoken(void);
+static int xxreadtoken(void);
+static int readtoken1(int, int, const char *, int);
+static int noexpand(char *);
+static void synexpect(int) __attribute__ ((noreturn));
+static void synerror(const char *) __attribute__ ((noreturn));
+static void setprompt(int);
/*
* valid parse tree indicating a blank line.)
*/
-static union node *
-parsecmd(int interact)
+static union node *parsecmd(int interact)
{
int t;
}
-static union node *
-list(int nlflag)
+static union node *list(int nlflag)
{
union node *n1, *n2, *n3;
int tok;
} else if (n2->type == NREDIR) {
n2->type = NBACKGND;
} else {
- n3 = (union node *)stalloc(sizeof (struct nredir));
+ n3 = (union node *) stalloc(sizeof(struct nredir));
n3->type = NBACKGND;
n3->nredir.n = n2;
n3->nredir.redirect = NULL;
}
if (n1 == NULL) {
n1 = n2;
- }
- else {
- n3 = (union node *)stalloc(sizeof (struct nbinary));
+ } else {
+ n3 = (union node *) stalloc(sizeof(struct nbinary));
n3->type = NSEMI;
n3->nbinary.ch1 = n1;
n3->nbinary.ch2 = n2;
if (heredoclist)
parseheredoc();
else
- pungetc(); /* push back EOF on input */
+ pungetc(); /* push back EOF on input */
return n1;
default:
if (nlflag)
-static union node *
-andor() {
+static union node *andor()
+{
union node *n1, *n2, *n3;
int t;
}
checkkwd = 2;
n2 = pipeline();
- n3 = (union node *)stalloc(sizeof (struct nbinary));
+ n3 = (union node *) stalloc(sizeof(struct nbinary));
n3->type = t;
n3->nbinary.ch1 = n1;
n3->nbinary.ch2 = n2;
-static union node *
-pipeline() {
+static union node *pipeline()
+{
union node *n1, *n2, *pipenode;
struct nodelist *lp, *prev;
int negate;
tokpushback++;
n1 = command();
if (readtoken() == TPIPE) {
- pipenode = (union node *)stalloc(sizeof (struct npipe));
+ pipenode = (union node *) stalloc(sizeof(struct npipe));
pipenode->type = NPIPE;
pipenode->npipe.backgnd = 0;
- lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
+ lp = (struct nodelist *) stalloc(sizeof(struct nodelist));
pipenode->npipe.cmdlist = lp;
lp->n = n1;
do {
prev = lp;
- lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
+ lp = (struct nodelist *) stalloc(sizeof(struct nodelist));
checkkwd = 2;
lp->n = command();
prev->next = lp;
}
tokpushback++;
if (negate) {
- n2 = (union node *)stalloc(sizeof (struct nnot));
+ n2 = (union node *) stalloc(sizeof(struct nnot));
n2->type = NNOT;
n2->nnot.com = n1;
return n2;
-static union node *
-command(void) {
+static union node *command(void)
+{
union node *n1, *n2;
union node *ap, **app;
union node *cp, **cpp;
switch (readtoken()) {
case TIF:
- n1 = (union node *)stalloc(sizeof (struct nif));
+ n1 = (union node *) stalloc(sizeof(struct nif));
n1->type = NIF;
n1->nif.test = list(0);
if (readtoken() != TTHEN)
n1->nif.ifpart = list(0);
n2 = n1;
while (readtoken() == TELIF) {
- n2->nif.elsepart = (union node *)stalloc(sizeof (struct nif));
+ n2->nif.elsepart = (union node *) stalloc(sizeof(struct nif));
n2 = n2->nif.elsepart;
n2->type = NIF;
n2->nif.test = list(0);
checkkwd = 1;
break;
case TWHILE:
- case TUNTIL: {
+ case TUNTIL:{
int got;
- n1 = (union node *)stalloc(sizeof (struct nbinary));
- n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL;
+ n1 = (union node *) stalloc(sizeof(struct nbinary));
+ n1->type = (lasttoken == TWHILE) ? NWHILE : NUNTIL;
n1->nbinary.ch1 = list(0);
- if ((got=readtoken()) != TDO) {
-TRACE(("expecting DO got %s %s\n", tokname(got), got == TWORD ? wordtext : ""));
+ if ((got = readtoken()) != TDO) {
+ TRACE(("expecting DO got %s %s\n", tokname(got),
+ got == TWORD ? wordtext : ""));
synexpect(TDO);
}
n1->nbinary.ch2 = list(0);
break;
}
case TFOR:
- if (readtoken() != TWORD || quoteflag || ! goodname(wordtext))
+ if (readtoken() != TWORD || quoteflag || !goodname(wordtext))
synerror("Bad for loop variable");
- n1 = (union node *)stalloc(sizeof (struct nfor));
+ n1 = (union node *) stalloc(sizeof(struct nfor));
n1->type = NFOR;
n1->nfor.var = wordtext;
checkkwd = 1;
if (readtoken() == TIN) {
app = ≈
while (readtoken() == TWORD) {
- n2 = (union node *)stalloc(sizeof (struct narg));
+ n2 = (union node *) stalloc(sizeof(struct narg));
n2->type = NARG;
n2->narg.text = wordtext;
n2->narg.backquote = backquotelist;
if (lasttoken != TNL && lasttoken != TSEMI)
synexpect(-1);
} else {
- static char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE,
- '@', '=', '\0'};
- n2 = (union node *)stalloc(sizeof (struct narg));
+ static char argvars[5] = { CTLVAR, VSNORMAL | VSQUOTE,
+ '@', '=', '\0'
+ };
+ n2 = (union node *) stalloc(sizeof(struct narg));
n2->type = NARG;
n2->narg.text = argvars;
n2->narg.backquote = NULL;
checkkwd = 1;
break;
case TCASE:
- n1 = (union node *)stalloc(sizeof (struct ncase));
+ n1 = (union node *) stalloc(sizeof(struct ncase));
n1->type = NCASE;
if (readtoken() != TWORD)
synexpect(TWORD);
- n1->ncase.expr = n2 = (union node *)stalloc(sizeof (struct narg));
+ n1->ncase.expr = n2 = (union node *) stalloc(sizeof(struct narg));
n2->type = NARG;
n2->narg.text = wordtext;
n2->narg.backquote = backquotelist;
do {
if (lasttoken == TLP)
readtoken();
- *cpp = cp = (union node *)stalloc(sizeof (struct nclist));
+ *cpp = cp = (union node *) stalloc(sizeof(struct nclist));
cp->type = NCLIST;
app = &cp->nclist.pattern;
for (;;) {
- *app = ap = (union node *)stalloc(sizeof (struct narg));
+ *app = ap = (union node *) stalloc(sizeof(struct narg));
ap->type = NARG;
ap->narg.text = wordtext;
ap->narg.backquote = backquotelist;
checkkwd = 2, readtoken();
}
cpp = &cp->nclist.next;
- } while(lasttoken != TESAC);
+ } while (lasttoken != TESAC);
*cpp = NULL;
checkkwd = 1;
break;
case TLP:
- n1 = (union node *)stalloc(sizeof (struct nredir));
+ n1 = (union node *) stalloc(sizeof(struct nredir));
n1->type = NSUBSHELL;
n1->nredir.n = list(0);
n1->nredir.redirect = NULL;
synexpect(TEND);
checkkwd = 1;
break;
- /* Handle an empty command like other simple commands. */
+ /* Handle an empty command like other simple commands. */
case TSEMI:
case TAND:
case TOR:
*rpp = NULL;
if (redir) {
if (n1->type != NSUBSHELL) {
- n2 = (union node *)stalloc(sizeof (struct nredir));
+ n2 = (union node *) stalloc(sizeof(struct nredir));
n2->type = NREDIR;
n2->nredir.n = n1;
n1 = n2;
}
-static union node *
-simplecmd(union node **rpp, union node *redir) {
+static union node *simplecmd(union node **rpp, union node *redir)
+{
union node *args, **app;
union node *n = NULL;
union node *vars, **vpp;
vpp = &vars;
/* If we don't have any redirections already, then we must reset
- rpp to be the address of the local redir variable. */
+ rpp to be the address of the local redir variable. */
if (redir == 0)
- rpp = &redir;
+ rpp = &redir;
/* We save the incoming value, because we need this for shell
- functions. There can not be a redirect or an argument between
- the function name and the open parenthesis. */
+ functions. There can not be a redirect or an argument between
+ the function name and the open parenthesis. */
orig_rpp = rpp;
checkalias = 2;
switch (readtoken()) {
case TWORD:
case TASSIGN:
- n = (union node *)stalloc(sizeof (struct narg));
+ n = (union node *) stalloc(sizeof(struct narg));
n->type = NARG;
n->narg.text = wordtext;
n->narg.backquote = backquotelist;
case TREDIR:
*rpp = n = redirnode;
rpp = &n->nfile.next;
- parsefname(); /* read name of redirection file */
+ parsefname(); /* read name of redirection file */
break;
case TLP:
- if (
- args && app == &args->narg.next &&
- !vars && rpp == orig_rpp
- ) {
+ if (args && app == &args->narg.next && !vars && rpp == orig_rpp) {
/* We have a function */
if (readtoken() != TRP)
synexpect(TRP);
goto out;
}
}
-out:
+ out:
*app = NULL;
*vpp = NULL;
*rpp = NULL;
- n = (union node *)stalloc(sizeof (struct ncmd));
+ n = (union node *) stalloc(sizeof(struct ncmd));
n->type = NCMD;
n->ncmd.backgnd = 0;
n->ncmd.args = args;
return n;
}
-static union node *
-makename(void) {
+static union node *makename(void)
+{
union node *n;
- n = (union node *)stalloc(sizeof (struct narg));
+ n = (union node *) stalloc(sizeof(struct narg));
n->type = NARG;
n->narg.next = NULL;
n->narg.text = wordtext;
}
-static void
-parsefname(void) {
+static void parsefname(void)
+{
union node *n = redirnode;
if (readtoken() != TWORD)
while (*wordtext == '\t')
wordtext++;
}
- if (! noexpand(wordtext) || (i = strlen(wordtext)) == 0 || i > EOFMARKLEN)
+ if (!noexpand(wordtext) || (i = strlen(wordtext)) == 0
+ || i > EOFMARKLEN)
synerror("Illegal eof marker for << redirection");
rmescapes(wordtext);
here->eofmark = wordtext;
if (heredoclist == NULL)
heredoclist = here;
else {
- for (p = heredoclist ; p->next ; p = p->next);
+ for (p = heredoclist; p->next; p = p->next);
p->next = here;
}
} else if (n->type == NTOFD || n->type == NFROMFD) {
* Input any here documents.
*/
-static void
-parseheredoc() {
+static void parseheredoc()
+{
struct heredoc *here;
union node *n;
setprompt(2);
needprompt = 0;
}
- readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX,
- here->eofmark, here->striptabs);
- n = (union node *)stalloc(sizeof (struct narg));
+ readtoken1(pgetc(), here->here->type == NHERE ? SQSYNTAX : DQSYNTAX,
+ here->eofmark, here->striptabs);
+ n = (union node *) stalloc(sizeof(struct narg));
n->narg.type = NARG;
n->narg.next = NULL;
n->narg.text = wordtext;
}
}
-static char
-peektoken() {
+static char peektoken()
+{
int t;
t = readtoken();
return tokname_array[t][0];
}
-static int
-readtoken() {
+static int readtoken()
+{
int t;
int savecheckalias = checkalias;
+
#ifdef CONFIG_ASH_ALIAS
int savecheckkwd = checkkwd;
struct alias *ap;
#endif
#ifdef CONFIG_ASH_ALIAS
-top:
+ top:
#endif
t = xxreadtoken();
/*
* check for keywords
*/
- if (t == TWORD && !quoteflag)
- {
+ if (t == TWORD && !quoteflag) {
const char *const *pp;
if ((pp = findkwd(wordtext))) {
lasttoken = t = TASSIGN;
} else if (checkalias) {
#ifdef CONFIG_ASH_ALIAS
- if (!quoteflag && (ap = *__lookupalias(wordtext)) != NULL && !(ap->flag & ALIASINUSE)) {
+ if (!quoteflag && (ap = *__lookupalias(wordtext)) != NULL
+ && !(ap->flag & ALIASINUSE)) {
if (*ap->val) {
pushstring(ap->val, strlen(ap->val), ap);
}
#endif
checkalias = 0;
}
-out:
+ out:
#ifdef DEBUG
if (!alreadyseen)
- TRACE(("token %s %s\n", tokname(t), t == TWORD || t == TASSIGN ? wordtext : ""));
+ TRACE(("token %s %s\n", tokname(t), t == TWORD
+ || t == TASSIGN ? wordtext : ""));
else
- TRACE(("reread token %s %s\n", tokname(t), t == TWORD || t == TASSIGN ? wordtext : ""));
+ TRACE(("reread token %s %s\n", tokname(t), t == TWORD
+ || t == TASSIGN ? wordtext : ""));
#endif
return (t);
}
#define NEW_xxreadtoken
#ifdef NEW_xxreadtoken
-static const char xxreadtoken_chars[] = "\n()&|;"; /* singles must be first! */
+static const char xxreadtoken_chars[] = "\n()&|;"; /* singles must be first! */
static const char xxreadtoken_tokens[] = {
- TNL, TLP, TRP, /* only single occurrence allowed */
- TBACKGND, TPIPE, TSEMI, /* if single occurrence */
- TEOF, /* corresponds to trailing nul */
- TAND, TOR, TENDCASE, /* if double occurrence */
+ TNL, TLP, TRP, /* only single occurrence allowed */
+ TBACKGND, TPIPE, TSEMI, /* if single occurrence */
+ TEOF, /* corresponds to trailing nul */
+ TAND, TOR, TENDCASE, /* if double occurrence */
};
#define xxreadtoken_doubles \
#define xxreadtoken_singles \
(sizeof(xxreadtoken_chars) - xxreadtoken_doubles - 1)
-static int
-xxreadtoken() {
+static int xxreadtoken()
+{
int c;
if (tokpushback) {
needprompt = 0;
}
startlinno = plinno;
- for (;;) { /* until token or start of word found */
+ for (;;) { /* until token or start of word found */
c = pgetc_macro();
- if ((c!=' ') && (c!='\t')
+ if ((c != ' ') && (c != '\t')
#ifdef CONFIG_ASH_ALIAS
- && (c!=PEOA)
+ && (c != PEOA)
#endif
) {
- if (c=='#') {
+ if (c == '#') {
while ((c = pgetc()) != '\n' && c != PEOF);
pungetc();
- } else if (c=='\\') {
+ } else if (c == '\\') {
if (pgetc() != '\n') {
pungetc();
goto READTOKEN1;
const char *p
= xxreadtoken_chars + sizeof(xxreadtoken_chars) - 1;
- if (c!=PEOF) {
- if (c=='\n') {
+ if (c != PEOF) {
+ if (c == '\n') {
plinno++;
needprompt = doprompt;
}
p = strchr(xxreadtoken_chars, c);
if (p == NULL) {
- READTOKEN1:
- return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
+ READTOKEN1:
+ return readtoken1(c, BASESYNTAX, (char *) NULL, 0);
}
-
- if (p-xxreadtoken_chars >= xxreadtoken_singles) {
- if (pgetc() == *p) { /* double occurrence? */
+
+ if (p - xxreadtoken_chars >= xxreadtoken_singles) {
+ if (pgetc() == *p) { /* double occurrence? */
p += xxreadtoken_doubles + 1;
} else {
pungetc();
}
}
- return lasttoken = xxreadtoken_tokens[p-xxreadtoken_chars];
+ return lasttoken = xxreadtoken_tokens[p - xxreadtoken_chars];
}
}
}
#else
#define RETURN(token) return lasttoken = token
-static int
-xxreadtoken() {
+static int xxreadtoken()
+{
int c;
if (tokpushback) {
needprompt = 0;
}
startlinno = plinno;
- for (;;) { /* until token or start of word found */
+ for (;;) { /* until token or start of word found */
c = pgetc_macro();
switch (c) {
- case ' ': case '\t':
+ case ' ':
+ case '\t':
#ifdef CONFIG_ASH_ALIAS
case PEOA:
#endif
goto breakloop;
}
}
-breakloop:
- return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
+ breakloop:
+ return readtoken1(c, BASESYNTAX, (char *) NULL, 0);
#undef RETURN
}
#endif
struct nodelist *bqlist;
int quotef;
int dblquote;
- int varnest; /* levels of variables expansion */
- int arinest; /* levels of arithmetic expansion */
- int parenlevel; /* levels of parens in arithmetic */
- int dqvarnest; /* levels of variables expansion within double quotes */
+ int varnest; /* levels of variables expansion */
+ int arinest; /* levels of arithmetic expansion */
+ int parenlevel; /* levels of parens in arithmetic */
+ int dqvarnest; /* levels of variables expansion within double quotes */
int oldstyle;
- int prevsyntax; /* syntax before arithmetic */
+ int prevsyntax; /* syntax before arithmetic */
+
#if __GNUC__
/* Avoid longjmp clobbering */
(void) &out;
dqvarnest = 0;
STARTSTACKSTR(out);
- loop: { /* for each line, until end of word */
- CHECKEND(); /* set c to PEOF if at end of here document */
- for (;;) { /* until end of line or end of word */
- CHECKSTRSPACE(3, out); /* permit 3 calls to USTPUTC */
- switch(SIT(c,syntax)) {
- case CNL: /* '\n' */
+ loop:{ /* for each line, until end of word */
+ CHECKEND(); /* set c to PEOF if at end of here document */
+ for (;;) { /* until end of line or end of word */
+ CHECKSTRSPACE(3, out); /* permit 3 calls to USTPUTC */
+ switch (SIT(c, syntax)) {
+ case CNL: /* '\n' */
if (syntax == BASESYNTAX)
- goto endword; /* exit outer loop */
+ goto endword; /* exit outer loop */
USTPUTC(c, out);
plinno++;
if (doprompt)
else
setprompt(0);
c = pgetc();
- goto loop; /* continue outer loop */
+ goto loop; /* continue outer loop */
case CWORD:
USTPUTC(c, out);
break;
case CCTL:
- if ((eofmark == NULL || dblquote) &&
- dqvarnest == 0)
+ if ((eofmark == NULL || dblquote) && dqvarnest == 0)
USTPUTC(CTLESC, out);
USTPUTC(c, out);
break;
- case CBACK: /* backslash */
+ case CBACK: /* backslash */
c = pgetc2();
if (c == PEOF) {
USTPUTC('\\', out);
setprompt(0);
} else {
if (dblquote && c != '\\' && c != '`' && c != '$'
- && (c != '"' || eofmark != NULL))
+ && (c != '"' || eofmark != NULL))
USTPUTC('\\', out);
- if (SIT(c,SQSYNTAX) == CCTL)
+ if (SIT(c, SQSYNTAX) == CCTL)
USTPUTC(CTLESC, out);
else if (eofmark == NULL)
USTPUTC(CTLQUOTEMARK, out);
dblquote = 1;
break;
case CENDQUOTE:
- if (eofmark != NULL && arinest == 0 &&
- varnest == 0) {
+ if (eofmark != NULL && arinest == 0 && varnest == 0) {
USTPUTC(c, out);
} else {
if (arinest) {
syntax = ARISYNTAX;
dblquote = 0;
- } else if (eofmark == NULL &&
- dqvarnest == 0) {
+ } else if (eofmark == NULL && dqvarnest == 0) {
syntax = BASESYNTAX;
dblquote = 0;
}
quotef++;
}
break;
- case CVAR: /* '$' */
- PARSESUB(); /* parse substitution */
+ case CVAR: /* '$' */
+ PARSESUB(); /* parse substitution */
break;
- case CENDVAR: /* '}' */
+ case CENDVAR: /* '}' */
if (varnest > 0) {
varnest--;
if (dqvarnest > 0) {
}
break;
#ifdef CONFIG_ASH_MATH_SUPPORT
- case CLP: /* '(' in arithmetic */
+ case CLP: /* '(' in arithmetic */
parenlevel++;
USTPUTC(c, out);
break;
- case CRP: /* ')' in arithmetic */
+ case CRP: /* ')' in arithmetic */
if (parenlevel > 0) {
USTPUTC(c, out);
--parenlevel;
}
break;
#endif
- case CBQUOTE: /* '`' */
+ case CBQUOTE: /* '`' */
PARSEBACKQOLD();
break;
case CENDFILE:
- goto endword; /* exit outer loop */
+ goto endword; /* exit outer loop */
case CIGN:
break;
default:
if (varnest == 0)
- goto endword; /* exit outer loop */
+ goto endword; /* exit outer loop */
#ifdef CONFIG_ASH_ALIAS
if (c != PEOA)
#endif
c = pgetc_macro();
}
}
-endword:
+ endword:
if (syntax == ARISYNTAX)
synerror("Missing '))'");
- if (syntax != BASESYNTAX && ! parsebackquote && eofmark == NULL)
+ if (syntax != BASESYNTAX && !parsebackquote && eofmark == NULL)
synerror("Unterminated quoted string");
if (varnest != 0) {
startlinno = plinno;
out = stackblock();
if (eofmark == NULL) {
if ((c == '>' || c == '<')
- && quotef == 0
- && len <= 2
- && (*out == '\0' || is_digit(*out))) {
+ && quotef == 0 && len <= 2 && (*out == '\0' || is_digit(*out))) {
PARSEREDIR();
return lasttoken = TREDIR;
} else {
* we are at the end of the here document, this routine sets the c to PEOF.
*/
-checkend: {
- if (eofmark) {
+ checkend:{
+ if (eofmark) {
#ifdef CONFIG_ASH_ALIAS
- if (c == PEOA) {
- c = pgetc2();
- }
-#endif
- if (striptabs) {
- while (c == '\t') {
+ if (c == PEOA) {
c = pgetc2();
}
- }
- if (c == *eofmark) {
- if (pfgets(line, sizeof line) != NULL) {
- const char *p, *q;
-
- p = line;
- for (q = eofmark + 1 ; *q && *p == *q ; p++, q++);
- if (*p == '\n' && *q == '\0') {
- c = PEOF;
- plinno++;
- needprompt = doprompt;
- } else {
- pushstring(line, strlen(line), NULL);
+#endif
+ if (striptabs) {
+ while (c == '\t') {
+ c = pgetc2();
+ }
+ }
+ if (c == *eofmark) {
+ if (pfgets(line, sizeof line) != NULL) {
+ const char *p, *q;
+
+ p = line;
+ for (q = eofmark + 1; *q && *p == *q; p++, q++);
+ if (*p == '\n' && *q == '\0') {
+ c = PEOF;
+ plinno++;
+ needprompt = doprompt;
+ } else {
+ pushstring(line, strlen(line), NULL);
+ }
}
}
}
+ goto checkend_return;
}
- goto checkend_return;
-}
/*
* first character of the redirection operator.
*/
-parseredir: {
- char fd = *out;
- union node *np;
+ parseredir:{
+ char fd = *out;
+ union node *np;
- np = (union node *)stalloc(sizeof (struct nfile));
- if (c == '>') {
- np->nfile.fd = 1;
- c = pgetc();
- if (c == '>')
- np->type = NAPPEND;
- else if (c == '&')
- np->type = NTOFD;
- else if (c == '|')
- np->type = NTOOV;
- else {
- np->type = NTO;
- pungetc();
- }
- } else { /* c == '<' */
- np->nfile.fd = 0;
- switch (c = pgetc()) {
- case '<':
- if (sizeof (struct nfile) != sizeof (struct nhere)) {
- np = (union node *)stalloc(sizeof (struct nhere));
- np->nfile.fd = 0;
- }
- np->type = NHERE;
- heredoc = (struct heredoc *)stalloc(sizeof (struct heredoc));
- heredoc->here = np;
- if ((c = pgetc()) == '-') {
- heredoc->striptabs = 1;
- } else {
- heredoc->striptabs = 0;
+ np = (union node *) stalloc(sizeof(struct nfile));
+ if (c == '>') {
+ np->nfile.fd = 1;
+ c = pgetc();
+ if (c == '>')
+ np->type = NAPPEND;
+ else if (c == '&')
+ np->type = NTOFD;
+ else if (c == '|')
+ np->type = NTOOV;
+ else {
+ np->type = NTO;
pungetc();
}
- break;
+ } else { /* c == '<' */
+ np->nfile.fd = 0;
+ switch (c = pgetc()) {
+ case '<':
+ if (sizeof(struct nfile) != sizeof(struct nhere)) {
+ np = (union node *) stalloc(sizeof(struct nhere));
+ np->nfile.fd = 0;
+ }
+ np->type = NHERE;
+ heredoc = (struct heredoc *) stalloc(sizeof(struct heredoc));
+ heredoc->here = np;
+ if ((c = pgetc()) == '-') {
+ heredoc->striptabs = 1;
+ } else {
+ heredoc->striptabs = 0;
+ pungetc();
+ }
+ break;
- case '&':
- np->type = NFROMFD;
- break;
+ case '&':
+ np->type = NFROMFD;
+ break;
- case '>':
- np->type = NFROMTO;
- break;
+ case '>':
+ np->type = NFROMTO;
+ break;
- default:
- np->type = NFROM;
- pungetc();
- break;
+ default:
+ np->type = NFROM;
+ pungetc();
+ break;
+ }
}
+ if (fd != '\0')
+ np->nfile.fd = digit_val(fd);
+ redirnode = np;
+ goto parseredir_return;
}
- if (fd != '\0')
- np->nfile.fd = digit_val(fd);
- redirnode = np;
- goto parseredir_return;
-}
/*
* and nothing else.
*/
-parsesub: {
- int subtype;
- int typeloc;
- int flags;
- char *p;
- static const char types[] = "}-+?=";
-
- c = pgetc();
- if (
- c <= PEOA ||
- (c != '(' && c != '{' && !is_name(c) && !is_special(c))
- ) {
- USTPUTC('$', out);
- pungetc();
- } else if (c == '(') { /* $(command) or $((arith)) */
- if (pgetc() == '(') {
- PARSEARITH();
- } else {
+ parsesub:{
+ int subtype;
+ int typeloc;
+ int flags;
+ char *p;
+ static const char types[] = "}-+?=";
+
+ c = pgetc();
+ if (c <= PEOA ||
+ (c != '(' && c != '{' && !is_name(c) && !is_special(c))
+ ) {
+ USTPUTC('$', out);
pungetc();
- PARSEBACKQNEW();
- }
- } else {
- USTPUTC(CTLVAR, out);
- typeloc = out - stackblock();
- USTPUTC(VSNORMAL, out);
- subtype = VSNORMAL;
- if (c == '{') {
- c = pgetc();
- if (c == '#') {
- if ((c = pgetc()) == '}')
- c = '#';
- else
- subtype = VSLENGTH;
+ } else if (c == '(') { /* $(command) or $((arith)) */
+ if (pgetc() == '(') {
+ PARSEARITH();
+ } else {
+ pungetc();
+ PARSEBACKQNEW();
}
- else
- subtype = 0;
- }
- if (c > PEOA && is_name(c)) {
- do {
- STPUTC(c, out);
+ } else {
+ USTPUTC(CTLVAR, out);
+ typeloc = out - stackblock();
+ USTPUTC(VSNORMAL, out);
+ subtype = VSNORMAL;
+ if (c == '{') {
c = pgetc();
- } while (c > PEOA && is_in_name(c));
- } else if (is_digit(c)) {
- do {
+ if (c == '#') {
+ if ((c = pgetc()) == '}')
+ c = '#';
+ else
+ subtype = VSLENGTH;
+ } else
+ subtype = 0;
+ }
+ if (c > PEOA && is_name(c)) {
+ do {
+ STPUTC(c, out);
+ c = pgetc();
+ } while (c > PEOA && is_in_name(c));
+ } else if (is_digit(c)) {
+ do {
+ USTPUTC(c, out);
+ c = pgetc();
+ } while (is_digit(c));
+ } else if (is_special(c)) {
USTPUTC(c, out);
c = pgetc();
- } while (is_digit(c));
- }
- else if (is_special(c)) {
- USTPUTC(c, out);
- c = pgetc();
- }
- else
-badsub: synerror("Bad substitution");
-
- STPUTC('=', out);
- flags = 0;
- if (subtype == 0) {
- switch (c) {
- case ':':
- flags = VSNUL;
- c = pgetc();
- /*FALLTHROUGH*/
- default:
- p = strchr(types, c);
- if (p == NULL)
- goto badsub;
- subtype = p - types + VSNORMAL;
- break;
- case '%':
- case '#':
+ } else
+ badsub:synerror("Bad substitution");
+
+ STPUTC('=', out);
+ flags = 0;
+ if (subtype == 0) {
+ switch (c) {
+ case ':':
+ flags = VSNUL;
+ c = pgetc();
+ /*FALLTHROUGH*/ default:
+ p = strchr(types, c);
+ if (p == NULL)
+ goto badsub;
+ subtype = p - types + VSNORMAL;
+ break;
+ case '%':
+ case '#':
{
int cc = c;
- subtype = c == '#' ? VSTRIMLEFT :
- VSTRIMRIGHT;
+
+ subtype = c == '#' ? VSTRIMLEFT : VSTRIMRIGHT;
c = pgetc();
if (c == cc)
subtype++;
pungetc();
break;
}
+ }
+ } else {
+ pungetc();
}
- } else {
- pungetc();
- }
- if (dblquote || arinest)
- flags |= VSQUOTE;
- *(stackblock() + typeloc) = subtype | flags;
- if (subtype != VSNORMAL) {
- varnest++;
- if (dblquote) {
- dqvarnest++;
+ if (dblquote || arinest)
+ flags |= VSQUOTE;
+ *(stackblock() + typeloc) = subtype | flags;
+ if (subtype != VSNORMAL) {
+ varnest++;
+ if (dblquote) {
+ dqvarnest++;
+ }
}
}
+ goto parsesub_return;
}
- goto parsesub_return;
-}
/*
* characters on the top of the stack which must be preserved.
*/
-parsebackq: {
- struct nodelist **nlpp;
- int savepbq;
- union node *n;
- char *volatile str;
- struct jmploc jmploc;
- struct jmploc *volatile savehandler;
- int savelen;
- int saveprompt;
+ parsebackq:{
+ struct nodelist **nlpp;
+ int savepbq;
+ union node *n;
+ char *volatile str;
+ struct jmploc jmploc;
+ struct jmploc *volatile savehandler;
+ int savelen;
+ int saveprompt;
+
#ifdef __GNUC__
- (void) &saveprompt;
+ (void) &saveprompt;
#endif
- savepbq = parsebackquote;
- if (setjmp(jmploc.loc)) {
- free(str);
- parsebackquote = 0;
- handler = savehandler;
- longjmp(handler->loc, 1);
- }
- INTOFF;
- str = NULL;
- savelen = out - stackblock();
- if (savelen > 0) {
- str = xmalloc(savelen);
- memcpy(str, stackblock(), savelen);
- }
- savehandler = handler;
- handler = &jmploc;
- INTON;
- if (oldstyle) {
- /* We must read until the closing backquote, giving special
- treatment to some slashes, and then push the string and
- reread it as input, interpreting it normally. */
- char *pout;
- int pc;
- int psavelen;
- char *pstr;
-
+ savepbq = parsebackquote;
+ if (setjmp(jmploc.loc)) {
+ free(str);
+ parsebackquote = 0;
+ handler = savehandler;
+ longjmp(handler->loc, 1);
+ }
+ INTOFF;
+ str = NULL;
+ savelen = out - stackblock();
+ if (savelen > 0) {
+ str = xmalloc(savelen);
+ memcpy(str, stackblock(), savelen);
+ }
+ savehandler = handler;
+ handler = &jmploc;
+ INTON;
+ if (oldstyle) {
+ /* We must read until the closing backquote, giving special
+ treatment to some slashes, and then push the string and
+ reread it as input, interpreting it normally. */
+ char *pout;
+ int pc;
+ int psavelen;
+ char *pstr;
- STARTSTACKSTR(pout);
- for (;;) {
- if (needprompt) {
- setprompt(2);
- needprompt = 0;
- }
- switch (pc = pgetc()) {
- case '`':
- goto done;
- case '\\':
- if ((pc = pgetc()) == '\n') {
- plinno++;
- if (doprompt)
- setprompt(2);
- else
- setprompt(0);
- /*
- * If eating a newline, avoid putting
- * the newline into the new character
- * stream (via the STPUTC after the
- * switch).
- */
- continue;
- }
- if (pc != '\\' && pc != '`' && pc != '$'
- && (!dblquote || pc != '"'))
- STPUTC('\\', pout);
- if (pc > PEOA) {
- break;
+ STARTSTACKSTR(pout);
+ for (;;) {
+ if (needprompt) {
+ setprompt(2);
+ needprompt = 0;
}
- /* fall through */
+ switch (pc = pgetc()) {
+ case '`':
+ goto done;
- case PEOF:
+ case '\\':
+ if ((pc = pgetc()) == '\n') {
+ plinno++;
+ if (doprompt)
+ setprompt(2);
+ else
+ setprompt(0);
+ /*
+ * If eating a newline, avoid putting
+ * the newline into the new character
+ * stream (via the STPUTC after the
+ * switch).
+ */
+ continue;
+ }
+ if (pc != '\\' && pc != '`' && pc != '$'
+ && (!dblquote || pc != '"'))
+ STPUTC('\\', pout);
+ if (pc > PEOA) {
+ break;
+ }
+ /* fall through */
+
+ case PEOF:
#ifdef CONFIG_ASH_ALIAS
- case PEOA:
+ case PEOA:
#endif
- startlinno = plinno;
- synerror("EOF in backquote substitution");
+ startlinno = plinno;
+ synerror("EOF in backquote substitution");
- case '\n':
- plinno++;
- needprompt = doprompt;
- break;
+ case '\n':
+ plinno++;
+ needprompt = doprompt;
+ break;
- default:
- break;
+ default:
+ break;
+ }
+ STPUTC(pc, pout);
+ }
+ done:
+ STPUTC('\0', pout);
+ psavelen = pout - stackblock();
+ if (psavelen > 0) {
+ pstr = grabstackstr(pout);
+ setinputstring(pstr);
}
- STPUTC(pc, pout);
- }
-done:
- STPUTC('\0', pout);
- psavelen = pout - stackblock();
- if (psavelen > 0) {
- pstr = grabstackstr(pout);
- setinputstring(pstr);
}
- }
- nlpp = &bqlist;
- while (*nlpp)
- nlpp = &(*nlpp)->next;
- *nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist));
- (*nlpp)->next = NULL;
- parsebackquote = oldstyle;
+ nlpp = &bqlist;
+ while (*nlpp)
+ nlpp = &(*nlpp)->next;
+ *nlpp = (struct nodelist *) stalloc(sizeof(struct nodelist));
+ (*nlpp)->next = NULL;
+ parsebackquote = oldstyle;
- if (oldstyle) {
- saveprompt = doprompt;
- doprompt = 0;
- }
+ if (oldstyle) {
+ saveprompt = doprompt;
+ doprompt = 0;
+ }
- n = list(0);
+ n = list(0);
- if (oldstyle)
- doprompt = saveprompt;
- else {
- if (readtoken() != TRP)
- synexpect(TRP);
- }
+ if (oldstyle)
+ doprompt = saveprompt;
+ else {
+ if (readtoken() != TRP)
+ synexpect(TRP);
+ }
- (*nlpp)->n = n;
- if (oldstyle) {
- /*
- * Start reading from old file again, ignoring any pushed back
- * tokens left from the backquote parsing
- */
- popfile();
- tokpushback = 0;
- }
- while (stackblocksize() <= savelen)
- growstackblock();
- STARTSTACKSTR(out);
- if (str) {
- memcpy(out, str, savelen);
- STADJUST(savelen, out);
- INTOFF;
- free(str);
- str = NULL;
- INTON;
+ (*nlpp)->n = n;
+ if (oldstyle) {
+ /*
+ * Start reading from old file again, ignoring any pushed back
+ * tokens left from the backquote parsing
+ */
+ popfile();
+ tokpushback = 0;
+ }
+ while (stackblocksize() <= savelen)
+ growstackblock();
+ STARTSTACKSTR(out);
+ if (str) {
+ memcpy(out, str, savelen);
+ STADJUST(savelen, out);
+ INTOFF;
+ free(str);
+ str = NULL;
+ INTON;
+ }
+ parsebackquote = savepbq;
+ handler = savehandler;
+ if (arinest || dblquote)
+ USTPUTC(CTLBACKQ | CTLQUOTE, out);
+ else
+ USTPUTC(CTLBACKQ, out);
+ if (oldstyle)
+ goto parsebackq_oldreturn;
+ else
+ goto parsebackq_newreturn;
}
- parsebackquote = savepbq;
- handler = savehandler;
- if (arinest || dblquote)
- USTPUTC(CTLBACKQ | CTLQUOTE, out);
- else
- USTPUTC(CTLBACKQ, out);
- if (oldstyle)
- goto parsebackq_oldreturn;
- else
- goto parsebackq_newreturn;
-}
/*
* Parse an arithmetic expansion (indicate start of one and set state)
*/
-parsearith: {
+ parsearith:{
- if (++arinest == 1) {
- prevsyntax = syntax;
- syntax = ARISYNTAX;
- USTPUTC(CTLARI, out);
- if (dblquote)
- USTPUTC('"',out);
- else
- USTPUTC(' ',out);
- } else {
- /*
- * we collapse embedded arithmetic expansion to
- * parenthesis, which should be equivalent
- */
- USTPUTC('(', out);
+ if (++arinest == 1) {
+ prevsyntax = syntax;
+ syntax = ARISYNTAX;
+ USTPUTC(CTLARI, out);
+ if (dblquote)
+ USTPUTC('"', out);
+ else
+ USTPUTC(' ', out);
+ } else {
+ /*
+ * we collapse embedded arithmetic expansion to
+ * parenthesis, which should be equivalent
+ */
+ USTPUTC('(', out);
+ }
+ goto parsearith_return;
}
- goto parsearith_return;
-}
-} /* end of readtoken */
+} /* end of readtoken */
/*
* or backquotes).
*/
-static int
-noexpand(char *text)
+static int noexpand(char *text)
{
char *p;
char c;
continue;
if (c == CTLESC)
p++;
- else if (SIT(c,BASESYNTAX) == CCTL)
+ else if (SIT(c, BASESYNTAX) == CCTL)
return 0;
}
return 1;
* underscore followed by zero or more letters, underscores, and digits).
*/
-static int
-goodname(const char *name)
+static int goodname(const char *name)
{
const char *p;
p = name;
- if (! is_name(*p))
+ if (!is_name(*p))
return 0;
while (*++p) {
- if (! is_in_name(*p))
+ if (!is_in_name(*p))
return 0;
}
return 1;
* occur at this point.
*/
-static void
-synexpect(int token)
+static void synexpect(int token)
{
char msg[64];
int l;
l = sprintf(msg, "%s unexpected", tokname(lasttoken));
if (token >= 0)
- sprintf(msg+l, " (expecting %s)", tokname(token));
+ sprintf(msg + l, " (expecting %s)", tokname(token));
synerror(msg);
/* NOTREACHED */
}
-static void
-synerror(const char *msg)
+static void synerror(const char *msg)
{
if (commandname)
out2fmt("%s: %d: ", commandname, startlinno);
out2fmt("Syntax error: %s\n", msg);
- error((char *)NULL);
+ error((char *) NULL);
/* NOTREACHED */
}
* called by editline -- any expansions to the prompt
* should be added here.
*/
-static void
-setprompt(int whichprompt)
+static void setprompt(int whichprompt)
{
- char *prompt;
- switch (whichprompt) {
+ char *prompt;
+
+ switch (whichprompt) {
case 1:
prompt = ps1val();
break;
case 2:
prompt = ps2val();
break;
- default: /* 0 */
+ default: /* 0 */
prompt = "";
- }
- putprompt(prompt);
+ }
+ putprompt(prompt);
}
* Code for dealing with input/output redirection.
*/
-#define EMPTY -2 /* marks an unused slot in redirtab */
+#define EMPTY -2 /* marks an unused slot in redirtab */
#ifndef PIPE_BUF
-# define PIPESIZE 4096 /* amount of buffering in a pipe */
+# define PIPESIZE 4096 /* amount of buffering in a pipe */
#else
# define PIPESIZE PIPE_BUF
#endif
* Open a file in noclobber mode.
* The code was copied from bash.
*/
-static inline int
-noclobberopen(const char *fname)
+static inline int noclobberopen(const char *fname)
{
int r, fd;
struct stat finfo, finfo2;
* file was not a regular file, we leave O_EXCL off.
*/
if (r != 0)
- return open(fname, O_WRONLY|O_CREAT|O_EXCL, 0666);
- fd = open(fname, O_WRONLY|O_CREAT, 0666);
+ return open(fname, O_WRONLY | O_CREAT | O_EXCL, 0666);
+ fd = open(fname, O_WRONLY | O_CREAT, 0666);
/* If the open failed, return the file descriptor right away. */
if (fd < 0)
* revealed that it was a regular file, and the file has not been
* replaced, return the file descriptor.
*/
- if (fstat(fd, &finfo2) == 0 && !S_ISREG(finfo2.st_mode) &&
- finfo.st_dev == finfo2.st_dev && finfo.st_ino == finfo2.st_ino)
+ if (fstat(fd, &finfo2) == 0 && !S_ISREG(finfo2.st_mode) &&
+ finfo.st_dev == finfo2.st_dev && finfo.st_ino == finfo2.st_ino)
return fd;
/* The file has been replaced. badness. */
* the pipe without forking.
*/
-static inline int
-openhere(const union node *redir)
+static inline int openhere(const union node *redir)
{
int pip[2];
int len = 0;
goto out;
}
}
- if (forkshell((struct job *)NULL, (union node *)NULL, FORK_NOJOB) == 0) {
+ if (forkshell((struct job *) NULL, (union node *) NULL, FORK_NOJOB) == 0) {
close(pip[0]);
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
expandhere(redir->nhere.doc, pip[1]);
_exit(0);
}
-out:
+ out:
close(pip[1]);
return pip[0];
}
-static inline int
-openredirect(const union node *redir)
+static inline int openredirect(const union node *redir)
{
char *fname;
int f;
break;
case NFROMTO:
fname = redir->nfile.expfname;
- if ((f = open(fname, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
+ if ((f = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666)) < 0)
goto ecreate;
break;
case NTO:
case NTOOV:
fname = redir->nfile.expfname;
#ifdef O_CREAT
- if ((f = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
+ if ((f = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
goto ecreate;
#else
if ((f = creat(fname, 0666)) < 0)
case NAPPEND:
fname = redir->nfile.expfname;
#ifdef O_APPEND
- if ((f = open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666)) < 0)
+ if ((f = open(fname, O_WRONLY | O_CREAT | O_APPEND, 0666)) < 0)
goto ecreate;
#else
- if ((f = open(fname, O_WRONLY)) < 0
- && (f = creat(fname, 0666)) < 0)
+ if ((f = open(fname, O_WRONLY)) < 0 && (f = creat(fname, 0666)) < 0)
goto ecreate;
- lseek(f, (off_t)0, 2);
+ lseek(f, (off_t) 0, 2);
#endif
break;
default:
}
return f;
-ecreate:
+ ecreate:
error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
-eopen:
+ eopen:
error("cannot open %s: %s", fname, errmsg(errno, E_OPEN));
}
* stdout.
*/
-static void
-redirect(union node *redir, int flags)
+static void redirect(union node *redir, int flags)
{
union node *n;
struct redirtab *sv = NULL;
int fd;
int newfd;
int try;
- int fd1dup = flags & REDIR_BACKQ;; /* stdout `cmd` redir to pipe */
+ int fd1dup = flags & REDIR_BACKQ;; /* stdout `cmd` redir to pipe */
if (flags & REDIR_PUSH) {
- sv = xmalloc(sizeof (struct redirtab));
- for (i = 0 ; i < 10 ; i++)
+ sv = xmalloc(sizeof(struct redirtab));
+ for (i = 0; i < 10; i++)
sv->renamed[i] = EMPTY;
sv->next = redirlist;
redirlist = sv;
}
- for (n = redir ; n ; n = n->nfile.next) {
+ for (n = redir; n; n = n->nfile.next) {
fd = n->nfile.fd;
try = 0;
if ((n->nfile.type == NTOFD || n->nfile.type == NFROMFD) &&
- n->ndup.dupfd == fd)
- continue; /* redirect from/to same file descriptor */
+ n->ndup.dupfd == fd)
+ continue; /* redirect from/to same file descriptor */
INTOFF;
newfd = openredirect(n);
try++;
break;
}
- /* FALLTHROUGH*/
+ /* FALLTHROUGH */
default:
if (newfd >= 0) {
close(newfd);
}
-static void
-dupredirect(const union node *redir, int f, int fd1dup)
+static void dupredirect(const union node *redir, int f, int fd1dup)
{
int fd = redir->nfile.fd;
- if(fd==1)
+ if (fd == 1)
fd1dup = 0;
if (redir->nfile.type == NTOFD || redir->nfile.type == NFROMFD) {
- if (redir->ndup.dupfd >= 0) { /* if not ">&-" */
- if (redir->ndup.dupfd!=1 || fd1dup!=1)
+ if (redir->ndup.dupfd >= 0) { /* if not ">&-" */
+ if (redir->ndup.dupfd != 1 || fd1dup != 1)
dup_as_newfd(redir->ndup.dupfd, fd);
}
return;
* Undo the effects of the last redirection.
*/
-static void
-popredir(void)
+static void popredir(void)
{
struct redirtab *rp = redirlist;
int i;
INTOFF;
- for (i = 0 ; i < 10 ; i++) {
+ for (i = 0; i < 10; i++) {
if (rp->renamed[i] != EMPTY) {
if (i == 0)
fd0_redirected--;
* Discard all saved file descriptors.
*/
-static void
-clearredir(void) {
+static void clearredir(void)
+{
struct redirtab *rp;
int i;
- for (rp = redirlist ; rp ; rp = rp->next) {
- for (i = 0 ; i < 10 ; i++) {
+ for (rp = redirlist; rp; rp = rp->next) {
+ for (i = 0; i < 10; i++) {
if (rp->renamed[i] >= 0) {
close(rp->renamed[i]);
}
* file descriptors left.
*/
-static int
-dup_as_newfd(int from, int to)
+static int dup_as_newfd(int from, int to)
{
int newfd;
/*
* Debugging stuff.
*/
-static void shtree (union node *, int, char *, FILE*);
-static void shcmd (union node *, FILE *);
-static void sharg (union node *, FILE *);
-static void indent (int, char *, FILE *);
-static void trstring (char *);
+static void shtree(union node *, int, char *, FILE *);
+static void shcmd(union node *, FILE *);
+static void sharg(union node *, FILE *);
+static void indent(int, char *, FILE *);
+static void trstring(char *);
-static void
-showtree(n)
+static void showtree(n)
unode *n;
{
trputs("showtree called\n");
}
-static void
-shtree(union node *n, int ind, char *pfx, FILE *fp)
+static void shtree(union node *n, int ind, char *pfx, FILE * fp)
{
struct nodelist *lp;
const char *s;
return;
indent(ind, pfx, fp);
- switch(n->type) {
+ switch (n->type) {
case NSEMI:
s = "; ";
goto binop;
goto binop;
case NOR:
s = " || ";
-binop:
+ binop:
shtree(n->nbinary.ch1, ind, NULL, fp);
- /* if (ind < 0) */
- fputs(s, fp);
+ /* if (ind < 0) */
+ fputs(s, fp);
shtree(n->nbinary.ch2, ind, NULL, fp);
break;
case NCMD:
putc('\n', fp);
break;
case NPIPE:
- for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
+ for (lp = n->npipe.cmdlist; lp; lp = lp->next) {
shcmd(lp->n, fp);
if (lp->next)
fputs(" | ", fp);
-static void
-shcmd(union node *cmd, FILE *fp)
+static void shcmd(union node *cmd, FILE * fp)
{
union node *np;
int first;
int dftfd;
first = 1;
- for (np = cmd->ncmd.args ; np ; np = np->narg.next) {
- if (! first)
+ for (np = cmd->ncmd.args; np; np = np->narg.next) {
+ if (!first)
putchar(' ');
sharg(np, fp);
first = 0;
}
- for (np = cmd->ncmd.redirect ; np ; np = np->nfile.next) {
- if (! first)
+ for (np = cmd->ncmd.redirect; np; np = np->nfile.next) {
+ if (!first)
putchar(' ');
#if 1
s = "*error*";
}
#else
switch (np->nfile.type) {
- case NTO: s = ">"; dftfd = 1; break;
- case NAPPEND: s = ">>"; dftfd = 1; break;
- case NTOFD: s = ">&"; dftfd = 1; break;
- case NTOOV: s = ">|"; dftfd = 1; break;
- case NFROM: s = "<"; dftfd = 0; break;
- case NFROMFD: s = "<&"; dftfd = 0; break;
- case NFROMTO: s = "<>"; dftfd = 0; break;
- default: s = "*error*"; dftfd = 0; break;
+ case NTO:
+ s = ">";
+ dftfd = 1;
+ break;
+ case NAPPEND:
+ s = ">>";
+ dftfd = 1;
+ break;
+ case NTOFD:
+ s = ">&";
+ dftfd = 1;
+ break;
+ case NTOOV:
+ s = ">|";
+ dftfd = 1;
+ break;
+ case NFROM:
+ s = "<";
+ dftfd = 0;
+ break;
+ case NFROMFD:
+ s = "<&";
+ dftfd = 0;
+ break;
+ case NFROMTO:
+ s = "<>";
+ dftfd = 0;
+ break;
+ default:
+ s = "*error*";
+ dftfd = 0;
+ break;
}
#endif
if (np->nfile.fd != dftfd)
}
}
-static void
-sharg(union node *arg, FILE *fp)
+static void sharg(union node *arg, FILE * fp)
{
char *p;
struct nodelist *bqlist;
abort();
}
bqlist = arg->narg.backquote;
- for (p = arg->narg.text ; *p ; p++) {
+ for (p = arg->narg.text; *p; p++) {
switch (*p) {
case CTLESC:
putc(*++p, fp);
}
break;
case CTLENDVAR:
- putc('}', fp);
- break;
+ putc('}', fp);
+ break;
case CTLBACKQ:
- case CTLBACKQ|CTLQUOTE:
+ case CTLBACKQ | CTLQUOTE:
putc('$', fp);
putc('(', fp);
shtree(bqlist->n, -1, NULL, fp);
}
-static void
-indent(int amount, char *pfx, FILE *fp)
+static void indent(int amount, char *pfx, FILE * fp)
{
int i;
- for (i = 0 ; i < amount ; i++) {
+ for (i = 0; i < amount; i++) {
if (pfx && i == amount - 1)
fputs(pfx, fp);
putc('\t', fp);
#endif
-static void
-trputc(int c)
+static void trputc(int c)
{
if (tracefile == NULL)
return;
fflush(tracefile);
}
-static void
-trace(const char *fmt, ...)
+static void trace(const char *fmt, ...)
{
va_list va;
+
va_start(va, fmt);
if (tracefile != NULL) {
(void) vfprintf(tracefile, fmt, va);
}
-static void
-trputs(const char *s)
+static void trputs(const char *s)
{
if (tracefile == NULL)
return;
}
-static void
-trstring(char *s)
+static void trstring(char *s)
{
char *p;
char c;
if (tracefile == NULL)
return;
putc('"', tracefile);
- for (p = s ; *p ; p++) {
+ for (p = s; *p; p++) {
switch (*p) {
- case '\n': c = 'n'; goto backslash;
- case '\t': c = 't'; goto backslash;
- case '\r': c = 'r'; goto backslash;
- case '"': c = '"'; goto backslash;
- case '\\': c = '\\'; goto backslash;
- case CTLESC: c = 'e'; goto backslash;
- case CTLVAR: c = 'v'; goto backslash;
- case CTLVAR+CTLQUOTE: c = 'V'; goto backslash;
- case CTLBACKQ: c = 'q'; goto backslash;
- case CTLBACKQ+CTLQUOTE: c = 'Q'; goto backslash;
-backslash: putc('\\', tracefile);
+ case '\n':
+ c = 'n';
+ goto backslash;
+ case '\t':
+ c = 't';
+ goto backslash;
+ case '\r':
+ c = 'r';
+ goto backslash;
+ case '"':
+ c = '"';
+ goto backslash;
+ case '\\':
+ c = '\\';
+ goto backslash;
+ case CTLESC:
+ c = 'e';
+ goto backslash;
+ case CTLVAR:
+ c = 'v';
+ goto backslash;
+ case CTLVAR + CTLQUOTE:
+ c = 'V';
+ goto backslash;
+ case CTLBACKQ:
+ c = 'q';
+ goto backslash;
+ case CTLBACKQ + CTLQUOTE:
+ c = 'Q';
+ goto backslash;
+ backslash:putc('\\', tracefile);
putc(c, tracefile);
break;
default:
}
-static void
-trargs(char **ap)
+static void trargs(char **ap)
{
if (tracefile == NULL)
return;
}
-static void
-opentrace()
+static void opentrace()
{
char s[100];
+
#ifdef O_APPEND
int flags;
#endif
#ifdef not_this_way
{
char *p;
+
if ((p = getenv("HOME")) == NULL) {
if (geteuid() == 0)
p = "/";
}
#else
strcpy(s, "./trace");
-#endif /* not_this_way */
+#endif /* not_this_way */
if ((tracefile = wfopen(s, "a")) == NULL)
return;
#ifdef O_APPEND
fputs("\nTracing started.\n", tracefile);
fflush(tracefile);
}
-#endif /* DEBUG */
+#endif /* DEBUG */
/*
* The trap builtin.
*/
-static int
-trapcmd(int argc, char **argv)
+static int trapcmd(int argc, char **argv)
{
char *action;
char **ap;
int signo;
if (argc <= 1) {
- for (signo = 0 ; signo < NSIG ; signo++) {
+ for (signo = 0; signo < NSIG; signo++) {
if (trap[signo] != NULL) {
char *p;
const char *sn;
p = single_quote(trap[signo]);
sn = sys_siglist[signo];
- if(sn==NULL)
+ if (sn == NULL)
sn = u_signal_names(0, &signo, 0);
- if(sn==NULL)
+ if (sn == NULL)
sn = "???";
printf("trap -- %s %s\n", p, sn);
stunalloc(p);
* out what it should be set to.
*/
-static void
-setsignal(int signo)
+static void setsignal(int signo)
{
int action;
char *t;
break;
case SIGQUIT:
#ifdef DEBUG
- {
+ {
if (debug)
break;
- }
+ }
#endif
/* FALLTHROUGH */
case SIGTERM:
}
if (act.sa_handler == SIG_IGN) {
if (mflag && (signo == SIGTSTP ||
- signo == SIGTTIN || signo == SIGTTOU)) {
- *t = S_IGN; /* don't hard ignore these */
+ signo == SIGTTIN || signo == SIGTTOU)) {
+ *t = S_IGN; /* don't hard ignore these */
} else
*t = S_HARD_IGN;
} else {
- *t = S_RESET; /* force to be set */
+ *t = S_RESET; /* force to be set */
}
}
if (*t == S_HARD_IGN || *t == action)
* Ignore a signal.
*/
-static void
-ignoresig(int signo)
+static void ignoresig(int signo)
{
if (sigmode[signo - 1] != S_IGN && sigmode[signo - 1] != S_HARD_IGN) {
signal(signo, SIG_IGN);
* Signal handler.
*/
-static void
-onsig(int signo)
+static void onsig(int signo)
{
if (signo == SIGINT && trap[SIGINT] == NULL) {
onint();
* handlers while we are executing a trap handler.
*/
-static void
-dotrap(void)
+static void dotrap(void)
{
int i;
int savestatus;
for (;;) {
- for (i = 1 ; ; i++) {
+ for (i = 1;; i++) {
if (gotsig[i - 1])
break;
if (i >= NSIG - 1)
goto done;
}
gotsig[i - 1] = 0;
- savestatus=exitstatus;
+ savestatus = exitstatus;
evalstring(trap[i], 0);
- exitstatus=savestatus;
+ exitstatus = savestatus;
}
-done:
+ done:
pendingsigs = 0;
}
* Called to exit the shell.
*/
-static void
-exitshell(int status)
+static void exitshell(int status)
{
struct jmploc loc1, loc2;
char *p;
trap[0] = NULL;
evalstring(p, 0);
}
-l1: handler = &loc2; /* probably unnecessary */
+ l1:handler = &loc2; /* probably unnecessary */
flushall();
#ifdef CONFIG_ASH_JOB_CONTROL
setjobctl(0);
#endif
-l2: _exit(status);
+ l2:_exit(status);
/* NOTREACHED */
}
return name ? signo : -1;
}
-static struct var **hashvar (const char *);
-static void showvars (const char *, int, int);
-static struct var **findvar (struct var **, const char *);
+static struct var **hashvar(const char *);
+static void showvars(const char *, int, int);
+static struct var **findvar(struct var **, const char *);
/*
* Initialize the varable symbol tables and import the environment
* shell is initialized and again when a shell procedure is spawned.
*/
-static void
-initvar() {
+static void initvar()
+{
const struct varinit *ip;
struct var *vp;
struct var **vpp;
- for (ip = varinit ; (vp = ip->var) != NULL ; ip++) {
+ for (ip = varinit; (vp = ip->var) != NULL; ip++) {
if ((vp->flags & VEXPORT) == 0) {
vpp = hashvar(ip->text);
vp->next = *vpp;
vpp = hashvar("PS1=$");
vps1.next = *vpp;
*vpp = &vps1;
- vps1.text = xstrdup(geteuid() ? "PS1=$ " : "PS1=# ");
- vps1.flags = VSTRFIXED|VTEXTFIXED;
+ vps1.text = xstrdup(geteuid()? "PS1=$ " : "PS1=# ");
+ vps1.flags = VSTRFIXED | VTEXTFIXED;
}
#endif
}
* flags of the variable. If val is NULL, the variable is unset.
*/
-static void
-setvar(const char *name, const char *val, int flags)
+static void setvar(const char *name, const char *val, int flags)
{
const char *p;
int len;
isbad = 0;
p = name;
- if (! is_name(*p))
+ if (!is_name(*p))
isbad = 1;
p++;
for (;;) {
- if (! is_in_name(*p)) {
+ if (!is_in_name(*p)) {
if (*p == '\0' || *p == '=')
break;
isbad = 1;
namelen = p - name;
if (isbad)
error("%.*s: bad variable name", namelen, name);
- len = namelen + 2; /* 2 is space for '=' and '\0' */
+ len = namelen + 2; /* 2 is space for '=' and '\0' */
if (val == NULL) {
flags |= VUNSET;
} else {
* will go away.
*/
-static void
-setvareq(char *s, int flags)
+static void setvareq(char *s, int flags)
{
struct var *vp, **vpp;
if ((vp = *findvar(vpp, s))) {
if (vp->flags & VREADONLY) {
size_t len = strchr(s, '=') - s;
+
error("%.*s: is read only", len, s);
}
INTOFF;
if (vp->func && (flags & VNOFUNC) == 0)
- (*vp->func)(strchr(s, '=') + 1);
+ (*vp->func) (strchr(s, '=') + 1);
- if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0)
+ if ((vp->flags & (VTEXTFIXED | VSTACK)) == 0)
free(vp->text);
- vp->flags &= ~(VTEXTFIXED|VSTACK|VUNSET);
+ vp->flags &= ~(VTEXTFIXED | VSTACK | VUNSET);
vp->flags |= flags;
vp->text = s;
return;
}
/* not found */
- vp = xmalloc(sizeof (*vp));
+ vp = xmalloc(sizeof(*vp));
vp->flags = flags;
vp->text = s;
vp->next = *vpp;
* Process a linked list of variable assignments.
*/
-static void
-listsetvar(struct strlist *mylist)
+static void listsetvar(struct strlist *mylist)
{
struct strlist *lp;
INTOFF;
- for (lp = mylist ; lp ; lp = lp->next) {
+ for (lp = mylist; lp; lp = lp->next) {
setvareq(xstrdup(lp->text), 0);
}
INTON;
* Find the value of a variable. Returns NULL if not set.
*/
-static const char *
-lookupvar(const char *name)
+static const char *lookupvar(const char *name)
{
struct var *v;
* Search the environment of a builtin command.
*/
-static const char *
-bltinlookup(const char *name)
+static const char *bltinlookup(const char *name)
{
const struct strlist *sp;
- for (sp = cmdenviron ; sp ; sp = sp->next) {
+ for (sp = cmdenviron; sp; sp = sp->next) {
if (varequal(sp->text, name))
return strchr(sp->text, '=') + 1;
}
* the third argument to execve when executing a program.
*/
-static char **
-environment() {
+static char **environment()
+{
int nenv;
struct var **vpp;
struct var *vp;
char **ep;
nenv = 0;
- for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
- for (vp = *vpp ; vp ; vp = vp->next)
+ for (vpp = vartab; vpp < vartab + VTABSIZE; vpp++) {
+ for (vp = *vpp; vp; vp = vp->next)
if (vp->flags & VEXPORT)
nenv++;
}
ep = env = stalloc((nenv + 1) * sizeof *env);
- for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
- for (vp = *vpp ; vp ; vp = vp->next)
+ for (vpp = vartab; vpp < vartab + VTABSIZE; vpp++) {
+ for (vp = *vpp; vp; vp = vp->next)
if (vp->flags & VEXPORT)
*ep++ = vp->text;
}
* VSTACK set since these are currently allocated on the stack.
*/
-static void
-shprocvar(void) {
+static void shprocvar(void)
+{
struct var **vpp;
struct var *vp, **prev;
- for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
- for (prev = vpp ; (vp = *prev) != NULL ; ) {
+ for (vpp = vartab; vpp < vartab + VTABSIZE; vpp++) {
+ for (prev = vpp; (vp = *prev) != NULL;) {
if ((vp->flags & VEXPORT) == 0) {
*prev = vp->next;
if ((vp->flags & VTEXTFIXED) == 0)
} else {
if (vp->flags & VSTACK) {
vp->text = xstrdup(vp->text);
- vp->flags &=~ VSTACK;
+ vp->flags &= ~VSTACK;
}
prev = &vp->next;
}
* any variables.
*/
-static int
-showvarscmd(int argc, char **argv)
+static int showvarscmd(int argc, char **argv)
{
showvars(nullstr, VUNSET, VUNSET);
return 0;
* The export and readonly commands.
*/
-static int
-exportcmd(int argc, char **argv)
+static int exportcmd(int argc, char **argv)
{
struct var *vp;
char *name;
const char *p;
- int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT;
+ int flag = argv[0][0] == 'r' ? VREADONLY : VEXPORT;
int pflag;
listsetvar(cmdenviron);
}
}
setvar(name, p, flag);
-found:;
+ found:;
}
} else {
showvars(argv[0], flag, 0);
/* funcnest nonzero if we are currently evaluating a function */
-static int
-localcmd(int argc, char **argv)
+static int localcmd(int argc, char **argv)
{
char *name;
- if (! funcnest)
+ if (!funcnest)
error("Not in a function");
while ((name = *argptr++) != NULL) {
mklocal(name);
* "-" as a special case.
*/
-static void
-mklocal(char *name)
+static void mklocal(char *name)
{
struct localvar *lvp;
struct var **vpp;
struct var *vp;
INTOFF;
- lvp = xmalloc(sizeof (struct localvar));
+ lvp = xmalloc(sizeof(struct localvar));
if (name[0] == '-' && name[1] == '\0') {
char *p;
+
p = xmalloc(sizeof optet_vals);
lvp->text = memcpy(p, optet_vals, sizeof optet_vals);
vp = NULL;
setvareq(xstrdup(name), VSTRFIXED);
else
setvar(name, NULL, VSTRFIXED);
- vp = *vpp; /* the new variable */
+ vp = *vpp; /* the new variable */
lvp->text = NULL;
lvp->flags = VUNSET;
} else {
lvp->text = vp->text;
lvp->flags = vp->flags;
- vp->flags |= VSTRFIXED|VTEXTFIXED;
+ vp->flags |= VSTRFIXED | VTEXTFIXED;
if (strchr(name, '='))
setvareq(xstrdup(name), 0);
}
* Called after a function returns.
*/
-static void
-poplocalvars() {
+static void poplocalvars()
+{
struct localvar *lvp;
struct var *vp;
while ((lvp = localvars) != NULL) {
localvars = lvp->next;
vp = lvp->vp;
- if (vp == NULL) { /* $- saved */
+ if (vp == NULL) { /* $- saved */
memcpy(optet_vals, lvp->text, sizeof optet_vals);
free(lvp->text);
- } else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) {
- (void)unsetvar(vp->text);
+ } else if ((lvp->flags & (VUNSET | VSTRFIXED)) == VUNSET) {
+ (void) unsetvar(vp->text);
} else {
if ((vp->flags & VTEXTFIXED) == 0)
free(vp->text);
}
-static int
-setvarcmd(int argc, char **argv)
+static int setvarcmd(int argc, char **argv)
{
if (argc <= 2)
return unsetcmd(argc, argv);
* with the same name.
*/
-static int
-unsetcmd(int argc, char **argv)
+static int unsetcmd(int argc, char **argv)
{
char **ap;
int i;
if (flg_func == 0 && flg_var == 0)
flg_var = 1;
- for (ap = argptr; *ap ; ap++) {
+ for (ap = argptr; *ap; ap++) {
if (flg_func)
unsetfunc(*ap);
if (flg_var)
* Unset the specified variable.
*/
-static int
-unsetvar(const char *s)
+static int unsetvar(const char *s)
{
struct var **vpp;
struct var *vp;
* Find the appropriate entry in the hash table from the name.
*/
-static struct var **
-hashvar(const char *p)
+static struct var **hashvar(const char *p)
{
unsigned int hashval;
* either '=' or '\0'.
*/
-static int
-varequal(const char *p, const char *q)
+static int varequal(const char *p, const char *q)
{
while (*p == *q++) {
if (*p++ == '=')
return 0;
}
-static void
-showvars(const char *myprefix, int mask, int xor)
+static void showvars(const char *myprefix, int mask, int xor)
{
struct var **vpp;
struct var *vp;
const char *sep = myprefix == nullstr ? myprefix : spcstr;
- for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
- for (vp = *vpp ; vp ; vp = vp->next) {
+ for (vpp = vartab; vpp < vartab + VTABSIZE; vpp++) {
+ for (vp = *vpp; vp; vp = vp->next) {
if ((vp->flags & mask) ^ xor) {
char *p;
int len;
len = p - vp->text;
p = single_quote(p);
- printf("%s%s%.*s%s\n", myprefix, sep, len,
- vp->text, p);
+ printf("%s%s%.*s%s\n", myprefix, sep, len, vp->text, p);
stunalloc(p);
}
}
}
}
-static struct var **
-findvar(struct var **vpp, const char *name)
+static struct var **findvar(struct var **vpp, const char *name)
{
for (; *vpp; vpp = &(*vpp)->next) {
if (varequal((*vpp)->text, name)) {
/*
* Copyright (c) 1999 Herbert Xu <herbert@debian.org>
* This file contains code for the times builtin.
- * $Id: ash.c,v 1.56 2002/08/02 06:39:47 aaronl Exp $
+ * $Id: ash.c,v 1.57 2002/08/22 18:30:15 bug1 Exp $
*/
-static int timescmd (int argc, char **argv)
+static int timescmd(int argc, char **argv)
{
struct tms buf;
long int clk_tck = sysconf(_SC_CLK_TCK);
times(&buf);
printf("%dm%fs %dm%fs\n%dm%fs %dm%fs\n",
- (int) (buf.tms_utime / clk_tck / 60),
- ((double) buf.tms_utime) / clk_tck,
- (int) (buf.tms_stime / clk_tck / 60),
- ((double) buf.tms_stime) / clk_tck,
- (int) (buf.tms_cutime / clk_tck / 60),
- ((double) buf.tms_cutime) / clk_tck,
- (int) (buf.tms_cstime / clk_tck / 60),
- ((double) buf.tms_cstime) / clk_tck);
+ (int) (buf.tms_utime / clk_tck / 60),
+ ((double) buf.tms_utime) / clk_tck,
+ (int) (buf.tms_stime / clk_tck / 60),
+ ((double) buf.tms_stime) / clk_tck,
+ (int) (buf.tms_cutime / clk_tck / 60),
+ ((double) buf.tms_cutime) / clk_tck,
+ (int) (buf.tms_cstime / clk_tck / 60),
+ ((double) buf.tms_cstime) / clk_tck);
return 0;
}
int letcmd(int argc, char **argv)
{
int errcode;
- long result=0;
+ long result = 0;
+
if (argc == 2) {
char *tmp, *expression, p[13];
+
expression = strchr(argv[1], '=');
if (!expression) {
/* Cannot use 'error()' here, or the return code
/* Cannot use 'error()' here, or the return code
* will be incorrect */
out2fmt("sh: let: ");
- if(errcode == -2)
+ if (errcode == -2)
out2fmt("divide by zero");
else
out2fmt("syntax error: \"%s=%s\"\n", argv[1], expression);