add new helpers for command completion that take arrays of strings

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1932 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Mike Frysinger 13 years ago
parent 94a2e63fcc
commit b4730561a1

@ -28,6 +28,12 @@
* src/cmd/cmd_endian.c (cmd_endian_complete): Add matches based on existing
local array of strings.
* src/cmd/cmd.h (urj_completion_mayben_add_matches_num,
urj_completion_mayben_add_matches): Helpers for adding arrays of matches.
* src/cmd/cmd_cmd.c (urj_completion_mayben_add_matches_num): New helper.
* src/cmd/cmd_bfin.c, src/cmd/cmd_cmd.c, src/cmd/cmd_debug.c,
src/cmd/cmd_print.c: Convert to new array helpers.
2011-06-27 Jie Zhang <jie.zhang@analog.com>
* include/urjtag/Makefile.am (nodist_pkginclude_HEADERS): New and

@ -112,6 +112,28 @@ void urj_completion_mayben_add_match (char ***matches, size_t *cnt,
const char *text, size_t text_len,
const char *match);
/**
* This is just like urj_completion_mayben_add_match, except you pass in
* an array of strings rather than just one single one.
*
* @param text the string to compare to match (e.g. user input)
* @param text_len the length of text
* @param matchs the array of strings to possibly add to the set of matches
* @param num the number of elements in the @matchs array
*/
void urj_completion_mayben_add_matches_num (char ***matches, size_t *cnt,
const char *text, size_t text_len,
const char * const *matchs,
size_t num);
/**
* This is just like urj_completion_mayben_add_matches_num, except the @num
* arg is automatically computed.
*/
#define urj_completion_mayben_add_matches(matches, cnt, text, text_len, matchs) \
urj_completion_mayben_add_matches_num (matches, cnt, text, text_len, \
matchs, ARRAY_SIZE (matchs))
/**
* Internal completion helper for matching against the signal list.
* Since many functions involve signals as an option, unify the code

@ -515,12 +515,17 @@ cmd_bfin_complete (urj_chain_t *chain, char ***matches, size_t *match_cnt,
char * const *tokens, const char *text, size_t text_len,
size_t token_point)
{
static const char * const main_cmds[] = {
"execute",
"emulation",
"reset",
};
if (token_point != 1)
return;
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "execute");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "emulation");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "reset");
urj_completion_mayben_add_matches (matches, match_cnt, text, text_len,
main_cmds);
}
const urj_cmd_t urj_cmd_bfin = {

@ -87,6 +87,18 @@ urj_completion_mayben_add_match (char ***matches, size_t *cnt, const char *text,
urj_completion_add_match_dupe (matches, cnt, match);
}
void
urj_completion_mayben_add_matches_num (char ***matches, size_t *cnt,
const char *text, size_t text_len,
const char * const *matchs, size_t num)
{
size_t n;
for (n = 0; n < num; ++n)
urj_completion_mayben_add_match (matches, cnt, text, text_len,
matchs[n]);
}
void
urj_completion_maybe_add_match (char ***matches, size_t *cnt, const char *text,
const char *match)

@ -136,17 +136,22 @@ cmd_debug_complete (urj_chain_t *chain, char ***matches, size_t *match_cnt,
char * const *tokens, const char *text, size_t text_len,
size_t token_point)
{
static const char * const levels[] = {
"all",
"comm",
"debug",
"detail",
"normal",
"warning",
"error",
"silent",
};
if (token_point != 1)
return;
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "all");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "comm");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "debug");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "detail");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "normal");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "warning");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "error");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "silent");
urj_completion_mayben_add_matches (matches, match_cnt, text, text_len,
levels);
}
const urj_cmd_t urj_cmd_debug = {

@ -284,13 +284,18 @@ cmd_print_complete (urj_chain_t *chain, char ***matches, size_t *match_cnt,
char * const *tokens, const char *text, size_t text_len,
size_t token_point)
{
static const char * const status[] = {
"chain",
"bus",
"signals",
"instructions",
};
if (token_point != 1)
return;
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "chain");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "bus");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "signals");
urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "instructions");
urj_completion_mayben_add_matches (matches, match_cnt, text, text_len,
status);
}
const urj_cmd_t urj_cmd_print = {

Loading…
Cancel
Save