1999-12-09 23:15:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "str.h"
|
|
|
|
|
|
2000-03-30 20:28:01 +00:00
|
|
|
int
|
|
|
|
|
get_args (char **argv, char *str, int max_args)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
char *delimiters = " \n\0";
|
|
|
|
|
char *item;
|
|
|
|
|
int i = 0;
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
if (!argv)
|
|
|
|
|
return -1;
|
|
|
|
|
if (!str)
|
|
|
|
|
return 0;
|
|
|
|
|
if (max_args < 1)
|
|
|
|
|
return 0;
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2007-06-17 10:39:49 +00:00
|
|
|
//debug("get_args(%i): string=%s", max_args, str);
|
2000-03-30 20:28:01 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
// Parse the command line...
|
|
|
|
|
for (item = strtok (str, delimiters); item; item = strtok (NULL, delimiters)) {
|
2007-06-17 10:39:49 +00:00
|
|
|
//debug("get_args: item=%s", item);
|
2000-04-03 22:13:57 +00:00
|
|
|
if (i < max_args) {
|
|
|
|
|
argv[i] = item;
|
|
|
|
|
i++;
|
|
|
|
|
} else
|
|
|
|
|
return i;
|
|
|
|
|
}
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
return i;
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|