1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

Fix for toupper('I') != 'i'

This commit is contained in:
Werner Koch 2001-06-12 18:42:40 +00:00
parent ff170c94f1
commit 01fe1dd2a9
22 changed files with 156 additions and 47 deletions

View file

@ -1,3 +1,12 @@
2001-06-12 Werner Koch <wk@gnupg.org>
* strgutil.c (ascii_memistr,ascii_isupper,ascii_islower,
ascii_toupper,ascii_tolower, ascii_strcasecmp, ascii_memcasecmp): New.
(set_native_charset): Use ascii_strcasecmp()
* fileutil.c (compare_filenames): Ditto
* miscutil.c (answer_is_yes): Ditto.
(answer_is_yes_no_quit): Ditto.
2001-06-06 Werner Koch <wk@gnupg.org>
* strgutil.c (vasprintf) [__MINGW32__]: New. Taken from libiberty.

View file

@ -127,7 +127,7 @@ compare_filenames( const char *a, const char *b )
* resolve symlinks?
*/
#ifdef HAVE_DRIVE_LETTERS
return stricmp(a,b);
return ascii_strcasecmp(a,b);
#else
return strcmp(a,b);
#endif

View file

@ -289,6 +289,7 @@ answer_is_yes( const char *s )
const char *long_no = _("no");
const char *short_no = _("nN");
/* Note: we have to use the local dependent strcasecmp here */
if( !stricmp(s, long_yes ) )
return 1;
if( *s && strchr( short_yes, *s ) && !s[1] )
@ -299,7 +300,7 @@ answer_is_yes( const char *s )
if( *s && strchr( short_no, *s ) && !s[1] )
return 0;
/* test for the english version (for those who are used to type yes) */
if( !stricmp(s, "yes" ) )
if( !ascii_strcasecmp(s, "yes" ) )
return 1;
if( *s && strchr( "yY", *s ) && !s[1] )
return 1;
@ -320,6 +321,7 @@ answer_is_yes_no_quit( const char *s )
const char *short_no = _("nN");
const char *short_quit = _("qQ");
/* Note: We have to use the locale dependent strcasecmp */
if( !stricmp(s, long_no ) )
return 0;
if( !stricmp(s, long_yes ) )
@ -332,9 +334,10 @@ answer_is_yes_no_quit( const char *s )
return 1;
if( *s && strchr( short_quit, *s ) && !s[1] )
return -1;
if( !stricmp(s, "yes" ) )
/* but not here */
if( !ascii_strcasecmp(s, "yes" ) )
return 1;
if( !stricmp(s, "quit" ) )
if( !ascii_strcasecmp(s, "quit" ) )
return -1;
if( *s && strchr( "yY", *s ) && !s[1] )
return 1;

View file

@ -65,6 +65,7 @@ static ushort latin2_unicode[128] = {
0x0159,0x016F,0x00FA,0x0171,0x00FC,0x00FD,0x0163,0x02D9
};
static const char *active_charset_name = "iso-8859-1";
static ushort *active_charset = NULL;
static int no_translation = 0;
@ -193,6 +194,25 @@ memistr( const char *buf, size_t buflen, const char *sub )
return NULL ;
}
const char *
ascii_memistr( const char *buf, size_t buflen, const char *sub )
{
const byte *t, *s ;
size_t n;
for( t=buf, n=buflen, s=sub ; n ; t++, n-- )
if( ascii_toupper(*t) == ascii_toupper(*s) ) {
for( buf=t++, buflen = n--, s++;
n && ascii_toupper(*t) == ascii_toupper(*s); t++, s++, n-- )
;
if( !*s )
return buf;
t = buf; n = buflen; s = sub ;
}
return NULL ;
}
/****************
* Wie strncpy(), aber es werden maximal n-1 zeichen kopiert und ein
* '\0' angehängt. Ist n = 0, so geschieht nichts, ist Destination
@ -325,22 +345,23 @@ string_count_chr( const char *string, int c )
int
set_native_charset( const char *newset )
{
if( !stricmp( newset, "iso-8859-1" ) ) {
if( !ascii_strcasecmp( newset, "iso-8859-1" ) ) {
active_charset_name = "iso-8859-1";
no_translation = 0;
active_charset = NULL;
}
else if( !stricmp( newset, "iso-8859-2" ) ) {
else if( !ascii_strcasecmp( newset, "iso-8859-2" ) ) {
active_charset_name = "iso-8859-2";
no_translation = 0;
active_charset = latin2_unicode;
}
else if( !stricmp( newset, "koi8-r" ) ) {
else if( !ascii_strcasecmp( newset, "koi8-r" ) ) {
active_charset_name = "koi8-r";
no_translation = 0;
active_charset = koi8_unicode;
}
else if( !stricmp (newset, "utf8" ) || !stricmp(newset, "utf-8") ) {
else if( !ascii_strcasecmp (newset, "utf8" )
|| !ascii_strcasecmp(newset, "utf-8") ) {
active_charset_name = "utf-8";
no_translation = 1;
active_charset = NULL;
@ -582,6 +603,63 @@ utf8_to_native( const char *string, size_t length )
}
}
/****************************************************
******** locale insensitive ctype functions ********
****************************************************/
/* FIXME: replace them by a table lookup and macros */
int
ascii_isupper (int c)
{
return c >= 'A' && c <= 'Z';
}
int
ascii_islower (int c)
{
return c >= 'a' && c <= 'z';
}
int
ascii_toupper (int c)
{
if (c >= 'a' && c <= 'z')
c &= ~0x20;
return c;
}
int
ascii_tolower (int c)
{
if (c >= 'A' && c <= 'Z')
c |= 0x20;
return c;
}
int
ascii_strcasecmp( const char *a, const char *b )
{
if (a == b)
return 0;
for (; *a && *b; a++, b++) {
if (*a != *b && ascii_toupper(*a) != ascii_toupper(*b))
break;
}
return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b));
}
int
ascii_memcasecmp( const char *a, const char *b, size_t n )
{
if (a == b)
return 0;
for ( ; n; n--, a++, b++ ) {
if( *a != *b && ascii_toupper (*a) != ascii_toupper (*b) )
return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b));
}
return 0;
}
/*********************************************