Files
libucore/src/ucore_getfields.c
T
Nils O. Selåsdal 16e1ac52ec Coding style change
2012-12-05 18:53:58 +01:00

39 lines
704 B
C

#include <string.h>
#include <ucore/ucore_string.h>
int
getfields(char *str, char **args, int max, int mflag, const char *set)
{
char r;
int intok, narg;
if (max <= 0)
return 0;
narg = 0;
args[narg] = str;
if (!mflag)
narg++;
intok = 0;
for (;; str++) {
r = *str;
if (r == 0)
break;
if (strchr(set, r)) {
if (narg >= max)
break;
*str = 0;
intok = 0;
args[narg] = str + 1;
if (!mflag)
narg++;
} else {
if (!intok && mflag)
narg++;
intok = 1;
}
}
return narg;
}