1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
/*
\funcref{fun\_fields}{void fun\_fields ()}
{}
{}
{}
{fun\makelist(), addtolist()}
{funfield.c}
{
This function is executed upon an opcode {\em op\_fields}. The last
pushed string is converted to a list, by splitting it according to the
separators which are found in the one-but-last pushed string.
When the separator-string is empty, then the string to split is split
into separate characters.
}
*/
#include "builtin.ih"
static char buf[2];
void fun_fields ()
{
char const *str = stringStr(top());
char const *sep = stringStr(top() - 1);
reg = *listConstructor();
if (*str)
{
char *string = xstrdup(str);
char *cp;
if (*sep)
{
if ((cp = strtok(string, sep)))
{
do
{
listAdd_cP(®, cp);
cp = strtok(NULL, sep);
}
while (cp);
}
}
else
{
cp = string;
while (*cp)
{
buf[0] = *cp++;
listAdd_cP(®, buf);
}
}
free(string);
}
}
|