Fossil SCM
Make sure that find_option() is called before the argument check for the test-looks-like-utf command.
Commit
fd2fbdb965a1f50e1067d755b92832ace5f60fa6
Parent
e545d3514e29b96…
1 file changed
+6
-5
+6
-5
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -361,11 +361,11 @@ | ||
| 361 | 361 | } |
| 362 | 362 | if( c==0 ){ |
| 363 | 363 | flags |= LOOK_NUL; /* NUL character in a file -> binary */ |
| 364 | 364 | }else if( c=='\r' ){ |
| 365 | 365 | flags |= LOOK_CR; |
| 366 | - if( n<2*sizeof(WCHAR_T) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){ | |
| 366 | + if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){ | |
| 367 | 367 | flags |= LOOK_LONE_CR; /* More chars, next char is not LF */ |
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | 370 | j = (c!='\n'); |
| 371 | 371 | if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */ |
| @@ -2600,19 +2600,20 @@ | ||
| 2600 | 2600 | int fUtf16; /* return value of starts_with_utf16_bom() */ |
| 2601 | 2601 | int fUnicode; /* return value of could_be_utf16() */ |
| 2602 | 2602 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| 2603 | 2603 | int bRevUtf16 = 0; /* non-zero -> UTF-16 byte order reversed */ |
| 2604 | 2604 | int bRevUnicode = 0; /* non-zero -> UTF-16 byte order reversed */ |
| 2605 | + int fForceUtf8 = find_option("utf8",0,0)!=0; | |
| 2606 | + int fForceUtf16 = find_option("utf16",0,0)!=0; | |
| 2605 | 2607 | if( g.argc!=3 ) usage("FILENAME"); |
| 2606 | 2608 | blob_read_from_file(&blob, g.argv[2]); |
| 2607 | 2609 | fUtf8 = starts_with_utf8_bom(&blob, 0); |
| 2608 | 2610 | fUtf16 = starts_with_utf16_bom(&blob, 0, &bRevUtf16); |
| 2609 | - fUnicode = could_be_utf16(&blob, &bRevUnicode); | |
| 2610 | - if( find_option("utf8",0,0)!=0 ){ | |
| 2611 | + if( fForceUtf8 ){ | |
| 2611 | 2612 | fUnicode = 0; |
| 2612 | - }else if( find_option("utf16",0,0)!=0 ){ | |
| 2613 | - fUnicode = 1; | |
| 2613 | + }else{ | |
| 2614 | + fUnicode = could_be_utf16(&blob, &bRevUnicode) || fForceUtf16; | |
| 2614 | 2615 | } |
| 2615 | 2616 | lookFlags = fUnicode ? looks_like_utf16(&blob, bRevUnicode, 0) : |
| 2616 | 2617 | looks_like_utf8(&blob, 0); |
| 2617 | 2618 | fossil_print("File \"%s\" has %d bytes.\n",g.argv[2],blob_size(&blob)); |
| 2618 | 2619 | fossil_print("Starts with UTF-8 BOM: %s\n",fUtf8?"yes":"no"); |
| 2619 | 2620 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -361,11 +361,11 @@ | |
| 361 | } |
| 362 | if( c==0 ){ |
| 363 | flags |= LOOK_NUL; /* NUL character in a file -> binary */ |
| 364 | }else if( c=='\r' ){ |
| 365 | flags |= LOOK_CR; |
| 366 | if( n<2*sizeof(WCHAR_T) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){ |
| 367 | flags |= LOOK_LONE_CR; /* More chars, next char is not LF */ |
| 368 | } |
| 369 | } |
| 370 | j = (c!='\n'); |
| 371 | if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */ |
| @@ -2600,19 +2600,20 @@ | |
| 2600 | int fUtf16; /* return value of starts_with_utf16_bom() */ |
| 2601 | int fUnicode; /* return value of could_be_utf16() */ |
| 2602 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| 2603 | int bRevUtf16 = 0; /* non-zero -> UTF-16 byte order reversed */ |
| 2604 | int bRevUnicode = 0; /* non-zero -> UTF-16 byte order reversed */ |
| 2605 | if( g.argc!=3 ) usage("FILENAME"); |
| 2606 | blob_read_from_file(&blob, g.argv[2]); |
| 2607 | fUtf8 = starts_with_utf8_bom(&blob, 0); |
| 2608 | fUtf16 = starts_with_utf16_bom(&blob, 0, &bRevUtf16); |
| 2609 | fUnicode = could_be_utf16(&blob, &bRevUnicode); |
| 2610 | if( find_option("utf8",0,0)!=0 ){ |
| 2611 | fUnicode = 0; |
| 2612 | }else if( find_option("utf16",0,0)!=0 ){ |
| 2613 | fUnicode = 1; |
| 2614 | } |
| 2615 | lookFlags = fUnicode ? looks_like_utf16(&blob, bRevUnicode, 0) : |
| 2616 | looks_like_utf8(&blob, 0); |
| 2617 | fossil_print("File \"%s\" has %d bytes.\n",g.argv[2],blob_size(&blob)); |
| 2618 | fossil_print("Starts with UTF-8 BOM: %s\n",fUtf8?"yes":"no"); |
| 2619 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -361,11 +361,11 @@ | |
| 361 | } |
| 362 | if( c==0 ){ |
| 363 | flags |= LOOK_NUL; /* NUL character in a file -> binary */ |
| 364 | }else if( c=='\r' ){ |
| 365 | flags |= LOOK_CR; |
| 366 | if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){ |
| 367 | flags |= LOOK_LONE_CR; /* More chars, next char is not LF */ |
| 368 | } |
| 369 | } |
| 370 | j = (c!='\n'); |
| 371 | if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */ |
| @@ -2600,19 +2600,20 @@ | |
| 2600 | int fUtf16; /* return value of starts_with_utf16_bom() */ |
| 2601 | int fUnicode; /* return value of could_be_utf16() */ |
| 2602 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| 2603 | int bRevUtf16 = 0; /* non-zero -> UTF-16 byte order reversed */ |
| 2604 | int bRevUnicode = 0; /* non-zero -> UTF-16 byte order reversed */ |
| 2605 | int fForceUtf8 = find_option("utf8",0,0)!=0; |
| 2606 | int fForceUtf16 = find_option("utf16",0,0)!=0; |
| 2607 | if( g.argc!=3 ) usage("FILENAME"); |
| 2608 | blob_read_from_file(&blob, g.argv[2]); |
| 2609 | fUtf8 = starts_with_utf8_bom(&blob, 0); |
| 2610 | fUtf16 = starts_with_utf16_bom(&blob, 0, &bRevUtf16); |
| 2611 | if( fForceUtf8 ){ |
| 2612 | fUnicode = 0; |
| 2613 | }else{ |
| 2614 | fUnicode = could_be_utf16(&blob, &bRevUnicode) || fForceUtf16; |
| 2615 | } |
| 2616 | lookFlags = fUnicode ? looks_like_utf16(&blob, bRevUnicode, 0) : |
| 2617 | looks_like_utf8(&blob, 0); |
| 2618 | fossil_print("File \"%s\" has %d bytes.\n",g.argv[2],blob_size(&blob)); |
| 2619 | fossil_print("Starts with UTF-8 BOM: %s\n",fUtf8?"yes":"no"); |
| 2620 |