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
23 #define _POSIX_C_SOURCE 200809L
31 *----------------------------------------------------------------------
33 * Divides a command line into a argv/argc pair.
34 *----------------------------------------------------------------------
49 static DFA mtable
[9][6] = {
50 {{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
51 {{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
52 {{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
53 {{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
54 {{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
55 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
56 {{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
57 {{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
58 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
62 next_token(char *word
, char **next
)
68 t
= ret
= malloc(strlen(word
)+1);
70 fprintf(stderr
, "Insufficient memory.\n");
86 else if (*ptr
==' ' || *ptr
=='\t')
91 if (mtable
[state
][ctype
].output
) {
95 state
= mtable
[state
][ctype
].nstate
;
97 if (mtable
[state
][0].output
<0) {
119 parse_command(char *command
, char ***argv
, int *argc
)
121 LinkedList
*list
= NULL
;
127 token
= next_token(line
, &line
);
129 list
= list_cons(token
, list
);
131 } while (token
!=NULL
&& line
!=NULL
);
133 count
= list_length(list
);
134 *argv
= malloc(sizeof(char*)*count
);
137 (*argv
)[--i
] = list
->head
;
138 list_remove_head(&list
);
144 execCommand(char *command
)
150 parse_command(command
, &argv
, &argc
);
156 if ((pid
=fork())==0) {
160 args
= malloc(sizeof(char*)*(argc
+1));
163 for (i
=0; i
<argc
; i
++) {
167 execvp(argv
[0], args
);