From e6921a8ed1ff62869cf608b3f7ec40ce26239db0 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Wed, 18 Aug 2021 16:54:35 +0800 Subject: [PATCH] Centralize customization in defines.h instead of Makefile + estruct.h. --- Makefile | 18 +------- buffer.c | 6 +-- defines.h | 67 +++++++++++++++++++++++---- display.c | 18 +++++--- display.h | 4 +- estruct.h | 135 ------------------------------------------------------ eval.c | 2 +- execute.c | 4 +- file.c | 1 - input.c | 2 +- isearch.c | 2 +- line.c | 2 +- lock.h | 2 +- main.c | 72 +++++++++++------------------ pklock.h | 2 +- posix.c | 2 +- random.c | 2 +- region.c | 2 +- search.c | 2 +- spawn.c | 6 +-- tcap.c | 2 +- termio.c | 2 +- window.c | 2 +- word.c | 2 +- 24 files changed, 119 insertions(+), 240 deletions(-) delete mode 100644 estruct.h diff --git a/Makefile b/Makefile index 8c506de..d233a93 100644 --- a/Makefile +++ b/Makefile @@ -13,11 +13,6 @@ else endif export E Q -uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') -# for windows based target, insure we strip the variant part -# CYGWIN_NT-6.1, CYGWIN_NT-6.1-WOW, CYGWIN_NT-6.1-WOW64, MSYS_NT-10.0-19042 -uname_S := $(shell sh -c 'echo $(uname_S) | sed s/_.*$$//') - PROGRAM=ue CC=gcc @@ -25,18 +20,7 @@ WARNINGS=-pedantic -Wall -Wextra -Wstrict-prototypes -Wno-unused-parameter CFLAGS=-O2 $(WARNINGS) LDFLAGS=-s LIBS=-lcurses -DEFINES=-DAUTOCONF -DPROGRAM=$(PROGRAM) -D_GNU_SOURCE # -DNDEBUG -ifeq ($(uname_S),Linux) # __unix__ __linux__ - DEFINES += -DUSG -DPOSIX -else ifeq ($(uname_S),CYGWIN) # __unix__ __CYGWIN__ - DEFINES += -DSYSV # -DPOSIX -else ifeq ($(uname_S),MSYS) # __unix__ __CYGWIN__ __MSYS__ - DEFINES += -DSYSV # -DPOSIX -else ifeq ($(uname_S),NetBSD) # __unix__ __NetBSD__ - DEFINES += -DBSD=1 -DPOSIX -else - $(error $(uname_S) needs configuration) -endif +DEFINES=-DPROGRAM=$(PROGRAM) -D_GNU_SOURCE # -DNDEBUG BINDIR=/usr/bin LIBDIR=/usr/lib diff --git a/buffer.c b/buffer.c index 120fc7b..40aa32d 100644 --- a/buffer.c +++ b/buffer.c @@ -1,8 +1,9 @@ /* buffer.c -- implements buffer.h */ #include "buffer.h" -/* Buffer management. Some of the functions are internal, and some are actually attached to - user keys. Like everyone else, they set hints for the display system. +/* Buffer management. Some of the functions are internal, and some are + actually attached to user keys. Like everyone else, they set hints for + the display system. modified by Petri Kutvonen */ @@ -11,7 +12,6 @@ #include #include "defines.h" -#include "estruct.h" #include "file.h" #include "input.h" #include "mlout.h" diff --git a/defines.h b/defines.h index c5959f2..4ef844e 100644 --- a/defines.h +++ b/defines.h @@ -1,17 +1,64 @@ -/* defines.h -- */ +/* defines.h -- customization based on gcc predefined macroes */ #ifndef __DEFINES_H__ #define __DEFINES_H__ -/* Must define one of - USG | BSD -*/ -#define USG 1 - -#define PKCODE 1 -#define SCROLLCODE 1 /* scrolling code P.K. */ -#define ENVFUNC 1 +#if __unix__ +# define UNIX 1 +# if __NetBSD__ +# define BSD 1 +# define POSIX 1 +# elsif __linux__ +# define USG 1 +# define SVR4 1 /* locks */ +# define POSIX 1 +# else /* __CYGWIN__ */ +# define USG 1 +//# define POSIX 1 +# endif +#else +# error Missing gcc predefined __unix__ +#endif #define NSTRING 128 /* # of bytes, string buffers */ +#define TERMCAP 1 /* UNIX */ +#define XONXOFF 1 /* UNIX */ + +#define VISMAC 0 /* update display during keyboard macros */ + +#define MSDOS 0 +#define IBMPC MSDOS +#define COLOR MSDOS +#define MEMMAP IBMPC + + +#define FILOCK (SVR4 | BSD) +#define ENVFUNC 1 /* only two types so far (USG | BSD) */ + +#define PKCODE 1 /* include P.K. extensions, define always */ +#define SCROLLCODE 1 /* scrolling code P.K. */ + +/* Dynamic RAM tracking and reporting redefinitions */ +#define RAMSIZE 0 /* dynamic RAM memory usage tracking */ +#if RAMSIZE +# define RAMSHOW 1 /* auto dynamic RAM reporting */ +# include + void *allocate( size_t size) ; + void release( void *ptr) ; + +# define malloc allocate +# define free release #endif -/* end of defines.h */ + +/* De-allocate memory always on exit (if the operating system or main + program can not +*/ +#define CLEAN 0 /* de-alloc memory on exit */ +#if CLEAN +# define exit(a) cexit(a) + + void cexit( int status) ; +#endif + +#endif +/* end of predefs.h */ diff --git a/display.c b/display.c index 492ed45..baa0ad1 100644 --- a/display.c +++ b/display.c @@ -12,12 +12,13 @@ */ #include +#include #include #include #include #include "buffer.h" -#include "estruct.h" +#include "defines.h" #include "input.h" #include "line.h" #include "termio.h" @@ -50,16 +51,16 @@ static video_p *pscreen ; /* Physical screen. */ #endif static int displaying = TRUE ; -#if UNIX -# include -#endif #ifdef SIGWINCH # include /* for window size changes */ - int chg_width, chg_height ; + int chg_width, chg_height ; + + static void sizesignal( int signr) ; #endif + static int currow ; /* Cursor row */ static int curcol ; /* Cursor column */ static int vtrow = 0 ; /* Row location of SW cursor */ @@ -105,6 +106,11 @@ static int newscreensize( int h, int w) ; completely redrawn on the first call to "update". */ void vtinit( void) { +#ifdef SIGWINCH + signal( SIGWINCH, sizesignal) ; +#endif + + setlocale( LC_CTYPE, "") ; /* expects $LANG like en_GB.UTF-8 */ TTopen() ; /* open the screen */ TTkopen() ; /* open the keyboard */ TTrev( FALSE) ; @@ -1404,7 +1410,7 @@ void getscreensize( int *widthp, int *heightp) { } #ifdef SIGWINCH -void sizesignal( int signr) { +static void sizesignal( int signr) { int w, h ; int old_errno = errno ; diff --git a/display.h b/display.h index 112d3b5..530a683 100644 --- a/display.h +++ b/display.h @@ -4,7 +4,7 @@ #include -#include "estruct.h" +#include "defines.h" /* UNIX */ #include "names.h" /* BINDABLE() */ #include "utf8.h" /* unicode_t */ @@ -40,8 +40,6 @@ void getscreensize( int *widthp, int *heightp) ; # include # ifdef SIGWINCH extern int chg_width, chg_height ; - - void sizesignal( int signr) ; # endif #endif diff --git a/estruct.h b/estruct.h deleted file mode 100644 index 1de6331..0000000 --- a/estruct.h +++ /dev/null @@ -1,135 +0,0 @@ -/* estruct.h -- */ -#ifndef _ESTRUCT_H_ -#define _ESTRUCT_H_ - -/* Structure and preprocessor defines - * - * written by Dave G. Conroy - * modified by Steve Wilhite, George Jones - * substantially modified by Daniel Lawrence - * modified by Petri Kutvonen - */ - -#ifdef MSDOS -# undef MSDOS -#endif - -/* Machine/OS definitions. */ - -#if defined(AUTOCONF) || defined(BSD) || defined(SYSV) - -/* Make an intelligent guess about the target system. */ - -# if defined(BSD) || defined(sun) || defined(ultrix) || defined(__osf__) -# ifndef BSD -# define BSD 1 /* Berkeley UNIX */ -# endif -# else -# define BSD 0 -# endif - -# if defined(SVR4) || defined(__linux__) /* ex. SunOS 5.3 */ -# define SVR4 1 -# define SYSV 1 -# undef BSD -# endif - -# if defined(SYSV) || defined(u3b2) || defined(_AIX) || (defined(i386) && defined(unix)) || defined( __unix__) -# define USG 1 /* System V UNIX */ -# else -# define USG 0 -# endif - -#else -# define BSD 0 /* UNIX BSD 4.2 and ULTRIX */ -# define USG 1 /* UNIX system V */ -#endif /*autoconf || BSD || SYSV */ - -#define MSDOS 0 /* MS-DOS */ - -/* Compiler definitions */ -#ifndef AUTOCONF -# define UNIX 1 /* a random UNIX compiler */ -#else -# define UNIX (BSD | USG) -#endif /*autoconf */ - -/* Debugging options */ - -#define RAMSIZE 0 /* dynamic RAM memory usage tracking */ -#if RAMSIZE -# define RAMSHOW 1 /* auto dynamic RAM reporting */ -#endif - -#ifndef AUTOCONF -/* Terminal Output definitions */ -# define TERMCAP 0 /* Use TERMCAP */ -# define IBMPC 1 /* IBM-PC CGA/MONO/EGA driver */ -#else -# define TERMCAP UNIX -# define IBMPC MSDOS -#endif /* Autoconf. */ - -/* Configuration options */ - -#define VISMAC 0 /* update display during keyboard macros */ - -#ifndef AUTOCONF -# define COLOR 1 /* color commands and windows */ -# define FILOCK 0 /* file locking under unix BSD 4.2 */ -#else -# define COLOR MSDOS -# ifdef SVR4 -# define FILOCK 1 -# else -# define FILOCK BSD -# endif -#endif /* Autoconf. */ - -#define CLEAN 0 /* de-alloc memory on exit */ - -#ifndef AUTOCONF -# define XONXOFF 0 /* don't disable XON-XOFF flow control P.K. */ -#else -# define XONXOFF UNIX -#endif /* Autoconf. */ - -#define PKCODE 1 /* include my extensions P.K., define always */ -#define SCROLLCODE 1 /* scrolling code P.K. */ - -/* Define some ability flags. */ - -#if IBMPC -# define MEMMAP 1 -#else -# define MEMMAP 0 -#endif - -#if USG | BSD -# define ENVFUNC 1 -#else -# define ENVFUNC 0 -#endif - -/* Dynamic RAM tracking and reporting redefinitions */ - -#if RAMSIZE -# include - void *allocate( size_t size) ; - void release( void *ptr) ; -# define malloc allocate -# define free release -#endif - -/* De-allocate memory always on exit (if the operating system or - main program can not -*/ - -#if CLEAN -# define exit(a) cexit(a) - - void cexit( int status) ; -#endif - -#endif -/* end of estruct.h */ diff --git a/eval.c b/eval.c index ee9edcb..ef875a7 100644 --- a/eval.c +++ b/eval.c @@ -15,8 +15,8 @@ #include "basic.h" #include "bind.h" #include "buffer.h" +#include "defines.h" #include "display.h" -#include "estruct.h" #include "exec.h" #include "execute.h" #include "flook.h" diff --git a/execute.c b/execute.c index 875f91d..3cdef0b 100644 --- a/execute.c +++ b/execute.c @@ -7,12 +7,12 @@ #include #include -#include "estruct.h" -#include "random.h" +#include "defines.h" #include "display.h" #include "file.h" #include "input.h" #include "mlout.h" +#include "random.h" #include "search.h" #include "terminal.h" #include "window.h" diff --git a/file.c b/file.c index 40ad584..4190591 100644 --- a/file.c +++ b/file.c @@ -17,7 +17,6 @@ #include "buffer.h" #include "defines.h" #include "display.h" -#include "estruct.h" #include "execute.h" #include "fileio.h" #include "input.h" diff --git a/input.c b/input.c index 2367b80..96012f2 100644 --- a/input.c +++ b/input.c @@ -13,8 +13,8 @@ #include #include "bind.h" -#include "estruct.h" #include "bindable.h" +#include "defines.h" #include "display.h" /* rubout(), echos(), echoc(), update() */ #include "exec.h" #include "isa.h" diff --git a/isearch.c b/isearch.c index fb6eddd..6d984b1 100644 --- a/isearch.c +++ b/isearch.c @@ -27,8 +27,8 @@ #include "basic.h" #include "buffer.h" +#include "defines.h" #include "display.h" -#include "estruct.h" #include "exec.h" #include "input.h" #include "line.h" diff --git a/line.c b/line.c index c5939e4..a29eabe 100644 --- a/line.c +++ b/line.c @@ -20,7 +20,7 @@ #include #include "buffer.h" -#include "estruct.h" +#include "defines.h" #include "mlout.h" #include "utf8.h" #include "window.h" diff --git a/lock.h b/lock.h index 9b82e91..e100935 100644 --- a/lock.h +++ b/lock.h @@ -2,7 +2,7 @@ #ifndef _LOCK_H_ #define _LOCK_H_ -#include "estruct.h" +#include "defines.h" /* BSD, SVR4 */ #if BSD | SVR4 int lockchk( const char *fname) ; diff --git a/main.c b/main.c index 71a35f4..268c18b 100644 --- a/main.c +++ b/main.c @@ -62,14 +62,13 @@ * */ -#include #include #include #include -#include "estruct.h" /* Global structures and defines. */ +#include "defines.h" /* OS specific customization */ #if UNIX -#include +# include #endif #include "basic.h" @@ -91,9 +90,8 @@ #include "window.h" #if UNIX -static void emergencyexit(int signr) -{ - quickexit(FALSE, 0); +static void emergencyexit( int signr) { + quickexit( FALSE, 0) ; quit( TRUE, 0) ; /* If quickexit fails (to save changes), do a force quit */ } #endif @@ -124,13 +122,12 @@ static void usage( void) { } -int main(int argc, char **argv) -{ - struct buffer *bp; /* temp buffer pointer */ +int main( int argc, char *argv[]) { + buffer_p bp; /* temp buffer pointer */ int firstfile; /* first file flag */ int carg; /* current arg to scan */ int startflag; /* startup executed flag */ - struct buffer *firstbp = NULL; /* ptr to first buffer in cmd line */ + buffer_p firstbp = NULL; /* ptr to first buffer in cmd line */ int viewflag; /* are we starting in view mode? */ int gotoflag; /* do we need to goto a line at start? */ int gline = 0; /* if so, what line? */ @@ -138,17 +135,10 @@ int main(int argc, char **argv) int errflag; /* C error processing? */ bname_t bname ; /* buffer name of file to read */ - setlocale( LC_CTYPE, "") ; /* expects $LANG like en_GB.UTF-8 */ - #if PKCODE & BSD sleep(1); /* Time for window manager. */ #endif -#if UNIX -#ifdef SIGWINCH - signal(SIGWINCH, sizesignal); -#endif -#endif if( argc == 2) { if( strcmp( argv[ 1], "--help") == 0) { usage() ; @@ -325,7 +315,7 @@ int main(int argc, char **argv) */ static void edinit( char *bname) { buffer_p bp; - struct window *wp; + window_p wp; if( !init_bindings() /* initialize mapping of function to name and key */ || NULL == (bp = bfind( bname, TRUE, 0)) /* First buffer */ @@ -442,42 +432,36 @@ static void dspram( void) #if CLEAN -/* - * cexit() +/* cexit() * * int status; return status of emacs */ void cexit( int status) { - struct buffer *bp; /* buffer list pointer */ - struct window *wp; /* window list pointer */ - struct window *tp; /* temporary window pointer */ - - /* first clean up the windows */ - wp = wheadp; - while (wp) { - tp = wp->w_wndp; - free(wp); - wp = tp; +/* first clean up the windows */ + window_p wp = wheadp ; + while( wp) { + window_p tp = wp->w_wndp ; + free( wp) ; + wp = tp ; } - wheadp = NULL; + + wheadp = NULL ; - /* then the buffers */ - bp = bheadp; - while (bp) { - bp->b_nwnd = 0; - bp->b_flag = 0; /* don't say anything about a changed buffer! */ - zotbuf(bp); - bp = bheadp; +/* then the buffers */ + buffer_p bp ; + while( (bp = bheadp) != NULL) { + bp->b_nwnd = 0 ; + bp->b_flag = 0 ; /* don't say anything about a changed buffer! */ + zotbuf( bp) ; } - /* and the kill buffer */ - kdelete(); +/* and the kill buffer */ + kdelete() ; - /* and the video buffers */ - vtfree(); +/* and the video buffers */ + vtfree() ; -#undef exit - exit(status); + (exit)( status) ; } #endif diff --git a/pklock.h b/pklock.h index 745aec5..0a24892 100644 --- a/pklock.h +++ b/pklock.h @@ -2,7 +2,7 @@ #ifndef _PKLOCK_H_ #define _PKLOCK_H_ -#include "estruct.h" +#include "defines.h" /* FILOCK, BSD, SVR4 */ #if (FILOCK && BSD) || SVR4 char *dolock( const char *fname) ; diff --git a/posix.c b/posix.c index 93bbbf4..1355b5c 100644 --- a/posix.c +++ b/posix.c @@ -1,6 +1,7 @@ /* posix.c -- posix implementation of termio.h */ #include "termio.h" +#include "defines.h" /* POSIX */ #ifdef POSIX /* The functions in this file negotiate with the operating system for @@ -22,7 +23,6 @@ #include #include -#include "estruct.h" #include "retcode.h" #include "utf8.h" diff --git a/random.c b/random.c index 4f2f3be..100e54e 100644 --- a/random.c +++ b/random.c @@ -14,8 +14,8 @@ #include "basic.h" #include "buffer.h" +#include "defines.h" #include "display.h" -#include "estruct.h" #include "execute.h" #include "input.h" #include "line.h" diff --git a/region.c b/region.c index c31a431..6f849e1 100644 --- a/region.c +++ b/region.c @@ -12,7 +12,7 @@ #include #include "buffer.h" -#include "estruct.h" +#include "defines.h" #include "line.h" #include "mlout.h" #include "random.h" diff --git a/search.c b/search.c index 7f6d4fd..c186a40 100644 --- a/search.c +++ b/search.c @@ -65,8 +65,8 @@ #include "basic.h" #include "buffer.h" +#include "defines.h" #include "display.h" -#include "estruct.h" #include "input.h" #include "isa.h" #include "line.h" diff --git a/spawn.c b/spawn.c index f48e74a..3b9e95e 100644 --- a/spawn.c +++ b/spawn.c @@ -12,11 +12,9 @@ #include #include -#include "defines.h" - #include "buffer.h" +#include "defines.h" #include "display.h" -#include "estruct.h" #include "exec.h" #include "file.h" #include "flook.h" @@ -27,8 +25,6 @@ #if USG | BSD #include -#ifdef SIGWINCH -#endif #endif diff --git a/tcap.c b/tcap.c index 7a37acb..53f829e 100644 --- a/tcap.c +++ b/tcap.c @@ -20,8 +20,8 @@ #include #include +#include "defines.h" #include "display.h" -#include "estruct.h" #include "termio.h" #if TERMCAP diff --git a/termio.c b/termio.c index a5e5b71..3ed67b0 100644 --- a/termio.c +++ b/termio.c @@ -1,6 +1,7 @@ /* termio.c -- implements termio.h */ #include "termio.h" +#include "defines.h" /* POSIX */ #ifndef POSIX /* The functions in this file negotiate with the operating system for @@ -13,7 +14,6 @@ #include #include -#include "estruct.h" #include "retcode.h" #include "utf8.h" diff --git a/window.c b/window.c index d5448fa..e9f31c9 100644 --- a/window.c +++ b/window.c @@ -9,8 +9,8 @@ #include "basic.h" #include "buffer.h" +#include "defines.h" #include "display.h" /* upmode() */ -#include "estruct.h" #include "execute.h" #include "line.h" #include "mlout.h" diff --git a/word.c b/word.c index 7b859f8..8893e5d 100644 --- a/word.c +++ b/word.c @@ -14,7 +14,7 @@ #include "basic.h" #include "buffer.h" -#include "estruct.h" +#include "defines.h" #include "isa.h" #include "line.h" #include "mlout.h"