simplify print_columns func argument: no need to return the first arg any more

This commit is contained in:
tg
2015-07-05 14:43:08 +00:00
parent bbf0558f6a
commit 62e27c3e07
4 changed files with 21 additions and 23 deletions

12
exec.c
View File

@@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.152 2015/04/29 18:32:43 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.153 2015/07/05 14:43:05 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL #ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL "/bin/sh" #define MKSH_DEFAULT_EXECSHELL "/bin/sh"
@@ -41,8 +41,8 @@ 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 */ /* XXX: horrible kludge to fit within the framework */
static char *plain_fmt_entry(char *, size_t, unsigned int, const void *); static void plain_fmt_entry(char *, size_t, unsigned int, const void *);
static char *select_fmt_entry(char *, size_t, unsigned int, const void *); static void select_fmt_entry(char *, size_t, unsigned int, const void *);
/* /*
* execute command tree * execute command tree
@@ -1610,7 +1610,7 @@ struct select_menu_info {
}; };
/* format a single select menu item */ /* format a single select menu item */
static char * static void
select_fmt_entry(char *buf, size_t buflen, unsigned 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 =
@@ -1618,7 +1618,6 @@ select_fmt_entry(char *buf, size_t buflen, unsigned int i, const void *arg)
shf_snprintf(buf, buflen, "%*u) %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);
} }
/* /*
@@ -1664,11 +1663,10 @@ pr_menu(const char * const *ap)
true); true);
} }
static char * static void
plain_fmt_entry(char *buf, size_t buflen, unsigned 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);
} }
void void

View File

@@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.273 2015/06/28 14:57:24 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.274 2015/07/05 14:43:06 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@@ -224,7 +224,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, unsigned int, const void *); static void 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 *);
@@ -1307,7 +1307,7 @@ c_fgbg(const char **wp)
#endif #endif
/* format a single kill item */ /* format a single kill item */
static char * static void
kill_fmt_entry(char *buf, size_t buflen, unsigned 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;
@@ -1317,7 +1317,6 @@ kill_fmt_entry(char *buf, size_t buflen, unsigned int i, const void *arg)
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);
return (buf);
} }
int int

21
misc.c
View File

@@ -30,7 +30,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.233 2015/07/05 14:33:21 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.234 2015/07/05 14:43:07 tg Exp $");
#define KSH_CHVT_FLAG #define KSH_CHVT_FLAG
#ifdef MKSH_SMALL #ifdef MKSH_SMALL
@@ -173,11 +173,11 @@ struct options_info {
int opts[NELEM(options)]; int opts[NELEM(options)];
}; };
static char *options_fmt_entry(char *, size_t, unsigned int, const void *); static void 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 void
options_fmt_entry(char *buf, size_t buflen, unsigned 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;
@@ -185,7 +185,6 @@ options_fmt_entry(char *buf, size_t buflen, unsigned int i, const void *arg)
shf_snprintf(buf, buflen, "%-*s %s", shf_snprintf(buf, buflen, "%-*s %s",
oi->opt_width, OFN(oi->opts[i]), oi->opt_width, OFN(oi->opts[i]),
Flag(oi->opts[i]) ? "on" : "off"); Flag(oi->opts[i]) ? "on" : "off");
return (buf);
} }
static void static void
@@ -1227,7 +1226,7 @@ print_value_quoted(struct shf *shf, const char *s)
*/ */
void void
print_columns(struct shf *shf, unsigned int n, print_columns(struct shf *shf, unsigned int n,
char *(*func)(char *, size_t, unsigned int, const void *), void (*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)
{ {
unsigned int i, r, c, rows, cols, nspace, max_col; unsigned int i, r, c, rows, cols, nspace, max_col;
@@ -1264,9 +1263,11 @@ print_columns(struct shf *shf, unsigned int n,
/* if we can only print one column anyway, skip the goo */ /* if we can only print one column anyway, skip the goo */
if (cols < 2) { if (cols < 2) {
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i) {
shf_fprintf(shf, "%s\n", (*func)(str, max_oct, i, arg);
(*func)(str, max_oct, i, arg)); shf_puts(str, shf);
shf_putc('\n', shf);
}
goto out; goto out;
} }
@@ -1284,8 +1285,8 @@ print_columns(struct shf *shf, unsigned int n,
for (c = 0; c < cols; c++) { for (c = 0; c < cols; c++) {
i = c * rows + r; i = c * rows + r;
if (i < n) { if (i < n) {
shf_fprintf(shf, "%*s", max_col, (*func)(str, max_oct, i, arg);
(*func)(str, max_oct, i, arg)); shf_fprintf(shf, "%*s", max_col, str);
if (i + rows < n) if (i + rows < n)
shf_fprintf(shf, "%*s", nspace, null); shf_fprintf(shf, "%*s", nspace, null);
} }

4
sh.h
View File

@@ -169,7 +169,7 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.731 2015/06/28 16:23:24 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.732 2015/07/05 14:43:08 tg Exp $");
#endif #endif
#define MKSH_VERSION "R51 2015/06/28" #define MKSH_VERSION "R51 2015/06/28"
@@ -1894,7 +1894,7 @@ 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 *, unsigned int, void print_columns(struct shf *, unsigned int,
char *(*)(char *, size_t, unsigned int, const void *), void (*)(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 *, size_t) void strip_nuls(char *, size_t)
MKSH_A_BOUNDED(__string__, 1, 2); MKSH_A_BOUNDED(__string__, 1, 2);