| | @@ -344,126 +344,10 @@ |
| 344 | 344 | free(g.zErrMsg); |
| 345 | 345 | if(g.db){ |
| 346 | 346 | db_close(0); |
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | | - |
| 350 | | -#if defined(_WIN32) && !defined(__MINGW32__) |
| 351 | | -/* |
| 352 | | -** Parse the command-line arguments passed to windows. We do this |
| 353 | | -** ourselves to work around bugs in the command-line parsing of MinGW. |
| 354 | | -** It is possible (in theory) to only use this routine when compiling |
| 355 | | -** with MinGW and to use built-in command-line parsing for MSVC and |
| 356 | | -** MinGW-64. However, the code is here, it is efficient, and works, and |
| 357 | | -** by using it in all cases we do a better job of testing it. If you suspect |
| 358 | | -** a bug in this code, test your theory by invoking "fossil test-echo". |
| 359 | | -** |
| 360 | | -** This routine is copied from TCL with some reformatting. |
| 361 | | -** The original comment text follows: |
| 362 | | -** |
| 363 | | -** Parse the Windows command line string into argc/argv. Done here |
| 364 | | -** because we don't trust the builtin argument parser in crt0. Windows |
| 365 | | -** applications are responsible for breaking their command line into |
| 366 | | -** arguments. |
| 367 | | -** |
| 368 | | -** 2N backslashes + quote -> N backslashes + begin quoted string |
| 369 | | -** 2N + 1 backslashes + quote -> literal |
| 370 | | -** N backslashes + non-quote -> literal |
| 371 | | -** quote + quote in a quoted string -> single quote |
| 372 | | -** quote + quote not in quoted string -> empty string |
| 373 | | -** quote -> begin quoted string |
| 374 | | -** |
| 375 | | -** Results: |
| 376 | | -** Fills argcPtr with the number of arguments and argvPtr with the array |
| 377 | | -** of arguments. |
| 378 | | -*/ |
| 379 | | -#define wchar_isspace(X) ((X)==' ' || (X)=='\t') |
| 380 | | -static void parse_windows_command_line( |
| 381 | | - int *argcPtr, /* Filled with number of argument strings. */ |
| 382 | | - void *argvPtr /* Filled with argument strings (malloc'd). */ |
| 383 | | -){ |
| 384 | | - WCHAR *cmdLine, *p, *arg, *argSpace; |
| 385 | | - WCHAR **argv; |
| 386 | | - int argc, size, inquote, copy, slashes; |
| 387 | | - |
| 388 | | - cmdLine = GetCommandLineW(); |
| 389 | | - |
| 390 | | - /* |
| 391 | | - ** Precompute an overly pessimistic guess at the number of arguments in |
| 392 | | - ** the command line by counting non-space spans. |
| 393 | | - */ |
| 394 | | - size = 2; |
| 395 | | - for(p=cmdLine; *p!='\0'; p++){ |
| 396 | | - if( wchar_isspace(*p) ){ |
| 397 | | - size++; |
| 398 | | - while( wchar_isspace(*p) ){ |
| 399 | | - p++; |
| 400 | | - } |
| 401 | | - if( *p=='\0' ){ |
| 402 | | - break; |
| 403 | | - } |
| 404 | | - } |
| 405 | | - } |
| 406 | | - |
| 407 | | - argSpace = fossil_malloc(size * sizeof(char*) |
| 408 | | - + (wcslen(cmdLine) * sizeof(WCHAR)) + sizeof(WCHAR)); |
| 409 | | - argv = (WCHAR**)argSpace; |
| 410 | | - argSpace += size*(sizeof(char*)/sizeof(WCHAR)); |
| 411 | | - size--; |
| 412 | | - |
| 413 | | - p = cmdLine; |
| 414 | | - for(argc=0; argc<size; argc++){ |
| 415 | | - argv[argc] = arg = argSpace; |
| 416 | | - while( wchar_isspace(*p) ){ |
| 417 | | - p++; |
| 418 | | - } |
| 419 | | - if (*p == '\0') { |
| 420 | | - break; |
| 421 | | - } |
| 422 | | - inquote = 0; |
| 423 | | - slashes = 0; |
| 424 | | - while(1){ |
| 425 | | - copy = 1; |
| 426 | | - while( *p=='\\' ){ |
| 427 | | - slashes++; |
| 428 | | - p++; |
| 429 | | - } |
| 430 | | - if( *p=='"' ){ |
| 431 | | - if( (slashes&1)==0 ){ |
| 432 | | - copy = 0; |
| 433 | | - if( inquote && p[1]=='"' ){ |
| 434 | | - p++; |
| 435 | | - copy = 1; |
| 436 | | - }else{ |
| 437 | | - inquote = !inquote; |
| 438 | | - } |
| 439 | | - } |
| 440 | | - slashes >>= 1; |
| 441 | | - } |
| 442 | | - while( slashes ){ |
| 443 | | - *arg = '\\'; |
| 444 | | - arg++; |
| 445 | | - slashes--; |
| 446 | | - } |
| 447 | | - if( *p=='\0' || (!inquote && wchar_isspace(*p)) ){ |
| 448 | | - break; |
| 449 | | - } |
| 450 | | - if( copy!=0 ){ |
| 451 | | - *arg = *p; |
| 452 | | - arg++; |
| 453 | | - } |
| 454 | | - p++; |
| 455 | | - } |
| 456 | | - *arg = '\0'; |
| 457 | | - argSpace = arg + 1; |
| 458 | | - } |
| 459 | | - argv[argc] = NULL; |
| 460 | | - *argcPtr = argc; |
| 461 | | - *((WCHAR ***)argvPtr) = argv; |
| 462 | | -} |
| 463 | | -#endif /* defined(_WIN32) && !defined(__MINGW32__) */ |
| 464 | | - |
| 465 | 349 | |
| 466 | 350 | /* |
| 467 | 351 | ** Convert all arguments from mbcs (or unicode) to UTF-8. Then |
| 468 | 352 | ** search g.argv for arguments "--args FILENAME". If found, then |
| 469 | 353 | ** (1) remove the two arguments from g.argv |
| | @@ -482,27 +366,23 @@ |
| 482 | 366 | int n; /* Number of bytes in one line */ |
| 483 | 367 | char *z; /* General use string pointer */ |
| 484 | 368 | char **newArgv; /* New expanded g.argv under construction */ |
| 485 | 369 | char const * zFileName; /* input file name */ |
| 486 | 370 | FILE * zInFile; /* input FILE */ |
| 487 | | -#if defined(_WIN32) && !defined(__MINGW32__) |
| 371 | +#if defined(_WIN32) |
| 488 | 372 | WCHAR buf[MAX_PATH]; |
| 489 | 373 | #endif |
| 490 | 374 | |
| 491 | 375 | g.argc = argc; |
| 492 | 376 | g.argv = argv; |
| 493 | | -#if defined(_WIN32) && !defined(__MINGW32__) |
| 494 | | - parse_windows_command_line(&g.argc, &g.argv); |
| 377 | +#if defined(_WIN32) |
| 495 | 378 | GetModuleFileNameW(NULL, buf, MAX_PATH); |
| 496 | 379 | g.nameOfExe = fossil_filename_to_utf8(buf); |
| 497 | | - for(i=0; i<g.argc; i++) g.argv[i] = fossil_filename_to_utf8(g.argv[i]); |
| 498 | | -#elif defined(__APPLE__) |
| 499 | | - for(i=0; i<g.argc; i++) g.argv[i] = fossil_filename_to_utf8(g.argv[i]); |
| 500 | | - g.nameOfExe = g.argv[0]; |
| 501 | 380 | #else |
| 502 | 381 | g.nameOfExe = g.argv[0]; |
| 503 | 382 | #endif |
| 383 | + for(i=0; i<g.argc; i++) g.argv[i] = fossil_filename_to_utf8(g.argv[i]); |
| 504 | 384 | for(i=1; i<g.argc-1; i++){ |
| 505 | 385 | z = g.argv[i]; |
| 506 | 386 | if( z[0]!='-' ) continue; |
| 507 | 387 | z++; |
| 508 | 388 | if( z[0]=='-' ) z++; |
| | @@ -569,15 +449,21 @@ |
| 569 | 449 | zNewArgv[i] = fossil_strdup(argv[i]); |
| 570 | 450 | } |
| 571 | 451 | return zNewArgv; |
| 572 | 452 | } |
| 573 | 453 | #endif |
| 454 | + |
| 574 | 455 | |
| 575 | 456 | /* |
| 576 | 457 | ** This procedure runs first. |
| 577 | 458 | */ |
| 459 | +#ifdef _WIN32 |
| 460 | +int _dowildcard = -1; /* This turns on command-line globbing in MinGW-w64 */ |
| 461 | +int wmain(int argc, wchar_t **argv) |
| 462 | +#else |
| 578 | 463 | int main(int argc, char **argv) |
| 464 | +#endif |
| 579 | 465 | { |
| 580 | 466 | const char *zCmdName = "unknown"; |
| 581 | 467 | int idx; |
| 582 | 468 | int rc; |
| 583 | 469 | |
| 584 | 470 | |