diff options
author | midipix <writeonce@midipix.org> | 2024-03-23 03:27:01 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2024-03-23 03:27:01 +0000 |
commit | bbc13d492947ef58bf7901e42e1fbed0a5ac1eda (patch) | |
tree | 11d48ed45073e86f4ccf70e911f417f894d73151 | |
parent | 41a8685b3f7beff9f2b7c5a2f7cf38fe7d5b0db2 (diff) | |
download | slibtool-bbc13d492947ef58bf7901e42e1fbed0a5ac1eda.tar.bz2 slibtool-bbc13d492947ef58bf7901e42e1fbed0a5ac1eda.tar.xz |
internals: added slbt_txtline_to_string_vector() by reusing existing code.
-rw-r--r-- | project/common.mk | 1 | ||||
-rw-r--r-- | project/headers.mk | 1 | ||||
-rw-r--r-- | src/driver/slbt_driver_ctx.c | 54 | ||||
-rw-r--r-- | src/internal/slibtool_txtline_impl.c | 67 | ||||
-rw-r--r-- | src/internal/slibtool_txtline_impl.h | 8 |
5 files changed, 79 insertions, 52 deletions
diff --git a/project/common.mk b/project/common.mk index 8373b35..1e2ae5e 100644 --- a/project/common.mk +++ b/project/common.mk @@ -80,6 +80,7 @@ INTERNAL_SRCS = \ src/internal/$(PACKAGE)_snprintf_impl.c \ src/internal/$(PACKAGE)_symlink_impl.c \ src/internal/$(PACKAGE)_tmpfile_impl.c \ + src/internal/$(PACKAGE)_txtline_impl.c \ APP_SRCS = \ src/slibtool.c diff --git a/project/headers.mk b/project/headers.mk index 8075b4b..1b77743 100644 --- a/project/headers.mk +++ b/project/headers.mk @@ -27,6 +27,7 @@ INTERNAL_HEADERS = \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_stoolie_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_symlink_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_tmpfile_impl.h \ + $(PROJECT_DIR)/src/internal/$(PACKAGE)_txtline_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_uninstall_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_visibility_impl.h \ diff --git a/src/driver/slbt_driver_ctx.c b/src/driver/slbt_driver_ctx.c index 0e17a31..956c435 100644 --- a/src/driver/slbt_driver_ctx.c +++ b/src/driver/slbt_driver_ctx.c @@ -22,6 +22,7 @@ #include "slibtool_objlist_impl.h" #include "slibtool_errinfo_impl.h" #include "slibtool_lconf_impl.h" +#include "slibtool_txtline_impl.h" #include "slibtool_ar_impl.h" #include "argv/argv.h" @@ -381,58 +382,7 @@ static int slbt_driver_fail_incompatible_args( static int slbt_driver_parse_tool_argv(const char * tool, char *** tool_argv) { - int argc; - char ** argv; - const char * ch; - const char * mark; - - if (!(ch = tool)) - return 0; - - argc = 1; - - for (; *ch == ' '; ) - ch++; - - for (; *ch; ) { - if (*ch++ == ' ') { - argc++; - - for (; (*ch == ' '); ) - ch++; - } - } - - if (argc == 1) - return 0; - - if (!(*tool_argv = calloc(++argc,sizeof(char *)))) - return -1; - - for (ch=tool; (*ch == ' '); ch++) - (void)0; - - argv = *tool_argv; - mark = ch; - - for (; *ch; ) { - if (*ch == ' ') { - if (!(*argv++ = strndup(mark,ch-mark))) - return -1; - - for (; (*ch == ' '); ) - ch++; - - mark = ch; - } else { - ch++; - } - } - - if (!(*argv++ = strndup(mark,ch-mark))) - return -1; - - return 0; + return slbt_txtline_to_string_vector(tool,tool_argv); } diff --git a/src/internal/slibtool_txtline_impl.c b/src/internal/slibtool_txtline_impl.c new file mode 100644 index 0000000..4c8f2ad --- /dev/null +++ b/src/internal/slibtool_txtline_impl.c @@ -0,0 +1,67 @@ +/*******************************************************************/ +/* slibtool: a strong libtool implementation, written in C */ +/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */ +/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */ +/*******************************************************************/ + +#include <string.h> +#include <stdlib.h> + +#include <slibtool/slibtool.h> +#include "slibtool_visibility_impl.h" + +slbt_hidden int slbt_txtline_to_string_vector(const char * txtline, char *** pargv) +{ + int argc; + char ** argv; + const char * ch; + const char * mark; + + if (!(ch = txtline)) + return 0; + + argc = 1; + + for (; *ch == ' '; ) + ch++; + + for (; *ch; ) { + if (*ch++ == ' ') { + argc++; + + for (; (*ch == ' '); ) + ch++; + } + } + + if (argc == 1) + return 0; + + if (!(*pargv = calloc(++argc,sizeof(char *)))) + return -1; + + for (ch=txtline; (*ch == ' '); ch++) + (void)0; + + argv = *pargv; + mark = ch; + + for (; *ch; ) { + if (*ch == ' ') { + if (!(*argv++ = strndup(mark,ch-mark))) + return -1; + + for (; (*ch == ' '); ) + ch++; + + mark = ch; + } else { + ch++; + } + } + + if (!(*argv++ = strndup(mark,ch-mark))) + return -1; + + return 0; +} diff --git a/src/internal/slibtool_txtline_impl.h b/src/internal/slibtool_txtline_impl.h new file mode 100644 index 0000000..2a647b1 --- /dev/null +++ b/src/internal/slibtool_txtline_impl.h @@ -0,0 +1,8 @@ +#ifndef SLIBTOOL_TXTLINE_IMPL_H +#define SLIBTOOL_TXTLINE_IMPL_H + +#include <slibtool/slibtool.h> + +int slbt_txtline_to_string_vector(const char *, char ***); + +#endif |