Fossil SCM
diff: extra empty lines in non-console output on Windows
Commit
476fe9e932f0113314db87ed9c20d73c7f335d1f
Parent
c1a77615cac26cb…
2 files changed
+13
-4
+1
+13
-4
| --- src/printf.c | ||
| +++ src/printf.c | ||
| @@ -875,24 +875,33 @@ | ||
| 875 | 875 | /* |
| 876 | 876 | ** Write to standard output or standard error. |
| 877 | 877 | ** |
| 878 | 878 | ** On windows, transform the output into the current terminal encoding |
| 879 | 879 | ** if the output is going to the screen. If output is redirected into |
| 880 | -** a file, no translation occurs. No translation ever occurs on unix. | |
| 880 | +** a file, no translation occurs. Switch output mode to binary to | |
| 881 | +** properly process line-endings, make sure to switch the mode back to | |
| 882 | +** text when done. | |
| 883 | +** No translation ever occurs on unix. | |
| 881 | 884 | */ |
| 882 | 885 | void fossil_puts(const char *z, int toStdErr){ |
| 886 | + FILE* out = (toStdErr ? stderr : stdout); | |
| 883 | 887 | int n = (int)strlen(z); |
| 884 | 888 | if( n==0 ) return; |
| 889 | + assert( toStdErr==0 || toStdErr==1 ); | |
| 885 | 890 | if( toStdErr==0 ) stdoutAtBOL = (z[n-1]=='\n'); |
| 886 | 891 | #if defined(_WIN32) |
| 887 | 892 | if( fossil_utf8_to_console(z, n, toStdErr) >= 0 ){ |
| 888 | 893 | return; |
| 889 | 894 | } |
| 895 | + fflush(out); | |
| 896 | + _setmode(_fileno(out), _O_BINARY); | |
| 890 | 897 | #endif |
| 891 | - assert( toStdErr==0 || toStdErr==1 ); | |
| 892 | - fwrite(z, 1, n, toStdErr ? stderr : stdout); | |
| 893 | - fflush(toStdErr ? stderr : stdout); | |
| 898 | + fwrite(z, 1, n, out); | |
| 899 | +#if defined(_WIN32) | |
| 900 | + fflush(out); | |
| 901 | + _setmode(_fileno(out), _O_TEXT); | |
| 902 | +#endif | |
| 894 | 903 | } |
| 895 | 904 | |
| 896 | 905 | /* |
| 897 | 906 | ** Force the standard output cursor to move to the beginning |
| 898 | 907 | ** of a line, if it is not there already. |
| 899 | 908 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -875,24 +875,33 @@ | |
| 875 | /* |
| 876 | ** Write to standard output or standard error. |
| 877 | ** |
| 878 | ** On windows, transform the output into the current terminal encoding |
| 879 | ** if the output is going to the screen. If output is redirected into |
| 880 | ** a file, no translation occurs. No translation ever occurs on unix. |
| 881 | */ |
| 882 | void fossil_puts(const char *z, int toStdErr){ |
| 883 | int n = (int)strlen(z); |
| 884 | if( n==0 ) return; |
| 885 | if( toStdErr==0 ) stdoutAtBOL = (z[n-1]=='\n'); |
| 886 | #if defined(_WIN32) |
| 887 | if( fossil_utf8_to_console(z, n, toStdErr) >= 0 ){ |
| 888 | return; |
| 889 | } |
| 890 | #endif |
| 891 | assert( toStdErr==0 || toStdErr==1 ); |
| 892 | fwrite(z, 1, n, toStdErr ? stderr : stdout); |
| 893 | fflush(toStdErr ? stderr : stdout); |
| 894 | } |
| 895 | |
| 896 | /* |
| 897 | ** Force the standard output cursor to move to the beginning |
| 898 | ** of a line, if it is not there already. |
| 899 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -875,24 +875,33 @@ | |
| 875 | /* |
| 876 | ** Write to standard output or standard error. |
| 877 | ** |
| 878 | ** On windows, transform the output into the current terminal encoding |
| 879 | ** if the output is going to the screen. If output is redirected into |
| 880 | ** a file, no translation occurs. Switch output mode to binary to |
| 881 | ** properly process line-endings, make sure to switch the mode back to |
| 882 | ** text when done. |
| 883 | ** No translation ever occurs on unix. |
| 884 | */ |
| 885 | void fossil_puts(const char *z, int toStdErr){ |
| 886 | FILE* out = (toStdErr ? stderr : stdout); |
| 887 | int n = (int)strlen(z); |
| 888 | if( n==0 ) return; |
| 889 | assert( toStdErr==0 || toStdErr==1 ); |
| 890 | if( toStdErr==0 ) stdoutAtBOL = (z[n-1]=='\n'); |
| 891 | #if defined(_WIN32) |
| 892 | if( fossil_utf8_to_console(z, n, toStdErr) >= 0 ){ |
| 893 | return; |
| 894 | } |
| 895 | fflush(out); |
| 896 | _setmode(_fileno(out), _O_BINARY); |
| 897 | #endif |
| 898 | fwrite(z, 1, n, out); |
| 899 | #if defined(_WIN32) |
| 900 | fflush(out); |
| 901 | _setmode(_fileno(out), _O_TEXT); |
| 902 | #endif |
| 903 | } |
| 904 | |
| 905 | /* |
| 906 | ** Force the standard output cursor to move to the beginning |
| 907 | ** of a line, if it is not there already. |
| 908 |
+1
| --- src/utf8.c | ||
| +++ src/utf8.c | ||
| @@ -317,10 +317,11 @@ | ||
| 317 | 317 | wchar_t *zUnicode; /* Unicode version of zUtf8 */ |
| 318 | 318 | DWORD dummy; |
| 319 | 319 | Blob blob; |
| 320 | 320 | |
| 321 | 321 | static int istty[2] = { -1, -1 }; |
| 322 | + assert( toStdErr==0 || toStdErr==1 ); | |
| 322 | 323 | if( istty[toStdErr]==-1 ){ |
| 323 | 324 | istty[toStdErr] = _isatty(toStdErr + 1) != 0; |
| 324 | 325 | } |
| 325 | 326 | if( !istty[toStdErr] ){ |
| 326 | 327 | /* stdout/stderr is not a console. */ |
| 327 | 328 |
| --- src/utf8.c | |
| +++ src/utf8.c | |
| @@ -317,10 +317,11 @@ | |
| 317 | wchar_t *zUnicode; /* Unicode version of zUtf8 */ |
| 318 | DWORD dummy; |
| 319 | Blob blob; |
| 320 | |
| 321 | static int istty[2] = { -1, -1 }; |
| 322 | if( istty[toStdErr]==-1 ){ |
| 323 | istty[toStdErr] = _isatty(toStdErr + 1) != 0; |
| 324 | } |
| 325 | if( !istty[toStdErr] ){ |
| 326 | /* stdout/stderr is not a console. */ |
| 327 |
| --- src/utf8.c | |
| +++ src/utf8.c | |
| @@ -317,10 +317,11 @@ | |
| 317 | wchar_t *zUnicode; /* Unicode version of zUtf8 */ |
| 318 | DWORD dummy; |
| 319 | Blob blob; |
| 320 | |
| 321 | static int istty[2] = { -1, -1 }; |
| 322 | assert( toStdErr==0 || toStdErr==1 ); |
| 323 | if( istty[toStdErr]==-1 ){ |
| 324 | istty[toStdErr] = _isatty(toStdErr + 1) != 0; |
| 325 | } |
| 326 | if( !istty[toStdErr] ){ |
| 327 | /* stdout/stderr is not a console. */ |
| 328 |