diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 6287cafa..ba13d4e4 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -9,6 +9,13 @@ * src/tap/chain.c (urj_tap_chain_connect): Replace look up code with new urj_tap_cable_find helper. + * src/cmd/cmd.h, src/cmd/cmd_cmd.c (urj_completion_mayben_add_param_list): + Add new helper which automatically adds urj_param_list_t for matches. + * src/cmd/cmd_cable.c (cmd_cable_complete): Use new helper to add cable + options to possible matches. + * cmd/cmd_initbus.c (cmd_initbus_complete): Use new helper rather than + adding parameters ourselves. + 2011-06-30 Jie Zhang * src/cmd/Makefile.am (generated_cmd_list.h): Depend on diff --git a/urjtag/src/cmd/cmd.h b/urjtag/src/cmd/cmd.h index d41cf365..7fed4523 100644 --- a/urjtag/src/cmd/cmd.h +++ b/urjtag/src/cmd/cmd.h @@ -37,6 +37,7 @@ #include /* qsort */ #include +#include #include typedef struct @@ -134,6 +135,18 @@ void urj_completion_mayben_add_matches_num (char ***matches, size_t *cnt, urj_completion_mayben_add_matches_num (matches, cnt, text, text_len, \ matchs, ARRAY_SIZE (matchs)) +/** + * This is just like urj_completion_mayben_add_matches_num, but the array + * info comes straight from the urj_param_list_t structure. + * + * @param text the string to compare to match (e.g. user input) + * @param text_len the length of text + * @param param_list the list of parameter strings to possibly add to the set of matches + */ +void urj_completion_mayben_add_param_list (char ***matches, size_t *cnt, + const char *text, size_t text_len, + urj_param_list_t param_list); + /** * Internal completion helper for matching against the signal list. * Since many functions involve signals as an option, unify the code diff --git a/urjtag/src/cmd/cmd_cable.c b/urjtag/src/cmd/cmd_cable.c index a55dd696..a666b1fb 100644 --- a/urjtag/src/cmd/cmd_cable.c +++ b/urjtag/src/cmd/cmd_cable.c @@ -149,8 +149,9 @@ cmd_cable_complete (urj_chain_t *chain, char ***matches, size_t *match_cnt, urj_tap_cable_drivers[i]->name); break; case 2: - /* XXX: in the future, we want to complete cable options too */ urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "help"); + urj_completion_mayben_add_param_list (matches, match_cnt, text, + text_len, urj_cable_param_list); break; } } diff --git a/urjtag/src/cmd/cmd_cmd.c b/urjtag/src/cmd/cmd_cmd.c index f12d03db..943d6cf6 100644 --- a/urjtag/src/cmd/cmd_cmd.c +++ b/urjtag/src/cmd/cmd_cmd.c @@ -99,6 +99,18 @@ urj_completion_mayben_add_matches_num (char ***matches, size_t *cnt, matchs[n]); } +void +urj_completion_mayben_add_param_list (char ***matches, size_t *cnt, + const char *text, size_t text_len, + urj_param_list_t param_list) +{ + size_t i; + + for (i = 0; i < param_list.n; ++i) + urj_completion_mayben_add_match (matches, cnt, text, text_len, + param_list.list[i].string); +} + void urj_completion_maybe_add_match (char ***matches, size_t *cnt, const char *text, const char *match) diff --git a/urjtag/src/cmd/cmd_initbus.c b/urjtag/src/cmd/cmd_initbus.c index 1219852e..3c2e4238 100644 --- a/urjtag/src/cmd/cmd_initbus.c +++ b/urjtag/src/cmd/cmd_initbus.c @@ -80,9 +80,8 @@ cmd_initbus_complete (urj_chain_t *chain, char ***matches, size_t *match_cnt, urj_bus_drivers[i]->name); break; default: - for (i = 0; i < urj_bus_param_list.n; ++i) - urj_completion_mayben_add_match (matches, match_cnt, text, text_len, - urj_bus_param_list.list[i].string); + urj_completion_mayben_add_param_list (matches, match_cnt, text, + text_len, urj_bus_param_list); break; } }