Initial import of libucore

This commit is contained in:
Nils O. Selåsdal
2012-10-29 23:07:32 +01:00
commit ed3866e49a
79 changed files with 6181 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
#include <string.h>
#include "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;
}