1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-09-30 01:05:54 -04:00

Use gcc predefined in conditional compilation (__CYGWIN__, __SIZEOF_WCHAR_T__).

This commit is contained in:
Renaud 2021-08-18 09:37:47 +08:00
parent 18a0fbe57f
commit 5f3b42f448
4 changed files with 33 additions and 44 deletions

View File

@ -25,15 +25,15 @@ WARNINGS=-pedantic -Wall -Wextra -Wstrict-prototypes -Wno-unused-parameter
CFLAGS=-O2 $(WARNINGS) CFLAGS=-O2 $(WARNINGS)
LDFLAGS=-s LDFLAGS=-s
LIBS=-lcurses LIBS=-lcurses
DEFINES=-DAUTOCONF -DPROGRAM=$(PROGRAM) # -DNDEBUG DEFINES=-DAUTOCONF -DPROGRAM=$(PROGRAM) -D_GNU_SOURCE # -DNDEBUG
ifeq ($(uname_S),Linux) ifeq ($(uname_S),Linux) # __unix__ __linux__
DEFINES += -DPOSIX -DUSG DEFINES += -DUSG -DPOSIX
else ifeq ($(uname_S),CYGWIN) else ifeq ($(uname_S),CYGWIN) # __unix__ __CYGWIN__
DEFINES += -DCYGWIN -DSYSV DEFINES += -DSYSV # -DPOSIX
else ifeq ($(uname_S),MSYS) else ifeq ($(uname_S),MSYS) # __unix__ __CYGWIN__ __MSYS__
DEFINES += -DCYGWIN -DSYSV DEFINES += -DSYSV # -DPOSIX
else ifeq ($(uname_S),NetBSD) else ifeq ($(uname_S),NetBSD) # __unix__ __NetBSD__
DEFINES += -DPOSIX -DBSD=1 DEFINES += -DBSD=1 -DPOSIX
else else
$(error $(uname_S) needs configuration) $(error $(uname_S) needs configuration)
endif endif

28
posix.c
View File

@ -1,18 +1,16 @@
/* posix.c -- posix implementation of termio.h */ /* posix.c -- posix implementation of termio.h */
#ifdef POSIX
#include "termio.h" #include "termio.h"
/* posix.c #ifdef POSIX
*
* The functions in this file negotiate with the operating system for /* The functions in this file negotiate with the operating system for
* characters, and write characters in a barely buffered fashion on the characters, and write characters in a barely buffered fashion on the
* display. All operating systems. display. All operating systems.
*
* modified by Petri Kutvonen modified by Petri Kutvonen
*
* based on termio.c, with all the old cruft removed, and based on termio.c, with all the old cruft removed, and
* fixed for termios rather than the old termio.. Linus Torvalds fixed for termios rather than the old termio.. Linus Torvalds
*/ */
#include <errno.h> #include <errno.h>
@ -38,7 +36,7 @@ int ttcol = HUGE ; /* Column location of HW cursor */
#define XCASE 0000004 #define XCASE 0000004
#endif #endif
#ifdef CYGWIN #ifdef __CYGWIN__ /* gcc predefined (see cpp -dM) */
#define XCASE 0 #define XCASE 0
#define ECHOPRT 0 #define ECHOPRT 0
#define PENDIN 0 #define PENDIN 0
@ -247,8 +245,6 @@ int typahead(void)
return x; return x;
} }
#else #endif
typedef void _pedantic_empty_translation_unit ;
#endif /* not POSIX */
/* end of posix.c */ /* end of posix.c */

View File

@ -1,15 +1,13 @@
/* termio.c -- implements termio.h */ /* termio.c -- implements termio.h */
#if !defined( POSIX)
#include "termio.h" #include "termio.h"
/* TERMIO.C #ifndef POSIX
*
* The functions in this file negotiate with the operating system for /* The functions in this file negotiate with the operating system for
* characters, and write characters in a barely buffered fashion on the display. characters, and write characters in a barely buffered fashion on the
* All operating systems. display. All operating systems.
*
* modified by Petri Kutvonen modified by Petri Kutvonen
*/ */
#include <stdio.h> #include <stdio.h>
@ -258,14 +256,12 @@ int typahead( void)
return kbdqp; return kbdqp;
#endif #endif
#if !UNIX # if !UNIX
return FALSE; return FALSE;
#endif # endif
} }
#endif # endif
#else
typedef void _pedantic_empty_translation_unit ;
#endif /* not POSIX */ #endif /* not POSIX */
/* end of termio.c */ /* end of termio.c */

7
utf8.c
View File

@ -1,16 +1,13 @@
/* utf8.c -- implements utf8.h, conversion between unicode and UTF-8 */ /* utf8.c -- implements utf8.h, conversion between unicode and UTF-8 */
#include "utf8.h" #include "utf8.h"
#define _XOPEN_SOURCE /* wcwidth in wchar.h */
#include <assert.h> #include <assert.h>
#include <wchar.h> #include <wchar.h> /* either _XOPEN_SOURCE or _GNU_SOURCE */
/* Display width of UTF-8 character */ /* Display width of UTF-8 character */
int _utf8_width( unicode_t c) { int _utf8_width( unicode_t c) {
#if CYGWIN #if __SIZEOF_WCHAR_T__ == 2 /* wcwidth only supports UTF-16 */
assert( sizeof( wchar_t) == 2) ; /* wcwidth only supports UTF-16 */
return (c < 0x10000) ? wcwidth( (wchar_t) c) : -1 ; return (c < 0x10000) ? wcwidth( (wchar_t) c) : -1 ;
#else #else
return wcwidth( (wchar_t) c) ; return wcwidth( (wchar_t) c) ;