diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index ba13d4e4..35862938 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -16,6 +16,12 @@ * cmd/cmd_initbus.c (cmd_initbus_complete): Use new helper rather than adding parameters ourselves. + * include/urjtag/params.h, src/global/params.c (urj_param_init_list): Add + new helper for creating a parameter list based on a param_list. + * src/tap/chain.c (urj_tap_chain_connect): Drop handcoded paramater list + setup and use new helper func instead. + * src/bus/buses.c (urj_bus_buses_set): Likewise. + 2011-06-30 Jie Zhang * src/cmd/Makefile.am (generated_cmd_list.h): Depend on diff --git a/urjtag/include/urjtag/params.h b/urjtag/include/urjtag/params.h index 7ee1afa8..e10e51f5 100644 --- a/urjtag/include/urjtag/params.h +++ b/urjtag/include/urjtag/params.h @@ -88,6 +88,8 @@ urj_param_list_t; /** Initialise a parameter assembly line */ int urj_param_init (const urj_param_t ***bp); +int urj_param_init_list (const urj_param_t ***bp, char *params[], + const urj_param_list_t *param_list); /** Clear the parameter assembly line */ int urj_param_clear (const urj_param_t ***bp); diff --git a/urjtag/src/bus/buses.c b/urjtag/src/bus/buses.c index 8da67bcc..8ca1cc11 100644 --- a/urjtag/src/bus/buses.c +++ b/urjtag/src/bus/buses.c @@ -145,8 +145,10 @@ urj_bus_buses_set (int n) int urj_bus_init (urj_chain_t *chain, const char *drivername, char *params[]) { - int drv, i; + int ret; + size_t i; const urj_param_t **bus_params; + const urj_bus_driver_t *bus_driver; if (urj_cmd_test_cable (chain) != URJ_STATUS_OK) return URJ_STATUS_FAIL; @@ -154,33 +156,28 @@ urj_bus_init (urj_chain_t *chain, const char *drivername, char *params[]) if (urj_tap_chain_active_part (chain) == NULL) return URJ_STATUS_FAIL; - for (drv = 0; urj_bus_drivers[drv] != NULL; drv++) - if (strcasecmp (urj_bus_drivers[drv]->name, drivername) == 0) + for (i = 0; urj_bus_drivers[i] != NULL; ++i) + if (strcasecmp (urj_bus_drivers[i]->name, drivername) == 0) break; - if (urj_bus_drivers[drv] == NULL) + bus_driver = urj_bus_drivers[i]; + if (bus_driver == NULL) { urj_error_set (URJ_ERROR_NOTFOUND, "Unknown bus: %s", drivername); return URJ_STATUS_FAIL; } - urj_param_init (&bus_params); - for (i = 0; params[i] != NULL; i++) - if (urj_param_push (&urj_bus_param_list, &bus_params, - params[i]) != URJ_STATUS_OK) - { - urj_param_clear (&bus_params); - return URJ_STATUS_FAIL; - } + ret = urj_param_init_list (&bus_params, params, &urj_bus_param_list); + if (ret != URJ_STATUS_OK) + return ret; - if (urj_bus_init_bus (chain, urj_bus_drivers[drv], bus_params) == NULL) - { - urj_param_clear (&bus_params); - return URJ_STATUS_FAIL; - } + if (urj_bus_init_bus (chain, bus_driver, bus_params) == NULL) + ret = URJ_STATUS_FAIL; + else + ret = URJ_STATUS_OK; urj_param_clear (&bus_params); - return URJ_STATUS_OK; + return ret; } urj_bus_t * diff --git a/urjtag/src/global/params.c b/urjtag/src/global/params.c index 6f9d9de9..9b35dca4 100644 --- a/urjtag/src/global/params.c +++ b/urjtag/src/global/params.c @@ -322,6 +322,28 @@ urj_param_init (const urj_param_t ***bp) return URJ_STATUS_OK; } +int +urj_param_init_list (const urj_param_t ***bp, char *params[], + const urj_param_list_t *param_list) +{ + int ret; + size_t i; + + ret = urj_param_init (bp); + if (ret != URJ_STATUS_OK) + return ret; + + for (i = 0; params[i] != NULL; ++i) + ret = urj_param_push (param_list, bp, params[i]); + if (ret != URJ_STATUS_OK) + { + urj_param_clear (bp); + return ret; + } + + return URJ_STATUS_OK; +} + int urj_param_clear (const urj_param_t ***bp) { diff --git a/urjtag/src/tap/chain.c b/urjtag/src/tap/chain.c index d160d951..57bc327b 100644 --- a/urjtag/src/tap/chain.c +++ b/urjtag/src/tap/chain.c @@ -125,14 +125,9 @@ urj_tap_chain_connect (urj_chain_t *chain, const char *drivername, char *params[ devname = NULL; } - urj_param_init (&cable_params); - for (j = param_start; params[j] != NULL; j++) - if (urj_param_push (&urj_cable_param_list, &cable_params, - params[j]) != URJ_STATUS_OK) - { - urj_param_clear (&cable_params); - return URJ_STATUS_FAIL; - } + if (urj_param_init_list (&cable_params, ¶ms[param_start], + &urj_cable_param_list) != URJ_STATUS_OK) + return URJ_STATUS_FAIL; switch (driver->device_type) {