File: field.c

package info (click to toggle)
icmake 6.30-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,360 kB
  • ctags: 1,415
  • sloc: ansic: 7,727; makefile: 1,465; sh: 244; asm: 126; cpp: 39
file content (65 lines) | stat: -rw-r--r-- 1,226 bytes parent folder | download
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(&reg, cp);
                    cp = strtok(NULL, sep);
                }
                while (cp);
            }
        }
        else
        {
            cp = string;
            while (*cp)
            {
                buf[0] = *cp++;
                listAdd_cP(&reg, buf);
            }
        }
        free(string);
    }
}