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 */
25 #define MAX_ARGS (256)
27 static char *kMyImage
= NULL
;
33 void cmdLineParseStr (const char *cmdline
) {
35 int maxLen
= strlen(cmdline
)+64;
36 char *pbuf
= malloc(maxLen
+4);
39 if (k8argv
) free(k8argv
);
40 k8argv
= calloc(MAX_ARGS
, sizeof(char *));
42 while (*cmdline
== ' ') ++cmdline
;
45 /* check first char: quoted? */
46 if (*cmdline
== '"' || *cmdline
== '\'') {
55 while (*cmdline
&& *cmdline
!= ech
) {
57 if (ech
!= ' ' && cmdline
[0] == ech
&& cmdline
[1] == ech
) {
58 /* two quotes is just a quote */
64 //fprintf(stderr, "[%s]\n", pbuf);
65 if (k8argc
< MAX_ARGS
) k8argv
[k8argc
++] = strdup(pbuf
);
66 /* skip quote, if any */
67 if (ech
!= ' ' && cmdline
[0] == ech
) ++cmdline
;
69 while (*cmdline
== ' ') ++cmdline
;
73 if (kMyImage
== NULL
) {
74 kMyImage
= calloc(MAX_PATH
+1, 1);
75 if (kMyImage
!= NULL
) {
76 GetModuleFileName(NULL
, kMyImage
, MAX_PATH
);
77 if (k8argv
[0]) free(k8argv
[0]);
78 k8argv
[0] = strdup(kMyImage
);
84 void cmdLineParse (void) {
85 return cmdLineParseStr(GetCommandLine());