浏览代码

G_ls_*_filter: Add case-insensitive option to the ls filters

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@62448 15284696-431f-4ddb-bdfa-cd5b030d7da7
Huidae Cho 10 年之前
父节点
当前提交
cc97c6e441
共有 2 个文件被更改,包括 10 次插入8 次删除
  1. 2 2
      include/defs/gis.h
  2. 8 6
      lib/gis/ls_filter.c

+ 2 - 2
include/defs/gis.h

@@ -414,8 +414,8 @@ void G_ls_format(char **, int, int, FILE *);
 
 /* ls_filter.c */
 #ifdef HAVE_REGEX_H
-void *G_ls_regex_filter(const char *, int, int);
-void *G_ls_glob_filter(const char *, int);
+void *G_ls_regex_filter(const char *, int, int, int);
+void *G_ls_glob_filter(const char *, int, int);
 void G_free_ls_filter(void *);
 #endif
 

+ 8 - 6
lib/gis/ls_filter.c

@@ -146,15 +146,17 @@ static int re_filter(const char *filename, void *closure)
 {
     regex_t *regex = closure;
 
-    return filename[0] != '.' &&
-	regexec(regex, filename, 0, NULL, 0) == 0;
+    return filename[0] != '.' && regexec(regex, filename, 0, NULL, 0) == 0;
 }
 
-void *G_ls_regex_filter(const char *pat, int exclude, int extended)
+void *G_ls_regex_filter(const char *pat, int exclude, int extended,
+			int ignorecase)
 {
     regex_t *regex = G_malloc(sizeof(regex_t));
 
-    if (regcomp(regex, pat, (extended ? REG_EXTENDED : 0) | REG_NOSUB) != 0) {
+    if (regcomp(regex, pat, REG_NOSUB |
+			    (extended ? REG_EXTENDED : 0) |
+			    (ignorecase ? REG_ICASE : 0)) != 0) {
 	G_free(regex);
 	return NULL;
     }
@@ -167,7 +169,7 @@ void *G_ls_regex_filter(const char *pat, int exclude, int extended)
     return regex;
 }
 
-void *G_ls_glob_filter(const char *pat, int exclude)
+void *G_ls_glob_filter(const char *pat, int exclude, int ignorecase)
 {
     struct buffer buf;
     regex_t *regex;
@@ -179,7 +181,7 @@ void *G_ls_glob_filter(const char *pat, int exclude)
 	return NULL;
     }
 
-    regex = G_ls_regex_filter(buf.buf, exclude, 1);
+    regex = G_ls_regex_filter(buf.buf, exclude, 1, ignorecase);
 
     fini(&buf);