diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 8549864a..6287cafa 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -2,6 +2,13 @@ * cmd/cmd_initbus.c (cmd_initbus_complete): Complete bus parameters too. + * include/urjtag/cable.h, src/tap/cable.c (urj_tap_cable_find): Add new + helper for looking up cable drivers by name. + * src/cmd/cmd_cable.c (cmd_cable_run): Use new helper to restore cable + specific help output. + * src/tap/chain.c (urj_tap_chain_connect): Replace look up code with new + urj_tap_cable_find helper. + 2011-06-30 Jie Zhang * src/cmd/Makefile.am (generated_cmd_list.h): Depend on diff --git a/urjtag/include/urjtag/cable.h b/urjtag/include/urjtag/cable.h index 08ff218d..7033ef26 100644 --- a/urjtag/include/urjtag/cable.h +++ b/urjtag/include/urjtag/cable.h @@ -178,6 +178,8 @@ struct URJ_CABLE void urj_tap_cable_free (urj_cable_t *cable); /** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on failure */ int urj_tap_cable_init (urj_cable_t *cable); +/** @return cable named by @cname; NULL on failure */ +const urj_cable_driver_t *urj_tap_cable_find (const char *cname); void urj_tap_cable_done (urj_cable_t *cable); void urj_tap_cable_flush (urj_cable_t *cable, urj_cable_flush_amount_t); diff --git a/urjtag/src/cmd/cmd_cable.c b/urjtag/src/cmd/cmd_cable.c index 939e78ae..a55dd696 100644 --- a/urjtag/src/cmd/cmd_cable.c +++ b/urjtag/src/cmd/cmd_cable.c @@ -95,6 +95,22 @@ cmd_cable_run (urj_chain_t *chain, char *params[]) } } + if (paramc >= 3 && strcasecmp (params[2], "help") == 0) + { + const urj_cable_driver_t *driver; + + driver = urj_tap_cable_find (params[1]); + if (!driver) + { + urj_error_set (URJ_ERROR_INVALID, + "unknown cable driver '%s'", params[1]); + return URJ_STATUS_FAIL; + } + + driver->help (URJ_LOG_LEVEL_NORMAL, driver->name); + return URJ_STATUS_OK; + } + return urj_tap_chain_connect (chain, params[1], ¶ms[2]); } diff --git a/urjtag/src/tap/cable.c b/urjtag/src/tap/cable.c index 9d3fe73f..d265b89b 100644 --- a/urjtag/src/tap/cable.c +++ b/urjtag/src/tap/cable.c @@ -51,6 +51,18 @@ const urj_cable_driver_t * const urj_tap_cable_drivers[] = { NULL /* last must be NULL */ }; +const urj_cable_driver_t * +urj_tap_cable_find (const char *cname) +{ + size_t i; + + for (i = 0; urj_tap_cable_drivers[i]; ++i) + if (strcasecmp (cname, urj_tap_cable_drivers[i]->name) == 0) + break; + + return urj_tap_cable_drivers[i]; +} + void urj_tap_cable_free (urj_cable_t *cable) { diff --git a/urjtag/src/tap/chain.c b/urjtag/src/tap/chain.c index 9ae1f593..d160d951 100644 --- a/urjtag/src/tap/chain.c +++ b/urjtag/src/tap/chain.c @@ -75,7 +75,7 @@ int urj_tap_chain_connect (urj_chain_t *chain, const char *drivername, char *params[]) { urj_cable_t *cable; - int i, j, paramc; + int j, paramc; const urj_param_t **cable_params; const urj_cable_driver_t *driver; @@ -86,12 +86,7 @@ urj_tap_chain_connect (urj_chain_t *chain, const char *drivername, char *params[ param_start = 0; paramc = urj_cmd_params (params); - /* search cable driver list */ - for (i = 0; urj_tap_cable_drivers[i]; i++) - if (strcasecmp (drivername, urj_tap_cable_drivers[i]->name) == 0) - break; - - driver = urj_tap_cable_drivers[i]; + driver = urj_tap_cable_find (drivername); if (!driver) { urj_error_set (URJ_ERROR_INVALID,