1 /* yesno.c - Yes/No questions
2 * Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
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.
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.
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,
30 answer_is_yes_no_default( const char *s
, int def_answer
)
32 /* TRANSLATORS: See doc/TRANSLATE about this string. */
33 const char *long_yes
= _("yes");
34 const char *short_yes
= _("yY");
35 /* TRANSLATORS: See doc/TRANSLATE about this string. */
36 const char *long_no
= _("no");
37 const char *short_no
= _("nN");
39 /* Note: we have to use the local dependent compare here. */
40 if ( match_multistr(long_yes
,s
) )
42 if ( *s
&& strchr( short_yes
, *s
) && !s
[1] )
44 /* Test for "no" strings to catch ambiguities for the next test. */
45 if ( match_multistr(long_no
,s
) )
47 if ( *s
&& strchr( short_no
, *s
) && !s
[1] )
49 /* Test for the english version (for those who are used to type yes). */
50 if ( !ascii_strcasecmp(s
, "yes" ) )
52 if ( *s
&& strchr( "yY", *s
) && !s
[1] )
58 answer_is_yes ( const char *s
)
60 return answer_is_yes_no_default(s
,0);
64 * Return 1 for yes, -1 for quit, or 0 for no
67 answer_is_yes_no_quit ( const char *s
)
69 /* TRANSLATORS: See doc/TRANSLATE about this string. */
70 const char *long_yes
= _("yes");
71 /* TRANSLATORS: See doc/TRANSLATE about this string. */
72 const char *long_no
= _("no");
73 /* TRANSLATORS: See doc/TRANSLATE about this string. */
74 const char *long_quit
= _("quit");
75 const char *short_yes
= _("yY");
76 const char *short_no
= _("nN");
77 const char *short_quit
= _("qQ");
79 /* Note: we have to use a local dependent compare here. */
80 if ( match_multistr(long_no
,s
) )
82 if ( match_multistr(long_yes
,s
) )
84 if ( match_multistr(long_quit
,s
) )
86 if ( *s
&& strchr( short_no
, *s
) && !s
[1] )
88 if ( *s
&& strchr( short_yes
, *s
) && !s
[1] )
90 if ( *s
&& strchr( short_quit
, *s
) && !s
[1] )
93 if ( !ascii_strcasecmp(s
, "yes" ) )
95 if ( !ascii_strcasecmp(s
, "quit" ) )
97 if ( *s
&& strchr( "yY", *s
) && !s
[1] )
99 if ( *s
&& strchr( "qQ", *s
) && !s
[1] )
105 Return 1 for okay, 0 for for cancel or DEF_ANSWER for default.
108 answer_is_okay_cancel (const char *s
, int def_answer
)
110 /* TRANSLATORS: See doc/TRANSLATE about this string. */
111 const char *long_okay
= _("okay|okay");
112 /* TRANSLATORS: See doc/TRANSLATE about this string. */
113 const char *long_cancel
= _("cancel|cancel");
114 const char *short_okay
= _("oO");
115 const char *short_cancel
= _("cC");
117 /* Note: We have to use the locale dependent compare. */
118 if ( match_multistr(long_okay
,s
) )
120 if ( match_multistr(long_cancel
,s
) )
122 if ( *s
&& strchr( short_okay
, *s
) && !s
[1] )
124 if ( *s
&& strchr( short_cancel
, *s
) && !s
[1] )
126 /* Always test for the English values (not locale here). */
127 if ( !ascii_strcasecmp(s
, "okay" ) )
129 if ( !ascii_strcasecmp(s
, "ok" ) )
131 if ( !ascii_strcasecmp(s
, "cancel" ) )
133 if ( *s
&& strchr( "oO", *s
) && !s
[1] )
135 if ( *s
&& strchr( "cC", *s
) && !s
[1] )