Kamil Dudka <[EMAIL PROTECTED]> wrote: > On Friday 03 of October 2008 09:55:40 Jim Meyering wrote: >> Please review these small changes that I expect to fold into your change >> set: - use c_isdigit, c_isalpha, c_isalnum directly; no need for casts - > Sorry, but I am not sure here. This was Bruno's suggestion from > http://lists.gnu.org/archive/html/bug-coreutils/2008-09/msg00115.html but we > moved from ctype.h to c-ctype.h since that. The c-ctype module is new to me. > I am not in office right now to probe it... > >> reword match_suffix comment >> - reword module description >> - s/0/NULL/ in test-filevercmp.c > No problem here...
FYI, here's the adjusted patch, using the relatively type-safe to_uchar function instead of casts. Also adjusted a misleadingly split/indented expression: >From 5f4f36b8607ba69bb2b672f1ea9c9b0717e74cb3 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[EMAIL PROTECTED]> Date: Fri, 3 Oct 2008 11:51:55 +0200 Subject: [PATCH] tweaks --- lib/filevercmp.c | 25 ++++++++++++++----------- modules/filevercmp | 2 +- tests/test-filevercmp.c | 3 +-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/filevercmp.c b/lib/filevercmp.c index a73c618..6aabf5f 100644 --- a/lib/filevercmp.c +++ b/lib/filevercmp.c @@ -26,16 +26,19 @@ #include <c-ctype.h> #include <limits.h> -#define ISDIGIT(c) c_isdigit ((unsigned char) (c)) -#define ISALPHA(c) c_isalpha ((unsigned char) (c)) -#define ISALNUM(c) c_isalnum ((unsigned char) (c)) - -/* - match file suffix defined as RE (\.[A-Za-z][A-Za-z0-9]*)*$ - - Scan string pointed by *str and return pointer to suffix begin or NULL if - not found. Pointer *str points to ending zero of scanned string after - return. */ +#define ISDIGIT(c) c_isdigit (to_uchar (c)) +#define ISALPHA(c) c_isalpha (to_uchar (c)) +#define ISALNUM(c) c_isalnum (to_uchar (c)) + +/* Convert a possibly-signed character to an unsigned character. This is + a bit safer than casting to unsigned char, since it catches some type + errors that the cast doesn't. */ +static inline unsigned char to_uchar (char ch) { return ch; } + +/* Match a file suffix defined by this regular expression: + /(\.[A-Za-z][A-Za-z0-9]*)*$/ + Scan the string *STR and return a pointer to the matching suffix, or + NULL if not found. Upon return, *STR points to terminating NUL. */ static const char * match_suffix (const char **str) { @@ -49,7 +52,7 @@ match_suffix (const char **str) if (!ISALPHA (**str)) match = NULL; } - else if ('.' == **str) + else if ('.' == **str) { read_alpha = true; if (!match) @@ -94,8 +97,8 @@ verrevcmp (const char *s1, size_t s1_len, const char *s2, size_t s2_len) while (s1_pos < s1_len || s2_pos < s2_len) { int first_diff = 0; - while ((s1_pos < s1_len && !ISDIGIT (s1[s1_pos])) || (s2_pos < s2_len - && !ISDIGIT (s2[s2_pos]))) + while ((s1_pos < s1_len && !ISDIGIT (s1[s1_pos])) + || (s2_pos < s2_len && !ISDIGIT (s2[s2_pos]))) { int s1_c = (s1_pos == s1_len) ? 0 : order (s1[s1_pos]); int s2_c = (s2_pos == s2_len) ? 0 : order (s2[s2_pos]); diff --git a/modules/filevercmp b/modules/filevercmp index db71442..12b0520 100644 --- a/modules/filevercmp +++ b/modules/filevercmp @@ -1,5 +1,5 @@ Description: -function comparing version strings (and file names with version) +compare version strings and version-containing file names Files: lib/filevercmp.h diff --git a/tests/test-filevercmp.c b/tests/test-filevercmp.c index af5ca4a..4efd108 100644 --- a/tests/test-filevercmp.c +++ b/tests/test-filevercmp.c @@ -56,7 +56,7 @@ static const char *const examples[] = "nss_ldap-1.0-0.1a.tar.gz", "nss_ldap-10beta1.fc8.tar.gz", "nss_ldap-10.11.8.6.20040204cvs.fc10.ebuild", - 0 + NULL }; int @@ -93,4 +93,3 @@ main (int argc, char **argv) return 0; } - -- 1.6.0.2.307.gc427