aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/ChangeLog4
-rw-r--r--util/miscutil.c35
2 files changed, 39 insertions, 0 deletions
diff --git a/util/ChangeLog b/util/ChangeLog
index 50e25370b..5501fd5c8 100644
--- a/util/ChangeLog
+++ b/util/ChangeLog
@@ -1,3 +1,7 @@
+2003-10-29 Werner Koch <[email protected]>
+
+ * miscutil.c (answer_is_okay_cancel): New.
+
2003-10-25 Werner Koch <[email protected]>
* Makefile.am: Replaced INTLLIBS by LIBINTL.
diff --git a/util/miscutil.c b/util/miscutil.c
index b266d27d4..e0ea0e7d2 100644
--- a/util/miscutil.c
+++ b/util/miscutil.c
@@ -359,3 +359,38 @@ answer_is_yes_no_quit( const char *s )
return -1;
return 0;
}
+
+
+/*
+ Return 1 for okay, 0 for for cancel or DEF_ANSWER for default.
+ */
+int
+answer_is_okay_cancel (const char *s, int def_answer)
+{
+ const char *long_okay = _("okay");
+ const char *long_cancel = _("cancel");
+ const char *short_okay = _("oO");
+ const char *short_cancel = _("cC");
+
+ /* Note: We have to use the locale dependent strcasecmp */
+ if ( !strcasecmp(s, long_okay ) )
+ return 1;
+ if ( !strcasecmp(s, long_cancel ) )
+ return 0;
+ if ( *s && strchr( short_okay, *s ) && !s[1] )
+ return 1;
+ if ( *s && strchr( short_cancel, *s ) && !s[1] )
+ return 0;
+ /* Always test for the English values (not locale here) */
+ if ( !ascii_strcasecmp(s, "okay" ) )
+ return 1;
+ if ( !ascii_strcasecmp(s, "ok" ) )
+ return 1;
+ if ( !ascii_strcasecmp(s, "cancel" ) )
+ return 0;
+ if ( *s && strchr( "oO", *s ) && !s[1] )
+ return 1;
+ if ( *s && strchr( "cC", *s ) && !s[1] )
+ return 0;
+ return def_answer;
+}