diff -uNr renameutils-0.12.0/src/editformats/getsubopt.c renameutils-0.12.0.mod/src/editformats/getsubopt.c --- renameutils-0.12.0/src/editformats/getsubopt.c 1970-01-01 03:00:00.000000000 +0300 +++ renameutils-0.12.0.mod/src/editformats/getsubopt.c 2020-01-02 20:56:21.548067937 +0200 @@ -0,0 +1,59 @@ +#include +#include +#include + +char *suboptarg; + +int +getsubopt(optionp, tokens, valuep) + char **optionp, **valuep; + char * const *tokens; +{ + int cnt; + char *p; + + /* optionp is tested below */ + + suboptarg = *valuep = NULL; + + if (!optionp || !*optionp) + return(-1); + + /* skip leading white-space, commas */ + for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); + + if (!*p) { + *optionp = p; + return(-1); + } + + /* save the start of the token, and skip the rest of the token. */ + for (suboptarg = p; + *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';); + + if (*p) { + /* + * If there's an equals sign, set the value pointer, and + * skip over the value part of the token. Terminate the + * token. + */ + if (*p == '=') { + *p = '\0'; + for (*valuep = ++p; + *p && *p != ',' && *p != ' ' && *p != '\t'; ++p); + if (*p) + *p++ = '\0'; + } else + *p++ = '\0'; + /* Skip any whitespace or commas after this token. */ + for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); + } + + /* set optionp for next round. */ + *optionp = p; + + for (cnt = 0; *tokens; ++tokens, ++cnt) + if (!strcmp(suboptarg, *tokens)) + return(cnt); + return(-1); +} diff -uNr renameutils-0.12.0/src/editformats/Makefile.am renameutils-0.12.0.mod/src/editformats/Makefile.am --- renameutils-0.12.0/src/editformats/Makefile.am 2012-04-23 14:11:26.000000000 +0300 +++ renameutils-0.12.0.mod/src/editformats/Makefile.am 2020-01-02 20:54:12.826838061 +0200 @@ -9,4 +9,5 @@ lib_editformats_a_SOURCES = \ destination-only.c \ dual-column.c \ - single-column.c + single-column.c \ + getsubopt.c diff -uNr renameutils-0.12.0/src/editformats/Makefile.in renameutils-0.12.0.mod/src/editformats/Makefile.in --- renameutils-0.12.0/src/editformats/Makefile.in 2012-04-23 14:24:11.000000000 +0300 +++ renameutils-0.12.0.mod/src/editformats/Makefile.in 2020-01-02 20:55:04.196335228 +0200 @@ -154,7 +154,7 @@ lib_editformats_a_AR = $(AR) $(ARFLAGS) lib_editformats_a_LIBADD = am_lib_editformats_a_OBJECTS = destination-only.$(OBJEXT) \ - dual-column.$(OBJEXT) single-column.$(OBJEXT) + dual-column.$(OBJEXT) single-column.$(OBJEXT) getsubopt.$(OBJEXT) lib_editformats_a_OBJECTS = $(am_lib_editformats_a_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp @@ -979,7 +979,8 @@ lib_editformats_a_SOURCES = \ destination-only.c \ dual-column.c \ - single-column.c + single-column.c \ + getsubopt.c all: all-am --- a/src/editformats/destination-only.c +++ b/src/editformats/destination-only.c @@ -36,6 +36,8 @@ #include "xalloc.h" /* Gnulib */ #include "qcmd.h" +#include "getsubopt.h" + static bool parse_options(char *options); static char *option_generator(const char *text, int state); static void output(FILE *out, LList *files); --- a/src/editformats/dual-column.c +++ b/src/editformats/dual-column.c @@ -43,6 +43,8 @@ #include "xalloc.h" /* Gnulib */ #include "qcmd.h" +#include "getsubopt.h" + static void reset_options(); static bool parse_options(char *options); static char *option_generator(const char *text, int state); --- a/src/editformats/single-column.c +++ b/src/editformats/single-column.c @@ -36,6 +36,8 @@ #include "common/llist.h" #include "qcmd.h" +#include "getsubopt.h" + static bool parse_options(char *options); static char *option_generator(const char *text, int state); static void output(FILE *out, LList *files); --- a/src/getsubopt.h +++ b/src/getsubopt.h @@ -0,0 +1,16 @@ +#ifndef _GETSUBOPT_H +#define _GETSUBOPT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined __ANDROID__ && __ANDROID_API__ < 26 +int getsubopt(char **, char *const *, char **); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _GETSUBOPT_H */