Add missing file and other changes.
[gnupg.git] / common / gpgrlhelp.c
1 /* gpgrlhelp.c - A readline wrapper.
2  *      Copyright (C) 2006 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuPG.
5  *
6  * GnuPG is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * GnuPG is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19  * USA.
20  */
21
22 /* This module may by used by applications to initializes readline
23    support.  It is required so that we can have hooks in other parts
24    of libcommon without actually requing to link against
25    libreadline. It works along ttyio.c which a proper part of
26    libcommon. */
27
28 #include <config.h>
29 #include <stdlib.h>
30 #include <stddef.h>
31
32 #ifdef HAVE_LIBREADLINE
33 #define GNUPG_LIBREADLINE_H_INCLUDED
34 #include <readline/readline.h>
35 #include <readline/history.h>
36 #endif
37
38 #include "util.h"
39 #include "common-defs.h"
40
41
42 static void
43 set_completer (rl_completion_func_t *completer)
44 {
45   rl_attempted_completion_function = completer;
46   rl_inhibit_completion = 0;
47 }
48
49 static void
50 inhibit_completion (int value)
51 {
52   rl_inhibit_completion = value;
53 }
54
55 static void
56 cleanup_after_signal (void)
57 {
58   rl_free_line_state ();
59   rl_cleanup_after_signal ();
60 }
61
62 static void
63 init_stream (FILE *fp)
64 {
65   rl_catch_signals = 0;
66   rl_instream = rl_outstream = fp;
67   rl_inhibit_completion = 1;
68 }
69
70
71 /* Initialize our readline code.  This should be called as early as
72    possible as it is actually a constructur.  */
73 void
74 gnupg_rl_initialize (void)
75 {
76   tty_private_set_rl_hooks (init_stream,
77                             set_completer,
78                             inhibit_completion,
79                             cleanup_after_signal,
80                             readline,
81                             add_history);
82   rl_readline_name = "GnuPG";
83
84 }
85
86
87
88