apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject cvs commit: apr/test testfnmatch.c Makefile.in Makefile.win test_apr.h testall.c
Date Fri, 05 Mar 2004 19:52:06 GMT
rbb         2004/03/05 11:52:06

  Modified:    include  apr_fnmatch.h
               strings  apr_fnmatch.c
               test     Makefile.in Makefile.win test_apr.h testall.c
  Added:       test     testfnmatch.c
  Log:
  Add apr_match_glob and two tests to make sure that it is working.  There
  is a problem that is documented in the code that requires an
  apr_filepath_basename.  That will be added soon.
  
  Revision  Changes    Path
  1.22      +12 -0     apr/include/apr_fnmatch.h
  
  Index: apr_fnmatch.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_fnmatch.h,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- apr_fnmatch.h	3 Sep 2003 18:37:38 -0000	1.21
  +++ apr_fnmatch.h	5 Mar 2004 19:52:06 -0000	1.22
  @@ -43,6 +43,7 @@
    */
   
   #include "apr_errno.h"
  +#include "apr_tables.h"
   
   #ifdef __cplusplus
   extern "C" {
  @@ -86,6 +87,17 @@
    * @return non-zero if pattern has any glob characters in it
    */
   APR_DECLARE(int) apr_fnmatch_test(const char *pattern);
  +
  +/**
  + * Find all files that match a specified pattern.
  + * @param pattern The pattern to use for finding files.
  + * @param result Array to use when storing the results
  + * @param p The pool to use.
  + * @return non-zero if pattern has any glob characters in it
  + */
  +APR_DECLARE(apr_status_t) apr_match_glob(const char *pattern, 
  +                                         apr_array_header_t **result,
  +                                         apr_pool_t *p);
   
   /** @} */
   
  
  
  
  1.9       +50 -0     apr/strings/apr_fnmatch.c
  
  Index: apr_fnmatch.c
  ===================================================================
  RCS file: /home/cvs/apr/strings/apr_fnmatch.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- apr_fnmatch.c	3 Sep 2003 18:37:38 -0000	1.8
  +++ apr_fnmatch.c	5 Mar 2004 19:52:06 -0000	1.9
  @@ -45,8 +45,11 @@
   #ifndef WIN32
   #include "apr_private.h"
   #endif
  +#include "apr_file_info.h"
   #include "apr_fnmatch.h"
  +#include "apr_tables.h"
   #include "apr_lib.h"
  +#include "apr_strings.h"
   #include <string.h>
   #if APR_HAVE_CTYPE_H
   # include <ctype.h>
  @@ -240,4 +243,51 @@
   	++pattern;
       }
       return 0;
  +}
  +
  +/* Find all files matching the specified pattern */
  +APR_DECLARE(apr_status_t) apr_match_glob(const char *pattern, 
  +                                         apr_array_header_t **result,
  +                                         apr_pool_t *p)
  +{
  +    apr_dir_t *dir;
  +    apr_finfo_t finfo;
  +    apr_status_t rv;
  +    char *path;
  +
  +    /* XXX So, this is kind of bogus.  Basically, I need to strip any leading
  +     * directories off the pattern, but there is no portable way to do that.
  +     * So, for now we just find the last occurance of '/' and if that doesn't
  +     * return anything, then we look for '\'.  This means that we could
  +     * screw up on unix if the pattern is something like "foo\.*"  That '\'
  +     * isn't a directory delimiter, it is a part of the filename.  To fix this,
  +     * we really need apr_filepath_basename, which will be coming as soon as
  +     * I get to it.  rbb
  +     */
  +    char *idx = strrchr(pattern, '/');
  +    
  +    if (idx == NULL) {
  +        idx = strrchr(pattern, '\\');
  +    }
  +    if (idx == NULL) {
  +        path = ".";
  +    }
  +    else {
  +        path = apr_pstrndup(p, pattern, idx - pattern);
  +        pattern = idx + 1;
  +    }
  +
  +    *result = apr_array_make(p, 0, sizeof(char *));
  +    rv = apr_dir_open(&dir, path, p);
  +    if (rv != APR_SUCCESS) {
  +        return rv;
  +    }
  +
  +    while (apr_dir_read(&finfo, APR_FINFO_NAME, dir) == APR_SUCCESS) {
  +        if (apr_fnmatch(pattern, finfo.name, 0) == APR_SUCCESS) {
  +            *(const char **)apr_array_push(*result) = finfo.name;
  +        }
  +    }
  +    apr_dir_close(dir);
  +    return APR_SUCCESS;
   }
  
  
  
  1.147     +1 -1      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.146
  retrieving revision 1.147
  diff -u -r1.146 -r1.147
  --- Makefile.in	6 Feb 2004 22:57:47 -0000	1.146
  +++ Makefile.in	5 Mar 2004 19:52:06 -0000	1.147
  @@ -120,7 +120,7 @@
   	testdso.lo testoc.lo testdup.lo testsockets.lo testproc.lo \
   	testpoll.lo testlock.lo testsockopt.lo testpipe.lo testthread.lo \
   	testhash.lo testargs.lo testnames.lo testuser.lo testpath.lo \
  -	testenv.lo testprocmutex.lo testrand2.lo
  +	testenv.lo testprocmutex.lo testrand2.lo testfnmatch.lo
   
   testall: $(TESTS) mod_test.la libmod_test.la occhild@EXEEXT@ \
   	 readchild@EXEEXT@ CuTest.lo proc_child@EXEEXT@ $(LOCAL_LIBS)
  
  
  
  1.12      +1 -1      apr/test/Makefile.win
  
  Index: Makefile.win
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.win,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Makefile.win	16 Nov 2003 23:49:15 -0000	1.11
  +++ Makefile.win	5 Mar 2004 19:52:06 -0000	1.12
  @@ -99,7 +99,7 @@
   	testdso.obj testoc.obj testdup.obj testsockets.obj testproc.obj \
   	testpoll.obj testlock.obj testsockopt.obj testpipe.obj testthread.obj \
   	testhash.obj testargs.obj testnames.obj testuser.obj testpath.obj \
  -	testenv.obj testprocmutex.obj testrand2.obj 
  +	testenv.obj testprocmutex.obj testrand2.obj testfnmatch.obj
   
   testall.exe: $(TESTS) CuTest.obj $(LOCAL_LIBS)
   	$(LINK) /debug /subsystem:console /machine:I386 $(TESTS) CuTest.obj \
  
  
  
  1.45      +1 -0      apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- test_apr.h	13 Feb 2004 09:38:34 -0000	1.44
  +++ test_apr.h	5 Mar 2004 19:52:06 -0000	1.45
  @@ -59,6 +59,7 @@
   CuSuite *testuser(void);
   CuSuite *testpath(void);
   CuSuite *testenv(void);
  +CuSuite *testfnmatch(void);
   
   /* Assert that RV is an APR_SUCCESS value; else fail giving strerror
    * for RV and CONTEXT message. */
  
  
  
  1.50      +1 -0      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- testall.c	13 Feb 2004 09:38:34 -0000	1.49
  +++ testall.c	5 Mar 2004 19:52:06 -0000	1.50
  @@ -70,6 +70,7 @@
       {"testuser", testuser},
       {"testpath", testpath},
       {"testenv", testenv},
  +    {"testfnmatch", testfnmatch},
       {"LastTest", NULL}
   };
   
  
  
  
  1.1                  apr/test/testfnmatch.c
  
  Index: testfnmatch.c
  ===================================================================
  /* Copyright 2000-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  #include "test_apr.h"
  
  #include <stdlib.h>
  #include <stdio.h>
  #include <string.h>
  
  #include "apr_file_info.h"
  #include "apr_fnmatch.h"
  #include "apr_tables.h"
  
  static void test_glob(CuTest *tc)
  {
      int i;
      char **list;
      apr_array_header_t *result;
      apr_status_t rv = apr_match_glob("data\\*.txt", &result, p);
  
      CuAssertIntEquals(tc, APR_SUCCESS, rv);
      /* XXX If we ever add a file that matches *.txt to data, then we need
       * to increase this.
       */
      CuAssertIntEquals(tc, 2, result->nelts);
  
      list = (char **)result->elts;
      for (i = 0; i < result->nelts; i++) {
          char *dot = strrchr(list[i], '.');
          CuAssertStrEquals(tc, dot, ".txt");
      }
  }
  
  static void test_glob_currdir(CuTest *tc)
  {
      int i;
      char **list;
      apr_array_header_t *result;
      apr_status_t rv;
      apr_filepath_set("data", p);
      rv = apr_match_glob("*.txt", &result, p);
  
      CuAssertIntEquals(tc, APR_SUCCESS, rv);
      /* XXX If we ever add a file that matches *.txt to data, then we need
       * to increase this.
       */
      CuAssertIntEquals(tc, 2, result->nelts);
  
      list = (char **)result->elts;
      for (i = 0; i < result->nelts; i++) {
          char *dot = strrchr(list[i], '.');
          CuAssertStrEquals(tc, dot, ".txt");
      }
  }
  
  CuSuite *testfnmatch(void)
  {
      CuSuite *suite = CuSuiteNew("Fnmatch");
  
      SUITE_ADD_TEST(suite, test_glob);
      SUITE_ADD_TEST(suite, test_glob_currdir);
  
      return suite;
  }
  
  
  
  

Mime
View raw message