automatically sort lists before showing them to the user

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

@ -6,6 +6,17 @@
* src/cmd/cmd_cmd.c (urj_cmd_run): Automatically show help for a command
when it fails with a syntax error.
* include/urjtag/flash.h (urj_flash_driver_t): Move name member up to start
of the structure to match other structures and make assumptions.
* src/flash/amd.c, src/flash/amd_flash.c, src/flash/intel.c: Re-order struct
initialization after re-ordering of the definition.
* src/cmd/cmd.h (urj_cmd_sort), src/cmd/cmd_cmd.c (_urj_cmd_alphasort): New
helper functions for sorting structure lists alphabetically.
* 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):
Automatically sort lists before displaying them.
2010-01-22 Mike Frysinger <vapier@gentoo.org>
* src/cmd/cmd_bit.c (cmd_bit_print_params): Fix strncat length handling.

@ -43,9 +43,9 @@ typedef struct URJ_FLASH_CFI_ARRAY urj_flash_cfi_array_t;
typedef struct
{
unsigned int bus_width; /* 1 for 8 bits, 2 for 16 bits, 4 for 32 bits, etc. */
const char *name;
const char *description;
unsigned int bus_width; /* 1 for 8 bits, 2 for 16 bits, 4 for 32 bits, etc. */
/** @return 1 if autodetected, 0 otherwise */
int (*autodetect) (urj_flash_cfi_array_t *cfi_array);
void (*print_info) (urj_log_level_t ll, urj_flash_cfi_array_t *cfi_array);

@ -34,6 +34,7 @@
#ifndef URJ_SRC_CMD_H
#define URJ_SRC_CMD_H
#include <stdlib.h> /* qsort */
#include <sysdep.h>
#include <urjtag/types.h>
@ -70,4 +71,16 @@ int urj_cmd_params (char *params[]);
*/
int urj_cmd_get_number (const char *s, long unsigned *i);
/**
* Internal command to help with sorting structures
*/
int _urj_cmd_alphasort (const void *a, const void *b);
#define urj_cmd_sort(arr) \
do { \
size_t nmemb; \
for (nmemb = 0; (arr)[nmemb]; ++nmemb) \
continue; \
qsort (arr, nmemb, sizeof(*arr), _urj_cmd_alphasort); \
} while (0)
#endif /* URJ_CMD_H */

@ -174,6 +174,7 @@ cmd_cable_help (void)
"\n" "List of supported cables:\n"),
"cable");
urj_cmd_sort (urj_tap_cable_drivers);
for (i = 0; urj_tap_cable_drivers[i]; i++)
urj_log (URJ_LOG_LEVEL_NORMAL,
_("%-13s %s\n"), urj_tap_cable_drivers[i]->name,

@ -178,3 +178,13 @@ urj_cmd_get_number (const char *s, long unsigned *i)
return URJ_STATUS_FAIL;
}
/*
* We could leverage offsetof() so that we don't assume the name is
* always the first member, but that requires passing state.
*/
#define qsort_ptr(p) (**(char ***)p)
int _urj_cmd_alphasort(const void *a, const void *b)
{
return strcasecmp (qsort_ptr(a), qsort_ptr(b));
}

@ -81,6 +81,7 @@ cmd_eraseflash_help (void)
"\n" "Supported Flash Memories:\n"),
"eraseflash");
urj_cmd_sort (urj_flash_flash_drivers);
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),

@ -107,6 +107,7 @@ cmd_flashmem_help (void)
"Supported Flash Memories:\n"),
"flashmem", "flashmem msbin", "msbin", "noverify");
urj_cmd_sort (urj_flash_flash_drivers);
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),

@ -48,6 +48,7 @@ cmd_help_run (urj_chain_t *chain, char *params[])
/* short description generation */
if (urj_cmd_params (params) == 1)
{
urj_cmd_sort (urj_cmds);
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,

@ -100,6 +100,7 @@ cmd_initbus_help (void)
"\n" "List of available buses:\n"),
"initbus");
urj_cmd_sort (urj_bus_drivers);
for (i = 0; urj_bus_drivers[i] != NULL; i++)
urj_log (URJ_LOG_LEVEL_NORMAL,
_("%-10s %s\n"), urj_bus_drivers[i]->name,

@ -643,9 +643,9 @@ amd_flash_program32 (urj_flash_cfi_array_t *cfi_array, uint32_t adr,
}
urj_flash_driver_t urj_flash_amd_32_flash_driver = {
4, /* buswidth */
N_("AMD/Fujitsu Standard Command Set"),
N_("supported: AMD 29LV640D, 29LV641D, 29LV642D; 2x16 Bit"),
4, /* buswidth */
amd_flash_autodetect32,
amd_flash_print_info,
amd_flash_erase_block,
@ -655,9 +655,9 @@ urj_flash_driver_t urj_flash_amd_32_flash_driver = {
};
urj_flash_driver_t urj_flash_amd_16_flash_driver = {
2, /* buswidth */
N_("AMD/Fujitsu Standard Command Set"),
N_("supported: AMD 29LV800B, S29GLxxxN; MX29LV640B, W19B320AT/B; 1x16 Bit"),
2, /* buswidth */
amd_flash_autodetect16,
amd_flash_print_info,
amd_flash_erase_block,
@ -667,9 +667,9 @@ urj_flash_driver_t urj_flash_amd_16_flash_driver = {
};
urj_flash_driver_t urj_flash_amd_8_flash_driver = {
1, /* buswidth */
N_("AMD/Fujitsu Standard Command Set"),
N_("supported: AMD 29LV160, AMD 29LV065D, AMD 29LV040B, S29GLxxxN, W19B320AT/B; 1x8 Bit"),
1, /* buswidth */
amd_flash_autodetect8,
amd_flash_print_info,
amd_flash_erase_block,

@ -410,9 +410,9 @@ amd_29xx040_unlock_block (urj_flash_cfi_array_t *cfi_array,
urj_flash_driver_t urj_flash_amd_29xx040_flash_driver = {
1, /* buswidth */
N_("AMD Standard Command Set"),
N_("supported: AMD 29LV040B, 29C040B, 1x8 Bit"),
1, /* buswidth */
amd_29xx040_autodetect,
amd_29xx040_print_info,
amd_29xx040_erase_block,

@ -526,9 +526,9 @@ intel_flash_readarray (urj_flash_cfi_array_t *cfi_array)
}
urj_flash_driver_t urj_flash_intel_32_flash_driver = {
4, /* buswidth */
N_("Intel Standard Command Set"),
N_("supported: 28Fxxxx, 2 x 16 bit"),
4, /* buswidth */
intel_flash_autodetect32,
intel_flash_print_info32,
intel_flash_erase_block32,
@ -538,9 +538,9 @@ urj_flash_driver_t urj_flash_intel_32_flash_driver = {
};
urj_flash_driver_t urj_flash_intel_16_flash_driver = {
2, /* buswidth */
N_("Intel Standard Command Set"),
N_("supported: 28Fxxxx, 1 x 16 bit"),
2, /* buswidth */
intel_flash_autodetect,
intel_flash_print_info,
intel_flash_erase_block,
@ -550,9 +550,9 @@ urj_flash_driver_t urj_flash_intel_16_flash_driver = {
};
urj_flash_driver_t urj_flash_intel_8_flash_driver = {
1, /* buswidth */
N_("Intel Standard Command Set"),
N_("supported: 28Fxxxx, 1 x 8 bit"),
1, /* buswidth */
intel_flash_autodetect8,
intel_flash_print_info,
intel_flash_erase_block,

Loading…
Cancel
Save