aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/termios.c2
-rw-r--r--win32/winansi.c108
2 files changed, 55 insertions, 55 deletions
diff --git a/win32/termios.c b/win32/termios.c
index 081a41e5b..11c24c8b3 100644
--- a/win32/termios.c
+++ b/win32/termios.c
@@ -128,7 +128,7 @@ int64_t FAST_FUNC windows_read_key(int fd, char *buf UNUSED_PARAM, int timeout)
128#else 128#else
129 if ( (record.Event.KeyEvent.uChar.AsciiChar & 0x80) == 0x80 ) { 129 if ( (record.Event.KeyEvent.uChar.AsciiChar & 0x80) == 0x80 ) {
130 char *s = &record.Event.KeyEvent.uChar.AsciiChar; 130 char *s = &record.Event.KeyEvent.uChar.AsciiChar;
131 OemToCharBuff(s, s, 1); 131 conToCharBuffA(s, 1);
132 } 132 }
133 ret = record.Event.KeyEvent.uChar.AsciiChar; 133 ret = record.Event.KeyEvent.uChar.AsciiChar;
134#endif 134#endif
diff --git a/win32/winansi.c b/win32/winansi.c
index faae44dac..552ccc6ca 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -7,6 +7,9 @@
7#include "lazyload.h" 7#include "lazyload.h"
8#undef PACKED 8#undef PACKED
9 9
10static BOOL charToConBuffA(LPSTR s, DWORD len);
11static BOOL charToConA(LPSTR s);
12
10/* 13/*
11 Functions to be wrapped: 14 Functions to be wrapped:
12*/ 15*/
@@ -29,10 +32,6 @@
29static WORD plain_attr = 0xffff; 32static WORD plain_attr = 0xffff;
30static WORD current_attr; 33static WORD current_attr;
31 34
32#if ENABLE_FEATURE_EURO
33static void init_codepage(void);
34#endif
35
36static HANDLE get_console(void) 35static HANDLE get_console(void)
37{ 36{
38 return GetStdHandle(STD_OUTPUT_HANDLE); 37 return GetStdHandle(STD_OUTPUT_HANDLE);
@@ -84,8 +83,12 @@ int terminal_mode(int reset)
84 static int mode = -1; 83 static int mode = -1;
85 84
86#if ENABLE_FEATURE_EURO 85#if ENABLE_FEATURE_EURO
87 if (mode < 0) 86 if (mode < 0) {
88 init_codepage(); 87 if (GetConsoleCP() == 850 && GetConsoleOutputCP() == 850) {
88 SetConsoleCP(858);
89 SetConsoleOutputCP(858);
90 }
91 }
89#endif 92#endif
90 93
91 if (mode < 0 || reset) { 94 if (mode < 0 || reset) {
@@ -543,7 +546,7 @@ static char *process_escape(char *pos)
543 (bel=strchr(pos+4, '\007')) && bel - pos < 260) { 546 (bel=strchr(pos+4, '\007')) && bel - pos < 260) {
544 /* set console title */ 547 /* set console title */
545 *bel++ = '\0'; 548 *bel++ = '\0';
546 CharToOem(pos+4, pos+4); 549 charToConA(pos+4);
547 SetConsoleTitle(pos+4); 550 SetConsoleTitle(pos+4);
548 return bel; 551 return bel;
549 } 552 }
@@ -711,78 +714,75 @@ static char *process_escape(char *pos)
711 return (char *)func + 1; 714 return (char *)func + 1;
712} 715}
713 716
714#if ENABLE_FEATURE_EURO 717static BOOL charToConBuffA(LPSTR s, DWORD len)
715static void init_codepage(void)
716{
717 if (GetConsoleCP() == 850 && GetConsoleOutputCP() == 850) {
718 SetConsoleCP(858);
719 SetConsoleOutputCP(858);
720 }
721}
722
723static BOOL winansi_CharToOemBuff(LPCSTR s, LPSTR d, DWORD len)
724{ 718{
719 UINT acp = GetACP(), conocp = GetConsoleOutputCP();
720 CPINFO acp_info, con_info;
725 WCHAR *buf; 721 WCHAR *buf;
726 int i;
727 722
728 if (GetConsoleOutputCP() != 858) 723 if (acp == conocp)
729 return CharToOemBuff(s, d, len); 724 return TRUE;
730 725
731 if (!s || !d) 726 if (!s || !GetCPInfo(acp, &acp_info) || !GetCPInfo(conocp, &con_info) ||
727 con_info.MaxCharSize > acp_info.MaxCharSize ||
728 (len == 1 && acp_info.MaxCharSize != 1))
732 return FALSE; 729 return FALSE;
733 730
734 terminal_mode(FALSE); 731 terminal_mode(FALSE);
735 buf = xmalloc(len*sizeof(WCHAR)); 732 buf = xmalloc(len*sizeof(WCHAR));
736 MultiByteToWideChar(CP_ACP, 0, s, len, buf, len); 733 MultiByteToWideChar(CP_ACP, 0, s, len, buf, len);
737 WideCharToMultiByte(CP_OEMCP, 0, buf, len, d, len, NULL, NULL); 734 WideCharToMultiByte(conocp, 0, buf, len, s, len, NULL, NULL);
738 for (i=0; i<len; ++i) { 735#if ENABLE_FEATURE_EURO
739 if (buf[i] == 0x20ac) { 736 if (conocp == 858) {
740 d[i] = 0xd5; 737 for (int i = 0; i < len; ++i) {
738 if (buf[i] == 0x20ac) {
739 s[i] = 0xd5;
740 }
741 } 741 }
742 } 742 }
743#endif
743 free(buf); 744 free(buf);
744 return TRUE; 745 return TRUE;
745} 746}
746 747
747static BOOL winansi_CharToOem(LPCSTR s, LPSTR d) 748static BOOL charToConA(LPSTR s)
748{ 749{
749 if (!s || !d) 750 if (!s)
750 return FALSE; 751 return FALSE;
751 return winansi_CharToOemBuff(s, d, strlen(s)+1); 752 return charToConBuffA(s, strlen(s)+1);
752} 753}
753 754
754#undef OemToCharBuff 755BOOL conToCharBuffA(LPSTR s, DWORD len)
755BOOL winansi_OemToCharBuff(LPCSTR s, LPSTR d, DWORD len)
756{ 756{
757 UINT acp = GetACP(), conicp = GetConsoleCP();
758 CPINFO acp_info, con_info;
757 WCHAR *buf; 759 WCHAR *buf;
758 int i;
759 760
760 if (GetConsoleCP() != 858) 761 if (acp == conicp)
761 return OemToCharBuffA(s, d, len); 762 return TRUE;
762 763
763 if (!s || !d) 764 if (!s || !GetCPInfo(acp, &acp_info) || !GetCPInfo(conicp, &con_info) ||
765 acp_info.MaxCharSize > con_info.MaxCharSize ||
766 (len == 1 && con_info.MaxCharSize != 1))
764 return FALSE; 767 return FALSE;
765 768
766 terminal_mode(FALSE); 769 terminal_mode(FALSE);
767 buf = xmalloc(len*sizeof(WCHAR)); 770 buf = xmalloc(len*sizeof(WCHAR));
768 MultiByteToWideChar(CP_OEMCP, 0, s, len, buf, len); 771 MultiByteToWideChar(conicp, 0, s, len, buf, len);
769 WideCharToMultiByte(CP_ACP, 0, buf, len, d, len, NULL, NULL); 772 WideCharToMultiByte(CP_ACP, 0, buf, len, s, len, NULL, NULL);
770 for (i=0; i<len; ++i) { 773#if ENABLE_FEATURE_EURO
771 if (buf[i] == 0x0131) { 774 if (conicp == 858) {
772 d[i] = 0x80; 775 for (int i = 0; i < len; ++i) {
776 if (buf[i] == 0x0131) {
777 s[i] = 0x80;
778 }
773 } 779 }
774 } 780 }
781#endif
775 free(buf); 782 free(buf);
776 return TRUE; 783 return TRUE;
777} 784}
778 785
779# undef CharToOemBuff
780# undef CharToOem
781# define CharToOemBuff winansi_CharToOemBuff
782# define CharToOem winansi_CharToOem
783# define OemToCharBuff winansi_OemToCharBuff
784#endif
785
786static int ansi_emulate(const char *s, FILE *stream) 786static int ansi_emulate(const char *s, FILE *stream)
787{ 787{
788 int rv = 0; 788 int rv = 0;
@@ -826,7 +826,7 @@ static int ansi_emulate(const char *s, FILE *stream)
826 826
827 if (len) { 827 if (len) {
828 *pos = '\0'; /* NB, '\033' has been overwritten */ 828 *pos = '\0'; /* NB, '\033' has been overwritten */
829 CharToOem(str, str); 829 charToConA(str);
830 if (fputs(str, stream) == EOF) 830 if (fputs(str, stream) == EOF)
831 return EOF; 831 return EOF;
832 rv += len; 832 rv += len;
@@ -849,7 +849,7 @@ static int ansi_emulate(const char *s, FILE *stream)
849 849
850 } else { 850 } else {
851 rv += strlen(str); 851 rv += strlen(str);
852 CharToOem(str, str); 852 charToConA(str);
853 return fputs(str, stream) == EOF ? EOF : rv; 853 return fputs(str, stream) == EOF ? EOF : rv;
854 } 854 }
855 } 855 }
@@ -864,7 +864,7 @@ int winansi_putchar(int c)
864 if (!is_console(STDOUT_FILENO)) 864 if (!is_console(STDOUT_FILENO))
865 return putchar(c); 865 return putchar(c);
866 866
867 CharToOemBuff(s, s, 1); 867 charToConBuffA(s, 1);
868 return putchar(t) == EOF ? EOF : (unsigned char)c; 868 return putchar(t) == EOF ? EOF : (unsigned char)c;
869} 869}
870 870
@@ -963,7 +963,7 @@ int winansi_fputc(int c, FILE *stream)
963 return ret; 963 return ret;
964 } 964 }
965 965
966 CharToOemBuff(s, s, 1); 966 charToConBuffA(s, 1);
967 return fputc(t, stream) == EOF ? EOF : (unsigned char )c; 967 return fputc(t, stream) == EOF ? EOF : (unsigned char )c;
968} 968}
969 969
@@ -1094,7 +1094,7 @@ static int ansi_emulate_write(int fd, const void *buf, size_t count)
1094 len = pos - str; 1094 len = pos - str;
1095 1095
1096 if (len) { 1096 if (len) {
1097 CharToOemBuff(str, str, len); 1097 charToConBuffA(str, len);
1098 out_len = write(fd, str, len); 1098 out_len = write(fd, str, len);
1099 if (out_len == -1) 1099 if (out_len == -1)
1100 return -1; 1100 return -1;
@@ -1111,7 +1111,7 @@ static int ansi_emulate_write(int fd, const void *buf, size_t count)
1111 pos = str; 1111 pos = str;
1112 } else { 1112 } else {
1113 len = strlen(str); 1113 len = strlen(str);
1114 CharToOem(str, str); 1114 charToConA(str);
1115 out_len = write(fd, str, len); 1115 out_len = write(fd, str, len);
1116 return (out_len == -1) ? -1 : rv+out_len; 1116 return (out_len == -1) ? -1 : rv+out_len;
1117 } 1117 }
@@ -1143,7 +1143,7 @@ int winansi_read(int fd, void *buf, size_t count)
1143 return rv; 1143 return rv;
1144 1144
1145 if ( rv > 0 ) { 1145 if ( rv > 0 ) {
1146 OemToCharBuff(buf, buf, rv); 1146 conToCharBuffA(buf, rv);
1147 } 1147 }
1148 1148
1149 return rv; 1149 return rv;
@@ -1160,7 +1160,7 @@ int winansi_getc(FILE *stream)
1160 if ( rv != EOF ) { 1160 if ( rv != EOF ) {
1161 unsigned char c = (unsigned char)rv; 1161 unsigned char c = (unsigned char)rv;
1162 char *s = (char *)&c; 1162 char *s = (char *)&c;
1163 OemToCharBuff(s, s, 1); 1163 conToCharBuffA(s, 1);
1164 rv = (int)c; 1164 rv = (int)c;
1165 } 1165 }
1166 1166