Fossil SCM

diff: extra empty lines in non-console output on Windows

ashepilko 2016-11-05 04:30 trunk
Commit 476fe9e932f0113314db87ed9c20d73c7f335d1f
2 files changed +13 -4 +1
+13 -4
--- src/printf.c
+++ src/printf.c
@@ -875,24 +875,33 @@
875875
/*
876876
** Write to standard output or standard error.
877877
**
878878
** On windows, transform the output into the current terminal encoding
879879
** 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.
881884
*/
882885
void fossil_puts(const char *z, int toStdErr){
886
+ FILE* out = (toStdErr ? stderr : stdout);
883887
int n = (int)strlen(z);
884888
if( n==0 ) return;
889
+ assert( toStdErr==0 || toStdErr==1 );
885890
if( toStdErr==0 ) stdoutAtBOL = (z[n-1]=='\n');
886891
#if defined(_WIN32)
887892
if( fossil_utf8_to_console(z, n, toStdErr) >= 0 ){
888893
return;
889894
}
895
+ fflush(out);
896
+ _setmode(_fileno(out), _O_BINARY);
890897
#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
894903
}
895904
896905
/*
897906
** Force the standard output cursor to move to the beginning
898907
** of a line, if it is not there already.
899908
--- 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 @@
317317
wchar_t *zUnicode; /* Unicode version of zUtf8 */
318318
DWORD dummy;
319319
Blob blob;
320320
321321
static int istty[2] = { -1, -1 };
322
+ assert( toStdErr==0 || toStdErr==1 );
322323
if( istty[toStdErr]==-1 ){
323324
istty[toStdErr] = _isatty(toStdErr + 1) != 0;
324325
}
325326
if( !istty[toStdErr] ){
326327
/* stdout/stderr is not a console. */
327328
--- 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

Keyboard Shortcuts

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