From b2b9914ad30a6c9cfc0eace52b409bcbb846738f Mon Sep 17 00:00:00 2001 From: amol Date: Sun, 14 Feb 2021 09:03:54 -0800 Subject: [PATCH] code cleanup. --- win32/Win10.termcap.c | 2 -- win32/nt.char.c | 48 +++++++++++++++++++++++++++++ win32/nt.screen.c | 72 ++++--------------------------------------- win32/ntport.h | 1 + 4 files changed, 55 insertions(+), 68 deletions(-) diff --git a/win32/Win10.termcap.c b/win32/Win10.termcap.c index f1ec861a..9922f603 100644 --- a/win32/Win10.termcap.c +++ b/win32/Win10.termcap.c @@ -35,8 +35,6 @@ #include "sh.h" -extern int nt_getsize(int*,int*,int*); - #define CAPABLEN 2 #define ISSPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n') diff --git a/win32/nt.char.c b/win32/nt.char.c index 6aa08e16..1a7ba7fb 100644 --- a/win32/nt.char.c +++ b/win32/nt.char.c @@ -43,6 +43,9 @@ static HMODULE hlangdll; extern DWORD gdwPlatform; +extern Char get_or_cache_utf8_mb(uint32_t inChar); +extern uint32_t get_cached_utf8_mb(Char); +extern void clear_utf8_maps(); #if !defined(WINNT_NATIVE_UTF8_SUPPORT) unsigned char oem_it(unsigned char ch) { @@ -169,5 +172,50 @@ NLSStringWidth(const Char *s) { return (int)Strlen(s); } +Char nt_make_utf8_multibyte(Char* cp, int len) { + + uint32_t mbchar = 0; + + if(len == 1){ + return *cp; + } + for(Char i = 0; i < len;i++) { + mbchar <<= 8; + mbchar |= *cp; + cp++; + } + Char i = get_or_cache_utf8_mb(mbchar); + return i | NT_UTF8_MB; +} #endif// WINNT_NATIVE_UTF8_SUPPORT +void putraw_utf8(Char c) { +#if defined(WINNT_NATIVE_UTF8_SUPPORT) + if (c & NT_UTF8_MB) { + Char index = c & ~NT_UTF8_MB; + if (index >= 0 && index < NT_UTF8_MB) { + uint32_t mbchar = get_cached_utf8_mb(index); + int start = 0; + // + // there have to be at least 2 bytes in the utf8 sequence + // (otherwise we would not have marked it with NT_UTF8_MB.) + // + if ((mbchar & 0xFF000000) == 0) { + start++; + } + if((mbchar & 0xFFFF0000) == 0) { + start = 2; + } + for(int i =start; i < 4;i++) { + unsigned char by = (mbchar >> (3-i)*8) & 0xFF; + putraw(by); + } + } + } + else { + putraw(c); + } +#else + putraw(c); +#endif +} diff --git a/win32/nt.screen.c b/win32/nt.screen.c index a6b6b224..44fc7613 100644 --- a/win32/nt.screen.c +++ b/win32/nt.screen.c @@ -1,3 +1,4 @@ +#ifndef WINNT_NATIVE_UTF8_SUPPORT /* * ed.screen.c: Editor/termcap-curses interface */ @@ -30,8 +31,6 @@ * SUCH DAMAGE. */ #include "sh.h" - - #include "ed.h" #include "tc.h" #include "ed.defns.h" @@ -54,29 +53,21 @@ extern void NT_ClearEOD( void) ; extern void NT_ClearScreen(void) ; extern void NT_WrapHorizontal(void); -#ifndef SIG_WINDOW -static int GetSize(int *lins, int *cols); -#endif +int GetSize(int *lins, int *cols); -#ifndef WINNT_NATIVE_UTF8_SUPPORT int DisplayWindowHSize; void terminit(void) { return; } -#endif //WINNT_NATIVE_UTF8_SUPPORT int T_ActualWindowSize; static void ReBufferDisplay (void); -extern Char get_or_cache_utf8_mb(uint32_t inChar); -extern uint32_t get_cached_utf8_mb(Char); -extern void clear_utf8_maps(); -#ifndef WINNT_NATIVE_UTF8_SUPPORT /*ARGSUSED*/ void TellTC(void) @@ -126,9 +117,7 @@ ReBufferDisplay(void) clear_utf8_maps(); } -#endif -#ifndef WINNT_NATIVE_UTF8_SUPPORT void SetTC(char *what, char *how) { @@ -323,56 +312,7 @@ MoveToChar(int where) NT_MoveToLineOrChar(where, 0); CursorH = where; /* now where is here */ } -#endif // WINNT_NATIVE_UTF8_SUPPORT - -#ifdef WINNT_NATIVE_UTF8_SUPPORT -Char nt_make_utf8_multibyte(Char* cp, int len) { - - uint32_t mbchar = 0; - if(len == 1){ - return *cp; - } - for(Char i = 0; i < len;i++) { - mbchar <<= 8; - mbchar |= *cp; - cp++; - } - Char i = get_or_cache_utf8_mb(mbchar); - return i | NT_UTF8_MB; -} -#endif // WINNT_NATIVE_UTF8_SUPPORT -void putraw_utf8(Char c) { -#if defined(WINNT_NATIVE_UTF8_SUPPORT) - if (c & NT_UTF8_MB) { - Char index = c & ~NT_UTF8_MB; - if (index >= 0 && index < NT_UTF8_MB) { - uint32_t mbchar = get_cached_utf8_mb(index); - int start = 0; - // - // there have to be at least 2 bytes in the utf8 sequence - // (otherwise we would not have marked it with NT_UTF8_MB.) - // - if ((mbchar & 0xFF000000) == 0) { - start++; - } - if((mbchar & 0xFFFF0000) == 0) { - start = 2; - } - for(int i =start; i < 4;i++) { - unsigned char by = (mbchar >> (3-i)*8) & 0xFF; - putraw(by); - } - } - } - else { - putraw(c); - } -#else - putraw(c); -#endif -} -#ifndef WINNT_NATIVE_UTF8_SUPPORT void so_write(register Char *cp, register int n) { @@ -524,12 +464,11 @@ GetTermCaps(void) return; } -#ifndef SIG_WINDOW /* GetSize(): * Return the new window size in lines and cols, and * true if the size was changed. */ - int +int GetSize(int *lins, int *cols) { @@ -551,8 +490,7 @@ GetSize(int *lins, int *cols) return ret; } -#endif // SIG_WINDOW - void +void ChangeSize(int lins, int cols) { @@ -602,5 +540,7 @@ void StartHighlight(void) void StopHighlight(void) { } +#else +#pragma warning(disable : 4206) //nonstandard extension used: translation unit is empty #endif // WINNT_NATIVE_UTF8_SUPPORT diff --git a/win32/ntport.h b/win32/ntport.h index b91372c8..763e68f6 100644 --- a/win32/ntport.h +++ b/win32/ntport.h @@ -414,6 +414,7 @@ extern void nt_set_size(int,int); //extern void set_raw_mode(HANDLE); //extern void set_arbitrary_mode(HANDLE,DWORD); extern void set_attributes(const unsigned char *color); +extern int nt_getsize(int*,int*,int*); /* ../sh.exec.c */ extern int nt_check_if_windir(char *);