Browse Source

added printf rewrap since it no longer works because of utf8 console output mode

Nicolas Cannasse 6 years ago
parent
commit
00a8471abf
2 changed files with 19 additions and 0 deletions
  1. 4 0
      src/hl.h
  2. 15 0
      src/std/ucs2.c

+ 4 - 0
src/hl.h

@@ -223,6 +223,10 @@ typedef wchar_t	uchar;
 #	define uprintf		wprintf
 #	define ustrlen		wcslen
 #	define ustrdup		_wcsdup
+#	ifdef HL_WIN_DESKTOP
+#		define printf		hl_win_cprintf
+HL_API void hl_win_cprintf( const char *fmt, ... );
+#	endif
 HL_API int uvszprintf( uchar *out, int out_size, const uchar *fmt, va_list arglist );
 #	define utod(s,end)	wcstod(s,end)
 #	define utoi(s,end)	wcstol(s,end,10)

+ 15 - 0
src/std/ucs2.c

@@ -261,4 +261,19 @@ sprintf_add:
 	return 0;
 }
 
+#ifdef HL_WIN
+// we can no longer use basic printf after we changed the console output encoding
+HL_PRIM void hl_win_cprintf( const char *fmt, ... ) {
+	char buf[4096];
+	uchar ubuf[4096];
+	va_list args;
+	va_start(args, fmt);
+	vsprintf(buf, fmt, args);
+	va_end(args);
+	hl_from_utf8(ubuf,4096,buf);
+	wprintf(USTR("%s"),ubuf);
+	fflush(stdout);
+}
+#endif
+
 #endif