]> mj.ucw.cz Git - libucw.git/commitdiff
Moved matching and splitting functions to lib/str-*.c.
authorMartin Mares <mj@ucw.cz>
Wed, 25 Jun 2008 18:42:36 +0000 (20:42 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 25 Jun 2008 18:42:36 +0000 (20:42 +0200)
lib/Makefile
lib/patimatch.c [deleted file]
lib/patmatch.c [deleted file]
lib/patmatch.h [deleted file]
lib/str-imatch.c [new file with mode: 0644]
lib/str-match.c [new file with mode: 0644]
lib/str-match.h [new file with mode: 0644]
lib/str-split.c [new file with mode: 0644]
lib/string.h
lib/wordsplit.c [deleted file]

index 6df66820bc493d4675d95cb341d1d4ad6faaa0c2..139995412fa44e10255e52003586cfdd246bc03b 100644 (file)
@@ -20,7 +20,7 @@ LIBUCW_MODS= \
        fastbuf ff-binary ff-string ff-printf ff-unicode \
        fb-file carefulio fb-mem fb-temp fb-mmap fb-limfd fb-buffer fb-grow fb-pool fb-atomic fb-param fb-socket \
        str_ctype str_upper str_lower unicode stkstring \
-       wildmatch wordsplit ctmatch patimatch patmatch regex \
+       wildmatch ctmatch regex \
        prime primetable random timer randomkey \
        bit-ffs bit-fls \
        db \
@@ -31,7 +31,7 @@ LIBUCW_MODS= \
        base64 base224 \
        sync \
        qache \
-       string str-esc \
+       string str-esc str-split str-match str-imatch \
        bbuf \
        getopt
 
diff --git a/lib/patimatch.c b/lib/patimatch.c
deleted file mode 100644 (file)
index ea5a4be..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- *     UCW Library -- Shell-Like Case-Insensitive Pattern Matching (currently only '?' and '*')
- *
- *     (c) 1997 Martin Mares <mj@ucw.cz>
- *
- *     This software may be freely distributed and used according to the terms
- *     of the GNU Lesser General Public License.
- */
-
-#include "lib/lib.h"
-#include "lib/chartype.h"
-
-#define Convert(x) Cupcase(x)
-#define MATCH_FUNC_NAME str_match_pattern_nocase
-
-#include "lib/patmatch.h"
diff --git a/lib/patmatch.c b/lib/patmatch.c
deleted file mode 100644 (file)
index 373054a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- *     UCW Library -- Shell-Like Pattern Matching (currently only '?' and '*')
- *
- *     (c) 1997 Martin Mares <mj@ucw.cz>
- *
- *     This software may be freely distributed and used according to the terms
- *     of the GNU Lesser General Public License.
- */
-
-#include "lib/lib.h"
-
-#define Convert(x) (x)
-#define MATCH_FUNC_NAME str_match_pattern
-
-#include "lib/patmatch.h"
diff --git a/lib/patmatch.h b/lib/patmatch.h
deleted file mode 100644 (file)
index ef8508a..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *     UCW Library -- Generic Shell-Like Pattern Matching (currently only '?' and '*')
- *
- *     (c) 1997 Martin Mares <mj@ucw.cz>
- *
- *     This software may be freely distributed and used according to the terms
- *     of the GNU Lesser General Public License.
- */
-
-#include "lib/string.h"
-
-int
-MATCH_FUNC_NAME(const char *p, const char *s)
-{
-  while (*p)
-    {
-      if (*p == '?' && *s)
-       p++, s++;
-      else if (*p == '*')
-       {
-         int z = p[1];
-
-         if (!z)
-           return 1;
-         if (z == '\\' && p[2])
-           z = p[2];
-         z = Convert(z);
-         for(;;)
-           {
-             while (*s && Convert(*s) != z)
-               s++;
-             if (!*s)
-               return 0;
-             if (MATCH_FUNC_NAME(p+1, s))
-               return 1;
-             s++;
-           }
-       }
-      else
-       {
-         if (*p == '\\' && p[1])
-           p++;
-         if (Convert(*p++) != Convert(*s++))
-           return 0;
-       }
-    }
-  return !*s;
-}
diff --git a/lib/str-imatch.c b/lib/str-imatch.c
new file mode 100644 (file)
index 0000000..9d739ef
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ *     UCW Library -- Shell-Like Case-Insensitive Pattern Matching (currently only '?' and '*')
+ *
+ *     (c) 1997 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
+ */
+
+#include "lib/lib.h"
+#include "lib/chartype.h"
+
+#define Convert(x) Cupcase(x)
+#define MATCH_FUNC_NAME str_match_pattern_nocase
+
+#include "lib/str-match.h"
diff --git a/lib/str-match.c b/lib/str-match.c
new file mode 100644 (file)
index 0000000..839da6c
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ *     UCW Library -- Shell-Like Pattern Matching (currently only '?' and '*')
+ *
+ *     (c) 1997 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
+ */
+
+#include "lib/lib.h"
+
+#define Convert(x) (x)
+#define MATCH_FUNC_NAME str_match_pattern
+
+#include "lib/str-match.h"
diff --git a/lib/str-match.h b/lib/str-match.h
new file mode 100644 (file)
index 0000000..ef8508a
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *     UCW Library -- Generic Shell-Like Pattern Matching (currently only '?' and '*')
+ *
+ *     (c) 1997 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
+ */
+
+#include "lib/string.h"
+
+int
+MATCH_FUNC_NAME(const char *p, const char *s)
+{
+  while (*p)
+    {
+      if (*p == '?' && *s)
+       p++, s++;
+      else if (*p == '*')
+       {
+         int z = p[1];
+
+         if (!z)
+           return 1;
+         if (z == '\\' && p[2])
+           z = p[2];
+         z = Convert(z);
+         for(;;)
+           {
+             while (*s && Convert(*s) != z)
+               s++;
+             if (!*s)
+               return 0;
+             if (MATCH_FUNC_NAME(p+1, s))
+               return 1;
+             s++;
+           }
+       }
+      else
+       {
+         if (*p == '\\' && p[1])
+           p++;
+         if (Convert(*p++) != Convert(*s++))
+           return 0;
+       }
+    }
+  return !*s;
+}
diff --git a/lib/str-split.c b/lib/str-split.c
new file mode 100644 (file)
index 0000000..97ce242
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ *     UCW Library -- Word Splitting
+ *
+ *     (c) 1997 Martin Mares <mj@ucw.cz>
+ *     (c) 2004 Robert Spalek <robert@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
+ */
+
+#include "lib/lib.h"
+#include "lib/chartype.h"
+#include "lib/string.h"
+
+#include <string.h>
+
+int
+str_sepsplit(char *str, uns sep, char **rec, uns max)
+{
+  uns cnt = 0;
+  while (1)
+  {
+    rec[cnt++] = str;
+    str = strchr(str, sep);
+    if (!str)
+      return cnt;
+    if (cnt >= max)
+      return -1;
+    *str++ = 0;
+  }
+}
+
+int
+str_wordsplit(char *src, char **dst, uns max)
+{
+  uns cnt = 0;
+
+  for(;;)
+    {
+      while (Cspace(*src))
+       *src++ = 0;
+      if (!*src)
+       break;
+      if (cnt >= max)
+       return -1;
+      if (*src == '"')
+       {
+         src++;
+         dst[cnt++] = src;
+         while (*src && *src != '"')
+           src++;
+         if (*src)
+           *src++ = 0;
+       }
+      else
+       {
+         dst[cnt++] = src;
+         while (*src && !Cspace(*src))
+           src++;
+       }
+    }
+  return cnt;
+}
index a9de082f9dc457489c61755f6ad2f99d610188da..50c4dc475b8aed3b1e0d3aa5419e2854cb2db6bd 100644 (file)
 #ifndef _UCW_STRING_H
 #define _UCW_STRING_H
 
-char *str_unesc(char *dest, const char *src);
+/* string.c */
+
 char *str_format_flags(char *dest, const char *fmt, uns flags);
 
-/* wordsplit.c */
+/* str-esc.c */
+
+char *str_unesc(char *dest, const char *src);
+
+/* str-split.c */
 
 int str_sepsplit(char *str, uns sep, char **rec, uns max);
 int str_wordsplit(char *str, char **rec, uns max);
 
-/* pat(i)match.c: Matching of shell patterns */
+/* str-(i)match.c: Matching of shell patterns */
 
 int str_match_pattern(const char *patt, const char *str);
 int str_match_pattern_nocase(const char *patt, const char *str);
diff --git a/lib/wordsplit.c b/lib/wordsplit.c
deleted file mode 100644 (file)
index 97ce242..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- *     UCW Library -- Word Splitting
- *
- *     (c) 1997 Martin Mares <mj@ucw.cz>
- *     (c) 2004 Robert Spalek <robert@ucw.cz>
- *
- *     This software may be freely distributed and used according to the terms
- *     of the GNU Lesser General Public License.
- */
-
-#include "lib/lib.h"
-#include "lib/chartype.h"
-#include "lib/string.h"
-
-#include <string.h>
-
-int
-str_sepsplit(char *str, uns sep, char **rec, uns max)
-{
-  uns cnt = 0;
-  while (1)
-  {
-    rec[cnt++] = str;
-    str = strchr(str, sep);
-    if (!str)
-      return cnt;
-    if (cnt >= max)
-      return -1;
-    *str++ = 0;
-  }
-}
-
-int
-str_wordsplit(char *src, char **dst, uns max)
-{
-  uns cnt = 0;
-
-  for(;;)
-    {
-      while (Cspace(*src))
-       *src++ = 0;
-      if (!*src)
-       break;
-      if (cnt >= max)
-       return -1;
-      if (*src == '"')
-       {
-         src++;
-         dst[cnt++] = src;
-         while (*src && *src != '"')
-           src++;
-         if (*src)
-           *src++ = 0;
-       }
-      else
-       {
-         dst[cnt++] = src;
-         while (*src && !Cspace(*src))
-           src++;
-       }
-    }
-  return cnt;
-}