Commit 4db73567 authored by DailyShana's avatar DailyShana

fix getting command args

parent 37fb1db6
......@@ -63,9 +63,57 @@ int main(int argc, char* argv[]) {
wchar_t* command = GetCommandLineW();
char buffer[2048];
BufferIO::EncodeUTF8(command, buffer);
argv[0] = strtok(buffer, " ");
for(int i = 1; i < argc; ++i)
argv[i] = strtok(NULL, " ");
char* p = buffer;
argc = 0;
int j = 0;
bool in_QM = false, in_TEXT = false, in_SPACE = true;
while(*p) {
if(in_QM) {
if(*p == '\"')
in_QM = false;
else
++j;
} else {
switch(*p) {
case '\"': {
in_QM = true;
in_TEXT = true;
if(in_SPACE) {
argv[argc] = p + 1;
j = 0;
}
in_SPACE = FALSE;
break;
}
case ' ':
case '\t':
case '\n':
case '\r': {
if(in_TEXT) {
argv[argc][j] = '\0';
++argc;
}
in_TEXT = FALSE;
in_SPACE = TRUE;
break;
}
default: {
in_TEXT = TRUE;
if(in_SPACE) {
argv[argc] = p;
j = 1;
} else
++j;
in_SPACE = FALSE;
break;
}
}
}
++p;
}
argv[argc][j] = '\0';
++argc;
argv[argc] = NULL;
#endif // _WIN32
bool keep_on_return = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment