aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/ChangeLog7
-rw-r--r--common/common-defs.h7
-rw-r--r--common/i18n.h24
-rw-r--r--common/ttyio.c52
4 files changed, 68 insertions, 22 deletions
diff --git a/common/ChangeLog b/common/ChangeLog
index cde4c4b3d..1657ae0be 100644
--- a/common/ChangeLog
+++ b/common/ChangeLog
@@ -1,3 +1,10 @@
+2006-09-22 Werner Koch <[email protected]>
+
+ * i18n.h: Changed license to an all permissive one.
+
+ * ttyio.c (tty_get): We need to use readline too. Added two more
+ hooks.
+
2006-09-21 Werner Koch <[email protected]>
* ttyio.c (tty_private_set_rl_hooks): New.
diff --git a/common/common-defs.h b/common/common-defs.h
index 0a6403a2c..96d0a1f32 100644
--- a/common/common-defs.h
+++ b/common/common-defs.h
@@ -23,9 +23,12 @@
#define GNUPG_COMMON_COMMON_DEFS_H
/*-- ttyio.c --*/
-void tty_private_set_rl_hooks (void (*set_completer) (rl_completion_func_t*),
+void tty_private_set_rl_hooks (void (*init_stream) (FILE *),
+ void (*set_completer) (rl_completion_func_t*),
void (*inhibit_completion) (int),
- void (*cleanup_after_signal) (void) );
+ void (*cleanup_after_signal) (void),
+ char *(*readline_fun) (const char*),
+ void (*add_history_fun) (const char*));
diff --git a/common/i18n.h b/common/i18n.h
index 0187ba265..6881a8a61 100644
--- a/common/i18n.h
+++ b/common/i18n.h
@@ -1,22 +1,14 @@
/* i18n.h
* Copyright (C) 1998, 2001 Free Software Foundation, Inc.
*
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- * USA.
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.
*/
#ifndef GNUPG_COMMON_I18N_H
diff --git a/common/ttyio.c b/common/ttyio.c
index 8b8f8835f..8f1e7b35c 100644
--- a/common/ttyio.c
+++ b/common/ttyio.c
@@ -81,7 +81,9 @@ static int no_terminal;
static void (*my_rl_set_completer) (rl_completion_func_t *);
static void (*my_rl_inhibit_completion) (int);
static void (*my_rl_cleanup_after_signal) (void);
-
+static void (*my_rl_init_stream) (FILE *);
+static char *(*my_rl_readline) (const char*);
+static void (*my_rl_add_history) (const char*);
/* This is a wrapper around ttyname so that we can use it even when
@@ -174,6 +176,10 @@ init_ttyfp(void)
exit(2);
}
#endif
+
+ if (my_rl_init_stream)
+ my_rl_init_stream (ttyfp);
+
#ifdef HAVE_TCGETATTR
atexit( cleanup );
#endif
@@ -520,7 +526,39 @@ do_get( const char *prompt, int hidden )
char *
tty_get( const char *prompt )
{
- return do_get( prompt, 0 );
+ if (!batchmode && !no_terminal && my_rl_readline && my_rl_add_history)
+ {
+ char *line;
+ char *buf;
+
+ if (!initialized)
+ init_ttyfp();
+
+ last_prompt_len = 0;
+
+ line = my_rl_readline (prompt?prompt:"");
+
+ /* We need to copy it to memory controlled by our malloc
+ implementations; further we need to convert an EOF to our
+ convention. */
+ buf = xmalloc(line? strlen(line)+1:2);
+ if (line)
+ {
+ strcpy (buf, line);
+ trim_spaces (buf);
+ if (strlen (buf) > 2 )
+ my_rl_add_history (line); /* Note that we test BUF but add LINE. */
+ free (line);
+ }
+ else
+ {
+ buf[0] = CONTROL_D;
+ buf[1] = 0;
+ }
+ return buf;
+ }
+ else
+ return do_get ( prompt, 0 );
}
char *
@@ -573,13 +611,19 @@ tty_get_answer_is_yes( const char *prompt )
/* Called by gnupg_rl_initialize to setup the reradline support. */
void
-tty_private_set_rl_hooks (void (*set_completer) (rl_completion_func_t*),
+tty_private_set_rl_hooks (void (*init_stream) (FILE *),
+ void (*set_completer) (rl_completion_func_t*),
void (*inhibit_completion) (int),
- void (*cleanup_after_signal) (void))
+ void (*cleanup_after_signal) (void),
+ char *(*readline_fun) (const char*),
+ void (*add_history_fun) (const char*))
{
+ my_rl_init_stream = init_stream;
my_rl_set_completer = set_completer;
my_rl_inhibit_completion = inhibit_completion;
my_rl_cleanup_after_signal = cleanup_after_signal;
+ my_rl_readline = readline_fun;
+ my_rl_add_history = add_history_fun;
}