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

jan.nijtmans 2012-10-26 08:19 UTC trunk
Commit cbb24cf854fc03528f5745ceb671b7d7ca6a1657
1 file changed +3 -13
+3 -13
--- src/main.c
+++ src/main.c
@@ -476,13 +476,12 @@
476476
int n; /* Number of bytes in one line */
477477
char *z; /* General use string pointer */
478478
char **newArgv; /* New expanded g.argv under construction */
479479
char const * zFileName; /* input file name */
480480
FILE * zInFile; /* input FILE */
481
- int foundBom = -1; /* -1= not searched yet, 0 = no; 1=yes */
482481
#ifdef _WIN32
483
- wchar_t buf[MAX_PATH];
482
+ WCHAR buf[MAX_PATH];
484483
#endif
485484
486485
g.argc = argc;
487486
g.argv = argv;
488487
#ifdef _WIN32
@@ -514,10 +513,11 @@
514513
if(stdin != zInFile){
515514
fclose(zInFile);
516515
}
517516
zInFile = NULL;
518517
}
518
+ blob_strip_bom(&file, 1);
519519
z = blob_str(&file);
520520
for(k=0, nLine=1; z[k]; k++) if( z[k]=='\n' ) nLine++;
521521
newArgv = fossil_malloc( sizeof(char*)*(g.argc + nLine*2) );
522522
for(j=0; j<i; j++) newArgv[j] = g.argv[j];
523523
@@ -524,24 +524,14 @@
524524
blob_rewind(&file);
525525
while( (n = blob_line(&file, &line))>0 ){
526526
if( n<=1 ) continue;
527527
z = blob_buffer(&line);
528528
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
- }
536529
if((n>1) && ('\r'==z[n-2])){
537530
if(n==2) continue /*empty line*/;
538531
z[n-2] = 0;
539532
}
540
- if (!foundBom) {
541
- z = fossil_mbcs_to_utf8(z);
542
- }
543533
newArgv[j++] = z;
544534
if( z[0]=='-' ){
545535
for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
546536
if( z[k] ){
547537
z[k] = 0;
@@ -850,11 +840,11 @@
850840
#if defined(_WIN32)
851841
/* On windows, we have to put double-quotes around the entire command.
852842
** Who knows why - this is just the way windows works.
853843
*/
854844
char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
855
- wchar_t *zUnicode = fossil_utf8_to_unicode(zNewCmd);
845
+ WCHAR *zUnicode = fossil_utf8_to_unicode(zNewCmd);
856846
if( g.fSystemTrace ) {
857847
char *zOut = mprintf("SYSTEM: %s\n", zNewCmd);
858848
fossil_puts(zOut, 1);
859849
fossil_free(zOut);
860850
}
861851
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button