LCOV - code coverage report
Current view: top level - common - gpgrlhelp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 20 20.0 %
Date: 2016-11-29 15:00:56 Functions: 1 5 20.0 %

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

Generated by: LCOV version 1.11