33 memset(
this, 0x00,
sizeof(
Keyword));
53 if (strlen(argument) < len)
return 0;
70 printf(
"'%s' does not look like a keyword!\n", _name);
77 if (!strcmp(_name, (*root)->name))
79 printf(
"Keyword '%s' encountered twice\n", _name);
83 root = &(*root)->
next;
86 Keyword *key = *root =
new Keyword(_name, _arg_num_min, _arg_num_max, _fun,
94 #define FALLOUT(key, why, ret) \
95 {printf("\n [PARSER]: '%s' --> %s!\n\n", (key), (why)); return (ret); }
108 if (argc == 1)
return 0;
111 if (!
isKeyword(argv[1]))
FALLOUT(argv[1],
"first argument is not a keyword", -1);
114 for(
int ik=1; ik<argc; ik++)
116 keys[key_num++].
start = ik;
120 for(
int ik=0; ik<key_num; ik++)
125 key->
arg_num = (ik == key_num - 1) ? argc - key->
start - 1 :
126 (key+1)->start - key->
start - 1;
129 for(
Keyword *pattern=
this; pattern; pattern=pattern->
next)
130 if (!strcmp(argv[key->
start], pattern->name))
133 if (pattern->activated &&
135 FALLOUT(pattern->name,
"key used more than once", -2);
137 if (pattern->arg_num_min != -1 && key->
arg_num < pattern->arg_num_min)
138 FALLOUT(pattern->name,
"wrong number of arguments", -3);
139 if (pattern->arg_num_max != -1 && key->
arg_num > pattern->arg_num_max)
140 FALLOUT(pattern->name,
"wrong number of arguments", -3);
142 pattern->activated = 1;
156 for(
int ik=0; ik<key_num; ik++)