From 011e64d492ad781a4e5303a097531d8583fbc465 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 29 Jan 2010 09:09:11 +0000 Subject: [PATCH] statically sort lists so we can constify them all git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1746 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/src/bus/buses_list.h | 27 +++++++----- urjtag/src/cmd/cmd.h | 30 ++++++------- urjtag/src/cmd/cmd_cable.c | 8 +--- urjtag/src/cmd/cmd_cmd.c | 12 +---- urjtag/src/cmd/cmd_eraseflash.c | 8 +--- urjtag/src/cmd/cmd_flashmem.c | 8 +--- urjtag/src/cmd/cmd_help.c | 8 +--- urjtag/src/cmd/cmd_initbus.c | 8 +--- urjtag/src/cmd/cmd_list.h | 71 ++++++++++++++++-------------- urjtag/src/tap/cable/ft2232_list.h | 8 ++-- urjtag/src/tap/cable_list.h | 61 +++++++++++++------------ urjtag/src/tap/usbconn_list.h | 11 +++-- 12 files changed, 121 insertions(+), 139 deletions(-) diff --git a/urjtag/src/bus/buses_list.h b/urjtag/src/bus/buses_list.h index 75cfc3fc..78afda94 100644 --- a/urjtag/src/bus/buses_list.h +++ b/urjtag/src/bus/buses_list.h @@ -22,6 +22,11 @@ * */ + +/* + * Please keep this list sorted alphabetically + */ + #ifdef ENABLE_BUS_ARM9TDMI _URJ_BUS(arm9tdmi) #endif @@ -40,18 +45,18 @@ _URJ_BUS(bf526_ezkit) #ifdef ENABLE_BUS_BF527_EZKIT _URJ_BUS(bf527_ezkit) #endif -#ifdef ENABLE_BUS_BF533_STAMP -_URJ_BUS(bf533_stamp) -#endif #ifdef ENABLE_BUS_BF533_EZKIT _URJ_BUS(bf533_ezkit) #endif -#ifdef ENABLE_BUS_BF537_STAMP -_URJ_BUS(bf537_stamp) +#ifdef ENABLE_BUS_BF533_STAMP +_URJ_BUS(bf533_stamp) #endif #ifdef ENABLE_BUS_BF537_EZKIT _URJ_BUS(bf537_ezkit) #endif +#ifdef ENABLE_BUS_BF537_STAMP +_URJ_BUS(bf537_stamp) +#endif #ifdef ENABLE_BUS_BF538F_EZKIT _URJ_BUS(bf538f_ezkit) #endif @@ -71,6 +76,9 @@ _URJ_BUS(ejtag_dma) #ifdef ENABLE_BUS_FJMEM _URJ_BUS(fjmem) #endif +#ifdef ENABLE_BUS_H7202 +_URJ_BUS(h7202) +#endif #ifdef ENABLE_BUS_IXP425 _URJ_BUS(ixp425) #endif @@ -83,9 +91,6 @@ _URJ_BUS(ixp465) #ifdef ENABLE_BUS_JOPCYC _URJ_BUS(jopcyc) #endif -#ifdef ENABLE_BUS_H7202 -_URJ_BUS(h7202) -#endif #ifdef ENABLE_BUS_LH7A400 _URJ_BUS(lh7a400) #endif @@ -107,12 +112,12 @@ _URJ_BUS(ppc440gx_ebc8) #ifdef ENABLE_BUS_PROTOTYPE _URJ_BUS(prototype) #endif -#ifdef ENABLE_BUS_PXA2X0 -_URJ_BUS(pxa2x0) -#endif #ifdef ENABLE_BUS_PXA27X _URJ_BUS(pxa27x) #endif +#ifdef ENABLE_BUS_PXA2X0 +_URJ_BUS(pxa2x0) +#endif #ifdef ENABLE_BUS_S3C4510 _URJ_BUS(s3c4510) #endif diff --git a/urjtag/src/cmd/cmd.h b/urjtag/src/cmd/cmd.h index 8012bcab..9a63daf6 100644 --- a/urjtag/src/cmd/cmd.h +++ b/urjtag/src/cmd/cmd.h @@ -42,7 +42,7 @@ typedef struct { char *name; - char *desc; + char *description; void (*help) (void); /** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error, both * syntax and library errors */ @@ -52,7 +52,7 @@ typedef struct #define _URJ_CMD(cmd) extern const urj_cmd_t urj_cmd_##cmd; #include "cmd_list.h" -extern const urj_cmd_t *urj_cmds[]; +extern const urj_cmd_t * const urj_cmds[]; /** * Tests if chain has a cable pointer @@ -72,19 +72,19 @@ int urj_cmd_params (char *params[]); int urj_cmd_get_number (const char *s, long unsigned *i); /** - * Internal command to help with sorting structures for display + * Show a list of structures with name/desc */ -int _urj_cmd_alphasort (const void *a, const void *b); -#define urj_cmd_sort(arr, max_len) \ - do { \ - size_t nmemb; \ - 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) +#define urj_cmd_show_list(arr) \ +do { \ + int i, max_len = 0; \ + for (i = 0; arr[i]; ++i) { \ + int this_len = strlen(arr[i]->name); \ + if (max_len < this_len) \ + max_len = this_len; \ + } \ + for (i = 0; arr[i]; ++i) \ + urj_log (URJ_LOG_LEVEL_NORMAL, "%-*s %s\n", max_len + 1, \ + arr[i]->name, _(arr[i]->description)); \ +} while (0) #endif /* URJ_CMD_H */ diff --git a/urjtag/src/cmd/cmd_cable.c b/urjtag/src/cmd/cmd_cable.c index 8c5307f9..87ddc281 100644 --- a/urjtag/src/cmd/cmd_cable.c +++ b/urjtag/src/cmd/cmd_cable.c @@ -161,8 +161,6 @@ cmd_cable_run (urj_chain_t *chain, char *params[]) static void cmd_cable_help (void) { - int i, pad; - urj_log (URJ_LOG_LEVEL_NORMAL, _("Usage: %s DRIVER [DRIVER_OPTS]\n" "Select JTAG cable type.\n" @@ -174,11 +172,7 @@ cmd_cable_help (void) "\n" "List of supported cables:\n"), "cable"); - urj_cmd_sort (urj_tap_cable_drivers, pad); - for (i = 0; urj_tap_cable_drivers[i]; i++) - urj_log (URJ_LOG_LEVEL_NORMAL, "%-*s %s\n", pad + 1, - urj_tap_cable_drivers[i]->name, - _(urj_tap_cable_drivers[i]->description)); + urj_cmd_show_list (urj_tap_cable_drivers); } const urj_cmd_t urj_cmd_cable = { diff --git a/urjtag/src/cmd/cmd_cmd.c b/urjtag/src/cmd/cmd_cmd.c index d4ab6b44..0fe09540 100644 --- a/urjtag/src/cmd/cmd_cmd.c +++ b/urjtag/src/cmd/cmd_cmd.c @@ -34,7 +34,7 @@ #include "cmd.h" -const urj_cmd_t *urj_cmds[] = { +const urj_cmd_t * const urj_cmds[] = { #define _URJ_CMD(cmd) &urj_cmd_##cmd, #include "cmd_list.h" NULL /* last must be NULL */ @@ -178,13 +178,3 @@ 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)); -} diff --git a/urjtag/src/cmd/cmd_eraseflash.c b/urjtag/src/cmd/cmd_eraseflash.c index e4f8ea88..beef959e 100644 --- a/urjtag/src/cmd/cmd_eraseflash.c +++ b/urjtag/src/cmd/cmd_eraseflash.c @@ -68,8 +68,6 @@ cmd_eraseflash_run (urj_chain_t *chain, char *params[]) static void cmd_eraseflash_help (void) { - int i, pad; - urj_log (URJ_LOG_LEVEL_NORMAL, _("Usage: %s ADDR BLOCKS\n" "Erase flash memory from ADDR.\n" @@ -81,11 +79,7 @@ cmd_eraseflash_help (void) "\n" "Supported Flash Memories:\n"), "eraseflash"); - urj_cmd_sort (urj_flash_flash_drivers, pad); - for (i = 0; urj_flash_flash_drivers[i]; i++) - urj_log (URJ_LOG_LEVEL_NORMAL, "%-*s %s\n", pad + 1, - urj_flash_flash_drivers[i]->name, - _(urj_flash_flash_drivers[i]->description)); + urj_cmd_show_list (urj_flash_flash_drivers); } const urj_cmd_t urj_cmd_eraseflash = { diff --git a/urjtag/src/cmd/cmd_flashmem.c b/urjtag/src/cmd/cmd_flashmem.c index d619acc5..08e944b9 100644 --- a/urjtag/src/cmd/cmd_flashmem.c +++ b/urjtag/src/cmd/cmd_flashmem.c @@ -90,8 +90,6 @@ cmd_flashmem_run (urj_chain_t *chain, char *params[]) static void cmd_flashmem_help (void) { - int i, pad; - urj_log (URJ_LOG_LEVEL_NORMAL, _("Usage: %s ADDR FILENAME [noverify]\n" "Usage: %s FILENAME [noverify]\n" @@ -107,11 +105,7 @@ cmd_flashmem_help (void) "Supported Flash Memories:\n"), "flashmem", "flashmem msbin", "msbin", "noverify"); - urj_cmd_sort (urj_flash_flash_drivers, pad); - for (i = 0; urj_flash_flash_drivers[i]; i++) - urj_log (URJ_LOG_LEVEL_NORMAL, "%-*s %s\n", pad + 1, - urj_flash_flash_drivers[i]->name, - _(urj_flash_flash_drivers[i]->description)); + urj_cmd_show_list (urj_flash_flash_drivers); } const urj_cmd_t urj_cmd_flashmem = { diff --git a/urjtag/src/cmd/cmd_help.c b/urjtag/src/cmd/cmd_help.c index 77475542..117ddc4c 100644 --- a/urjtag/src/cmd/cmd_help.c +++ b/urjtag/src/cmd/cmd_help.c @@ -48,14 +48,8 @@ cmd_help_run (urj_chain_t *chain, char *params[]) /* short description generation */ if (urj_cmd_params (params) == 1) { - 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, "%-*s %s\n", pad + 1, - urj_cmds[i]->name, - urj_cmds[i]->desc ? _(urj_cmds[i]->desc) : - _("(no description available)")); + urj_cmd_show_list (urj_cmds); urj_log (URJ_LOG_LEVEL_NORMAL, _("\nType \"help COMMAND\" for details about a particular command.\n")); return URJ_STATUS_OK; diff --git a/urjtag/src/cmd/cmd_initbus.c b/urjtag/src/cmd/cmd_initbus.c index fbb4100f..d35004c8 100644 --- a/urjtag/src/cmd/cmd_initbus.c +++ b/urjtag/src/cmd/cmd_initbus.c @@ -90,8 +90,6 @@ cmd_initbus_run (urj_chain_t *chain, char *params[]) static void cmd_initbus_help (void) { - int i, pad; - urj_log (URJ_LOG_LEVEL_NORMAL, _("Usage: %s BUSNAME\n" "Initialize new bus driver for active part.\n" @@ -100,11 +98,7 @@ cmd_initbus_help (void) "\n" "List of available buses:\n"), "initbus"); - urj_cmd_sort (urj_bus_drivers, pad); - for (i = 0; urj_bus_drivers[i] != NULL; i++) - urj_log (URJ_LOG_LEVEL_NORMAL, "%-*s %s\n", pad + 1, - urj_bus_drivers[i]->name, - _(urj_bus_drivers[i]->description)); + urj_cmd_show_list (urj_bus_drivers); } const const urj_cmd_t urj_cmd_initbus = { diff --git a/urjtag/src/cmd/cmd_list.h b/urjtag/src/cmd/cmd_list.h index 6634e529..48e5b324 100644 --- a/urjtag/src/cmd/cmd_list.h +++ b/urjtag/src/cmd/cmd_list.h @@ -31,50 +31,55 @@ * */ -_URJ_CMD(quit) -_URJ_CMD(help) -_URJ_CMD(frequency) + +/* + * Please keep this list sorted alphabetically + */ + +_URJ_CMD(addpart) +_URJ_CMD(bfin) +_URJ_CMD(bit) +#ifdef ENABLE_BSDL +_URJ_CMD(bsdl) +#endif +_URJ_CMD(bus) _URJ_CMD(cable) -_URJ_CMD(reset) +_URJ_CMD(debug) +_URJ_CMD(detect) +_URJ_CMD(detectflash) _URJ_CMD(discovery) +_URJ_CMD(dr) +_URJ_CMD(endian) +_URJ_CMD(eraseflash) +_URJ_CMD(flashmem) +_URJ_CMD(frequency) +_URJ_CMD(get) +_URJ_CMD(help) _URJ_CMD(idcode) -_URJ_CMD(detect) -_URJ_CMD(signal) -_URJ_CMD(scan) -_URJ_CMD(salias) -_URJ_CMD(bit) -_URJ_CMD(register) +_URJ_CMD(include) _URJ_CMD(initbus) -_URJ_CMD(print) -_URJ_CMD(part) -_URJ_CMD(bus) _URJ_CMD(instruction) -_URJ_CMD(shift) -_URJ_CMD(dr) -_URJ_CMD(get) -_URJ_CMD(test) -_URJ_CMD(shell) -_URJ_CMD(set) -_URJ_CMD(endian) +_URJ_CMD(part) _URJ_CMD(peek) -_URJ_CMD(poke) _URJ_CMD(pod) +_URJ_CMD(poke) +_URJ_CMD(print) +_URJ_CMD(quit) _URJ_CMD(readmem) -_URJ_CMD(writemem) -_URJ_CMD(detectflash) -_URJ_CMD(flashmem) -_URJ_CMD(eraseflash) +_URJ_CMD(register) +_URJ_CMD(reset) +_URJ_CMD(salias) +_URJ_CMD(scan) _URJ_CMD(script) -_URJ_CMD(include) -_URJ_CMD(addpart) -_URJ_CMD(usleep) +_URJ_CMD(set) +_URJ_CMD(shell) +_URJ_CMD(shift) +_URJ_CMD(signal) #ifdef ENABLE_SVF _URJ_CMD(svf) #endif -#ifdef ENABLE_BSDL -_URJ_CMD(bsdl) -#endif -_URJ_CMD(debug) -_URJ_CMD(bfin) +_URJ_CMD(test) +_URJ_CMD(usleep) +_URJ_CMD(writemem) #undef _URJ_CMD diff --git a/urjtag/src/tap/cable/ft2232_list.h b/urjtag/src/tap/cable/ft2232_list.h index 7bc0a7c5..63063f95 100644 --- a/urjtag/src/tap/cable/ft2232_list.h +++ b/urjtag/src/tap/cable/ft2232_list.h @@ -26,16 +26,16 @@ * */ -_URJ_FTDI(ft2232) _URJ_FTDI(armusbocd) +_URJ_FTDI(flyswatter) +_URJ_FTDI(ft2232) _URJ_FTDI(gnice) _URJ_FTDI(gniceplus) _URJ_FTDI(jtagkey) _URJ_FTDI(oocdlinks) -_URJ_FTDI(turtelizer2) -_URJ_FTDI(usbtojtagif) _URJ_FTDI(signalyzer) -_URJ_FTDI(flyswatter) +_URJ_FTDI(turtelizer2) _URJ_FTDI(usbscarab2) +_URJ_FTDI(usbtojtagif) #undef _URJ_FTDI diff --git a/urjtag/src/tap/cable_list.h b/urjtag/src/tap/cable_list.h index 5f4f6ac8..cb3d7069 100644 --- a/urjtag/src/tap/cable_list.h +++ b/urjtag/src/tap/cable_list.h @@ -22,73 +22,80 @@ * */ + +/* + * Please keep this list sorted alphabetically + */ + #ifdef ENABLE_CABLE_ARCOM _URJ_CABLE(arcom) #endif #ifdef ENABLE_CABLE_BYTEBLASTER _URJ_CABLE(byteblaster) #endif -#ifdef ENABLE_CABLE_USBBLASTER -_URJ_CABLE(usbblaster) +#ifdef ENABLE_CABLE_DLC5 +_URJ_CABLE(dlc5) +#endif +#ifdef ENABLE_CABLE_EA253 +_URJ_CABLE(ea253) +#endif +#ifdef ENABLE_CABLE_EI012 +_URJ_CABLE(ei012) +#endif +#ifdef ENABLE_CABLE_EP9307 +_URJ_CABLE(ep9307) #endif #ifdef ENABLE_CABLE_FT2232 _URJ_CABLE(ft2232) -_URJ_CABLE(ft2232_jtagkey) _URJ_CABLE(ft2232_armusbocd) _URJ_CABLE(ft2232_armusbtiny_h) +_URJ_CABLE(ft2232_flyswatter) _URJ_CABLE(ft2232_gnice) _URJ_CABLE(ft2232_gniceplus) +_URJ_CABLE(ft2232_jtagkey) _URJ_CABLE(ft2232_oocdlinks) _URJ_CABLE(ft2232_signalyzer) _URJ_CABLE(ft2232_turtelizer2) -_URJ_CABLE(ft2232_usbtojtagif) -_URJ_CABLE(ft2232_flyswatter) _URJ_CABLE(ft2232_usbscarab2) -#endif -#ifdef ENABLE_CABLE_DLC5 -_URJ_CABLE(dlc5) -#endif -#ifdef ENABLE_CABLE_EA253 -_URJ_CABLE(ea253) -#endif -#ifdef ENABLE_CABLE_EI012 -_URJ_CABLE(ei012) +_URJ_CABLE(ft2232_usbtojtagif) #endif #ifdef ENABLE_CABLE_IGLOO _URJ_CABLE(igloo) #endif +#ifdef ENABLE_JIM +_URJ_CABLE(jim) +#endif +#ifdef ENABLE_CABLE_JLINK +_URJ_CABLE(jlink) +#endif #ifdef ENABLE_CABLE_KEITHKOEP _URJ_CABLE(keithkoep) #endif #ifdef ENABLE_CABLE_LATTICE _URJ_CABLE(lattice) #endif +#ifdef ENABLE_CABLE_WIGGLER +_URJ_CABLE(minimal) +#endif #ifdef ENABLE_CABLE_MPCBDM _URJ_CABLE(mpcbdm) #endif #ifdef ENABLE_CABLE_TRITON _URJ_CABLE(triton) #endif -#ifdef ENABLE_JIM -_URJ_CABLE(jim) +#ifdef ENABLE_CABLE_TS7800 +_URJ_CABLE(ts7800) +#endif +#ifdef ENABLE_CABLE_USBBLASTER +_URJ_CABLE(usbblaster) #endif #ifdef ENABLE_CABLE_WIGGLER -_URJ_CABLE(minimal) _URJ_CABLE(wiggler) _URJ_CABLE(wiggler2) #endif #ifdef ENABLE_CABLE_XPC -_URJ_CABLE(xpc_int) _URJ_CABLE(xpc_ext) -#endif -#ifdef ENABLE_CABLE_JLINK -_URJ_CABLE(jlink) -#endif -#ifdef ENABLE_CABLE_EP9307 -_URJ_CABLE(ep9307) -#endif -#ifdef ENABLE_CABLE_TS7800 -_URJ_CABLE(ts7800) +_URJ_CABLE(xpc_int) #endif #undef _URJ_CABLE diff --git a/urjtag/src/tap/usbconn_list.h b/urjtag/src/tap/usbconn_list.h index d71df61f..16a0a2c7 100644 --- a/urjtag/src/tap/usbconn_list.h +++ b/urjtag/src/tap/usbconn_list.h @@ -22,9 +22,11 @@ * */ -#ifdef HAVE_LIBUSB -_URJ_LIST(libusb) -#endif + +/* + * Please keep this list sorted alphabetically + */ + #ifdef ENABLE_LOWLEVEL_FTD2XX _URJ_LIST(ftd2xx) _URJ_LIST(ftd2xx_mpsse) @@ -33,5 +35,8 @@ _URJ_LIST(ftd2xx_mpsse) _URJ_LIST(ftdi) _URJ_LIST(ftdi_mpsse) #endif +#ifdef HAVE_LIBUSB +_URJ_LIST(libusb) +#endif #undef _URJ_LIST