From 75f7b98334875cf761b182575e8ca53c4be0470a Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 22 Feb 2011 08:48:43 +0000 Subject: [PATCH] add command completion to "flashmem", "endian", and "readmem" git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1893 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 4 ++++ urjtag/src/cmd/cmd_endian.c | 14 +++++++++++- urjtag/src/cmd/cmd_flashmem.c | 41 ++++++++++++++++++++++++++++++++++- urjtag/src/cmd/cmd_readmem.c | 40 +++++++++++++++++++++++++++++++++- 4 files changed, 96 insertions(+), 3 deletions(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 28fc0556..1b5a76e1 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -13,6 +13,10 @@ from an earlier commit -- make sure the literal "signal" is the 2nd arg in the help text and for completion handlers. + * src/cmd/cmd_flashmem.c: Add a completion handler. + * src/cmd/cmd_endian.c: Likewise. + * src/cmd/cmd_readmem.c: Likewise. + 2011-02-21 Mike Frysinger * data/Makefile.am (nobase_dist_pkgdata_DATA): Add missing analog/bfin/bfin. diff --git a/urjtag/src/cmd/cmd_endian.c b/urjtag/src/cmd/cmd_endian.c index c51a8044..9e74d11d 100644 --- a/urjtag/src/cmd/cmd_endian.c +++ b/urjtag/src/cmd/cmd_endian.c @@ -121,9 +121,21 @@ cmd_endian_help (void) "endian [little|big]"); } +static void +cmd_endian_complete (urj_chain_t *chain, char ***matches, size_t *match_cnt, + const char *text, size_t text_len, size_t token_point) +{ + if (token_point != 1) + return; + + urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "big"); + urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "little"); +} + const urj_cmd_t urj_cmd_endian = { "endian", N_("set/print endianess"), cmd_endian_help, - cmd_endian_run + cmd_endian_run, + cmd_endian_complete, }; diff --git a/urjtag/src/cmd/cmd_flashmem.c b/urjtag/src/cmd/cmd_flashmem.c index 08e944b9..c0cbb06a 100644 --- a/urjtag/src/cmd/cmd_flashmem.c +++ b/urjtag/src/cmd/cmd_flashmem.c @@ -29,6 +29,10 @@ #include #include +#ifdef HAVE_LIBREADLINE +#include +#endif + #include #include #include @@ -108,9 +112,44 @@ cmd_flashmem_help (void) urj_cmd_show_list (urj_flash_flash_drivers); } +static void +cmd_flashmem_complete (urj_chain_t *chain, char ***matches, size_t *match_cnt, + const char *text, size_t text_len, size_t token_point) +{ + switch (token_point) + { + case 1: /* [addr|msbin] */ + break; + + case 2: /* filename */ + { +#ifdef HAVE_LIBREADLINE + int state; + char *match; + + state = 0; + while (1) + { + match = rl_filename_completion_function (text, state++); + if (!match) + break; + urj_completion_add_match_dupe (matches, match_cnt, match); + free (match); + } +#endif + break; + } + + case 3: /* [noverify] */ + urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "noverify"); + break; + } +} + const urj_cmd_t urj_cmd_flashmem = { "flashmem", N_("burn flash memory with data from a file"), cmd_flashmem_help, - cmd_flashmem_run + cmd_flashmem_run, + cmd_flashmem_complete, }; diff --git a/urjtag/src/cmd/cmd_readmem.c b/urjtag/src/cmd/cmd_readmem.c index e4d97cad..f9b7f165 100644 --- a/urjtag/src/cmd/cmd_readmem.c +++ b/urjtag/src/cmd/cmd_readmem.c @@ -29,6 +29,10 @@ #include #include +#ifdef HAVE_LIBREADLINE +#include +#endif + #include #include @@ -89,9 +93,43 @@ cmd_readmem_help (void) "readmem"); } +static void +cmd_readmem_complete (urj_chain_t *chain, char ***matches, size_t *match_cnt, + const char *text, size_t text_len, size_t token_point) +{ + switch (token_point) + { + case 1: /* addr */ + break; + + case 2: /* len */ + break; + + case 3: /* filename */ + { +#ifdef HAVE_LIBREADLINE + int state; + char *match; + + state = 0; + while (1) + { + match = rl_filename_completion_function (text, state++); + if (!match) + break; + urj_completion_add_match_dupe (matches, match_cnt, match); + free (match); + } +#endif + break; + } + } +} + const urj_cmd_t urj_cmd_readmem = { "readmem", N_("read content of the memory and write it to file"), cmd_readmem_help, - cmd_readmem_run + cmd_readmem_run, + cmd_readmem_complete, };