23 static DFA mtable
[9][6] = {
24 {{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
25 {{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
26 {{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
27 {{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
28 {{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
29 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
30 {{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
31 {{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
32 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
36 wtokennext(char *word
, char **next
)
42 t
= ret
= wmalloc(strlen(word
)+1);
56 else if (*ptr
==' ' || *ptr
=='\t')
61 if (mtable
[state
][ctype
].output
) {
65 state
= mtable
[state
][ctype
].nstate
;
67 if (mtable
[state
][0].output
<0) {
88 /* separate a string in tokens, taking " and ' into account */
90 wtokensplit(char *command
, char ***argv
, int *argc
)
98 token
= wtokennext(line
, &line
);
101 *argv
= wmalloc(sizeof(char**));
103 *argv
= wrealloc(*argv
, (count
+1)*sizeof(char**));
104 (*argv
)[count
++] = token
;
106 } while (token
!=NULL
&& line
!=NULL
);
116 wtokenjoin(char **list
, int count
)
119 char *flat_string
, *wspace
;
122 for (i
=0; i
<count
; i
++) {
123 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
124 j
+= strlen(list
[i
]);
125 if (strpbrk(list
[i
], " \t"))
130 flat_string
= wmalloc(j
+count
+1);
133 for (i
=0; i
<count
; i
++) {
134 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
136 strcat(flat_string
, " ");
137 wspace
= strpbrk(list
[i
], " \t");
139 strcat(flat_string
, "\"");
140 strcat(flat_string
, list
[i
]);
142 strcat(flat_string
, "\"");
152 wtokenfree(char **tokens
, int count
)
154 while (--count
) wfree(tokens
[count
]);
166 while (isspace(*s
) && *s
) s
++;
168 while (t
> s
&& isspace(*t
)) t
--;