diff options
author | Roy Marples <roy@marples.name> | 2007-04-27 11:24:05 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-04-27 11:24:05 +0000 |
commit | abfd181ddecbe1ecc67acbcd36a885cc6bd2a06d (patch) | |
tree | c2afebd4f76d25bc433e539e25e366a39107b79a /src/librc-strlist.c | |
parent | e6a610fbc7139130e4523965a167288da3b2d27f (diff) |
env-update now respects COLON_SEPARATED and SPACE_SEPARATED env.d values, #176198.
Diffstat (limited to 'src/librc-strlist.c')
-rw-r--r-- | src/librc-strlist.c | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/librc-strlist.c b/src/librc-strlist.c index 68491816..4c72cf45 100644 --- a/src/librc-strlist.c +++ b/src/librc-strlist.c @@ -9,7 +9,7 @@ #include "librc.h" -char **rc_strlist_add (char **list, const char *item) +static char **_rc_strlist_add (char **list, const char *item, bool uniq) { char **newlist; int i = 0; @@ -17,8 +17,11 @@ char **rc_strlist_add (char **list, const char *item) if (! item) return (list); - while (list && list[i]) + while (list && list[i]) { + if (uniq && strcmp (list[i], item) == 0) + return (list); i++; + } newlist = rc_xrealloc (list, sizeof (char *) * (i + 2)); newlist[i] = rc_xstrdup (item); @@ -26,8 +29,19 @@ char **rc_strlist_add (char **list, const char *item) return (newlist); } + +char **rc_strlist_add (char **list, const char *item) +{ + return (_rc_strlist_add (list, item, false)); +} librc_hidden_def(rc_strlist_add) +char **rc_strlist_addu (char **list, const char *item) +{ + return (_rc_strlist_add (list, item, true)); +} +librc_hidden_def(rc_strlist_addu) + static char **_rc_strlist_addsort (char **list, const char *item, int (*sortfunc) (const char *s1, const char *s2), @@ -107,6 +121,39 @@ char **rc_strlist_delete (char **list, const char *item) } librc_hidden_def(rc_strlist_delete) +char **rc_strlist_join (char **this, char **that) +{ + char **newlist; + int i = 0; + int j = 0; + + if (! this && that) + return (that); + if (! that && this) + return (this); + if (! that && ! this) + return (NULL); + + while (this[i]) + i++; + + while (that[j]) + j++; + + newlist = rc_xrealloc (this, sizeof (char *) * (i + j + 1)); + + j = 0; + while (that[j]) { + newlist[i] = that[j]; + i++; + j++; + } + newlist[i] = NULL; + + return (newlist); +} +librc_hidden_def(rc_strlist_join) + void rc_strlist_reverse (char **list) { char *item; |