Put the ending quote on the help entry...
[oweals/busybox.git] / shell / ash.c
index 0697a4785d30a098a2f3a8a48f7aea533493b1f3..c8ccf19b5c31abd4d5b166bb29f861aa5b78ec0c 100644 (file)
  * This code is derived from software contributed to Berkeley by
  * Kenneth Almquist.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  *
  * Original BSD copyright notice is retained at the end of this file.
  */
@@ -70,7 +58,6 @@
 #include <sys/param.h>
 #include <sys/resource.h>
 #include <sys/stat.h>
-#include <sys/time.h>
 #include <sys/wait.h>
 
 #include <stdio.h>
@@ -233,11 +220,11 @@ static volatile sig_atomic_t pendingsigs;
 /* EXSIG is turned off by evalbltin(). */
 
 
-static void exraise(int) __attribute__((__noreturn__));
-static void onint(void) __attribute__((__noreturn__));
+static void exraise(int) ATTRIBUTE_NORETURN;
+static void onint(void) ATTRIBUTE_NORETURN;
 
-static void sh_error(const char *, ...) __attribute__((__noreturn__));
-static void exerror(int, const char *, ...) __attribute__((__noreturn__));
+static void sh_error(const char *, ...) ATTRIBUTE_NORETURN;
+static void exerror(int, const char *, ...) ATTRIBUTE_NORETURN;
 
 static void sh_warnx(const char *, ...);
 
@@ -740,6 +727,9 @@ static const char *tokname(int tok)
 #define is_name(c)      ((c) == '_' || isalpha((unsigned char)(c)))
 #define is_in_name(c)   ((c) == '_' || isalnum((unsigned char)(c)))
 
+/* C99 say: "char" declaration may be signed or unsigned default */
+#define SC2INT(chr2may_be_negative_int) (int)((signed char)chr2may_be_negative_int)
+
 /*
  * is_special(c) evaluates to 1 for c in "!#$*-0123456789?@"; 0 otherwise
  * (assuming ascii char codes, as the original implementation did)
@@ -853,7 +843,7 @@ static int SIT(int c, int syntax)
        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]
 
@@ -1154,7 +1144,7 @@ static const char syntax_index_table[258] = {
        /* 257   127      */ CWORD_CWORD_CWORD_CWORD,
 };
 
-#endif                                                  /* USE_SIT_FUNCTION */
+#endif  /* USE_SIT_FUNCTION */
 
 /*      alias.c      */
 
