1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2001,2008 Oracle.  All rights reserved.
5 *
6 * $Id: util_arg.c,v 12.9 2008/01/08 20:58:08 bostic Exp $
7 */
8
9#include "db_config.h"
10
11#include "db_int.h"
12
13#if DB_VERSION_MAJOR < 4 || DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 5
14/*
15 * !!!
16 * We build this file in old versions of Berkeley DB when we're doing test
17 * runs using the test_micro tool.   Without a prototype in place, we get
18 * warnings, and there's no simple workaround.
19 */
20char *strsep();
21#endif
22
23/*
24 * __db_util_arg --
25 *	Convert a string into an argc/argv pair.
26 *
27 * PUBLIC: int __db_util_arg __P((char *, char *, int *, char ***));
28 */
29int
30__db_util_arg(arg0, str, argcp, argvp)
31	char *arg0, *str, ***argvp;
32	int *argcp;
33{
34	int n, ret;
35	char **ap, **argv;
36
37#define	MAXARGS	25
38	if ((ret =
39	    __os_malloc(NULL, (MAXARGS + 1) * sizeof(char **), &argv)) != 0)
40		return (ret);
41
42	ap = argv;
43	*ap++ = arg0;
44	for (n = 1; (*ap = strsep(&str, " \t")) != NULL;)
45		if (**ap != '\0') {
46			++ap;
47			if (++n == MAXARGS)
48				break;
49		}
50	*ap = NULL;
51
52	*argcp = ap - argv;
53	*argvp = argv;
54
55	return (0);
56}
57