* 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.
*/
#include <sys/param.h>
#include <sys/resource.h>
#include <sys/stat.h>
-#include <sys/time.h>
#include <sys/wait.h>
#include <stdio.h>
/* 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 *, ...);
#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)
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]
/* 257 127 */ CWORD_CWORD_CWORD_CWORD,
};
-#endif /* USE_SIT_FUNCTION */
+#endif /* USE_SIT_FUNCTION */
/* alias.c */
{ 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 },
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 *);
#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
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);
/*
static void exverror(int, const char *, va_list)
- __attribute__((__noreturn__));
+ ATTRIBUTE_NORETURN;
/*
* Called to raise an exception. Since C doesn't include exceptions, we
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)
q = makestrspace(len * 2, q);
while (len--) {
- int c = *p++;
+ int c = SC2INT(*p++);
if (!c)
continue;
if (quotes && (SIT(c, syntax) == CCTL || SIT(c, syntax) == CBACK))
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:
* 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()
#endif
popstring();
if (--parsenleft >= 0)
- return (*parsenextc++);
+ return SC2INT(*parsenextc++);
}
if (parsenleft == EOF_NLEFT || parsefile->buf == NULL)
return PEOF;
*q = savec;
- return *parsenextc++;
+ return SC2INT(*parsenextc++);
}
/*
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) {
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);
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;
if (doprompt)
setprompt(2);
} else {
- if (
- dblquote &&
+ if (dblquote &&
c != '\\' && c != '`' &&
c != '$' && (
c != '"' ||
- eofmark != NULL
- )
+ eofmark != NULL)
) {
USTPUTC(CTLESC, out);
USTPUTC('\\', out);
struct jmploc jmploc;
struct jmploc *volatile savehandler;
size_t savelen;
- int saveprompt;
+ int saveprompt = 0;
#ifdef __GNUC__
(void) &saveprompt;
#endif
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++;
}
}
}
/* 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-- */