From 4847d8c58946909a7a500371b4fb29eb38958c73 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Tue, 16 Jun 2020 14:09:44 +0800 Subject: [PATCH] Merge NetBSD adaptation. --- Makefile | 8 ++++++-- lock.c | 4 ++++ pklock.c | 4 ++++ posix.c | 2 +- tcap.c | 12 ++++++------ utf8.c | 7 +++++-- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 6941088..077a7e0 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ uname_S := $(shell sh -c 'echo $(uname_S) | sed s/_.*$$//') PROGRAM=ue CC=gcc -WARNINGS=-pedantic -Wall -Wextra -Wstrict-prototypes -Wno-unused-parameter -Wimplicit-fallthrough=2 +WARNINGS=-pedantic -Wall -Wextra -Wstrict-prototypes -Wno-unused-parameter CFLAGS=-O2 $(WARNINGS) #CC=c89 +O3 # HP #CFLAGS= -D_HPUX_SOURCE -DSYSV @@ -51,6 +51,10 @@ ifeq ($(uname_S),MINGW32) DEFINES=-DAUTOCONF -DPOSIX -DSYSV -DPROGRAM=$(PROGRAM) -IC:/MinGW/include/ncursesw LIBS= endif +ifeq ($(uname_S),NetBSD) + DEFINES=-DAUTOCONF -DPOSIX -DBSD=1 -DPROGRAM=$(PROGRAM) + LIBS=-lcurses +endif #DEFINES=-DAUTOCONF #LIBS=-ltermcap # BSD #LIBS=-lcurses # SYSV @@ -130,7 +134,7 @@ depend: ${SRC} $(Q) ${CC} ${CFLAGS} ${DEFINES} -c $*.c # DO NOT DELETE THIS LINE -- make depend uses it -# Updated Mon Nov 25 12:50:00 CST 2019 +# Updated Tue Jun 16 13:25:24 CST 2020 basic.o: basic.c basic.h retcode.h input.h bind.h mlout.h random.h \ terminal.h defines.h utf8.h window.h buffer.h line.h diff --git a/lock.c b/lock.c index 2e7c99b..4c0f40e 100644 --- a/lock.c +++ b/lock.c @@ -24,7 +24,11 @@ #include "pklock.h" #endif +#if BSD +#include +#else #include +#endif #define NLOCKS 100 /* max # of file locks active */ static char *lname[ NLOCKS] ; /* names of all locked files */ diff --git a/pklock.c b/pklock.c index efea64c..6f98f57 100644 --- a/pklock.c +++ b/pklock.c @@ -93,7 +93,11 @@ char *dolock( const char *fname) ** logname = getlogin() ; ** strcpy( locker, logname ? logname : cuserid( NULL)) ; */ +#if BSD + strcpy( locker, getlogin()) ; +#else strcpy( locker, cuserid( NULL)) ; +#endif strcat(locker + strlen(locker), "@"); gethostname(locker + strlen(locker), 64); diff --git a/posix.c b/posix.c index c9f535d..29b1a37 100644 --- a/posix.c +++ b/posix.c @@ -33,7 +33,7 @@ int ttcol = HUGE ; /* Column location of HW cursor */ /* Since Mac OS X's termios.h doesn't have the following 2 macros, define them. */ -#if defined(SYSV) && (defined(_DARWIN_C_SOURCE) || defined(_FREEBSD_C_SOURCE)) +#if BSD || defined(SYSV) && (defined(_DARWIN_C_SOURCE) || defined(_FREEBSD_C_SOURCE)) #define OLCUC 0000002 #define XCASE 0000004 #endif diff --git a/tcap.c b/tcap.c index 86aa9a5..7d62909 100644 --- a/tcap.c +++ b/tcap.c @@ -74,7 +74,7 @@ static void tcapscroll_delins(int from, int to, int linestoscroll); #define TCAPSLEN 315 static char tcapbuf[TCAPSLEN]; -static char *UP, PC, *CM, *CE, *CL, *SO, *SE; +static char *_UP, _PC, *CM, *CE, *CL, *SO, *SE; #if PKCODE static char *TI, *TE; @@ -167,14 +167,14 @@ static void tcapopen(void) p = tcapbuf; t = tgetstr("pc", &p); if (t) - PC = *t; + _PC = *t; else - PC = 0; + _PC = 0; CL = tgetstr("cl", &p); CM = tgetstr("cm", &p); CE = tgetstr("ce", &p); - UP = tgetstr("up", &p); + _UP = tgetstr("up", &p); SE = tgetstr("se", &p); SO = tgetstr("so", &p); if (SO != NULL) @@ -189,7 +189,7 @@ static void tcapopen(void) TE = tgetstr("te", &p); #endif - if (CL == NULL || CM == NULL || UP == NULL) { + if (CL == NULL || CM == NULL || _UP == NULL) { fputs( "Incomplete termcap entry\n", stderr) ; exit( EXIT_FAILURE) ; } @@ -338,7 +338,7 @@ static void tcapscroll_delins(int from, int to, int howmanylines) /* cs is set up just like cm, so we use tgoto... */ static void tcapscrollregion(int top, int bot) { - ttputc(PC); + ttputc(_PC); putpad(tgoto(CS, bot, top)); } diff --git a/utf8.c b/utf8.c index f06b7ac..c7dc148 100644 --- a/utf8.c +++ b/utf8.c @@ -11,9 +11,12 @@ * Display width of UTF-8 character */ unsigned utf8_width( unicode_t c) { -#ifdef CYGWIN - assert( sizeof( wchar_t) == 2) ; /* wcwidth only handle UTF-16 */ +#if CYGWIN + assert( sizeof( wchar_t) == 2) ; /* wcwidth only handles UTF-16 */ return (c < 0x10000) ? (unsigned) wcwidth( (wchar_t) c) : 2 ; +#elif BSD + assert( sizeof( wchar_t) == 4) ; /* wcwidth should handle UTF-32 */ + return 1 ; #else return (unsigned) wcwidth( (wchar_t) c) ; #endif