25
static DFA mtable[9][6] = {
26
{{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
27
{{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
28
{{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
29
{{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
30
{{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
31
{{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
32
{{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
33
{{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
34
{{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
38
wtokennext(char *word, char **next)
44
t = ret = wmalloc(strlen(word)+1);
58
else if (*ptr==' ' || *ptr=='\t')
63
if (mtable[state][ctype].output) {
67
state = mtable[state][ctype].nstate;
69
if (mtable[state][0].output<0) {
90
/* separate a string in tokens, taking " and ' into account */
92
wtokensplit(char *command, char ***argv, int *argc)
100
token = wtokennext(line, &line);
103
*argv = wmalloc(sizeof(char**));
105
*argv = wrealloc(*argv, (count+1)*sizeof(char**));
106
(*argv)[count++] = token;
108
} while (token!=NULL && line!=NULL);
118
wtokenjoin(char **list, int count)
121
char *flat_string, *wspace;
124
for (i=0; i<count; i++) {
125
if (list[i]!=NULL && list[i][0]!=0) {
126
j += strlen(list[i]);
127
if (strpbrk(list[i], " \t"))
132
flat_string = wmalloc(j+count+1);
135
for (i=0; i<count; i++) {
136
if (list[i]!=NULL && list[i][0]!=0) {
138
strcat(flat_string, " ");
139
wspace = strpbrk(list[i], " \t");
141
strcat(flat_string, "\"");
142
strcat(flat_string, list[i]);
144
strcat(flat_string, "\"");
154
wtokenfree(char **tokens, int count)
156
while (--count) wfree(tokens[count]);
168
while (isspace(*s) && *s) s++;
170
while (t > s && isspace(*t)) t--;
185
return strcpy(wmalloc(strlen(str)+1), str);
190
wstrndup(char *str, size_t len)
196
len = WMIN(len, strlen(str));
197
copy = strncpy(wmalloc(len+1), str, len);
205
wstrconcat(char *str1, char *str2)
210
return wstrdup(str2);
212
return wstrdup(str1);
214
str = wmalloc(strlen(str1)+strlen(str2)+1);
223
wstrappend(char *dst, char *src)
227
else if (!src || *src==0)
230
dst = wrealloc(dst, strlen(dst)+strlen(src)+1);
237
#ifndef HAVE_STRCASECMP
239
strcasecmp(const char *s1, const char *s2)
241
while (*s1 && *s2 && (tolower(*s1)==tolower(*s2))) {
246
return (tolower(*s1) - tolower(*s2));