Fossil

Check-in [7fd74e72]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:write unicode to console, when possible.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | eclipse-project
Files: files | file ages | folders
SHA1: 7fd74e72f8ab8a0799b7b90aa758c894e6138bb2
User & Date: jan.nijtmans 2012-09-05 08:15:12
Context
2012-09-05
09:00
fix writing to stderr console, last commit broke that. check-in: b4bab791 user: jan.nijtmans tags: eclipse-project
08:15
write unicode to console, when possible. check-in: 7fd74e72 user: jan.nijtmans tags: eclipse-project
07:31
make output to the Windows console binary-safe check-in: a830168d user: jan.nijtmans tags: eclipse-project
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/file.c.

1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
....
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
#endif
  return zValue;
}

/*
** Display UTF8 on the console.  Return the number of
** Characters written. If stdout or stderr is redirected
** to a file, so it is not a console, -1 is returned and
** nothing is written.
*/
int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
#ifdef _WIN32
  int nChar;
  WCHAR *zUnicode;   /* Unicode version of zUtf8 */
  char *zConsole;    /* Console version of zUtf8 */
  int codepage;      /* Console code page */

  static int once = 1;
  static int istty[2];
  if( once ){
    istty[0] = _isatty(fileno(stdout));
    istty[1] = _isatty(fileno(stderr));
    once = 0;
................................................................................
    return 0;
  }
  nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar);
  if( nChar==0 ){
    free(zUnicode);
    return 0;
  }
  zUnicode[nChar] = '\0';
  codepage = GetConsoleCP();
  nByte = WideCharToMultiByte(codepage, 0, zUnicode, nChar, 0, 0, 0, 0);
  zConsole = malloc( nByte + 1);
  if( zConsole==0 ){
    free(zUnicode);
    return 0;
  }
  nByte = WideCharToMultiByte(codepage, 0, zUnicode, nChar, zConsole, nByte, 0, 0);
  zConsole[nByte] = '\0';
  free(zUnicode);
  if( nByte == 0 ){
    free(zConsole);
    zConsole = 0;
    return 0;
  }
  fwrite(zConsole, 1, nByte, toStdErr ? stderr : stdout);
  fflush(toStdErr ? stderr : stdout);
  return nChar;
#else
  return -1;  /* No-op on unix */
#endif  
}

/*







|
|




|
|
<







 







|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130

1131
1132
1133
1134
1135
1136
1137
....
1147
1148
1149
1150
1151
1152
1153
1154
1155
















1156
1157
1158
1159
1160
1161
1162
#endif
  return zValue;
}

/*
** Display UTF8 on the console.  Return the number of
** Characters written. If stdout or stderr is redirected
** to a file, -1 is returned and ** nothing is written
** to the console.
*/
int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
#ifdef _WIN32
  int nChar;
  wchar_t *zUnicode; /* Unicode version of zUtf8 */
  DWORD dummy;


  static int once = 1;
  static int istty[2];
  if( once ){
    istty[0] = _isatty(fileno(stdout));
    istty[1] = _isatty(fileno(stderr));
    once = 0;
................................................................................
    return 0;
  }
  nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar);
  if( nChar==0 ){
    free(zUnicode);
    return 0;
  }
  zUnicode[nChar] = '\0';;
  WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE + toStdErr), zUnicode, nChar, &dummy, 0);
















  return nChar;
#else
  return -1;  /* No-op on unix */
#endif  
}

/*

Changes to src/printf.c.

813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
** On windows, transform the output into the current terminal encoding
** if the output is going to the screen.  If output is redirected into
** a file, no translation occurs.  No translation ever occurs on unix.
*/
void fossil_puts(const char *z, int toStdErr){
#if defined(_WIN32)
  if( fossil_utf8_to_console(z, strlen(z), toStdErr) >= 0 ){
	  return;
  }
#endif
  assert( toStdErr==0 || toStdErr==1 );
  fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
  fflush(toStdErr ? stderr : stdout);
}








|







813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
** On windows, transform the output into the current terminal encoding
** if the output is going to the screen.  If output is redirected into
** a file, no translation occurs.  No translation ever occurs on unix.
*/
void fossil_puts(const char *z, int toStdErr){
#if defined(_WIN32)
  if( fossil_utf8_to_console(z, strlen(z), toStdErr) >= 0 ){
    return;
  }
#endif
  assert( toStdErr==0 || toStdErr==1 );
  fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
  fflush(toStdErr ? stderr : stdout);
}