Fossil SCM
use blob_strip_blob in main.c <p>This has the effect that on Windows the --args file accepts a unicode file, starting with a UTF-16 BOM as well
Commit
cbb24cf854fc03528f5745ceb671b7d7ca6a1657
Parent
511405f4268502e…
1 file changed
+3
-13
+3
-13
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -476,13 +476,12 @@ | ||
| 476 | 476 | int n; /* Number of bytes in one line */ |
| 477 | 477 | char *z; /* General use string pointer */ |
| 478 | 478 | char **newArgv; /* New expanded g.argv under construction */ |
| 479 | 479 | char const * zFileName; /* input file name */ |
| 480 | 480 | FILE * zInFile; /* input FILE */ |
| 481 | - int foundBom = -1; /* -1= not searched yet, 0 = no; 1=yes */ | |
| 482 | 481 | #ifdef _WIN32 |
| 483 | - wchar_t buf[MAX_PATH]; | |
| 482 | + WCHAR buf[MAX_PATH]; | |
| 484 | 483 | #endif |
| 485 | 484 | |
| 486 | 485 | g.argc = argc; |
| 487 | 486 | g.argv = argv; |
| 488 | 487 | #ifdef _WIN32 |
| @@ -514,10 +513,11 @@ | ||
| 514 | 513 | if(stdin != zInFile){ |
| 515 | 514 | fclose(zInFile); |
| 516 | 515 | } |
| 517 | 516 | zInFile = NULL; |
| 518 | 517 | } |
| 518 | + blob_strip_bom(&file, 1); | |
| 519 | 519 | z = blob_str(&file); |
| 520 | 520 | for(k=0, nLine=1; z[k]; k++) if( z[k]=='\n' ) nLine++; |
| 521 | 521 | newArgv = fossil_malloc( sizeof(char*)*(g.argc + nLine*2) ); |
| 522 | 522 | for(j=0; j<i; j++) newArgv[j] = g.argv[j]; |
| 523 | 523 | |
| @@ -524,24 +524,14 @@ | ||
| 524 | 524 | blob_rewind(&file); |
| 525 | 525 | while( (n = blob_line(&file, &line))>0 ){ |
| 526 | 526 | if( n<=1 ) continue; |
| 527 | 527 | z = blob_buffer(&line); |
| 528 | 528 | z[n-1] = 0; |
| 529 | - if (foundBom == -1) { | |
| 530 | - static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; | |
| 531 | - foundBom = memcmp(z, bom, 3)==0; | |
| 532 | - if( foundBom ) { | |
| 533 | - z += 3; n -= 3; | |
| 534 | - } | |
| 535 | - } | |
| 536 | 529 | if((n>1) && ('\r'==z[n-2])){ |
| 537 | 530 | if(n==2) continue /*empty line*/; |
| 538 | 531 | z[n-2] = 0; |
| 539 | 532 | } |
| 540 | - if (!foundBom) { | |
| 541 | - z = fossil_mbcs_to_utf8(z); | |
| 542 | - } | |
| 543 | 533 | newArgv[j++] = z; |
| 544 | 534 | if( z[0]=='-' ){ |
| 545 | 535 | for(k=1; z[k] && !fossil_isspace(z[k]); k++){} |
| 546 | 536 | if( z[k] ){ |
| 547 | 537 | z[k] = 0; |
| @@ -850,11 +840,11 @@ | ||
| 850 | 840 | #if defined(_WIN32) |
| 851 | 841 | /* On windows, we have to put double-quotes around the entire command. |
| 852 | 842 | ** Who knows why - this is just the way windows works. |
| 853 | 843 | */ |
| 854 | 844 | char *zNewCmd = mprintf("\"%s\"", zOrigCmd); |
| 855 | - wchar_t *zUnicode = fossil_utf8_to_unicode(zNewCmd); | |
| 845 | + WCHAR *zUnicode = fossil_utf8_to_unicode(zNewCmd); | |
| 856 | 846 | if( g.fSystemTrace ) { |
| 857 | 847 | char *zOut = mprintf("SYSTEM: %s\n", zNewCmd); |
| 858 | 848 | fossil_puts(zOut, 1); |
| 859 | 849 | fossil_free(zOut); |
| 860 | 850 | } |
| 861 | 851 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -476,13 +476,12 @@ | |
| 476 | int n; /* Number of bytes in one line */ |
| 477 | char *z; /* General use string pointer */ |
| 478 | char **newArgv; /* New expanded g.argv under construction */ |
| 479 | char const * zFileName; /* input file name */ |
| 480 | FILE * zInFile; /* input FILE */ |
| 481 | int foundBom = -1; /* -1= not searched yet, 0 = no; 1=yes */ |
| 482 | #ifdef _WIN32 |
| 483 | wchar_t buf[MAX_PATH]; |
| 484 | #endif |
| 485 | |
| 486 | g.argc = argc; |
| 487 | g.argv = argv; |
| 488 | #ifdef _WIN32 |
| @@ -514,10 +513,11 @@ | |
| 514 | if(stdin != zInFile){ |
| 515 | fclose(zInFile); |
| 516 | } |
| 517 | zInFile = NULL; |
| 518 | } |
| 519 | z = blob_str(&file); |
| 520 | for(k=0, nLine=1; z[k]; k++) if( z[k]=='\n' ) nLine++; |
| 521 | newArgv = fossil_malloc( sizeof(char*)*(g.argc + nLine*2) ); |
| 522 | for(j=0; j<i; j++) newArgv[j] = g.argv[j]; |
| 523 | |
| @@ -524,24 +524,14 @@ | |
| 524 | blob_rewind(&file); |
| 525 | while( (n = blob_line(&file, &line))>0 ){ |
| 526 | if( n<=1 ) continue; |
| 527 | z = blob_buffer(&line); |
| 528 | z[n-1] = 0; |
| 529 | if (foundBom == -1) { |
| 530 | static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; |
| 531 | foundBom = memcmp(z, bom, 3)==0; |
| 532 | if( foundBom ) { |
| 533 | z += 3; n -= 3; |
| 534 | } |
| 535 | } |
| 536 | if((n>1) && ('\r'==z[n-2])){ |
| 537 | if(n==2) continue /*empty line*/; |
| 538 | z[n-2] = 0; |
| 539 | } |
| 540 | if (!foundBom) { |
| 541 | z = fossil_mbcs_to_utf8(z); |
| 542 | } |
| 543 | newArgv[j++] = z; |
| 544 | if( z[0]=='-' ){ |
| 545 | for(k=1; z[k] && !fossil_isspace(z[k]); k++){} |
| 546 | if( z[k] ){ |
| 547 | z[k] = 0; |
| @@ -850,11 +840,11 @@ | |
| 850 | #if defined(_WIN32) |
| 851 | /* On windows, we have to put double-quotes around the entire command. |
| 852 | ** Who knows why - this is just the way windows works. |
| 853 | */ |
| 854 | char *zNewCmd = mprintf("\"%s\"", zOrigCmd); |
| 855 | wchar_t *zUnicode = fossil_utf8_to_unicode(zNewCmd); |
| 856 | if( g.fSystemTrace ) { |
| 857 | char *zOut = mprintf("SYSTEM: %s\n", zNewCmd); |
| 858 | fossil_puts(zOut, 1); |
| 859 | fossil_free(zOut); |
| 860 | } |
| 861 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -476,13 +476,12 @@ | |
| 476 | int n; /* Number of bytes in one line */ |
| 477 | char *z; /* General use string pointer */ |
| 478 | char **newArgv; /* New expanded g.argv under construction */ |
| 479 | char const * zFileName; /* input file name */ |
| 480 | FILE * zInFile; /* input FILE */ |
| 481 | #ifdef _WIN32 |
| 482 | WCHAR buf[MAX_PATH]; |
| 483 | #endif |
| 484 | |
| 485 | g.argc = argc; |
| 486 | g.argv = argv; |
| 487 | #ifdef _WIN32 |
| @@ -514,10 +513,11 @@ | |
| 513 | if(stdin != zInFile){ |
| 514 | fclose(zInFile); |
| 515 | } |
| 516 | zInFile = NULL; |
| 517 | } |
| 518 | blob_strip_bom(&file, 1); |
| 519 | z = blob_str(&file); |
| 520 | for(k=0, nLine=1; z[k]; k++) if( z[k]=='\n' ) nLine++; |
| 521 | newArgv = fossil_malloc( sizeof(char*)*(g.argc + nLine*2) ); |
| 522 | for(j=0; j<i; j++) newArgv[j] = g.argv[j]; |
| 523 | |
| @@ -524,24 +524,14 @@ | |
| 524 | blob_rewind(&file); |
| 525 | while( (n = blob_line(&file, &line))>0 ){ |
| 526 | if( n<=1 ) continue; |
| 527 | z = blob_buffer(&line); |
| 528 | z[n-1] = 0; |
| 529 | if((n>1) && ('\r'==z[n-2])){ |
| 530 | if(n==2) continue /*empty line*/; |
| 531 | z[n-2] = 0; |
| 532 | } |
| 533 | newArgv[j++] = z; |
| 534 | if( z[0]=='-' ){ |
| 535 | for(k=1; z[k] && !fossil_isspace(z[k]); k++){} |
| 536 | if( z[k] ){ |
| 537 | z[k] = 0; |
| @@ -850,11 +840,11 @@ | |
| 840 | #if defined(_WIN32) |
| 841 | /* On windows, we have to put double-quotes around the entire command. |
| 842 | ** Who knows why - this is just the way windows works. |
| 843 | */ |
| 844 | char *zNewCmd = mprintf("\"%s\"", zOrigCmd); |
| 845 | WCHAR *zUnicode = fossil_utf8_to_unicode(zNewCmd); |
| 846 | if( g.fSystemTrace ) { |
| 847 | char *zOut = mprintf("SYSTEM: %s\n", zNewCmd); |
| 848 | fossil_puts(zOut, 1); |
| 849 | fossil_free(zOut); |
| 850 | } |
| 851 |