~ubuntu-branches/ubuntu/karmic/gnupg2/karmic-security

« back to all changes in this revision

Viewing changes to common/yesno.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * GnuPG is free software; you can redistribute it and/or modify
7
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
 
8
 * the Free Software Foundation; either version 3 of the License, or
9
9
 * (at your option) any later version.
10
10
 *
11
11
 * GnuPG is distributed in the hope that it will be useful,
14
14
 * GNU General Public License for more details.
15
15
 *
16
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
20
#include <config.h>
28
27
int
29
28
answer_is_yes_no_default( const char *s, int def_answer )
30
29
{
31
 
    const char *long_yes = _("yes");
32
 
    const char *short_yes = _("yY");
33
 
    const char *long_no = _("no");
34
 
    const char *short_no = _("nN");
 
30
  /* TRANSLATORS: See doc/TRANSLATE about this string. */
 
31
  const char *long_yes = _("yes");
 
32
  const char *short_yes = _("yY");
 
33
  /* TRANSLATORS: See doc/TRANSLATE about this string. */
 
34
  const char *long_no = _("no");
 
35
  const char *short_no = _("nN");
35
36
 
36
 
    /* Note: we have to use the local dependent strcasecmp here */
37
 
    if( !strcasecmp(s, long_yes ) )
38
 
        return 1;
39
 
    if( *s && strchr( short_yes, *s ) && !s[1] )
40
 
        return 1;
41
 
    /* test for no strings to catch ambiguities for the next test */
42
 
    if( !strcasecmp(s, long_no ) )
43
 
        return 0;
44
 
    if( *s && strchr( short_no, *s ) && !s[1] )
45
 
        return 0;
46
 
    /* test for the english version (for those who are used to type yes) */
47
 
    if( !ascii_strcasecmp(s, "yes" ) )
48
 
        return 1;
49
 
    if( *s && strchr( "yY", *s ) && !s[1] )
50
 
        return 1;
51
 
    return def_answer;
 
37
  /* Note: we have to use the local dependent compare here. */
 
38
  if ( match_multistr(long_yes,s) )
 
39
    return 1;
 
40
  if ( *s && strchr( short_yes, *s ) && !s[1] )
 
41
    return 1;
 
42
  /* Test for "no" strings to catch ambiguities for the next test. */
 
43
  if ( match_multistr(long_no,s) )
 
44
    return 0;
 
45
  if ( *s && strchr( short_no, *s ) && !s[1] )
 
46
    return 0;
 
47
  /* Test for the english version (for those who are used to type yes). */
 
48
  if ( !ascii_strcasecmp(s, "yes" ) )
 
49
    return 1;
 
50
  if ( *s && strchr( "yY", *s ) && !s[1] )
 
51
    return 1;
 
52
  return def_answer;
52
53
}
53
54
 
54
55
int
55
 
answer_is_yes( const char *s )
 
56
answer_is_yes ( const char *s )
56
57
{
57
58
  return answer_is_yes_no_default(s,0);
58
59
}
61
62
 * Return 1 for yes, -1 for quit, or 0 for no
62
63
 */
63
64
int
64
 
answer_is_yes_no_quit( const char *s )
65
 
{
66
 
    const char *long_yes = _("yes");
67
 
    const char *long_no = _("no");
68
 
    const char *long_quit = _("quit");
69
 
    const char *short_yes = _("yY");
70
 
    const char *short_no = _("nN");
71
 
    const char *short_quit = _("qQ");
72
 
 
73
 
    /* Note: We have to use the locale dependent strcasecmp */
74
 
    if( !strcasecmp(s, long_no ) )
75
 
        return 0;
76
 
    if( !strcasecmp(s, long_yes ) )
77
 
        return 1;
78
 
    if( !strcasecmp(s, long_quit ) )
79
 
        return -1;
80
 
    if( *s && strchr( short_no, *s ) && !s[1] )
81
 
        return 0;
82
 
    if( *s && strchr( short_yes, *s ) && !s[1] )
83
 
        return 1;
84
 
    if( *s && strchr( short_quit, *s ) && !s[1] )
85
 
        return -1;
86
 
    /* but not here */
87
 
    if( !ascii_strcasecmp(s, "yes" ) )
88
 
        return 1;
89
 
    if( !ascii_strcasecmp(s, "quit" ) )
90
 
        return -1;
91
 
    if( *s && strchr( "yY", *s ) && !s[1] )
92
 
        return 1;
93
 
    if( *s && strchr( "qQ", *s ) && !s[1] )
94
 
        return -1;
95
 
    return 0;
96
 
}
 
