section, category and icon fixes
[awish.git] / src / cmdline.c
blobbe185b5a7c4dcc1d6bcdf5e0c94013fab03237f9
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 "awishcommon.h"
17 #include "cmdline.h"
19 #include <windows.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
26 #define MAX_ARGS (256)
28 static char *kMyImage = NULL;
30 int k8argc = 0;
31 char **k8argv = NULL;
34 void cmdLineParseStr (const char *cmdline) {
35 char ech, *cp;
36 int maxLen = strlen(cmdline)+64;
37 char *pbuf = malloc(maxLen+4);
39 /* skip spaces */
40 if (k8argv) free(k8argv);
41 k8argv = calloc(MAX_ARGS, sizeof(char *));
42 k8argc = 0;
43 while (*cmdline == ' ') ++cmdline;
44 /* parse args */
45 while (*cmdline) {
46 /* check first char: quoted? */
47 if (*cmdline == '"' || *cmdline == '\'') {
48 /* quoted arg */
49 ech = *cmdline++;
50 } else {
51 /* normal arg */
52 ech = ' ';
54 /* collect chars */
55 cp = pbuf;
56 while (*cmdline && *cmdline != ech) {
57 *cp++ = *cmdline++;
58 if (ech != ' ' && cmdline[0] == ech && cmdline[1] == ech) {
59 /* two quotes is just a quote */
60 *cp++ = *cmdline++;
61 ++cmdline;
64 *cp = '\0';
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;
69 /* skip spaces */
70 while (*cmdline == ' ') ++cmdline;
72 free(pbuf);
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());