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 next_token(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
= next_token(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
= malloc(j
+count
+1);
136 for (i
=0; i
<count
; i
++) {
137 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
139 strcat(flat_string
, " ");
140 wspace
= strpbrk(list
[i
], " \t");
142 strcat(flat_string
, "\"");
143 strcat(flat_string
, list
[i
]);
145 strcat(flat_string
, "\"");
155 wtokenfree(char **tokens
, int count
)
157 while (--count
) free(tokens
[count
]);
169 while (isspace(*s
) && *s
) s
++;
171 while (t
> s
&& isspace(*t
)) t
--;
173 c
= wmalloc(t
-s
+ 1);