diff --git a/ChangeLog b/ChangeLog index e721bdff5..06cb9ea94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2001-06-08 Werner Koch + + * configure.in (DYNLINK_MOD_CFLAGS): Use -shared with dec-osf. + Reported by Chris Adams. Merged some cases. + 2001-05-29 Werner Koch Released version 1.0.6. diff --git a/THANKS b/THANKS index 64682cd83..86d1c1997 100644 --- a/THANKS +++ b/THANKS @@ -21,6 +21,7 @@ Caskey L. Dickson caskey@technocage.com Cees van de Griend cees-list@griend.xs4all.nl Charles Levert charles@comm.polymtl.ca Chip Salzenberg chip@valinux.com +Chris Adams cmadams@hiwaay.net Christian Kurz shorty@debian.org Christian von Roques roques@pond.sub.org Christopher Oliver oliver@fritz.traverse.net diff --git a/TODO b/TODO index 8521e512c..e6d8ceb0e 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,6 @@ + * replace all isfoo() by ascii_usfoo() ? + * set default charset from nl_langinfo. * check all mpi_read() for error returns. diff --git a/cipher/ChangeLog b/cipher/ChangeLog index 7c26c571e..087c45838 100644 --- a/cipher/ChangeLog +++ b/cipher/ChangeLog @@ -1,3 +1,11 @@ +2001-06-12 Werner Koch + + * rndw32.c (slow_gatherer_windowsNT): Ditto. Not really needed here but anyway. + + * cipher.c (string_to_cipher_algo): Use ascii_strcasecmp(). + * md.c (string_to_digest_algo): Ditto. + * pubkey.c (string_to_pubkey_algo): Ditto. + 2001-04-29 Werner Koch * random.c (fast_random_poll): Do not check the return code of diff --git a/cipher/cipher.c b/cipher/cipher.c index a68679a73..0d9ebaf01 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -258,7 +258,7 @@ string_to_cipher_algo( const char *string ) do { for(i=0; (s=cipher_table[i].name); i++ ) - if( !stricmp( s, string ) ) + if( !ascii_strcasecmp( s, string ) ) return cipher_table[i].algo; } while( load_cipher_modules() ); return 0; diff --git a/cipher/md.c b/cipher/md.c index 3064b47d2..6d84772d2 100644 --- a/cipher/md.c +++ b/cipher/md.c @@ -152,7 +152,7 @@ string_to_digest_algo( const char *string ) do { for(r = digest_list; r; r = r->next ) - if( !stricmp( r->name, string ) ) + if( !ascii_strcasecmp( r->name, string ) ) return r->algo; } while( !r && load_digest_module(-1) ); return 0; diff --git a/cipher/pubkey.c b/cipher/pubkey.c index 7e320856e..9136fa544 100644 --- a/cipher/pubkey.c +++ b/cipher/pubkey.c @@ -296,7 +296,7 @@ string_to_pubkey_algo( const char *string ) do { for(i=0; (s=pubkey_table[i].name); i++ ) - if( !stricmp( s, string ) ) + if( !ascii_strcasecmp( s, string ) ) return pubkey_table[i].algo; } while( load_pubkey_modules() ); return 0; diff --git a/cipher/rndw32.c b/cipher/rndw32.c index d4d7d22e4..63b78791c 100644 --- a/cipher/rndw32.c +++ b/cipher/rndw32.c @@ -561,7 +561,8 @@ slow_gatherer_windowsNT( void (*add)(const void*, size_t, int), int requester ) log_debug ("rndw32#slow_gatherer_nt: check product options\n" ); status = RegQueryValueEx (hKey, "ProductType", 0, NULL, szValue, &dwSize); - if (status == ERROR_SUCCESS && stricmp (szValue, "WinNT")) { + if (status == ERROR_SUCCESS + && ascii_strcasecmp (szValue, "WinNT")) { /* Note: There are (at least) three cases for ProductType: * WinNT = NT Workstation, ServerNT = NT Server, LanmanNT = * NT Server acting as a Domain Controller */ diff --git a/configure.in b/configure.in index 55abb64d2..683f4995c 100644 --- a/configure.in +++ b/configure.in @@ -256,25 +256,13 @@ AC_DEFINE_UNQUOTED(PRINTABLE_OS_NAME, "$PRINTABLE_OS_NAME") dnl Fixme: Are these the best flags for OpenBSD???? case "${target}" in - *-openbsd*) + *-openbsd* | *-netbsd*) NAME_OF_DEV_RANDOM="/dev/srandom" NAME_OF_DEV_URANDOM="/dev/urandom" DYNLINK_MOD_CFLAGS="-shared -rdynamic $CFLAGS_PIC -Wl,-Bshareable -Wl,-x" ;; - *-netbsd*) - NAME_OF_DEV_RANDOM="/dev/random" - NAME_OF_DEV_URANDOM="/dev/urandom" - DYNLINK_MOD_CFLAGS="-shared -rdynamic $CFLAGS_PIC -Wl,-Bshareable -Wl,-x" - ;; - - *-solaris*) - NAME_OF_DEV_RANDOM="/dev/random" - NAME_OF_DEV_URANDOM="/dev/random" - DYNLINK_MOD_CFLAGS="-shared $CFLAGS_PIC" - ;; - - *-irix*) + *-solaris* | *-irix* | *-dec-osf* ) NAME_OF_DEV_RANDOM="/dev/random" NAME_OF_DEV_URANDOM="/dev/urandom" DYNLINK_MOD_CFLAGS="-shared $CFLAGS_PIC" diff --git a/g10/ChangeLog b/g10/ChangeLog index 2b56b82a2..03a52b153 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,13 @@ +2001-06-12 Werner Koch + + * getkey.c (compare_name): Use ascii_memistr(), ascii_memcasecmp() + * keyedit.c (keyedit_menu): Use ascii_strcasecmp(). + * armor.c (radix64_read): Use ascii_toupper(). + * ringedit.c (do_bm_search): Ditto. + * keygen.c (read_parameter_file): Ditto. + * openfile.c (CMP_FILENAME): Ditto. + * g10.c (i18n_init): We can now use just LC_ALL. + 2001-05-29 Werner Koch * keygen.c (generate_subkeypair): Print a warning if a subkey is diff --git a/g10/armor.c b/g10/armor.c index 8ffa5e6ea..a9c520ab5 100644 --- a/g10/armor.c +++ b/g10/armor.c @@ -649,9 +649,9 @@ radix64_read( armor_filter_context_t *afx, IOBUF a, size_t *retn, if( isxdigit(cc1) && isxdigit(cc2) && strchr( "=\n\r\t ", cc3 )) { /* well it seems to be the case - adjust */ - c = isdigit(cc1)? (cc1 - '0'): (toupper(cc1)-'A'+10); + c = isdigit(cc1)? (cc1 - '0'): (ascii_toupper(cc1)-'A'+10); c <<= 4; - c |= isdigit(cc2)? (cc2 - '0'): (toupper(cc2)-'A'+10); + c |= isdigit(cc2)? (cc2 - '0'): (ascii_toupper(cc2)-'A'+10); afx->buffer_pos += 2; afx->qp_detected = 1; goto again; diff --git a/g10/g10.c b/g10/g10.c index ad2d47ded..cd4e2bf04 100644 --- a/g10/g10.c +++ b/g10/g10.c @@ -513,12 +513,7 @@ i18n_init(void) set_gettext_file( PACKAGE ); #else #ifdef ENABLE_NLS - #ifdef HAVE_LC_MESSAGES - setlocale( LC_TIME, "" ); - setlocale( LC_MESSAGES, "" ); - #else - setlocale( LC_ALL, "" ); - #endif + setlocale( LC_ALL, "" ); bindtextdomain( PACKAGE, G10_LOCALEDIR ); textdomain( PACKAGE ); #endif diff --git a/g10/getkey.c b/g10/getkey.c index f2f831b9b..bd21f956f 100644 --- a/g10/getkey.c +++ b/g10/getkey.c @@ -1273,7 +1273,7 @@ compare_name( const char *uid, size_t uidlen, const char *name, int mode ) return 0; /* found */ } else if( mode == 2 ) { /* case insensitive substring */ - if( memistr( uid, uidlen, name ) ) + if( ascii_memistr( uid, uidlen, name ) ) return 0; } else if( mode >= 3 && mode <= 5 ) { /* look at the email address */ @@ -1287,11 +1287,12 @@ compare_name( const char *uid, size_t uidlen, const char *name, int mode ) if( i < uidlen ) { i = se - s; if( mode == 3 ) { /* exact email address */ - if( strlen(name)-2 == i && !memicmp( s, name+1, i) ) + if( strlen(name)-2 == i + && !ascii_memcasecmp( s, name+1, i) ) return 0; } else if( mode == 4 ) { /* email substring */ - if( memistr( s, i, name ) ) + if( ascii_memistr( s, i, name ) ) return 0; } else { /* email from end */ diff --git a/g10/keyedit.c b/g10/keyedit.c index ca141b4a4..1a948d038 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -721,7 +721,7 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands, } for(i=0; cmds[i].name; i++ ) { - if( !stricmp( answer, cmds[i].name ) ) + if( !ascii_strcasecmp( answer, cmds[i].name ) ) break; } if( sign_mode && !cmds[i].signmode ) diff --git a/g10/keygen.c b/g10/keygen.c index 2639ac07f..c3e44b553 100644 --- a/g10/keygen.c +++ b/g10/keygen.c @@ -1292,17 +1292,17 @@ read_parameter_file( const char *fname ) ; value = p; trim_trailing_ws( value, strlen(value) ); - if( !stricmp( keyword, "%echo" ) ) + if( !ascii_strcasecmp( keyword, "%echo" ) ) log_info("%s\n", value ); - else if( !stricmp( keyword, "%dry-run" ) ) + else if( !ascii_strcasecmp( keyword, "%dry-run" ) ) outctrl.dryrun = 1; - else if( !stricmp( keyword, "%commit" ) ) { + else if( !ascii_strcasecmp( keyword, "%commit" ) ) { outctrl.lnr = lnr; proc_parameter_file( para, fname, &outctrl ); release_parameter_list( para ); para = NULL; } - else if( !stricmp( keyword, "%pubring" ) ) { + else if( !ascii_strcasecmp( keyword, "%pubring" ) ) { if( outctrl.pub.fname && !strcmp( outctrl.pub.fname, value ) ) ; /* still the same file - ignore it */ else { @@ -1311,7 +1311,7 @@ read_parameter_file( const char *fname ) outctrl.use_files = 1; } } - else if( !stricmp( keyword, "%secring" ) ) { + else if( !ascii_strcasecmp( keyword, "%secring" ) ) { if( outctrl.sec.fname && !strcmp( outctrl.sec.fname, value ) ) ; /* still the same file - ignore it */ else { @@ -1344,7 +1344,7 @@ read_parameter_file( const char *fname ) trim_trailing_ws( value, strlen(value) ); for(i=0; keywords[i].name; i++ ) { - if( !stricmp( keywords[i].name, keyword ) ) + if( !ascii_strcasecmp( keywords[i].name, keyword ) ) break; } if( !keywords[i].name ) { diff --git a/g10/openfile.c b/g10/openfile.c index f207dd2bb..99b81fe7b 100644 --- a/g10/openfile.c +++ b/g10/openfile.c @@ -43,7 +43,7 @@ #endif #ifdef HAVE_DRIVE_LETTERS - #define CMP_FILENAME(a,b) stricmp( (a), (b) ) + #define CMP_FILENAME(a,b) ascii_strcasecmp( (a), (b) ) #else #define CMP_FILENAME(a,b) strcmp( (a), (b) ) #endif diff --git a/g10/ringedit.c b/g10/ringedit.c index 5e9102477..f89bda35d 100644 --- a/g10/ringedit.c +++ b/g10/ringedit.c @@ -1000,8 +1000,8 @@ do_bm_search( const byte *buf, size_t buflen, int c, c1; for( i = --patlen; i < buflen; i += dist[c1] ) - for( j=patlen, k=i, c1=c=toupper(buf[k]); c == pat[j]; - j--, k--, c=toupper(buf[k]) ) { + for( j=patlen, k=i, c1=c=ascii_toupper(buf[k]); c == pat[j]; + j--, k--, c=ascii_toupper(buf[k]) ) { if( !j ) return buf+k; } diff --git a/include/util.h b/include/util.h index d8294f6db..527961336 100644 --- a/include/util.h +++ b/include/util.h @@ -170,6 +170,7 @@ STRLIST append_to_strlist2( STRLIST *list, const char *string, int is_utf8 ); STRLIST strlist_prev( STRLIST head, STRLIST node ); STRLIST strlist_last( STRLIST node ); const char *memistr( const char *buf, size_t buflen, const char *sub ); +const char *ascii_memistr( const char *buf, size_t buflen, const char *sub ); char *mem2str( char *, const void *, size_t); char *trim_spaces( char *string ); unsigned int trim_trailing_chars( byte *line, unsigned int len, @@ -185,6 +186,13 @@ char *native_to_utf8( const char *string ); char *utf8_to_native( const char *string, size_t length ); int check_utf8_string( const char *string ); +int ascii_isupper (int c); +int ascii_islower (int c); +int ascii_toupper (int c); +int ascii_tolower (int c); +int ascii_strcasecmp( const char *a, const char *b ); +int ascii_memcasecmp( const char *a, const char *b, size_t n ); + #ifndef HAVE_MEMICMP int memicmp( const char *a, const char *b, size_t n ); #endif diff --git a/util/ChangeLog b/util/ChangeLog index a8854f618..7e600e111 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,12 @@ +2001-06-12 Werner Koch + + * 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 * strgutil.c (vasprintf) [__MINGW32__]: New. Taken from libiberty. diff --git a/util/fileutil.c b/util/fileutil.c index 7910631c2..1e8ad75ad 100644 --- a/util/fileutil.c +++ b/util/fileutil.c @@ -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 diff --git a/util/miscutil.c b/util/miscutil.c index 2fc7545b4..dbe6db4ff 100644 --- a/util/miscutil.c +++ b/util/miscutil.c @@ -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; diff --git a/util/strgutil.c b/util/strgutil.c index 9a8cffe9e..def52f31e 100644 --- a/util/strgutil.c +++ b/util/strgutil.c @@ -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; +} /*********************************************