aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/commas.c22
-rw-r--r--lib/lib.h1
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/commas.c b/lib/commas.c
index 03b2e345..22676847 100644
--- a/lib/commas.c
+++ b/lib/commas.c
@@ -59,7 +59,7 @@ char *comma_iterate(char **list, int *len)
return start;
}
-// check all instances of opt and "no"opt in optlist, return true if opt
+// Check all instances of opt and "no"opt in optlist, return true if opt
// found and last instance wasn't no. If clean, remove each instance from list.
int comma_scan(char *optlist, char *opt, int clean)
{
@@ -97,3 +97,23 @@ int comma_scanall(char *optlist, char *scanlist)
return i;
}
+
+// Returns true and removes `opt` from `optlist` if present, false otherwise.
+// Doesn't have the magic "no" behavior of comma_scan.
+int comma_remove(char *optlist, char *opt)
+{
+ int optlen = strlen(opt), len, got = 0;
+
+ if (optlist) for (;;) {
+ char *s = comma_iterate(&optlist, &len);
+
+ if (!s) break;
+ if (optlen == len && !strncmp(opt, s, optlen)) {
+ got = 1;
+ if (optlist) memmove(s, optlist, strlen(optlist)+1);
+ else *s = 0;
+ }
+ }
+
+ return got;
+}
diff --git a/lib/lib.h b/lib/lib.h
index b74cfbff..e354a82a 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -366,6 +366,7 @@ void comma_collate(char **old, char *new);
char *comma_iterate(char **list, int *len);
int comma_scan(char *optlist, char *opt, int clean);
int comma_scanall(char *optlist, char *scanlist);
+int comma_remove(char *optlist, char *opt);
// deflate.c