From 46619984b7dd0b796733e710fce79f9c03cc42b6 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Tue, 14 Oct 2025 15:34:30 +0200 Subject: Reworked option filter functions Escaping is now done with backslashes. Escaped options are correctly handed over to fuse3. --- src/misc.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/misc.h') diff --git a/src/misc.h b/src/misc.h index 07c0472..9d4eede 100644 --- a/src/misc.h +++ b/src/misc.h @@ -35,6 +35,8 @@ int count_substrs(const char *s, const char *sub); an end character is reached. */ char *strdup_until(const char *s, const char *endchars); +char *strdup_or_die(const char *s); + /* Like sprintf but writes to an automatically malloc'ed buffer. */ char *sprintf_new(const char *format, ...); @@ -57,16 +59,19 @@ const char *my_dirname(char *path); Assumes 'strlen(prefix) == prefix_len'. */ bool path_starts_with(const char *path, const char* prefix, size_t prefix_len); -/* Filters arguments in comma-separated lists prefixed by '-o'. - * Allocates 'new_argv' and its strings, as well as some temporary data, into 'arena'. */ -void filter_o_opts( - bool (*keep)(const char* opt), - int argc, - const char * const *argv, - int *new_argc, - char ***new_argv, - struct arena *arena -); +char *strtok_escape_r(char *str, const char *delim, char escape, char **saveptr); +char *strtok_escape(char *str, const char *delim, char escape); + +/* NEW: like above, but preserves the backslash in the token ("\," stays two chars) */ +char *strtok_escape_preserve_r(char *str, const char *delim, char escape, char **saveptr); +char *strtok_escape_preserve(char *str, const char *delim, char escape); + +void filter_o_opts(bool (*keep_option)(const char *opt), + int argc_in, + const char * const *argv_in, + int *argc_out, + char ***argv_out, + struct arena *arena); /* Reallocs `*array` (may be NULL) to be at least one larger than `*capacity` (may be 0) and stores the new capacity -- cgit v1.2.3