Skip to content

Commit

Permalink
code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
amoldeshpande committed Jun 2, 2021
1 parent 0d6d26b commit b2b9914
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 68 deletions.
2 changes: 0 additions & 2 deletions win32/Win10.termcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
48 changes: 48 additions & 0 deletions win32/nt.char.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

72 changes: 6 additions & 66 deletions win32/nt.screen.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifndef WINNT_NATIVE_UTF8_SUPPORT
/*
* ed.screen.c: Editor/termcap-curses interface
*/
Expand Down Expand Up @@ -30,8 +31,6 @@
* SUCH DAMAGE.
*/
#include "sh.h"


#include "ed.h"
#include "tc.h"
#include "ed.defns.h"
Expand All @@ -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)
Expand Down Expand Up @@ -126,9 +117,7 @@ ReBufferDisplay(void)

clear_utf8_maps();
}
#endif

#ifndef WINNT_NATIVE_UTF8_SUPPORT
void
SetTC(char *what, char *how)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{

Expand All @@ -551,8 +490,7 @@ GetSize(int *lins, int *cols)

return ret;
}
#endif // SIG_WINDOW
void
void
ChangeSize(int lins, int cols)
{

Expand Down Expand Up @@ -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

1 change: 1 addition & 0 deletions win32/ntport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down

0 comments on commit b2b9914

Please sign in to comment.