| 3215 | } |
| 3216 | |
| 3217 | QStringList ParseArgsList(const QString &args) |
| 3218 | { |
| 3219 | QStringList ret; |
| 3220 | |
| 3221 | if(args.isEmpty()) |
| 3222 | return ret; |
| 3223 | |
| 3224 | // on windows just use the function provided by the system |
| 3225 | #if defined(Q_OS_WIN32) |
| 3226 | std::wstring wargs = args.toStdWString(); |
| 3227 | |
| 3228 | int argc = 0; |
| 3229 | wchar_t **argv = CommandLineToArgvW(wargs.c_str(), &argc); |
| 3230 | |
| 3231 | for(int i = 0; i < argc; i++) |
| 3232 | ret << QString::fromWCharArray(argv[i]); |
| 3233 | |
| 3234 | LocalFree(argv); |
| 3235 | #else |
| 3236 | rdcstr argString = args; |
| 3237 | |
| 3238 | // perform some kind of sane parsing |
| 3239 | bool dquot = false, squot = false; // are we inside ''s or ""s |
| 3240 | |
| 3241 | // current character |
| 3242 | char *c = &argString[0]; |
| 3243 | |
| 3244 | // current argument we're building |
| 3245 | rdcstr a; |
| 3246 | |
| 3247 | while(*c) |
| 3248 | { |
| 3249 | if(!dquot && !squot && (*c == ' ' || *c == '\t')) |
| 3250 | { |
| 3251 | if(!a.empty()) |
| 3252 | ret << QString(a); |
| 3253 | |
| 3254 | a = ""; |
| 3255 | } |
| 3256 | else if(!dquot && *c == '"') |
| 3257 | { |
| 3258 | dquot = true; |
| 3259 | } |
| 3260 | else if(!squot && *c == '\'') |
| 3261 | { |
| 3262 | squot = true; |
| 3263 | } |
| 3264 | else if(dquot && *c == '"') |
| 3265 | { |
| 3266 | dquot = false; |
| 3267 | } |
| 3268 | else if(squot && *c == '\'') |
| 3269 | { |
| 3270 | squot = false; |
| 3271 | } |
| 3272 | else if(squot) |
| 3273 | { |
| 3274 | // single quotes don't escape, just copy literally until we leave single quote mode |