repair choiceless select builtin

This commit is contained in:
tg 2012-10-03 15:13:34 +00:00
parent 0d72035990
commit 167995da22
4 changed files with 41 additions and 44 deletions

30
exec.c
View File

@ -23,7 +23,7 @@
#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
#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 void dbteste_error(Test_env *, int, const char *);
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
@ -1529,7 +1532,7 @@ do_selectargs(const char **ap, bool print_menu)
getn(s, &i);
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;
};
static char *select_fmt_entry(char *, size_t, int, const void *);
/* format a single select menu item */
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 *)arg;
shf_snprintf(buf, buflen, "%*d) %s",
shf_snprintf(buf, buflen, "%*u) %s",
smi->num_width, i + 1, smi->args[i]);
return (buf);
}
@ -1555,13 +1556,13 @@ select_fmt_entry(char *buf, size_t buflen, int i, const void *arg)
/*
* print a select style menu
*/
int
void
pr_menu(const char * const *ap)
{
struct select_menu_info smi;
const char * const *pp;
size_t acols = 0, aocts = 0, i;
int n;
unsigned int n;
/*
* 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,
smi.num_width + 2 + aocts, smi.num_width + 2 + acols,
true);
return (n);
}
/* XXX: horrible kludge to fit within the framework */
static char *plain_fmt_entry(char *, size_t, int, const void *);
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);
return (buf);
}
int
void
pr_list(char * const *ap)
{
size_t acols = 0, aocts = 0, i;
int n;
unsigned int n;
char * const *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,
aocts, acols, false);
return (n);
}
/*

10
funcs.c
View File

@ -38,7 +38,7 @@
#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
/*
@ -218,7 +218,7 @@ static int test_primary(Test_env *, bool);
static Test_op ptest_isa(Test_env *, Test_meta);
static const char *ptest_getopnd(Test_env *, Test_op, bool);
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,
const char *, const char *)
MKSH_A_NONNULL((__nonnull__ (6, 7)));
@ -1267,12 +1267,12 @@ c_fgbg(const char **wp)
/* format a single kill item */
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;
i++;
shf_snprintf(buf, buflen, "%*d %*s %s",
shf_snprintf(buf, buflen, "%*u %*s %s",
ki->num_width, i,
ki->name_width, sigtraps[i].name,
sigtraps[i].mess);
@ -1357,7 +1357,7 @@ c_kill(const char **wp)
mess_cols = w;
}
print_columns(shl_stdout, NSIG - 1,
print_columns(shl_stdout, (unsigned int)(NSIG - 1),
kill_fmt_entry, (void *)&ki,
ki.num_width + 1 + ki.name_width + 1 + mess_octs,
ki.num_width + 1 + ki.name_width + 1 + mess_cols,

35
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h>
#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
#ifdef MKSH_SMALL
@ -155,12 +155,12 @@ struct options_info {
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);
/* format a single select menu item */
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;
@ -176,7 +176,7 @@ printoptions(bool verbose)
size_t i = 0;
if (verbose) {
ssize_t n = 0, len, octs = 0;
size_t n = 0, len, octs = 0;
struct options_info oi;
/* verbose version */
@ -190,8 +190,8 @@ printoptions(bool verbose)
if (len > octs)
octs = len;
len = utf_mbswidth(options[i].name);
if (len > oi.opt_width)
oi.opt_width = len;
if ((int)len > oi.opt_width)
oi.opt_width = (int)len;
}
++i;
}
@ -1158,29 +1158,32 @@ print_value_quoted(struct shf *shf, const char *s)
* the i-th element
*/
void
print_columns(struct shf *shf, int n,
char *(*func)(char *, size_t, int, const void *),
print_columns(struct shf *shf, unsigned int n,
char *(*func)(char *, size_t, unsigned int, const void *),
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;
if (n <= 0) {
if (!n)
return;
if (max_colz > 2147483646) {
#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
return;
}
max_col = (unsigned int)max_colz;
if (max_colz > 2147483647) {
if (max_oct > 2147483646) {
#ifndef MKSH_SMALL
internal_warningf("print_columns called with max_col=%zu > INT_MAX",
max_colz);
internal_warningf("print_columns called with %s=%zu >= INT_MAX",
"max_oct", max_oct);
#endif
return;
}
max_col = (int)max_colz;
++max_oct;
str = alloc(max_oct, ATEMP);

10
sh.h
View File

@ -157,7 +157,7 @@
#endif
#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
#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);
void flushcom(bool);
const char *search_path(const char *, const char *, int, int *);
int pr_menu(const char * const *);
int pr_list(char * const *);
void pr_menu(const char * const *);
void pr_list(char * const *);
/* expr.c */
int evaluate(const char *, mksh_ari_t *, 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 *);
void print_value_quoted(struct shf *, const char *);
char *quote_value(const char *);
void print_columns(struct shf *, int,
char *(*)(char *, size_t, int, const void *),
void print_columns(struct shf *, unsigned int,
char *(*)(char *, size_t, unsigned int, const void *),
const void *, size_t, size_t, bool);
void strip_nuls(char *, int);
ssize_t blocking_read(int, char *, size_t)