urj_param_init_list: unify code for parsing user params based on a param_list struct

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1946 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Mike Frysinger 14 years ago
parent a16e5c82ed
commit 70612aab1b

@ -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 <jie.zhang@analog.com>
* src/cmd/Makefile.am (generated_cmd_list.h): Depend on

@ -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);

@ -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 *

@ -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)
{

@ -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, &params[param_start],
&urj_cable_param_list) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
switch (driver->device_type)
{

Loading…
Cancel
Save