chiark / gitweb /
gpg agent lockup fix: Interrupt main loop when active_connections_value==0
[gnupg2.git] / g10 / helptext.c
1 /* helptext.c  - English help texts
2  * Copyright (C) 1998, 1999, 2000, 2001, 2002,
3  *               2004, 2007 Free Software Foundation, Inc.
4  *
5  * This file is part of GnuPG.
6  *
7  * GnuPG is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * GnuPG is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see <https://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "gpg.h"
27 #include "util.h"
28 #include "ttyio.h"
29 #include "main.h"
30 #include "i18n.h"
31
32
33
34
35 /* Helper to get the help through the configurable GnuPG help
36    system.  */
37 static char *
38 get_help_from_file (const char *keyword)
39 {
40   char *key, *result;
41
42   key = xtrymalloc (4 + strlen (keyword) + 1);
43   if (key)
44     {
45       strcpy (stpcpy (key, "gpg."), keyword);
46       result = gnupg_get_help_string (key, 0);
47       xfree (key);
48       if (result && !is_native_utf8 ())
49         {
50           char *tmp = utf8_to_native (result, strlen (result), -1);
51           if (tmp)
52             {
53               xfree (result);
54               result = tmp;
55             }
56         }
57     }
58   else
59     result = NULL;
60   return result;
61 }
62
63
64 void
65 display_online_help( const char *keyword )
66 {
67   char *result;
68   int need_final_lf = 1;
69
70   tty_kill_prompt();
71   if ( !keyword )
72     tty_printf (_("No help available") );
73   else if ( (result = get_help_from_file (keyword)) )
74     {
75       tty_printf ("%s", result);
76       if (*result && result[strlen (result)-1] == '\n')
77         need_final_lf = 0;
78       xfree (result);
79     }
80   else
81     {
82       tty_printf (_("No help available for '%s'"), keyword );
83     }
84   if (need_final_lf)
85     tty_printf("\n");
86 }