diff --git a/util/ChangeLog b/util/ChangeLog index da8806977..8675faf5f 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,11 @@ +2003-11-20 David Shaw + + * miscutil.c (match_multistr): New. Match against each segment in + a string with tokens separated by |. + (answer_is_yes_no_default, answer_is_yes_no_quit, + answer_is_okay_cancel): Use it here to enable alternate + translations. + 2003-11-01 David Shaw * http.c (connect_server): Differentiate between generic "can't diff --git a/util/miscutil.c b/util/miscutil.c index e0ea0e7d2..512bac64c 100644 --- a/util/miscutil.c +++ b/util/miscutil.c @@ -293,18 +293,20 @@ make_printable_string( const byte *p, size_t n, int delim ) int answer_is_yes_no_default( const char *s, int def_answer ) { - const char *long_yes = _("yes"); + /* NOTE TO TRANSLATOR: See doc/TRANSLATE about this string. */ + const char *long_yes = _("yes|yes"); const char *short_yes = _("yY"); - const char *long_no = _("no"); + /* NOTE TO TRANSLATOR: See doc/TRANSLATE about this string. */ + const char *long_no = _("no|no"); const char *short_no = _("nN"); /* Note: we have to use the local dependent strcasecmp here */ - if( !strcasecmp(s, long_yes ) ) + if( match_multistr(long_yes,s) ) return 1; if( *s && strchr( short_yes, *s ) && !s[1] ) return 1; /* test for no strings to catch ambiguities for the next test */ - if( !strcasecmp(s, long_no ) ) + if( match_multistr(long_no,s) ) return 0; if( *s && strchr( short_no, *s ) && !s[1] ) return 0; @@ -328,19 +330,21 @@ answer_is_yes( const char *s ) int answer_is_yes_no_quit( const char *s ) { - const char *long_yes = _("yes"); - const char *long_no = _("no"); - const char *long_quit = _("quit"); + /* NOTE TO TRANSLATOR: See doc/TRANSLATE about this string. */ + const char *long_yes = _("yes|yes"); + /* NOTE TO TRANSLATOR: See doc/TRANSLATE about this string. */ + const char *long_no = _("no|no"); + /* NOTE TO TRANSLATOR: See doc/TRANSLATE about this string. */ + const char *long_quit = _("quit|quit"); const char *short_yes = _("yY"); const char *short_no = _("nN"); const char *short_quit = _("qQ"); - /* Note: We have to use the locale dependent strcasecmp */ - if( !strcasecmp(s, long_no ) ) + if( match_multistr(long_no,s) ) return 0; - if( !strcasecmp(s, long_yes ) ) + if( match_multistr(long_yes,s) ) return 1; - if( !strcasecmp(s, long_quit ) ) + if( match_multistr(long_quit,s) ) return -1; if( *s && strchr( short_no, *s ) && !s[1] ) return 0; @@ -360,22 +364,23 @@ answer_is_yes_no_quit( const char *s ) 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"); + /* NOTE TO TRANSLATOR: See doc/TRANSLATE about this string. */ + const char *long_okay = _("okay|okay"); + /* NOTE TO TRANSLATOR: See doc/TRANSLATE about this string. */ + const char *long_cancel = _("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 ) ) + if ( match_multistr(long_okay,s) ) return 1; - if ( !strcasecmp(s, long_cancel ) ) + if ( match_multistr(long_cancel,s) ) return 0; if ( *s && strchr( short_okay, *s ) && !s[1] ) return 1; @@ -394,3 +399,24 @@ answer_is_okay_cancel (const char *s, int def_answer) return 0; return def_answer; } + +/* Try match against each substring of multistr, delimited by | */ +int +match_multistr(const char *multistr,const char *match) +{ + do + { + size_t seglen=strcspn(multistr,"|"); + if(!seglen) + break; + /* Using the localized strncasecmp */ + if(strncasecmp(multistr,match,seglen)==0) + return 1; + multistr+=seglen; + if(*multistr=='|') + multistr++; + } + while(*multistr); + + return 0; +}