sound extension fixed
[awish.git] / src / cmdline.c
blob4363004368b4be17c0d3a721becb87f6d89ea35e
1 /*
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 "cmdline.h"
18 #include <windows.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
25 #define MAX_ARGS (256)
27 static char *kMyImage = NULL;
29 int k8argc = 0;
30 char **k8argv = NULL;
33 void cmdLineParseStr (const char *cmdline) {
34 char ech, *cp;
35 int maxLen = strlen(cmdline)+64;
36 char *pbuf = malloc(maxLen+4);
38 /* skip spaces */
39 if (k8argv) free(k8argv);
40 k8argv = calloc(MAX_ARGS, sizeof(char *));
41 k8argc = 0;
42 while (*cmdline == ' ') ++cmdline;
43 /* parse args */
44 while (*cmdline) {
45 /* check first char: quoted? */
46 if (*cmdline == '"' || *cmdline == '\'') {
47 /* quoted arg */
48 ech = *cmdline++;
49 } else {
50 /* normal arg */
51 ech = ' ';
53 /* collect chars */
54 cp = pbuf;
55 while (*cmdline && *cmdline != ech) {
56 *cp++ = *cmdline++;
57 if (ech != ' ' && cmdline[0] == ech && cmdline[1] == ech) {
58 /* two quotes is just a quote */
59 *cp++ = *cmdline++;
60 ++cmdline;
63 *cp = '\0';
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;
68 /* skip spaces */
69 while (*cmdline == ' ') ++cmdline;
71 free(pbuf);
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());