65
answer_is_yes_no_quit ( const char *s )
 
66
{
 
67
  /* TRANSLATORS: See doc/TRANSLATE about this string. */
 
68
  const char *long_yes = _("yes");
 
69
  /* TRANSLATORS: See doc/TRANSLATE about this string. */
 
70
  const char *long_no = _("no");
 
71
  /* TRANSLATORS: See doc/TRANSLATE about this string. */
 
72
  const char *long_quit = _("quit");
 
73
  const char *short_yes = _("yY");
 
74
  const char *short_no = _("nN");
 
75
  const char *short_quit = _("qQ");
 
76
 
 
77
  /* Note: we have to use a local dependent compare here. */
 
78
  if ( match_multistr(long_no,s) )
 
79
    return 0;
 
80
  if ( match_multistr(long_yes,s) )
 
81
    return 1;
 
82
  if ( match_multistr(long_quit,s) )
 
83
    return -1;
 
84
  if ( *s && strchr( short_no, *s ) && !s[1] )
 
85
    return 0;
 
86
  if ( *s && strchr( short_yes, *s ) && !s[1] )
 
87
      return 1;
 
88
  if ( *s && strchr( short_quit, *s ) && !s[1] )
 
89
    return -1;
 
90
  /* but not here. */
 
91
  if ( !ascii_strcasecmp(s, "yes" ) )
 
92
    return 1;
 
93
  if ( !ascii_strcasecmp(s, "quit" ) )
 
94
      return -1;
 
95
  if ( *s && strchr( "yY", *s ) && !s[1] )
 
96
    return 1;
 
97
  if ( *s && strchr( "qQ", *s ) && !s[1] )
 
98
    return -1;
 
99
  return 0;
 
100
}
 
101
 
 
102
/*
 
103
   Return 1 for okay, 0 for for cancel or DEF_ANSWER for default. 
 
104
 */
 
105
int
 
106
answer_is_okay_cancel (const char *s, int def_answer)
 
107
{
 
108
  /* TRANSLATORS: See doc/TRANSLATE about this string. */
 
109
  const char *long_okay = _("okay|okay");
 
110
  /* TRANSLATORS: See doc/TRANSLATE about this string. */
 
111
  const char *long_cancel = _("cancel|cancel");
 
112
  const char *short_okay = _("oO");
 
113
  const char *short_cancel = _("cC");
 
114
  
 
115
  /* Note: We have to use the locale dependent compare. */
 
116
  if ( match_multistr(long_okay,s) )
 
117
    return 1;
 
118
  if ( match_multistr(long_cancel,s) )
 
119
    return 0;
 
120
  if ( *s && strchr( short_okay, *s ) && !s[1] )
 
121
    return 1;
 
122
  if ( *s && strchr( short_cancel, *s ) && !s[1] )
 
123
    return 0;
 
124
  /* Always test for the English values (not locale here). */
 
125
  if ( !ascii_strcasecmp(s, "okay" ) )
 
126
    return 1;
 
127
  if ( !ascii_strcasecmp(s, "ok" ) )
 
128
    return 1;
 
129
  if ( !ascii_strcasecmp(s, "cancel" ) )
 
130
    return 0;
 
131
  if ( *s && strchr( "oO", *s ) && !s[1] )
 
132
    return 1;
 
133
  if ( *s && strchr( "cC", *s ) && !s[1] )
 
134
    return 0;
 
135
  return def_answer;
 
136
}
 
137