Blame src/internal/slibtool_txtline_impl.c

bbc13d
/*******************************************************************/
bbc13d
/*  slibtool: a strong libtool implementation, written in C        */
bbc13d
/*  Copyright (C) 2016--2024  SysDeer Technologies, LLC            */
bbc13d
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
bbc13d
/*******************************************************************/
bbc13d
bbc13d
#include <string.h>
bbc13d
#include <stdlib.h>
bbc13d
bbc13d
#include <slibtool/slibtool.h>
bbc13d
#include "slibtool_visibility_impl.h"
bbc13d
bbc13d
slbt_hidden int slbt_txtline_to_string_vector(const char * txtline, char *** pargv)
bbc13d
{
bbc13d
	int             argc;
bbc13d
	char **         argv;
bbc13d
	const char *    ch;
bbc13d
	const char *    mark;
bbc13d
bbc13d
	if (!(ch = txtline))
bbc13d
		return 0;
bbc13d
bbc13d
	argc = 1;
bbc13d
bbc13d
	for (; *ch == ' '; )
bbc13d
		ch++;
bbc13d
bbc13d
	for (; *ch; ) {
bbc13d
		if (*ch++ == ' ') {
bbc13d
			argc++;
bbc13d
bbc13d
			for (; (*ch == ' '); )
bbc13d
				ch++;
bbc13d
		}
bbc13d
	}
bbc13d
bbc13d
	if (argc == 1)
bbc13d
		return 0;
bbc13d
bbc13d
	if (!(*pargv = calloc(++argc,sizeof(char *))))
bbc13d
		return -1;
bbc13d
bbc13d
	for (ch=txtline; (*ch == ' '); ch++)
bbc13d
		(void)0;
bbc13d
bbc13d
	argv = *pargv;
bbc13d
	mark = ch;
bbc13d
bbc13d
	for (; *ch; ) {
bbc13d
		if (*ch == ' ') {
bbc13d
			if (!(*argv++ = strndup(mark,ch-mark)))
bbc13d
				return -1;
bbc13d
bbc13d
			for (; (*ch == ' '); )
bbc13d
				ch++;
bbc13d
bbc13d
			mark = ch;
bbc13d
		} else {
bbc13d
			ch++;
bbc13d
		}
bbc13d
	}
bbc13d
bbc13d
	if (!(*argv++ = strndup(mark,ch-mark)))
bbc13d
		return -1;
bbc13d
bbc13d
	return 0;
bbc13d
}