I discovered this too whilst writing my puzzle competition entry. I had to write my own command line parser. It parses it into the standard c/c++ argc/argv format so after parsing it I pass it to a fake main() function just because i feel more comfortable and it looks more "right" - you can completly skip that function if you wish though
My game only needed a quick simple read of the arguments, you may wish to make the code in my davemain() function a bit more complex. and you might wish to change the name
anyway this will parse the command line directly:
void davemain(int argc, char * argv[]) {
if (argc > 1) {
sprintf(cmdl, "%s", argv[1]);
sprintf(cmdl2, "%s", argv[2]);
}
}
extern "C" {
int uisspace(int c) {
return ((c == ' ') || (c == '\t') || (c == '\r') ||
(c == '\n') || (c == '\f') || (c == '\v') ||
(c == 0x1680) || ((c >= 0x2000) && (c <= 0x200A)) ||
(c == 0x2028) || (c == 0x202f) || (c == 0x3000));
}
}
void CommandGrab() {
char *argbuf;
char *cmdline;
char **argv;
int argc;
int argc_max;
int i, q;
cmdline = GetCommandLine();
i = strlen(cmdline) + 1;
argbuf = (char *)malloc(i);
memcpy(argbuf, cmdline, i);
argc = 0;
argc_max = 64;
argv = (char **)malloc(64);
if (!argv) {
free(argbuf);
return;
}
i = 0;
/* parse commandline into argc/argv format */
while (argbuf[i]) {
while ((argbuf[i]) && (uisspace(argbuf[i])))
i++;
if (argbuf[i]) {
if ((argbuf[i] == '\'') || (argbuf[i] == '"')) {
q = argbuf[i++];
if (!argbuf[i])
break;
} else
q = 0;
argv[argc++] = &argbuf[i];
if (argc >= argc_max) {
argc_max += 64;
argv = (char **)realloc(argv, sizeof(char *) * argc_max);
if (!argv) {
free(argbuf);
return;
}
}
while ((argbuf[i]) && ((q) ? (argbuf[i] != q) : (!uisspace(argbuf[i]))))
i++;
if (argbuf[i]) {
argbuf[i] = 0;
i++;
}
}
}
argv[argc] = NULL;
/* call the fake application entry point */
davemain(argc, argv);
}
obviously davemain() needs to be prototyped. put your parsing into davemain() to whatever degreeyou need, works just like a normal main() entry point. Start the process by calling CommandGrab() at the start of the DarkSDK() function somewhere.
Hope thats usful