1 /* wmgeneral miscellaneous functions
3 * from dock.c - built-in Dock module for WindowMaker window manager
5 * Copyright (c) 1997 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
30 *----------------------------------------------------------------------
32 * Divides a command line into a argv/argc pair.
33 *----------------------------------------------------------------------
48 static DFA mtable
[9][6] = {
49 {{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
50 {{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
51 {{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
52 {{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
53 {{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
54 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
55 {{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
56 {{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
57 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
61 next_token(char *word
, char **next
)
67 t
= ret
= malloc(strlen(word
)+1);
69 fprintf(stderr
, "Insufficient memory.\n");
85 else if (*ptr
==' ' || *ptr
=='\t')
90 if (mtable
[state
][ctype
].output
) {
94 state
= mtable
[state
][ctype
].nstate
;
96 if (mtable
[state
][0].output
<0) {
118 parse_command(char *command
, char ***argv
, int *argc
)
120 LinkedList
*list
= NULL
;
126 token
= next_token(line
, &line
);
128 list
= list_cons(token
, list
);
130 } while (token
!=NULL
&& line
!=NULL
);
132 count
= list_length(list
);
133 *argv
= malloc(sizeof(char*)*count
);
136 (*argv
)[--i
] = list
->head
;
137 list_remove_head(&list
);
143 execCommand(char *command
)
149 parse_command(command
, &argv
, &argc
);
155 if ((pid
=fork())==0) {
159 args
= malloc(sizeof(char*)*(argc
+1));
162 for (i
=0; i
<argc
; i
++) {
166 execvp(argv
[0], args
);