From 424f2ec2254371ffdb364fccbb80044e059be80d Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 7 Jul 2011 00:12:44 +0000 Subject: [PATCH] add command completion support to more commands git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1964 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 4 ++++ urjtag/src/cmd/cmd_bsdl.c | 37 ++++++++++++++++++++++++++++++++++- urjtag/src/cmd/cmd_bus.c | 24 ++++++++++++++++++++++- urjtag/src/cmd/cmd_dr.c | 19 +++++++++++++++++- urjtag/src/cmd/cmd_part.c | 30 +++++++++++++++++++++++++++- urjtag/src/cmd/cmd_pod.c | 20 ++++++++++++++++++- urjtag/src/cmd/cmd_shell.c | 12 +++++++++++- urjtag/src/cmd/cmd_svf.c | 27 ++++++++++++++++++++++++- urjtag/src/cmd/cmd_writemem.c | 21 +++++++++++++++++++- 9 files changed, 186 insertions(+), 8 deletions(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 6393322d..ced3ba71 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -8,6 +8,10 @@ * src/cmd/cmd_part.c (cmd_part_help): Update output to reflect reality. + * src/cmd/cmd_bsdl.c, src/cmd/cmd_bus.c, src/cmd/cmd_dr.c, + src/cmd/cmd_part.c, src/cmd/cmd_pod.c, src/cmd/cmd_shell.c, + src/cmd/cmd_svf.c, src/cmd/cmd_writemem.c: Add completion handlers. + 2011-07-06 Jie Zhang * src/tap/chain.c (urj_tap_chain_connect): Correct checking of the diff --git a/urjtag/src/cmd/cmd_bsdl.c b/urjtag/src/cmd/cmd_bsdl.c index beb7ff74..c7b96cc0 100644 --- a/urjtag/src/cmd/cmd_bsdl.c +++ b/urjtag/src/cmd/cmd_bsdl.c @@ -116,6 +116,40 @@ cmd_bsdl_run (urj_chain_t *chain, char *params[]) return (result >= 0) ? URJ_STATUS_OK : URJ_STATUS_FAIL; } +static void +cmd_bsdl_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[] = { + "path", + "test", + "dump", + "debug", + }; + + static const char * const debug_cmds[] = { + "on", "off", + }; + + switch (token_point) + { + case 1: + urj_completion_mayben_add_matches (matches, match_cnt, text, text_len, + main_cmds); + break; + + case 2: + /* XXX: For "test" and "dump", we'll want to search the bsdl paths */ + if (!strcmp (tokens[1], "path")) + urj_completion_mayben_add_file (matches, match_cnt, text, + text_len, false); + else if (!strcmp (tokens[1], "debug")) + urj_completion_mayben_add_matches (matches, match_cnt, text, + text_len, debug_cmds); + break; + } +} static void cmd_bsdl_help (void) @@ -136,7 +170,8 @@ const urj_cmd_t urj_cmd_bsdl = { "bsdl", N_("manage BSDL files"), cmd_bsdl_help, - cmd_bsdl_run + cmd_bsdl_run, + cmd_bsdl_complete, }; diff --git a/urjtag/src/cmd/cmd_bus.c b/urjtag/src/cmd/cmd_bus.c index 62b9efdf..66b1a5cc 100644 --- a/urjtag/src/cmd/cmd_bus.c +++ b/urjtag/src/cmd/cmd_bus.c @@ -64,6 +64,27 @@ cmd_bus_run (urj_chain_t *chain, char *params[]) return urj_bus_buses_set (n); } +static void +cmd_bus_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) +{ + int i; + + if (token_point != 1) + return; + + for (i = 0; i < urj_buses.len; ++i) + { + /* We assume you'll never have more than 15*10 buses */ + char num[16]; + + sprintf (num, "%i", i); + urj_completion_mayben_add_match (matches, match_cnt, text, + text_len, num); + } +} + static void cmd_bus_help (void) { @@ -78,5 +99,6 @@ const urj_cmd_t urj_cmd_bus = { "bus", N_("change active bus"), cmd_bus_help, - cmd_bus_run + cmd_bus_run, + cmd_bus_complete, }; diff --git a/urjtag/src/cmd/cmd_dr.c b/urjtag/src/cmd/cmd_dr.c index 5dd92e41..5cac94a0 100644 --- a/urjtag/src/cmd/cmd_dr.c +++ b/urjtag/src/cmd/cmd_dr.c @@ -104,6 +104,22 @@ cmd_dr_run (urj_chain_t *chain, char *params[]) return URJ_STATUS_OK; } +static void +cmd_dr_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", + }; + + if (token_point != 1) + return; + + urj_completion_mayben_add_matches (matches, match_cnt, text, text_len, dir); +} + static void cmd_dr_help (void) { @@ -124,5 +140,6 @@ const urj_cmd_t urj_cmd_dr = { "dr", N_("display active data register for a part"), cmd_dr_help, - cmd_dr_run + cmd_dr_run, + cmd_dr_complete, }; diff --git a/urjtag/src/cmd/cmd_part.c b/urjtag/src/cmd/cmd_part.c index 96f8fb71..0e4418df 100644 --- a/urjtag/src/cmd/cmd_part.c +++ b/urjtag/src/cmd/cmd_part.c @@ -126,6 +126,33 @@ cmd_part_run (urj_chain_t *chain, char *params[]) return URJ_STATUS_OK; } +static void +cmd_part_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) +{ + int i; + + if (token_point != 1) + return; + + urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "alias"); + + for (i = 0; i < chain->parts->len; ++i) + { + /* We assume you'll never have more than 15*10 parts */ + char num[16]; + + sprintf (num, "%i", i); + urj_completion_mayben_add_match (matches, match_cnt, text, + text_len, num); + + if (chain->parts->parts[i]->alias) + urj_completion_mayben_add_match (matches, match_cnt, text, text_len, + chain->parts->parts[i]->alias); + } +} + static void cmd_part_help (void) { @@ -141,5 +168,6 @@ const urj_cmd_t urj_cmd_part = { "part", N_("change active part for current JTAG chain"), cmd_part_help, - cmd_part_run + cmd_part_run, + cmd_part_complete, }; diff --git a/urjtag/src/cmd/cmd_pod.c b/urjtag/src/cmd/cmd_pod.c index ac472265..9c57daf3 100644 --- a/urjtag/src/cmd/cmd_pod.c +++ b/urjtag/src/cmd/cmd_pod.c @@ -98,6 +98,23 @@ cmd_pod_run (urj_chain_t *chain, char *params[]) return URJ_STATUS_OK; } +static void +cmd_pod_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 signals[] = { + "TCK=", + "TMS=", + "TDI=", + "TRST=", + "RESET=", + }; + + urj_completion_mayben_add_matches (matches, match_cnt, text, + text_len, signals); +} + static void cmd_pod_help (void) { @@ -114,5 +131,6 @@ const urj_cmd_t urj_cmd_pod = { "pod", N_("Set state of POD signal(s)"), cmd_pod_help, - cmd_pod_run + cmd_pod_run, + cmd_pod_complete, }; diff --git a/urjtag/src/cmd/cmd_shell.c b/urjtag/src/cmd/cmd_shell.c index d55c19cf..018f8b16 100644 --- a/urjtag/src/cmd/cmd_shell.c +++ b/urjtag/src/cmd/cmd_shell.c @@ -88,6 +88,15 @@ cmd_shell_run (urj_chain_t *chain, char *params[]) return URJ_STATUS_OK; } +static void +cmd_shell_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) +{ + /* XXX: Should first token complete via $PATH ? */ + urj_completion_mayben_add_file (matches, match_cnt, text, text_len, false); +} + static void cmd_shell_help (void) { @@ -102,5 +111,6 @@ const urj_cmd_t urj_cmd_shell = { "shell", N_("run a shell command"), cmd_shell_help, - cmd_shell_run + cmd_shell_run, + cmd_shell_complete, }; diff --git a/urjtag/src/cmd/cmd_svf.c b/urjtag/src/cmd/cmd_svf.c index 48d672d5..63ad6757 100644 --- a/urjtag/src/cmd/cmd_svf.c +++ b/urjtag/src/cmd/cmd_svf.c @@ -95,6 +95,30 @@ cmd_svf_run (urj_chain_t *chain, char *params[]) return result; } +static void +cmd_svf_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[] = { + "stop", + "progress", + "ref_freq=", + }; + + switch (token_point) + { + case 1: + urj_completion_mayben_add_file (matches, match_cnt, text, + text_len, false); + break; + + default: + urj_completion_mayben_add_matches (matches, match_cnt, text, text_len, + main_cmds); + break; + } +} static void cmd_svf_help (void) @@ -113,5 +137,6 @@ const urj_cmd_t urj_cmd_svf = { "svf", N_("execute svf commands from file"), cmd_svf_help, - cmd_svf_run + cmd_svf_run, + cmd_svf_complete, }; diff --git a/urjtag/src/cmd/cmd_writemem.c b/urjtag/src/cmd/cmd_writemem.c index b3281e7a..090bafa2 100644 --- a/urjtag/src/cmd/cmd_writemem.c +++ b/urjtag/src/cmd/cmd_writemem.c @@ -72,6 +72,24 @@ cmd_writemem_run (urj_chain_t *chain, char *params[]) return r; } +static void +cmd_writemem_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) +{ + switch (token_point) + { + case 1: /* addr */ + case 2: /* len */ + break; + + case 3: /* filename */ + urj_completion_mayben_add_file (matches, match_cnt, text, + text_len, false); + break; + } +} + static void cmd_writemem_help (void) { @@ -92,5 +110,6 @@ const urj_cmd_t urj_cmd_writemem = { "writemem", N_("write content of file to the memory"), cmd_writemem_help, - cmd_writemem_run + cmd_writemem_run, + cmd_writemem_complete, };