-# $OpenBSD: Makefile,v 1.36 2018/01/01 19:45:56 millert Exp $
+# $OpenBSD: Makefile,v 1.37 2018/01/04 19:06:16 millert Exp $
PROG= ksh
SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c eval.c \
misc.c path.c shf.c syn.c table.c trap.c tree.c tty.c var.c \
version.c vi.c
-WARNINGS=yes
-DEFS= -DEMACS -DVI
+DEFS= -Wall -Wshadow -DEMACS -DVI
CFLAGS+=${DEFS} -I. -I${.CURDIR} -I${.CURDIR}/../../lib/libc/gen
MAN= ksh.1 sh.1
-/* $OpenBSD: c_ksh.c,v 1.53 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: c_ksh.c,v 1.54 2018/01/04 19:06:16 millert Exp $ */
/*
* built-in Korn commands: c_*
ki.num_width++;
for (i = 0; i < NSIG; i++) {
- w = sigtraps[i].name ?
- (int)strlen(sigtraps[i].name) :
+ w = sigtraps[i].name ? strlen(sigtraps[i].name) :
ki.num_width;
if (w > ki.name_width)
ki.name_width = w;
-/* $OpenBSD: edit.c,v 1.59 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: edit.c,v 1.60 2018/01/04 19:06:16 millert Exp $ */
/*
* Command line editing - common code
#endif
};
char *rcp;
- unsigned int ele;
+ int i;
if ((rcp = strrchr(ed, '/')))
ed = ++rcp;
- for (ele = 0; ele < NELEM(edit_flags); ele++)
- if (strstr(ed, sh_options[(int) edit_flags[ele]].name)) {
- change_flag(edit_flags[ele], OF_SPECIAL, 1);
+ for (i = 0; i < NELEM(edit_flags); i++)
+ if (strstr(ed, sh_options[(int) edit_flags[i]].name)) {
+ change_flag(edit_flags[i], OF_SPECIAL, 1);
return;
}
}
-/* $OpenBSD: emacs.c,v 1.78 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: emacs.c,v 1.79 2018/01/04 19:06:16 millert Exp $ */
/*
* Emacs-like command line editing and history
kb_decode(const char *s)
{
static char l[LINE + 1];
- unsigned int i, at = 0;
+ int i, at = 0;
l[0] = '\0';
for (i = 0; i < strlen(s); i++) {
static struct kb_entry *
kb_add_string(void *func, void *args, char *str)
{
- unsigned int i, count;
+ int i, count;
struct kb_entry *k;
struct x_ftab *xf = NULL;
int macro, /* bind -m */
int list) /* bind -l */
{
- unsigned int i;
+ int i;
struct kb_entry *k, *kb;
char in[LINE + 1];
-/* $OpenBSD: eval.c,v 1.55 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: eval.c,v 1.56 2018/01/04 19:06:16 millert Exp $ */
/*
* Expansion - quoting, separation, substitution, globbing
char *d, *s;
if ((s = strchr(sp, MAGIC))) {
- size_t slen = s - sp;
- if (slen >= dlen)
+ if (s - sp >= dlen)
return dp;
- memcpy(dp, sp, slen);
- for (d = dp + slen; *s && (d < dp + dlen); s++)
+ memcpy(dp, sp, s - sp);
+ for (d = dp + (s - sp); *s && (d - dp < dlen); s++)
if (!ISMAGIC(*s) || !(*++s & 0x80) ||
!strchr("*+?@! ", *s & 0x7f))
*d++ = *s;
/* extended pattern operators: *+?@! */
if ((*s & 0x7f) != ' ')
*d++ = *s & 0x7f;
- if (d < dp + dlen)
+ if (d - dp < dlen)
*d++ = '(';
}
*d = '\0';
-/* $OpenBSD: expand.h,v 1.13 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: expand.h,v 1.14 2018/01/04 19:06:16 millert Exp $ */
/*
* Expanding strings
/* check if there are at least n bytes left */
#define XcheckN(xs, xp, n) do { \
- size_t more = ((xp) + (n)) - (xs).end; \
+ int more = ((xp) + (n)) - (xs).end; \
if (more > 0) \
xp = Xcheck_grow_(&xs, xp, more); \
} while (0)
#define Xsavepos(xs, xp) ((xp) - (xs).beg)
#define Xrestpos(xs, xp, n) ((xs).beg + (n))
-char * Xcheck_grow_(XString *xsp, char *xp, size_t more);
+char * Xcheck_grow_(XString *xsp, char *xp, int more);
/*
* expandable vector of generic pointers
-/* $OpenBSD: history.c,v 1.76 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: history.c,v 1.77 2018/01/04 19:06:16 millert Exp $ */
/*
* command history
void
sethistsize(int n)
{
- if (n > 0 && (uint32_t)n != histsize) {
+ if (n > 0 && n != histsize) {
int offset = histptr - history;
/* save most recent history */
-/* $OpenBSD: lex.c,v 1.75 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: lex.c,v 1.76 2018/01/04 19:06:16 millert Exp $ */
/*
* lexical analysis and source input
struct ioword *heres[HERES], **herep;
char ident[IDENT+1];
-char **history; /* saved commands */
-char **histptr; /* last history item */
-uint32_t histsize; /* history size */
+char **history; /* saved commands */
+char **histptr; /* last history item */
+int histsize; /* history size */
/* optimized getsc_bn() */
#define getsc() (*source->str != '\0' && *source->str != '\\' \
-/* $OpenBSD: lex.h,v 1.18 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: lex.h,v 1.19 2018/01/04 19:06:16 millert Exp $ */
/*
* Source input, lexer and parser
extern char **history; /* saved commands */
extern char **histptr; /* last history item */
-extern uint32_t histsize; /* history size */
+extern int histsize; /* history size */
#endif /* HISTORY */
-/* $OpenBSD: misc.c,v 1.62 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: misc.c,v 1.63 2018/01/04 19:06:16 millert Exp $ */
/*
* Miscellaneous functions
/* called from expand.h:XcheckN() to grow buffer */
char *
-Xcheck_grow_(XString *xsp, char *xp, size_t more)
+Xcheck_grow_(XString *xsp, char *xp, int more)
{
char *old_beg = xsp->beg;
int
option(const char *n)
{
- unsigned int ele;
+ int i;
- for (ele = 0; ele < NELEM(sh_options); ele++)
- if (sh_options[ele].name && strcmp(sh_options[ele].name, n) == 0)
- return ele;
+ for (i = 0; i < NELEM(sh_options); i++)
+ if (sh_options[i].name && strcmp(sh_options[i].name, n) == 0)
+ return i;
return -1;
}
static void
printoptions(int verbose)
{
- unsigned int ele;
+ int i;
if (verbose) {
struct options_info oi;
- unsigned int n;
- int len;
+ int n, len;
/* verbose version */
shprintf("Current option settings\n");
- for (ele = n = oi.opt_width = 0; ele < NELEM(sh_options); ele++) {
- if (sh_options[ele].name) {
- len = strlen(sh_options[ele].name);
- oi.opts[n].name = sh_options[ele].name;
- oi.opts[n++].flag = ele;
+ for (i = n = oi.opt_width = 0; i < NELEM(sh_options); i++) {
+ if (sh_options[i].name) {
+ len = strlen(sh_options[i].name);
+ oi.opts[n].name = sh_options[i].name;
+ oi.opts[n++].flag = i;
if (len > oi.opt_width)
oi.opt_width = len;
}
} else {
/* short version ala ksh93 */
shprintf("set");
- for (ele = 0; ele < NELEM(sh_options); ele++) {
- if (sh_options[ele].name)
+ for (i = 0; i < NELEM(sh_options); i++) {
+ if (sh_options[i].name)
shprintf(" %co %s",
- Flag(ele) ? '-' : '+',
- sh_options[ele].name);
+ Flag(i) ? '-' : '+',
+ sh_options[i].name);
}
shprintf("\n");
}
char *
getoptions(void)
{
- unsigned int ele;
+ int i;
char m[(int) FNFLAGS + 1];
char *cp = m;
- for (ele = 0; ele < NELEM(sh_options); ele++)
- if (sh_options[ele].c && Flag(ele))
- *cp++ = sh_options[ele].c;
+ for (i = 0; i < NELEM(sh_options); i++)
+ if (sh_options[i].c && Flag(i))
+ *cp++ = sh_options[i].c;
*cp = 0;
return str_save(m, ATEMP);
}
char *opts;
char *array = NULL;
Getopt go;
- int i, optc, sortargs = 0, arrayset = 0;
- unsigned int ele;
+ int i, optc, set, sortargs = 0, arrayset = 0;
/* First call? Build option strings... */
if (cmd_opts[0] == '\0') {
/* see set_opts[] declaration */
strlcpy(set_opts, "A:o;s", sizeof set_opts);
q = set_opts + strlen(set_opts);
- for (ele = 0; ele < NELEM(sh_options); ele++) {
- if (sh_options[ele].c) {
- if (sh_options[ele].flags & OF_CMDLINE)
- *p++ = sh_options[ele].c;
- if (sh_options[ele].flags & OF_SET)
- *q++ = sh_options[ele].c;
+ for (i = 0; i < NELEM(sh_options); i++) {
+ if (sh_options[i].c) {
+ if (sh_options[i].flags & OF_CMDLINE)
+ *p++ = sh_options[i].c;
+ if (sh_options[i].flags & OF_SET)
+ *q++ = sh_options[i].c;
}
}
*p = '\0';
opts = set_opts;
ksh_getopt_reset(&go, GF_ERROR|GF_PLUSOPT);
while ((optc = ksh_getopt(argv, &go, opts)) != -1) {
- int set = (go.info & GI_PLUS) ? 0 : 1;
+ set = (go.info & GI_PLUS) ? 0 : 1;
switch (optc) {
case 'A':
arrayset = set ? 1 : -1;
break;
}
i = option(go.optarg);
- if (i != -1 && set == Flag(i))
+ if (i >= 0 && set == Flag(i))
/* Don't check the context if the flag
* isn't changing - makes "set -o interactive"
* work if you're already interactive. Needed
* if the output of "set +o" is to be used.
*/
;
- else if (i != -1 && (sh_options[i].flags & what))
+ else if (i >= 0 && (sh_options[i].flags & what))
change_flag((enum sh_flag) i, what, set);
else {
bi_errorf("%s: bad option", go.optarg);
sortargs = 1;
break;
}
- for (ele = 0; ele < NELEM(sh_options); ele++)
- if (optc == sh_options[ele].c &&
- (what & sh_options[ele].flags)) {
- change_flag((enum sh_flag) ele, what,
+ for (i = 0; i < NELEM(sh_options); i++)
+ if (optc == sh_options[i].c &&
+ (what & sh_options[i].flags)) {
+ change_flag((enum sh_flag) i, what,
set);
break;
}
- if (ele == NELEM(sh_options)) {
+ if (i == NELEM(sh_options)) {
internal_errorf(1, "parse_args: `%c'", optc);
return -1; /* not reached */
}
* the pattern. If check fails, just to a strcmp().
*/
if (!isfile && !has_globbing(p, pe)) {
- size_t len = pe - p + 1;
+ int len = pe - p + 1;
char tbuf[64];
char *t = len <= sizeof(tbuf) ? tbuf :
alloc(len, ATEMP);
-/* $OpenBSD: path.c,v 1.20 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: path.c,v 1.21 2018/01/04 19:06:16 millert Exp $ */
#include <sys/stat.h>
p++;
if (!*p)
break;
- len = (q = strchr(p, '/')) ? (size_t)(q - p) : strlen(p);
+ len = (q = strchr(p, '/')) ? q - p : strlen(p);
if (len == 1 && p[0] == '.')
continue;
if (len == 2 && p[0] == '.' && p[1] == '.') {
-/* $OpenBSD: tree.c,v 1.28 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: tree.c,v 1.29 2018/01/04 19:06:16 millert Exp $ */
/*
* command tree climbing
case 'c':
tputc(va_arg(va, int), shf);
break;
- case 'd': /* decimal */
- n = va_arg(va, int);
- neg = n < 0;
- p = ulton(neg ? -n : n, 10);
- if (neg)
- *--p = '-';
- while (*p)
- tputc(*p++, shf);
- break;
case 's':
p = va_arg(va, char *);
while (*p)
p = va_arg(va, char *);
tputS(p, shf);
break;
- case 'u': /* unsigned decimal */
- p = ulton(va_arg(va, unsigned int), 10);
+ case 'd': case 'u': /* decimal */
+ n = (c == 'd') ? va_arg(va, int) :
+ va_arg(va, unsigned int);
+ neg = c=='d' && n<0;
+ p = ulton((neg) ? -n : n, 10);
+ if (neg)
+ *--p = '-';
while (*p)
tputc(*p++, shf);
break;
-/* $OpenBSD: var.c,v 1.61 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: var.c,v 1.62 2018/01/04 19:06:16 millert Exp $ */
#include <sys/stat.h>
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" :
"0123456789abcdefghijklmnopqrstuvwxyz";
unsigned long n;
- unsigned int base;
+ int base;
s = strbuf + sizeof(strbuf);
if (vp->flag & INT_U)
break;
case V_HISTSIZE:
vp->flag &= ~SPECIAL;
- sethistsize(intval(vp));
+ sethistsize((int) intval(vp));
vp->flag |= SPECIAL;
break;
case V_HISTFILE:
-/* $OpenBSD: vi.c,v 1.51 2018/01/01 19:45:56 millert Exp $ */
+/* $OpenBSD: vi.c,v 1.52 2018/01/04 19:06:16 millert Exp $ */
/*
* vi command editing
x_putc('\r'); x_putc('\n'); x_flush();
- if (c == -1 || len <= (size_t)es->linelen)
+ if (c == -1 || len <= es->linelen)
return -1;
if (es->cbuf != buf)