diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2007-11-23 08:21:23 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2007-11-23 08:21:23 +0200 |
commit | 115d698252464f907a4932b4bfeb63d72a3098a2 (patch) | |
tree | 051a541c3b788bfc1f7349b9d5ca6787d6f381f4 | |
parent | d6990c3ab1095e0637a5113fe062b9eb6e1a2238 (diff) | |
download | librpm-tizen-115d698252464f907a4932b4bfeb63d72a3098a2.tar.gz librpm-tizen-115d698252464f907a4932b4bfeb63d72a3098a2.tar.bz2 librpm-tizen-115d698252464f907a4932b4bfeb63d72a3098a2.zip |
Move string helpers from lib/misc.h to rpmio/rpmstring.h
- splitString, freeSplitString, stripTrailingChar
-rw-r--r-- | build/files.c | 1 | ||||
-rw-r--r-- | build/parsePrep.c | 1 | ||||
-rw-r--r-- | lib/misc.c | 43 | ||||
-rw-r--r-- | lib/misc.h | 30 | ||||
-rw-r--r-- | lib/rpmfi.c | 2 | ||||
-rw-r--r-- | lib/transaction.c | 3 | ||||
-rw-r--r-- | rpmdb/legacy.c | 2 | ||||
-rw-r--r-- | rpmio/rpmstring.c | 51 | ||||
-rw-r--r-- | rpmio/rpmstring.h | 23 |
9 files changed, 78 insertions, 78 deletions
diff --git a/build/files.c b/build/files.c index c79a300f6..6f944ecc8 100644 --- a/build/files.c +++ b/build/files.c @@ -30,7 +30,6 @@ #include "buildio.h" #include "legacy.h" /* XXX domd5, expandFileList, compressFileList */ -#include "misc.h" /* for splitString, freeSplitString */ #include <rpmlog.h> #include "debug.h" diff --git a/build/parsePrep.c b/build/parsePrep.c index 7f5b734d1..783b48f1c 100644 --- a/build/parsePrep.c +++ b/build/parsePrep.c @@ -7,7 +7,6 @@ #include <rpmbuild.h> #include <rpmlog.h> -#include "misc.h" /* XXX for splitString */ #include "debug.h" /* These have to be global to make up for stupid compilers */ diff --git a/lib/misc.c b/lib/misc.c index 6a2cf401b..d0151e2c8 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -47,49 +47,6 @@ rpmRC rpmMkdirPath (const char * dpath, const char * dname) return RPMRC_OK; } -char ** splitString(const char * str, int length, char sep) -{ - const char * source; - char * s, * dest; - char ** list; - int i; - int fields; - - s = xmalloc(length + 1); - - fields = 1; - for (source = str, dest = s, i = 0; i < length; i++, source++, dest++) { - *dest = *source; - if (*dest == sep) fields++; - } - - *dest = '\0'; - - list = xmalloc(sizeof(*list) * (fields + 1)); - - dest = s; - list[0] = dest; - i = 1; - while (i < fields) { - if (*dest == sep) { - list[i++] = dest + 1; - *dest = 0; - } - dest++; - } - - list[i] = NULL; - -/* FIX: list[i] is NULL */ - return list; -} - -void freeSplitString(char ** list) -{ - list[0] = _free(list[0]); - list = _free(list); -} - int doputenv(const char *str) { char * a; diff --git a/lib/misc.h b/lib/misc.h index 180740a69..0730045f0 100644 --- a/lib/misc.h +++ b/lib/misc.h @@ -22,36 +22,6 @@ extern "C" { rpmRC rpmMkdirPath (const char * dpath, const char * dname); /** - * Split string into fields separated by a character. - * @param str string - * @param length length of string - * @param sep separator character - * @return (malloc'd) argv array - */ -char ** splitString(const char * str, int length, char sep); - -/** - * Free split string argv array. - * @param list argv array - */ -void freeSplitString( char ** list); - -/** - * Remove occurences of trailing character from string. - * @param s string - * @param c character to strip - * @return string - */ -static inline -char * stripTrailingChar(char * s, char c) -{ - char * t; - for (t = s + strlen(s) - 1; *t == c && t >= s; t--) - *t = '\0'; - return s; -} - -/** * Like the libc function, but malloc()'s the space needed. * @param name variable name * @param value variable value diff --git a/lib/rpmfi.c b/lib/rpmfi.c index 3a12cb5e7..d38b4d359 100644 --- a/lib/rpmfi.c +++ b/lib/rpmfi.c @@ -20,7 +20,7 @@ #include <rpmts.h> #include "legacy.h" /* XXX domd5 */ -#include "misc.h" /* XXX stripTrailingChar */ +#include <rpmstring.h> #include <rpmmacro.h> /* XXX rpmCleanPath */ #include "debug.h" diff --git a/lib/transaction.c b/lib/transaction.c index 23d9a8875..be028b8d6 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -28,7 +28,8 @@ #include "cpio.h" #include "fprint.h" #include "legacy.h" /* XXX domd5 */ -#include "misc.h" /* XXX (free)splitString, currentDirectory */ +#include <rpmstring.h> +#include "misc.h" /* currentDirectory */ #include "debug.h" diff --git a/rpmdb/legacy.c b/rpmdb/legacy.c index 2514d59cc..0be71e256 100644 --- a/rpmdb/legacy.c +++ b/rpmdb/legacy.c @@ -21,7 +21,7 @@ #include "rpmio_internal.h" /* XXX fdInitDigest, fdFiniDigest */ #include <rpmlib.h> #include <rpmmacro.h> -#include "misc.h" /* XXX stripTrailingChar */ +#include <rpmstring.h> #include "legacy.h" #include "debug.h" diff --git a/rpmio/rpmstring.c b/rpmio/rpmstring.c index a14f9ad92..45314bee5 100644 --- a/rpmio/rpmstring.c +++ b/rpmio/rpmstring.c @@ -23,6 +23,57 @@ static inline int xisspace(int c) { return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v'); } +char * stripTrailingChar(char * s, char c) +{ + char * t; + for (t = s + strlen(s) - 1; *t == c && t >= s; t--) + *t = '\0'; + return s; +} + +char ** splitString(const char * str, int length, char sep) +{ + const char * source; + char * s, * dest; + char ** list; + int i; + int fields; + + s = xmalloc(length + 1); + + fields = 1; + for (source = str, dest = s, i = 0; i < length; i++, source++, dest++) { + *dest = *source; + if (*dest == sep) fields++; + } + + *dest = '\0'; + + list = xmalloc(sizeof(*list) * (fields + 1)); + + dest = s; + list[0] = dest; + i = 1; + while (i < fields) { + if (*dest == sep) { + list[i++] = dest + 1; + *dest = 0; + } + dest++; + } + + list[i] = NULL; + +/* FIX: list[i] is NULL */ + return list; +} + +void freeSplitString(char ** list) +{ + list[0] = _free(list[0]); + list = _free(list); +} + StringBuf newStringBuf(void) { StringBuf sb = xmalloc(sizeof(*sb)); diff --git a/rpmio/rpmstring.h b/rpmio/rpmstring.h index ff0bdebbd..a31957e77 100644 --- a/rpmio/rpmstring.h +++ b/rpmio/rpmstring.h @@ -10,6 +10,29 @@ extern "C" { #endif /** + * Split string into fields separated by a character. + * @param str string + * @param length length of string + * @param sep separator character + * @return (malloc'd) argv array + */ +char ** splitString(const char * str, int length, char sep); + +/** + * Free split string argv array. + * @param list argv array + */ +void freeSplitString( char ** list); + +/** + * Remove occurences of trailing character from string. + * @param s string + * @param c character to strip + * @return string + */ +char * stripTrailingChar(char * s, char c); + +/** */ typedef struct StringBufRec *StringBuf; |