From 1ddde8e7ec7502fc558caa73ee9e69ac46feb025 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 30 Jun 2011 03:18:52 +0000 Subject: [PATCH] cmd_{bfin,set}: add sub-command completions only when earlier tokens indicate that it makes sense to git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1933 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 3 +++ urjtag/src/cmd/cmd_bfin.c | 35 ++++++++++++++++++++++++++++++----- urjtag/src/cmd/cmd_set.c | 17 ++++++++++++----- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index dc748c02..eb176ecb 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -34,6 +34,9 @@ * 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. + * src/cmd/cmd_bfin.c, src/cmd/cmd_set.c: Use new tokens arg to selectively + add matches for specific sub-commands. + 2011-06-27 Jie Zhang * include/urjtag/Makefile.am (nodist_pkginclude_HEADERS): New and diff --git a/urjtag/src/cmd/cmd_bfin.c b/urjtag/src/cmd/cmd_bfin.c index d3db0076..afc0e080 100644 --- a/urjtag/src/cmd/cmd_bfin.c +++ b/urjtag/src/cmd/cmd_bfin.c @@ -520,12 +520,37 @@ cmd_bfin_complete (urj_chain_t *chain, char ***matches, size_t *match_cnt, "emulation", "reset", }; + static const char * const emu_cmds[] = { + "enable", + "trigger", + "enter", + "return", + "disable", + "exit", + "singlestep", + "status", + }; + static const char * const reset_cmds[] = { + "core", + "system", + }; - if (token_point != 1) - return; - - urj_completion_mayben_add_matches (matches, match_cnt, text, text_len, - main_cmds); + switch (token_point) + { + case 1: + urj_completion_mayben_add_matches (matches, match_cnt, text, text_len, + main_cmds); + break; + + case 2: + if (!strcmp (tokens[1], "reset")) + urj_completion_mayben_add_matches (matches, match_cnt, text, + text_len, reset_cmds); + else if (!strcmp (tokens[1], "emulation")) + urj_completion_mayben_add_matches (matches, match_cnt, text, + text_len, emu_cmds); + break; + } } const urj_cmd_t urj_cmd_bfin = { diff --git a/urjtag/src/cmd/cmd_set.c b/urjtag/src/cmd/cmd_set.c index e465d10f..87530877 100644 --- a/urjtag/src/cmd/cmd_set.c +++ b/urjtag/src/cmd/cmd_set.c @@ -122,6 +122,13 @@ cmd_set_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 dir[] = { + "in", "out", + }; + static const char * const data[] = { + "0", "1", + }; + switch (token_point) { case 1: @@ -133,14 +140,14 @@ cmd_set_complete (urj_chain_t *chain, char ***matches, size_t *match_cnt, break; case 3: /* direction */ - urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "in"); - urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "out"); + urj_completion_mayben_add_matches (matches, match_cnt, text, text_len, + dir); break; case 4: /* value */ - /* XXX: Only applies if token[1] == "out" ... */ - urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "0"); - urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "1"); + if (!strcmp (tokens[3], "out")) + urj_completion_mayben_add_matches (matches, match_cnt, text, + text_len, data); break; } }