]> mj.ucw.cz Git - libucw.git/commitdiff
Introduced new header "lib/string.h".
authorMartin Mares <mj@ucw.cz>
Wed, 25 Jun 2008 17:36:50 +0000 (19:36 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 25 Jun 2008 17:36:50 +0000 (19:36 +0200)
Started moving string functions from lib.h there. The first ones
are those from string.c.

Also split off the unescaping functions to str-esc.c.

lib/Makefile
lib/conf-input.c
lib/lib.h
lib/shell/config.c
lib/str-esc.c [new file with mode: 0644]
lib/string.c
lib/string.h [new file with mode: 0644]

index 9efb1f69299034290a28364a692ba8d82e796874..e8db62e78db10681bacb5ad4c3b76f4be88731c8 100644 (file)
@@ -1,4 +1,4 @@
-# Makefile for the UCW Library (c) 1997--2007 Martin Mares <mj@ucw.cz>
+# Makefile for the UCW Library (c) 1997--2008 Martin Mares <mj@ucw.cz>
 
 DIRS+=lib
 CONFIGS+=library
@@ -31,7 +31,7 @@ LIBUCW_MODS= \
        base64 base224 \
        sync \
        qache \
-       string \
+       string str-esc \
        bbuf \
        getopt
 
@@ -40,6 +40,7 @@ LIBUCW_INCLUDES= \
        mempool.h pagecache.h \
        arraysort.h \
        lists.h clists.h slists.h simple-lists.h \
+       string.h \
        unaligned.h prefetch.h \
        bbuf.h gbuf.h bitarray.h bitsig.h \
        hashfunc.h hashtable.h \
index c5d2527772548911bd3f163b115392e90f2f3035..08e5b09831975b5a9f01b4e836a48bc57a5dc50c 100644 (file)
@@ -15,6 +15,7 @@
 #include "lib/mempool.h"
 #include "lib/fastbuf.h"
 #include "lib/chartype.h"
+#include "lib/string.h"
 #include "lib/stkstring.h"
 
 #include <stdlib.h>
index e93bdf6a750157a8ba29e642c09bd7cb0845772d..1ce5a463356ecbc7c0ddf171a73c074093e1b704 100644 (file)
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -263,11 +263,6 @@ void handle_signal(int signum);
 void unhandle_signal(int signum);
 sh_sighandler_t set_signal_handler(int signum, sh_sighandler_t new);
 
-/* string.c */
-
-char *str_unesc(char *dest, const char *src);
-char *str_format_flags(char *dest, const char *fmt, uns flags);
-
 /* bigalloc.c */
 
 void *page_alloc(u64 len) LIKE_MALLOC; // allocates a multiple of CPU_PAGE_SIZE bytes with mmap
index 4208b8665438987f55d834fe700176a8bcbe1362..44ca438156d323bb005f4ac3a7a2a374fb3c06a7 100644 (file)
@@ -25,6 +25,7 @@
 #include "lib/mempool.h"
 #include "lib/chartype.h"
 #include "lib/bbuf.h"
+#include "lib/string.h"
 
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/lib/str-esc.c b/lib/str-esc.c
new file mode 100644 (file)
index 0000000..d294438
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ *     UCW Library -- String Unescaping
+ *
+ *     (c) 2006 Pavel Charvat <pchar@ucw.cz>
+ *     (c) 2007 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
+ */
+
+#undef LOCAL_DEBUG
+
+#include "lib/lib.h"
+#include "lib/string.h"
+#include "lib/chartype.h"
+#include <stdlib.h>
+
+/* Expands C99-like escape sequences.
+ * It is safe to use the same buffer for both input and output. */
+char *
+str_unesc(char *d, const char *s)
+{
+  while (*s)
+    {
+      if (*s == '\\')
+       switch (s[1])
+         {
+           case 'a': *d++ = '\a'; s += 2; break;
+           case 'b': *d++ = '\b'; s += 2; break;
+           case 'f': *d++ = '\f'; s += 2; break;
+           case 'n': *d++ = '\n'; s += 2; break;
+           case 'r': *d++ = '\r'; s += 2; break;
+           case 't': *d++ = '\t'; s += 2; break;
+           case 'v': *d++ = '\v'; s += 2; break;
+           case '\?': *d++ = '\?'; s += 2; break;
+           case '\'': *d++ = '\''; s += 2; break;
+           case '\"': *d++ = '\"'; s += 2; break;
+           case '\\': *d++ = '\\'; s += 2; break;
+           case 'x':
+             if (!Cxdigit(s[2]))
+               {
+                 s++;
+                 DBG("\\x used with no following hex digits");
+               }
+             else
+               {
+                 char *p;
+                 uns v = strtoul(s + 2, &p, 16);
+                 if (v <= 255)
+                   *d++ = v;
+                 else
+                   DBG("hex escape sequence out of range");
+                  s = (char *)p;
+               }
+             break;
+            default:
+             if (s[1] >= '0' && s[1] <= '7')
+               {
+                 uns v = s[1] - '0';
+                 s += 2;
+                 for (uns i = 0; i < 2 && *s >= '0' && *s <= '7'; s++, i++)
+                   v = (v << 3) + *s - '0';
+                 if (v <= 255)
+                   *d++ = v;
+                 else
+                   DBG("octal escape sequence out of range");
+               }
+             *d++ = *s++;
+             break;
+         }
+      else
+       *d++ = *s++;
+    }
+  *d = 0;
+  return d;
+}
index 602a7d730074b24ab3e4a5700994c6fe569580d4..28fe36ef7e317415020fb6e9393bab3f248963a4 100644 (file)
 #undef LOCAL_DEBUG
 
 #include "lib/lib.h"
-#include "lib/chartype.h"
-#include <stdlib.h>
-
-/* Expands C99-like escape sequences.
- * It is safe to use the same buffer for both input and output. */
-char *
-str_unesc(char *d, const char *s)
-{
-  while (*s)
-    {
-      if (*s == '\\')
-       switch (s[1])
-         {
-           case 'a': *d++ = '\a'; s += 2; break;
-           case 'b': *d++ = '\b'; s += 2; break;
-           case 'f': *d++ = '\f'; s += 2; break;
-           case 'n': *d++ = '\n'; s += 2; break;
-           case 'r': *d++ = '\r'; s += 2; break;
-           case 't': *d++ = '\t'; s += 2; break;
-           case 'v': *d++ = '\v'; s += 2; break;
-           case '\?': *d++ = '\?'; s += 2; break;
-           case '\'': *d++ = '\''; s += 2; break;
-           case '\"': *d++ = '\"'; s += 2; break;
-           case '\\': *d++ = '\\'; s += 2; break;
-           case 'x':
-             if (!Cxdigit(s[2]))
-               {
-                 s++;
-                 DBG("\\x used with no following hex digits");
-               }
-             else
-               {
-                 char *p;
-                 uns v = strtoul(s + 2, &p, 16);
-                 if (v <= 255)
-                   *d++ = v;
-                 else
-                   DBG("hex escape sequence out of range");
-                  s = (char *)p;
-               }
-             break;
-            default:
-             if (s[1] >= '0' && s[1] <= '7')
-               {
-                 uns v = s[1] - '0';
-                 s += 2;
-                 for (uns i = 0; i < 2 && *s >= '0' && *s <= '7'; s++, i++)
-                   v = (v << 3) + *s - '0';
-                 if (v <= 255)
-                   *d++ = v;
-                 else
-                   DBG("octal escape sequence out of range");
-               }
-             *d++ = *s++;
-             break;
-         }
-      else
-       *d++ = *s++;
-    }
-  *d = 0;
-  return d;
-}
+#include "lib/string.h"
 
 char *
 str_format_flags(char *dest, const char *fmt, uns flags)
diff --git a/lib/string.h b/lib/string.h
new file mode 100644 (file)
index 0000000..c60a14d
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ *     UCW Library -- String Routines
+ *
+ *     (c) 2006 Pavel Charvat <pchar@ucw.cz>
+ *     (c) 2007--2008 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
+ */
+
+#ifndef _UCW_STRING_H
+#define _UCW_STRING_H
+
+char *str_unesc(char *dest, const char *src);
+char *str_format_flags(char *dest, const char *fmt, uns flags);
+
+#endif