From bbc13d492947ef58bf7901e42e1fbed0a5ac1eda Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 23 Mar 2024 03:27:01 +0000 Subject: internals: added slbt_txtline_to_string_vector() by reusing existing code. --- src/internal/slibtool_txtline_impl.c | 67 ++++++++++++++++++++++++++++++++++++ src/internal/slibtool_txtline_impl.h | 8 +++++ 2 files changed, 75 insertions(+) create mode 100644 src/internal/slibtool_txtline_impl.c create mode 100644 src/internal/slibtool_txtline_impl.h (limited to 'src/internal') 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 +#include + +#include +#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 + +int slbt_txtline_to_string_vector(const char *, char ***); + +#endif -- cgit v1.2.3