2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation, either version 3 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 /* command line parser */
16 #include "awishcommon.h"
26 #define MAX_ARGS (256)
28 static char *kMyImage
= NULL
;
34 void cmdLineParseStr (const char *cmdline
) {
36 int maxLen
= strlen(cmdline
)+64;
37 char *pbuf
= malloc(maxLen
+4);
40 if (k8argv
) free(k8argv
);
41 k8argv
= calloc(MAX_ARGS
, sizeof(char *));
43 while (*cmdline
== ' ') ++cmdline
;
46 /* check first char: quoted? */
47 if (*cmdline
== '"' || *cmdline
== '\'') {
56 while (*cmdline
&& *cmdline
!= ech
) {
58 if (ech
!= ' ' && cmdline
[0] == ech
&& cmdline
[1] == ech
) {
59 /* two quotes is just a quote */
65 //fprintf(stderr, "[%s]\n", pbuf);
66 if (k8argc
< MAX_ARGS
) k8argv
[k8argc
++] = strdup(pbuf
);
67 /* skip quote, if any */
68 if (ech
!= ' ' && cmdline
[0] == ech
) ++cmdline
;
70 while (*cmdline
== ' ') ++cmdline
;
74 if (kMyImage
== NULL
) {
75 kMyImage
= calloc(MAX_PATH
+1, 1);
76 if (kMyImage
!= NULL
) {
77 GetModuleFileName(NULL
, kMyImage
, MAX_PATH
);
78 if (k8argv
[0]) free(k8argv
[0]);
79 k8argv
[0] = strdup(kMyImage
);
85 void cmdLineParse (void) {
86 return cmdLineParseStr(GetCommandLine());