automatically align the ouptut of various lists to the right sizes

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1705 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Mike Frysinger 15 years ago
parent a2b24ccacc
commit 720768ad02

@ -17,6 +17,14 @@
src/cmd/cmd_help.c (cmd_help_run), src/cmd/cmd_cable.c (cmd_cable_help):
Automatically sort lists before displaying them.
* src/cmd/cmd.h (urj_cmd_sort): Automatically calculate the longest name in
the array of structures.
* src/cmd/cmd_eraseflash.c (cmd_eraseflash_help), src/cmd/cmd_flashmem.c
(cmd_flashmem_help), src/cmd/cmd_initbus.c (cmd_initbus_help),
src/cmd/cmd_help.c (cmd_help_run), src/cmd/cmd_cable.c (cmd_cable_help):
Use the length to automatically align output correctly. Standardize
gettext handling of strings here too (only translate descriptions).
2010-01-22 Mike Frysinger <vapier@gentoo.org>
* src/cmd/cmd_bit.c (cmd_bit_print_params): Fix strncat length handling.

@ -72,14 +72,18 @@ int urj_cmd_params (char *params[]);
int urj_cmd_get_number (const char *s, long unsigned *i);
/**
* Internal command to help with sorting structures
* Internal command to help with sorting structures for display
*/
int _urj_cmd_alphasort (const void *a, const void *b);
#define urj_cmd_sort(arr) \
#define urj_cmd_sort(arr, max_len) \
do { \
size_t nmemb; \
for (nmemb = 0; (arr)[nmemb]; ++nmemb) \
continue; \
max_len = 0; \
for (nmemb = 0; (arr)[nmemb]; ++nmemb) { \
int this_len = strlen(*(char **)((arr)[nmemb])); \
if (max_len < this_len) \
max_len = this_len; \
} \
qsort (arr, nmemb, sizeof(*arr), _urj_cmd_alphasort); \
} while (0)

@ -161,7 +161,7 @@ cmd_cable_run (urj_chain_t *chain, char *params[])
static void
cmd_cable_help (void)
{
int i;
int i, pad;
urj_log (URJ_LOG_LEVEL_NORMAL,
_("Usage: %s DRIVER [DRIVER_OPTS]\n"
@ -174,11 +174,11 @@ cmd_cable_help (void)
"\n" "List of supported cables:\n"),
"cable");
urj_cmd_sort (urj_tap_cable_drivers);
urj_cmd_sort (urj_tap_cable_drivers, pad);
for (i = 0; urj_tap_cable_drivers[i]; i++)
urj_log (URJ_LOG_LEVEL_NORMAL,
_("%-13s %s\n"), urj_tap_cable_drivers[i]->name,
_(urj_tap_cable_drivers[i]->description));
urj_log (URJ_LOG_LEVEL_NORMAL, "%-*s %s\n", pad + 1,
urj_tap_cable_drivers[i]->name,
_(urj_tap_cable_drivers[i]->description));
}
const urj_cmd_t urj_cmd_cable = {

@ -68,7 +68,7 @@ cmd_eraseflash_run (urj_chain_t *chain, char *params[])
static void
cmd_eraseflash_help (void)
{
int i;
int i, pad;
urj_log (URJ_LOG_LEVEL_NORMAL,
_("Usage: %s ADDR BLOCKS\n"
@ -81,11 +81,11 @@ cmd_eraseflash_help (void)
"\n" "Supported Flash Memories:\n"),
"eraseflash");
urj_cmd_sort (urj_flash_flash_drivers);
urj_cmd_sort (urj_flash_flash_drivers, pad);
for (i = 0; urj_flash_flash_drivers[i]; i++)
urj_log (URJ_LOG_LEVEL_NORMAL,
_("%s\n %s\n"), _(urj_flash_flash_drivers[i]->name),
_(urj_flash_flash_drivers[i]->description));
urj_log (URJ_LOG_LEVEL_NORMAL, "%-*s %s\n", pad + 1,
urj_flash_flash_drivers[i]->name,
_(urj_flash_flash_drivers[i]->description));
}
const urj_cmd_t urj_cmd_eraseflash = {

@ -90,7 +90,7 @@ cmd_flashmem_run (urj_chain_t *chain, char *params[])
static void
cmd_flashmem_help (void)
{
int i;
int i, pad;
urj_log (URJ_LOG_LEVEL_NORMAL,
_("Usage: %s ADDR FILENAME [noverify]\n"
@ -107,10 +107,10 @@ cmd_flashmem_help (void)
"Supported Flash Memories:\n"),
"flashmem", "flashmem msbin", "msbin", "noverify");
urj_cmd_sort (urj_flash_flash_drivers);
urj_cmd_sort (urj_flash_flash_drivers, pad);
for (i = 0; urj_flash_flash_drivers[i]; i++)
urj_log (URJ_LOG_LEVEL_NORMAL,
_("%s\n %s\n"), _(urj_flash_flash_drivers[i]->name),
urj_log (URJ_LOG_LEVEL_NORMAL, "%-*s %s\n", pad + 1,
urj_flash_flash_drivers[i]->name,
_(urj_flash_flash_drivers[i]->description));
}

@ -48,10 +48,12 @@ cmd_help_run (urj_chain_t *chain, char *params[])
/* short description generation */
if (urj_cmd_params (params) == 1)
{
urj_cmd_sort (urj_cmds);
int pad;
urj_cmd_sort (urj_cmds, pad);
urj_log (URJ_LOG_LEVEL_NORMAL, _("Command list:\n\n"));
for (i = 0; urj_cmds[i]; i++)
urj_log (URJ_LOG_LEVEL_NORMAL, _("%-13s %s\n"), urj_cmds[i]->name,
urj_log (URJ_LOG_LEVEL_NORMAL, "%-*s %s\n", pad + 1,
urj_cmds[i]->name,
urj_cmds[i]->desc ? _(urj_cmds[i]->desc) :
_("(no description available)"));
urj_log (URJ_LOG_LEVEL_NORMAL,

@ -90,7 +90,7 @@ cmd_initbus_run (urj_chain_t *chain, char *params[])
static void
cmd_initbus_help (void)
{
int i;
int i, pad;
urj_log (URJ_LOG_LEVEL_NORMAL,
_("Usage: %s BUSNAME\n"
@ -100,11 +100,11 @@ cmd_initbus_help (void)
"\n" "List of available buses:\n"),
"initbus");
urj_cmd_sort (urj_bus_drivers);
urj_cmd_sort (urj_bus_drivers, pad);
for (i = 0; urj_bus_drivers[i] != NULL; i++)
urj_log (URJ_LOG_LEVEL_NORMAL,
_("%-10s %s\n"), urj_bus_drivers[i]->name,
urj_bus_drivers[i]->description);
urj_log (URJ_LOG_LEVEL_NORMAL, "%-*s %s\n", pad + 1,
urj_bus_drivers[i]->name,
_(urj_bus_drivers[i]->description));
}
const const urj_cmd_t urj_cmd_initbus = {

Loading…
Cancel
Save