1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-02-02 16:43:03 +01:00

* card-util.c (command_generator, card_edit_completion)

[GNUPG_MAJOR_VERSION==1 && HAVE_LIBREADLINE]: New functions to enable
command completion in the --card-edit menu.  (card_edit): Call them
here.
This commit is contained in:
David Shaw 2005-03-20 03:59:07 +00:00
parent 8885f0b0cc
commit f30b25e565
2 changed files with 76 additions and 14 deletions

View File

@ -1,3 +1,10 @@
2005-03-19 David Shaw <dshaw@jabberwocky.com>
* card-util.c (command_generator, card_edit_completion)
[GNUPG_MAJOR_VERSION==1 && HAVE_LIBREADLINE]: New functions to
enable command completion in the --card-edit menu.
(card_edit): Call them here.
2005-03-18 David Shaw <dshaw@jabberwocky.com>
* keyedit.c (command_generator, keyedit_completion)

View File

@ -36,6 +36,10 @@
#include "main.h"
#include "keyserver-internal.h"
#if GNUPG_MAJOR_VERSION == 1
#ifdef HAVE_LIBREADLINE
#include <stdio.h>
#include <readline/readline.h>
#endif
#include "cardglue.h"
#else
#include "call-agent.h"
@ -1271,13 +1275,8 @@ card_store_subkey (KBNODE node, int use)
#endif
}
/* Menu to edit all user changeable values on an OpenPGP card. Only
Key creation is not handled here. */
void
card_edit (STRLIST commands)
{
enum cmdids {
enum cmdids
{
cmdNOP = 0,
cmdQUIT, cmdADMIN, cmdHELP, cmdLIST, cmdDEBUG,
cmdNAME, cmdURL, cmdFETCH, cmdLOGIN, cmdLANG, cmdSEX, cmdCAFPR,
@ -1285,12 +1284,14 @@ card_edit (STRLIST commands)
cmdINVCMD
};
static struct {
static struct
{
const char *name;
enum cmdids id;
int admin_only;
const char *desc;
} cmds[] = {
} cmds[] =
{
{ "quit" , cmdQUIT , 0, N_("quit this menu")},
{ "q" , cmdQUIT , 0, NULL },
{ "admin" , cmdADMIN , 0, N_("show admin commands")},
@ -1314,6 +1315,54 @@ card_edit (STRLIST commands)
{ NULL, cmdINVCMD, 0, NULL }
};
#if GNUPG_MAJOR_VERSION == 1 && defined (HAVE_LIBREADLINE)
/* These two functions are used by readline for command completion. */
static char *command_generator(const char *text,int state)
{
static int list_index,len;
const char *name;
/* If this is a new word to complete, initialize now. This includes
saving the length of TEXT for efficiency, and initializing the
index variable to 0. */
if(!state)
{
list_index=0;
len=strlen(text);
}
/* Return the next partial match */
while((name=cmds[list_index].name))
{
/* Only complete commands that have help text */
if(cmds[list_index++].desc && strncmp(name,text,len)==0)
return strdup(name);
}
return NULL;
}
static char **card_edit_completion(const char *text, int start, int end)
{
/* If we are at the start of a line, we try and command-complete.
If not, just do nothing for now. */
if(start==0)
return rl_completion_matches(text,command_generator);
rl_attempted_completion_over=1;
return NULL;
}
#endif
/* Menu to edit all user changeable values on an OpenPGP card. Only
Key creation is not handled here. */
void
card_edit (STRLIST commands)
{
enum cmdids cmd = cmdNOP;
int have_commands = !!commands;
int redisplay = 1;
@ -1374,8 +1423,14 @@ card_edit (STRLIST commands)
if (!have_commands)
{
#if GNUPG_MAJOR_VERSION == 1
tty_enable_completion(card_edit_completion);
#endif
answer = cpr_get_no_help("cardedit.prompt", _("Command> "));
cpr_kill_prompt();
#if GNUPG_MAJOR_VERSION == 1
tty_disable_completion();
#endif
}
trim_spaces(answer);
}