repair choiceless select builtin
This commit is contained in:
30
exec.c
30
exec.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.99 2012/06/24 20:05:23 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.100 2012/10/03 15:13:30 tg Exp $");
|
||||||
|
|
||||||
#ifndef MKSH_DEFAULT_EXECSHELL
|
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||||
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
||||||
@ -40,6 +40,9 @@ static Test_op dbteste_isa(Test_env *, Test_meta);
|
|||||||
static const char *dbteste_getopnd(Test_env *, Test_op, bool);
|
static const char *dbteste_getopnd(Test_env *, Test_op, bool);
|
||||||
static void dbteste_error(Test_env *, int, const char *);
|
static void dbteste_error(Test_env *, int, const char *);
|
||||||
static int search_access(const char *, int);
|
static int search_access(const char *, int);
|
||||||
|
/* XXX: horrible kludge to fit within the framework */
|
||||||
|
static char *plain_fmt_entry(char *, size_t, unsigned int, const void *);
|
||||||
|
static char *select_fmt_entry(char *, size_t, unsigned int, const void *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* execute command tree
|
* execute command tree
|
||||||
@ -1529,7 +1532,7 @@ do_selectargs(const char **ap, bool print_menu)
|
|||||||
getn(s, &i);
|
getn(s, &i);
|
||||||
return ((i >= 1 && i <= argct) ? ap[i - 1] : null);
|
return ((i >= 1 && i <= argct) ? ap[i - 1] : null);
|
||||||
}
|
}
|
||||||
print_menu = 1;
|
print_menu = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1538,16 +1541,14 @@ struct select_menu_info {
|
|||||||
int num_width;
|
int num_width;
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *select_fmt_entry(char *, size_t, int, const void *);
|
|
||||||
|
|
||||||
/* format a single select menu item */
|
/* format a single select menu item */
|
||||||
static char *
|
static char *
|
||||||
select_fmt_entry(char *buf, size_t buflen, int i, const void *arg)
|
select_fmt_entry(char *buf, size_t buflen, unsigned int i, const void *arg)
|
||||||
{
|
{
|
||||||
const struct select_menu_info *smi =
|
const struct select_menu_info *smi =
|
||||||
(const struct select_menu_info *)arg;
|
(const struct select_menu_info *)arg;
|
||||||
|
|
||||||
shf_snprintf(buf, buflen, "%*d) %s",
|
shf_snprintf(buf, buflen, "%*u) %s",
|
||||||
smi->num_width, i + 1, smi->args[i]);
|
smi->num_width, i + 1, smi->args[i]);
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
@ -1555,13 +1556,13 @@ select_fmt_entry(char *buf, size_t buflen, int i, const void *arg)
|
|||||||
/*
|
/*
|
||||||
* print a select style menu
|
* print a select style menu
|
||||||
*/
|
*/
|
||||||
int
|
void
|
||||||
pr_menu(const char * const *ap)
|
pr_menu(const char * const *ap)
|
||||||
{
|
{
|
||||||
struct select_menu_info smi;
|
struct select_menu_info smi;
|
||||||
const char * const *pp;
|
const char * const *pp;
|
||||||
size_t acols = 0, aocts = 0, i;
|
size_t acols = 0, aocts = 0, i;
|
||||||
int n;
|
unsigned int n;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* width/column calculations were done once and saved, but this
|
* width/column calculations were done once and saved, but this
|
||||||
@ -1593,25 +1594,20 @@ pr_menu(const char * const *ap)
|
|||||||
print_columns(shl_out, n, select_fmt_entry, (void *)&smi,
|
print_columns(shl_out, n, select_fmt_entry, (void *)&smi,
|
||||||
smi.num_width + 2 + aocts, smi.num_width + 2 + acols,
|
smi.num_width + 2 + aocts, smi.num_width + 2 + acols,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
return (n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: horrible kludge to fit within the framework */
|
|
||||||
static char *plain_fmt_entry(char *, size_t, int, const void *);
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
plain_fmt_entry(char *buf, size_t buflen, int i, const void *arg)
|
plain_fmt_entry(char *buf, size_t buflen, unsigned int i, const void *arg)
|
||||||
{
|
{
|
||||||
strlcpy(buf, ((const char * const *)arg)[i], buflen);
|
strlcpy(buf, ((const char * const *)arg)[i], buflen);
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
pr_list(char * const *ap)
|
pr_list(char * const *ap)
|
||||||
{
|
{
|
||||||
size_t acols = 0, aocts = 0, i;
|
size_t acols = 0, aocts = 0, i;
|
||||||
int n;
|
unsigned int n;
|
||||||
char * const *pp;
|
char * const *pp;
|
||||||
|
|
||||||
for (n = 0, pp = ap; *pp; n++, pp++) {
|
for (n = 0, pp = ap; *pp; n++, pp++) {
|
||||||
@ -1625,8 +1621,6 @@ pr_list(char * const *ap)
|
|||||||
|
|
||||||
print_columns(shl_out, n, plain_fmt_entry, (const void *)ap,
|
print_columns(shl_out, n, plain_fmt_entry, (const void *)ap,
|
||||||
aocts, acols, false);
|
aocts, acols, false);
|
||||||
|
|
||||||
return (n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
10
funcs.c
10
funcs.c
@ -38,7 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.223 2012/08/03 18:30:13 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.224 2012/10/03 15:13:31 tg Exp $");
|
||||||
|
|
||||||
#if HAVE_KILLPG
|
#if HAVE_KILLPG
|
||||||
/*
|
/*
|
||||||
@ -218,7 +218,7 @@ static int test_primary(Test_env *, bool);
|
|||||||
static Test_op ptest_isa(Test_env *, Test_meta);
|
static Test_op ptest_isa(Test_env *, Test_meta);
|
||||||
static const char *ptest_getopnd(Test_env *, Test_op, bool);
|
static const char *ptest_getopnd(Test_env *, Test_op, bool);
|
||||||
static void ptest_error(Test_env *, int, const char *);
|
static void ptest_error(Test_env *, int, const char *);
|
||||||
static char *kill_fmt_entry(char *, size_t, int, const void *);
|
static char *kill_fmt_entry(char *, size_t, unsigned int, const void *);
|
||||||
static void p_time(struct shf *, bool, long, int, int,
|
static void p_time(struct shf *, bool, long, int, int,
|
||||||
const char *, const char *)
|
const char *, const char *)
|
||||||
MKSH_A_NONNULL((__nonnull__ (6, 7)));
|
MKSH_A_NONNULL((__nonnull__ (6, 7)));
|
||||||
@ -1267,12 +1267,12 @@ c_fgbg(const char **wp)
|
|||||||
|
|
||||||
/* format a single kill item */
|
/* format a single kill item */
|
||||||
static char *
|
static char *
|
||||||
kill_fmt_entry(char *buf, size_t buflen, int i, const void *arg)
|
kill_fmt_entry(char *buf, size_t buflen, unsigned int i, const void *arg)
|
||||||
{
|
{
|
||||||
const struct kill_info *ki = (const struct kill_info *)arg;
|
const struct kill_info *ki = (const struct kill_info *)arg;
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
shf_snprintf(buf, buflen, "%*d %*s %s",
|
shf_snprintf(buf, buflen, "%*u %*s %s",
|
||||||
ki->num_width, i,
|
ki->num_width, i,
|
||||||
ki->name_width, sigtraps[i].name,
|
ki->name_width, sigtraps[i].name,
|
||||||
sigtraps[i].mess);
|
sigtraps[i].mess);
|
||||||
@ -1357,7 +1357,7 @@ c_kill(const char **wp)
|
|||||||
mess_cols = w;
|
mess_cols = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
print_columns(shl_stdout, NSIG - 1,
|
print_columns(shl_stdout, (unsigned int)(NSIG - 1),
|
||||||
kill_fmt_entry, (void *)&ki,
|
kill_fmt_entry, (void *)&ki,
|
||||||
ki.num_width + 1 + ki.name_width + 1 + mess_octs,
|
ki.num_width + 1 + ki.name_width + 1 + mess_octs,
|
||||||
ki.num_width + 1 + ki.name_width + 1 + mess_cols,
|
ki.num_width + 1 + ki.name_width + 1 + mess_cols,
|
||||||
|
35
misc.c
35
misc.c
@ -30,7 +30,7 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.197 2012/07/30 21:37:13 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.198 2012/10/03 15:13:33 tg Exp $");
|
||||||
|
|
||||||
#define KSH_CHVT_FLAG
|
#define KSH_CHVT_FLAG
|
||||||
#ifdef MKSH_SMALL
|
#ifdef MKSH_SMALL
|
||||||
@ -155,12 +155,12 @@ struct options_info {
|
|||||||
int opts[NELEM(options)];
|
int opts[NELEM(options)];
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *options_fmt_entry(char *, size_t, int, const void *);
|
static char *options_fmt_entry(char *, size_t, unsigned int, const void *);
|
||||||
static void printoptions(bool);
|
static void printoptions(bool);
|
||||||
|
|
||||||
/* format a single select menu item */
|
/* format a single select menu item */
|
||||||
static char *
|
static char *
|
||||||
options_fmt_entry(char *buf, size_t buflen, int i, const void *arg)
|
options_fmt_entry(char *buf, size_t buflen, unsigned int i, const void *arg)
|
||||||
{
|
{
|
||||||
const struct options_info *oi = (const struct options_info *)arg;
|
const struct options_info *oi = (const struct options_info *)arg;
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ printoptions(bool verbose)
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
ssize_t n = 0, len, octs = 0;
|
size_t n = 0, len, octs = 0;
|
||||||
struct options_info oi;
|
struct options_info oi;
|
||||||
|
|
||||||
/* verbose version */
|
/* verbose version */
|
||||||
@ -190,8 +190,8 @@ printoptions(bool verbose)
|
|||||||
if (len > octs)
|
if (len > octs)
|
||||||
octs = len;
|
octs = len;
|
||||||
len = utf_mbswidth(options[i].name);
|
len = utf_mbswidth(options[i].name);
|
||||||
if (len > oi.opt_width)
|
if ((int)len > oi.opt_width)
|
||||||
oi.opt_width = len;
|
oi.opt_width = (int)len;
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
@ -1158,29 +1158,32 @@ print_value_quoted(struct shf *shf, const char *s)
|
|||||||
* the i-th element
|
* the i-th element
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
print_columns(struct shf *shf, int n,
|
print_columns(struct shf *shf, unsigned int n,
|
||||||
char *(*func)(char *, size_t, int, const void *),
|
char *(*func)(char *, size_t, unsigned int, const void *),
|
||||||
const void *arg, size_t max_oct, size_t max_colz, bool prefcol)
|
const void *arg, size_t max_oct, size_t max_colz, bool prefcol)
|
||||||
{
|
{
|
||||||
int i, r, c, rows, cols, nspace, max_col;
|
unsigned int i, r, c, rows, cols, nspace, max_col;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
if (n <= 0) {
|
if (!n)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (max_colz > 2147483646) {
|
||||||
#ifndef MKSH_SMALL
|
#ifndef MKSH_SMALL
|
||||||
internal_warningf("print_columns called with n=%d <= 0", n);
|
internal_warningf("print_columns called with %s=%zu >= INT_MAX",
|
||||||
|
"max_col", max_colz);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
max_col = (unsigned int)max_colz;
|
||||||
|
|
||||||
if (max_colz > 2147483647) {
|
if (max_oct > 2147483646) {
|
||||||
#ifndef MKSH_SMALL
|
#ifndef MKSH_SMALL
|
||||||
internal_warningf("print_columns called with max_col=%zu > INT_MAX",
|
internal_warningf("print_columns called with %s=%zu >= INT_MAX",
|
||||||
max_colz);
|
"max_oct", max_oct);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
max_col = (int)max_colz;
|
|
||||||
|
|
||||||
++max_oct;
|
++max_oct;
|
||||||
str = alloc(max_oct, ATEMP);
|
str = alloc(max_oct, ATEMP);
|
||||||
|
|
||||||
|
10
sh.h
10
sh.h
@ -157,7 +157,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#ifdef EXTERN
|
||||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.587 2012/09/21 17:20:22 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.588 2012/10/03 15:13:34 tg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#define MKSH_VERSION "R40 2012/09/07"
|
#define MKSH_VERSION "R40 2012/09/07"
|
||||||
|
|
||||||
@ -1644,8 +1644,8 @@ const char *builtin(const char *, int (*)(const char **));
|
|||||||
struct tbl *findcom(const char *, int);
|
struct tbl *findcom(const char *, int);
|
||||||
void flushcom(bool);
|
void flushcom(bool);
|
||||||
const char *search_path(const char *, const char *, int, int *);
|
const char *search_path(const char *, const char *, int, int *);
|
||||||
int pr_menu(const char * const *);
|
void pr_menu(const char * const *);
|
||||||
int pr_list(char * const *);
|
void pr_list(char * const *);
|
||||||
/* expr.c */
|
/* expr.c */
|
||||||
int evaluate(const char *, mksh_ari_t *, int, bool);
|
int evaluate(const char *, mksh_ari_t *, int, bool);
|
||||||
int v_evaluate(struct tbl *, const char *, volatile int, bool);
|
int v_evaluate(struct tbl *, const char *, volatile int, bool);
|
||||||
@ -1854,8 +1854,8 @@ void ksh_getopt_reset(Getopt *, int);
|
|||||||
int ksh_getopt(const char **, Getopt *, const char *);
|
int ksh_getopt(const char **, Getopt *, const char *);
|
||||||
void print_value_quoted(struct shf *, const char *);
|
void print_value_quoted(struct shf *, const char *);
|
||||||
char *quote_value(const char *);
|
char *quote_value(const char *);
|
||||||
void print_columns(struct shf *, int,
|
void print_columns(struct shf *, unsigned int,
|
||||||
char *(*)(char *, size_t, int, const void *),
|
char *(*)(char *, size_t, unsigned int, const void *),
|
||||||
const void *, size_t, size_t, bool);
|
const void *, size_t, size_t, bool);
|
||||||
void strip_nuls(char *, int);
|
void strip_nuls(char *, int);
|
||||||
ssize_t blocking_read(int, char *, size_t)
|
ssize_t blocking_read(int, char *, size_t)
|
||||||
|
Reference in New Issue
Block a user