LCOV - code coverage report
Current view: top level - common - yesno.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 72 0.0 %
Date: 2015-11-05 17:10:59 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* yesno.c - Yes/No questions
       2             :  * Copyright (C) 1998, 1999, 2000, 2001, 2003 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 3 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, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include <config.h>
      21             : #include <stdlib.h>
      22             : #include <errno.h>
      23             : 
      24             : #include "i18n.h"
      25             : #include "util.h"
      26             : 
      27             : 
      28             : /* Check the string S for a YES or NO answer and take care of
      29             :    localization.  If no valid string is given the value of DEF_ANSWER
      30             :    is returned.  Returns 1 for yes and 0 for no.  */
      31             : int
      32           0 : answer_is_yes_no_default (const char *s, int def_answer)
      33             : {
      34             :   /* TRANSLATORS: See doc/TRANSLATE about this string. */
      35           0 :   const char *long_yes = _("yes");
      36           0 :   const char *short_yes = _("yY");
      37             :   /* TRANSLATORS: See doc/TRANSLATE about this string. */
      38           0 :   const char *long_no = _("no");
      39           0 :   const char *short_no = _("nN");
      40             : 
      41             :   /* Note: we have to use the local dependent compare here. */
      42           0 :   if ( match_multistr(long_yes,s) )
      43           0 :     return 1;
      44           0 :   if ( *s && strchr( short_yes, *s ) && !s[1] )
      45           0 :     return 1;
      46             :   /* Test for "no" strings to catch ambiguities for the next test. */
      47           0 :   if ( match_multistr(long_no,s) )
      48           0 :     return 0;
      49           0 :   if ( *s && strchr( short_no, *s ) && !s[1] )
      50           0 :     return 0;
      51             :   /* Test for the english version (for those who are used to type yes). */
      52           0 :   if ( !ascii_strcasecmp(s, "yes" ) )
      53           0 :     return 1;
      54           0 :   if ( *s && strchr( "yY", *s ) && !s[1] )
      55           0 :     return 1;
      56           0 :   return def_answer;
      57             : }
      58             : 
      59             : int
      60           0 : answer_is_yes ( const char *s )
      61             : {
      62           0 :   return answer_is_yes_no_default(s,0);
      63             : }
      64             : 
      65             : /****************
      66             :  * Return 1 for yes, -1 for quit, or 0 for no
      67             :  */
      68             : int
      69           0 : answer_is_yes_no_quit ( const char *s )
      70             : {
      71             :   /* TRANSLATORS: See doc/TRANSLATE about this string. */
      72           0 :   const char *long_yes = _("yes");
      73             :   /* TRANSLATORS: See doc/TRANSLATE about this string. */
      74           0 :   const char *long_no = _("no");
      75             :   /* TRANSLATORS: See doc/TRANSLATE about this string. */
      76           0 :   const char *long_quit = _("quit");
      77           0 :   const char *short_yes = _("yY");
      78           0 :   const char *short_no = _("nN");
      79           0 :   const char *short_quit = _("qQ");
      80             : 
      81             :   /* Note: we have to use a local dependent compare here. */
      82           0 :   if ( match_multistr(long_no,s) )
      83           0 :     return 0;
      84           0 :   if ( match_multistr(long_yes,s) )
      85           0 :     return 1;
      86           0 :   if ( match_multistr(long_quit,s) )
      87           0 :     return -1;
      88           0 :   if ( *s && strchr( short_no, *s ) && !s[1] )
      89           0 :     return 0;
      90           0 :   if ( *s && strchr( short_yes, *s ) && !s[1] )
      91           0 :       return 1;
      92           0 :   if ( *s && strchr( short_quit, *s ) && !s[1] )
      93           0 :     return -1;
      94             :   /* but not here. */
      95           0 :   if ( !ascii_strcasecmp(s, "yes" ) )
      96           0 :     return 1;
      97           0 :   if ( !ascii_strcasecmp(s, "quit" ) )
      98           0 :       return -1;
      99           0 :   if ( *s && strchr( "yY", *s ) && !s[1] )
     100           0 :     return 1;
     101           0 :   if ( *s && strchr( "qQ", *s ) && !s[1] )
     102           0 :     return -1;
     103           0 :   return 0;
     104             : }
     105             : 
     106             : /*
     107             :    Return 1 for okay, 0 for for cancel or DEF_ANSWER for default.
     108             :  */
     109             : int
     110           0 : answer_is_okay_cancel (const char *s, int def_answer)
     111             : {
     112             :   /* TRANSLATORS: See doc/TRANSLATE about this string. */
     113           0 :   const char *long_okay = _("okay|okay");
     114             :   /* TRANSLATORS: See doc/TRANSLATE about this string. */
     115           0 :   const char *long_cancel = _("cancel|cancel");
     116           0 :   const char *short_okay = _("oO");
     117           0 :   const char *short_cancel = _("cC");
     118             : 
     119             :   /* Note: We have to use the locale dependent compare. */
     120           0 :   if ( match_multistr(long_okay,s) )
     121           0 :     return 1;
     122           0 :   if ( match_multistr(long_cancel,s) )
     123           0 :     return 0;
     124           0 :   if ( *s && strchr( short_okay, *s ) && !s[1] )
     125           0 :     return 1;
     126           0 :   if ( *s && strchr( short_cancel, *s ) && !s[1] )
     127           0 :     return 0;
     128             :   /* Always test for the English values (not locale here). */
     129           0 :   if ( !ascii_strcasecmp(s, "okay" ) )
     130           0 :     return 1;
     131           0 :   if ( !ascii_strcasecmp(s, "ok" ) )
     132           0 :     return 1;
     133           0 :   if ( !ascii_strcasecmp(s, "cancel" ) )
     134           0 :     return 0;
     135           0 :   if ( *s && strchr( "oO", *s ) && !s[1] )
     136           0 :     return 1;
     137           0 :   if ( *s && strchr( "cC", *s ) && !s[1] )
     138           0 :     return 0;
     139           0 :   return def_answer;
     140             : }

Generated by: LCOV version 1.11