OSDN Git Service

Honour GLOB_CASEMATCH for globbing sets; cf. issue [#2327].
authorJason Hood <jadoxa@yahoo.com.au>
Thu, 26 Jan 2017 20:34:13 +0000 (20:34 +0000)
committerJason Hood <jadoxa@yahoo.com.au>
Thu, 26 Jan 2017 20:34:13 +0000 (20:34 +0000)
mingwrt/ChangeLog
mingwrt/include/glob.h
mingwrt/mingwex/glob.c

index 67091e8..41a6e08 100644 (file)
@@ -1,3 +1,11 @@
+2017-01-26  Jason Hood  <jadoxa@yahoo.com.au>
+
+       Honour GLOB_CASEMATCH for globbing sets; cf. issue [#2327].
+
+       * include/glob.h (GLOB_CASEMATCH): Update comment.
+       * mingwex/glob.c (glob_case_match): Move before, and use it in...
+       (glob_in_set): ...this function, to test characters in the set.
+
 2017-01-26  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Avoid snprintf() overhead in directory stream functions.
index 9cfa169..45e1c9a 100644 (file)
@@ -8,7 +8,7 @@
  * $Id$
  *
  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2011, 2012, 2014, 2016, MinGW.org Project.
+ * Copyright (C) 2011, 2012, 2014, 2016, 2017, MinGW.org Project.
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -94,10 +94,7 @@ enum {
    *                       but to better support the MS-Windows
    *                       file system, the MinGW implementation
    *                       of glob() performs a CASE INSENSITIVE
-   *                       character match by default, (except
-   *                       when matching within character group
-   *                       patterns, which are ALWAYS assumed to
-   *                       require CASE SENSITIVE matching).
+   *                       character match by default.
    */
   __GLOB_CASEMATCH_OFFSET,
   /*
index 8b5332a..1f064e1 100644 (file)
@@ -7,7 +7,7 @@
  * $Id$
  *
  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2011-2014, MinGW.org Project.
+ * Copyright (C) 2011-2014, 2017, MinGW.org Project.
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -227,6 +227,15 @@ static const char *glob_set_adjusted( const char *pattern, int flags )
   return ++p;
 }
 
+GLOB_INLINE int glob_case_match( int flags, int check, int match )
+{
+  /* Local helper function, used to facilitate the case insensitive
+   * glob character matching appropriate for MS-Windows systems.
+   */
+  return (flags & GLOB_CASEMATCH) ? check - match
+    : tolower( check ) - tolower( match );
+}
+
 static const char *glob_in_set( const char *set, int test, int flags )
 {
   /* Check if the single character "test" is present in the set
@@ -283,7 +292,7 @@ static const char *glob_in_set( const char *set, int test, int flags )
        /* ...in incremental collating sequence order, to the next
         * character following the '-'...
         */
-       if( lastc++ == test )
+       if( glob_case_match( flags, lastc++, test ) == 0 )
          /*
           * ...returning immediately on a successful match...
           */
@@ -295,7 +304,7 @@ static const char *glob_in_set( const char *set, int test, int flags )
         * range may have been specified in decrementing collating
         * sequence order...
         */
-       if( lastc-- == test )
+       if( glob_case_match( flags, lastc--, test ) == 0 )
          /*
           * ...once again, return immediately on a successful match.
           */
@@ -316,7 +325,7 @@ static const char *glob_in_set( const char *set, int test, int flags )
        */
       return NULL;
 
-    if( c == test )
+    if( glob_case_match( flags, c, test ) == 0 )
       /*
        * We found the test character within the set; adjust the pattern
        * reference, to resume after the end of the set, and return the
@@ -337,15 +346,6 @@ static const char *glob_in_set( const char *set, int test, int flags )
   return NULL;
 }
 
-GLOB_INLINE int glob_case_match( int flags, int check, int match )
-{
-  /* Local helper function, used to facilitate the case insensitive
-   * glob character matching appropriate for MS-Windows systems.
-   */
-  return (flags & GLOB_CASEMATCH) ? check - match
-    : tolower( check ) - tolower( match );
-}
-
 static int glob_strcmp( const char *pattern, const char *text, int flags )
 {
   /* Compare "text" to a specified globbing "pattern" using semantics