@@ -1362,6 +1352,7 @@ static const struct builtincmd builtincmd[] = {
        { BUILTIN_SPEC_REG_ASSG "readonly", exportcmd },
        { BUILTIN_SPEC_REG      "return", returncmd },
        { BUILTIN_SPEC_REG      "set", setcmd },
+       { BUILTIN_SPEC_REG      "source", dotcmd },
        { BUILTIN_SPEC_REG      "shift", shiftcmd },
        { BUILTIN_SPEC_REG      "times", timescmd },
        { BUILTIN_SPEC_REG      "trap", trapcmd },
@@ -1400,7 +1391,7 @@ struct cmdentry {
 static const char *pathopt;     /* set by padvance */
 
 static void shellexec(char **, const char *, int)
-    __attribute__((__noreturn__));
+    ATTRIBUTE_NORETURN;
 static char *padvance(const char **, const char *);
 static void find_command(char *, struct cmdentry *, int, const char *);
 static struct builtincmd *find_builtin(const char *);
@@ -1411,8 +1402,10 @@ static void unsetfunc(const char *);
 
 #ifdef CONFIG_ASH_MATH_SUPPORT_64
 typedef int64_t arith_t;
+#define arith_t_type (long long)
 #else
 typedef long arith_t;
+#define arith_t_type (long)
 #endif
 
 #ifdef CONFIG_ASH_MATH_SUPPORT
@@ -2026,7 +2019,7 @@ static void ignoresig(int);
 static void onsig(int);
 static int dotrap(void);
 static void setinteractive(int);
-static void exitshell(void) __attribute__((__noreturn__));
+static void exitshell(void) ATTRIBUTE_NORETURN;
 static int decode_signal(const char *, int);
 
 /*
@@ -2504,7 +2497,7 @@ setpwd(const char *val, int setold)
 
 
 static void exverror(int, const char *, va_list)
-    __attribute__((__noreturn__));
+    ATTRIBUTE_NORETURN;
 
 /*
  * Called to raise an exception.  Since C doesn't include exceptions, we
@@ -4518,7 +4511,7 @@ static size_t esclen(const char *, const char *);
 static char *scanleft(char *, char *, char *, char *, int, int);
 static char *scanright(char *, char *, char *, char *, int, int);
 static void varunset(const char *, const char *, const char *, int)
-       __attribute__((__noreturn__));
+       ATTRIBUTE_NORETURN;
 
 
 #define pmatch(a, b) !fnmatch((a), (b), 0)
@@ -5256,7 +5249,7 @@ memtodest(const char *p, size_t len, int syntax, int quotes) {
        q = makestrspace(len * 2, q);
 
        while (len--) {
-               int c = (unsigned char)*p++;
+               int c = SC2INT(*p++);
                if (!c)
                        continue;
                if (quotes && (SIT(c, syntax) == CCTL || SIT(c, syntax) == CBACK))
@@ -5330,7 +5323,7 @@ numvar:
                        goto param;
                /* fall through */
        case '*':
-               sep = ifsset() ? ifsval()[0] : ' ';
+               sep = ifsset() ? SC2INT(ifsval()[0]) : ' ';
                if (quotes && (SIT(sep, syntax) == CCTL || SIT(sep, syntax) == CBACK))
                        sepq = 1;
 param:
@@ -5932,7 +5925,8 @@ static void pushfile(void);
  * Nul characters in the input are silently discarded.
  */
 
-#define pgetc_as_macro()   (--parsenleft >= 0? *parsenextc++ : preadbuffer())
+
+#define pgetc_as_macro()   (--parsenleft >= 0? SC2INT(*parsenextc++) : preadbuffer())
 
 #ifdef CONFIG_ASH_OPTIMIZE_FOR_SIZE
 #define pgetc_macro() pgetc()
@@ -6097,7 +6091,7 @@ preadbuffer(void)
 #endif
                popstring();
                if (--parsenleft >= 0)
-                       return (*parsenextc++);
+                       return SC2INT(*parsenextc++);
        }
        if (parsenleft == EOF_NLEFT || parsefile->buf == NULL)
                return PEOF;
@@ -6149,7 +6143,7 @@ again:
 
        *q = savec;
 
-       return *parsenextc++;
+       return SC2INT(*parsenextc++);
 }
 
 /*
@@ -7152,8 +7146,8 @@ forkchild(struct job *jp, union node *n, int mode)
                ignoresig(SIGQUIT);
                if (jp->nprocs == 0) {
                        close(0);
-                       if (open(_PATH_DEVNULL, O_RDONLY) != 0)
-                               sh_error("Can't open %s", _PATH_DEVNULL);
+                       if (open(bb_dev_null, O_RDONLY) != 0)
+                               sh_error("Can't open %s", bb_dev_null);
                }
        }
        if (!oldlvl && iflag) {
@@ -9325,8 +9319,8 @@ static int readtoken(void);
 static int xxreadtoken(void);
 static int readtoken1(int firstc, int syntax, char *eofmark, int striptabs);
 static int noexpand(char *);
-static void synexpect(int) __attribute__((__noreturn__));
-static void synerror(const char *) __attribute__((__noreturn__));
+static void synexpect(int) ATTRIBUTE_NORETURN;
+static void synerror(const char *) ATTRIBUTE_NORETURN;
 static void setprompt(int);
 
 
@@ -10140,15 +10134,15 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs)
        char *out;
        int len;
        char line[EOFMARKLEN + 1];
-       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 oldstyle;
-       int prevsyntax; /* syntax before arithmetic */
+       struct nodelist *bqlist = 0;
+       int quotef = 0;
+       int dblquote = 0;
+       int varnest = 0;    /* levels of variables expansion */
+       int arinest = 0;    /* levels of arithmetic expansion */
+       int parenlevel = 0; /* levels of parens in arithmetic */
+       int dqvarnest = 0;  /* levels of variables expansion within double quotes */
+       int oldstyle = 0;
+       int prevsyntax = 0; /* syntax before arithmetic */
 #if __GNUC__
        /* Avoid longjmp clobbering */
        (void) &out;
@@ -10207,13 +10201,11 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs)
                                        if (doprompt)
                                                setprompt(2);
                                } else {
-                                       if (
-                                               dblquote &&
+                                       if (dblquote &&
                                                c != '\\' && c != '`' &&
                                                c != '$' && (
                                                        c != '"' ||
-                                                       eofmark != NULL
-                                               )
+                                                       eofmark != NULL)
                                        ) {
                                                USTPUTC(CTLESC, out);
                                                USTPUTC('\\', out);
@@ -10573,7 +10565,7 @@ parsebackq: {
        struct jmploc jmploc;
        struct jmploc *volatile savehandler;
        size_t savelen;
-       int saveprompt;
+       int saveprompt = 0;
 #ifdef __GNUC__
        (void) &saveprompt;
 #endif
@@ -11841,8 +11833,9 @@ setinteractive(int on)
 
                                if(!do_banner) {
                                        out1fmt(
-                       "\n\n" BB_BANNER " Built-in shell (ash)\n"
-                       "Enter 'help' for a list of built-in commands.\n\n");
+                       "\n\n%s Built-in shell (ash)\n"
+                       "Enter 'help' for a list of built-in commands.\n\n",
+                                       BB_BANNER);
                                        do_banner++;
                                }
                }
@@ -13390,9 +13383,9 @@ arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr)
                }
                /* save to shell variable */
 #ifdef CONFIG_ASH_MATH_SUPPORT_64
-               snprintf(buf, sizeof(buf), "%lld", rez);
+               snprintf(buf, sizeof(buf), "%lld", arith_t_type rez);
 #else
-               snprintf(buf, sizeof(buf), "%ld", rez);
+               snprintf(buf, sizeof(buf), "%ld", arith_t_type rez);
 #endif
                setvar(numptr_m1->var, buf, 0);
                /* after saving, make previous value for v++ or v-- */