Centralize customization in defines.h instead of Makefile + estruct.h.

This commit is contained in:
Renaud 2021-08-18 16:54:35 +08:00
parent d99b7fcbac
commit e6921a8ed1
24 changed files with 119 additions and 240 deletions

View File

@ -13,11 +13,6 @@ else
endif endif
export E Q 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 PROGRAM=ue
CC=gcc CC=gcc
@ -25,18 +20,7 @@ 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) -D_GNU_SOURCE # -DNDEBUG DEFINES=-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
BINDIR=/usr/bin BINDIR=/usr/bin
LIBDIR=/usr/lib LIBDIR=/usr/lib

View File

@ -1,8 +1,9 @@
/* buffer.c -- implements buffer.h */ /* buffer.c -- implements buffer.h */
#include "buffer.h" #include "buffer.h"
/* Buffer management. Some of the functions are internal, and some are actually attached to /* Buffer management. Some of the functions are internal, and some are
user keys. Like everyone else, they set hints for the display system. actually attached to user keys. Like everyone else, they set hints for
the display system.
modified by Petri Kutvonen modified by Petri Kutvonen
*/ */
@ -11,7 +12,6 @@
#include <string.h> #include <string.h>
#include "defines.h" #include "defines.h"
#include "estruct.h"
#include "file.h" #include "file.h"
#include "input.h" #include "input.h"
#include "mlout.h" #include "mlout.h"

View File

@ -1,17 +1,64 @@
/* defines.h -- */ /* defines.h -- customization based on gcc predefined macroes */
#ifndef __DEFINES_H__ #ifndef __DEFINES_H__
#define __DEFINES_H__ #define __DEFINES_H__
/* Must define one of #if __unix__
USG | BSD # define UNIX 1
*/ # if __NetBSD__
#define USG 1 # define BSD 1
# define POSIX 1
#define PKCODE 1 # elsif __linux__
#define SCROLLCODE 1 /* scrolling code P.K. */ # define USG 1
#define ENVFUNC 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 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 <stdlib.h>
void *allocate( size_t size) ;
void release( void *ptr) ;
# define malloc allocate
# define free release
#endif #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 */

View File

@ -12,12 +12,13 @@
*/ */
#include <errno.h> #include <errno.h>
#include <locale.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "buffer.h" #include "buffer.h"
#include "estruct.h" #include "defines.h"
#include "input.h" #include "input.h"
#include "line.h" #include "line.h"
#include "termio.h" #include "termio.h"
@ -50,16 +51,16 @@ static video_p *pscreen ; /* Physical screen. */
#endif #endif
static int displaying = TRUE ; static int displaying = TRUE ;
#if UNIX
# include <signal.h>
#endif
#ifdef SIGWINCH #ifdef SIGWINCH
# include <sys/ioctl.h> # include <sys/ioctl.h>
/* for window size changes */ /* for window size changes */
int chg_width, chg_height ; int chg_width, chg_height ;
static void sizesignal( int signr) ;
#endif #endif
static int currow ; /* Cursor row */ static int currow ; /* Cursor row */
static int curcol ; /* Cursor column */ static int curcol ; /* Cursor column */
static int vtrow = 0 ; /* Row location of SW cursor */ 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". completely redrawn on the first call to "update".
*/ */
void vtinit( void) { void vtinit( void) {
#ifdef SIGWINCH
signal( SIGWINCH, sizesignal) ;
#endif
setlocale( LC_CTYPE, "") ; /* expects $LANG like en_GB.UTF-8 */
TTopen() ; /* open the screen */ TTopen() ; /* open the screen */
TTkopen() ; /* open the keyboard */ TTkopen() ; /* open the keyboard */
TTrev( FALSE) ; TTrev( FALSE) ;
@ -1404,7 +1410,7 @@ void getscreensize( int *widthp, int *heightp) {
} }
#ifdef SIGWINCH #ifdef SIGWINCH
void sizesignal( int signr) { static void sizesignal( int signr) {
int w, h ; int w, h ;
int old_errno = errno ; int old_errno = errno ;

View File

@ -4,7 +4,7 @@
#include <stdarg.h> #include <stdarg.h>
#include "estruct.h" #include "defines.h" /* UNIX */
#include "names.h" /* BINDABLE() */ #include "names.h" /* BINDABLE() */
#include "utf8.h" /* unicode_t */ #include "utf8.h" /* unicode_t */
@ -40,8 +40,6 @@ void getscreensize( int *widthp, int *heightp) ;
# include <signal.h> # include <signal.h>
# ifdef SIGWINCH # ifdef SIGWINCH
extern int chg_width, chg_height ; extern int chg_width, chg_height ;
void sizesignal( int signr) ;
# endif # endif
#endif #endif

135
estruct.h
View File

@ -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 <stdlib.h>
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 */

2
eval.c
View File

@ -15,8 +15,8 @@
#include "basic.h" #include "basic.h"
#include "bind.h" #include "bind.h"
#include "buffer.h" #include "buffer.h"
#include "defines.h"
#include "display.h" #include "display.h"
#include "estruct.h"
#include "exec.h" #include "exec.h"
#include "execute.h" #include "execute.h"
#include "flook.h" #include "flook.h"

View File

@ -7,12 +7,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "estruct.h" #include "defines.h"
#include "random.h"
#include "display.h" #include "display.h"
#include "file.h" #include "file.h"
#include "input.h" #include "input.h"
#include "mlout.h" #include "mlout.h"
#include "random.h"
#include "search.h" #include "search.h"
#include "terminal.h" #include "terminal.h"
#include "window.h" #include "window.h"

1
file.c
View File

@ -17,7 +17,6 @@
#include "buffer.h" #include "buffer.h"
#include "defines.h" #include "defines.h"
#include "display.h" #include "display.h"
#include "estruct.h"
#include "execute.h" #include "execute.h"
#include "fileio.h" #include "fileio.h"
#include "input.h" #include "input.h"

View File

@ -13,8 +13,8 @@
#include <unistd.h> #include <unistd.h>
#include "bind.h" #include "bind.h"
#include "estruct.h"
#include "bindable.h" #include "bindable.h"
#include "defines.h"
#include "display.h" /* rubout(), echos(), echoc(), update() */ #include "display.h" /* rubout(), echos(), echoc(), update() */
#include "exec.h" #include "exec.h"
#include "isa.h" #include "isa.h"

View File

@ -27,8 +27,8 @@
#include "basic.h" #include "basic.h"
#include "buffer.h" #include "buffer.h"
#include "defines.h"
#include "display.h" #include "display.h"
#include "estruct.h"
#include "exec.h" #include "exec.h"
#include "input.h" #include "input.h"
#include "line.h" #include "line.h"

2
line.c
View File

@ -20,7 +20,7 @@
#include <string.h> #include <string.h>
#include "buffer.h" #include "buffer.h"
#include "estruct.h" #include "defines.h"
#include "mlout.h" #include "mlout.h"
#include "utf8.h" #include "utf8.h"
#include "window.h" #include "window.h"

2
lock.h
View File

@ -2,7 +2,7 @@
#ifndef _LOCK_H_ #ifndef _LOCK_H_
#define _LOCK_H_ #define _LOCK_H_
#include "estruct.h" #include "defines.h" /* BSD, SVR4 */
#if BSD | SVR4 #if BSD | SVR4
int lockchk( const char *fname) ; int lockchk( const char *fname) ;

72
main.c
View File

@ -62,14 +62,13 @@
* *
*/ */
#include <locale.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "estruct.h" /* Global structures and defines. */ #include "defines.h" /* OS specific customization */
#if UNIX #if UNIX
#include <signal.h> # include <signal.h>
#endif #endif
#include "basic.h" #include "basic.h"
@ -91,9 +90,8 @@
#include "window.h" #include "window.h"
#if UNIX #if UNIX
static void emergencyexit(int signr) static void emergencyexit( int signr) {
{ quickexit( FALSE, 0) ;
quickexit(FALSE, 0);
quit( TRUE, 0) ; /* If quickexit fails (to save changes), do a force quit */ quit( TRUE, 0) ; /* If quickexit fails (to save changes), do a force quit */
} }
#endif #endif
@ -124,13 +122,12 @@ static void usage( void) {
} }
int main(int argc, char **argv) int main( int argc, char *argv[]) {
{ buffer_p bp; /* temp buffer pointer */
struct buffer *bp; /* temp buffer pointer */
int firstfile; /* first file flag */ int firstfile; /* first file flag */
int carg; /* current arg to scan */ int carg; /* current arg to scan */
int startflag; /* startup executed flag */ 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 viewflag; /* are we starting in view mode? */
int gotoflag; /* do we need to goto a line at start? */ int gotoflag; /* do we need to goto a line at start? */
int gline = 0; /* if so, what line? */ int gline = 0; /* if so, what line? */
@ -138,17 +135,10 @@ int main(int argc, char **argv)
int errflag; /* C error processing? */ int errflag; /* C error processing? */
bname_t bname ; /* buffer name of file to read */ bname_t bname ; /* buffer name of file to read */
setlocale( LC_CTYPE, "") ; /* expects $LANG like en_GB.UTF-8 */
#if PKCODE & BSD #if PKCODE & BSD
sleep(1); /* Time for window manager. */ sleep(1); /* Time for window manager. */
#endif #endif
#if UNIX
#ifdef SIGWINCH
signal(SIGWINCH, sizesignal);
#endif
#endif
if( argc == 2) { if( argc == 2) {
if( strcmp( argv[ 1], "--help") == 0) { if( strcmp( argv[ 1], "--help") == 0) {
usage() ; usage() ;
@ -325,7 +315,7 @@ int main(int argc, char **argv)
*/ */
static void edinit( char *bname) { static void edinit( char *bname) {
buffer_p bp; buffer_p bp;
struct window *wp; window_p wp;
if( !init_bindings() /* initialize mapping of function to name and key */ if( !init_bindings() /* initialize mapping of function to name and key */
|| NULL == (bp = bfind( bname, TRUE, 0)) /* First buffer */ || NULL == (bp = bfind( bname, TRUE, 0)) /* First buffer */
@ -442,42 +432,36 @@ static void dspram( void)
#if CLEAN #if CLEAN
/* /* cexit()
* cexit()
* *
* int status; return status of emacs * int status; return status of emacs
*/ */
void cexit( int status) { void cexit( int status) {
struct buffer *bp; /* buffer list pointer */ /* first clean up the windows */
struct window *wp; /* window list pointer */ window_p wp = wheadp ;
struct window *tp; /* temporary window pointer */ while( wp) {
window_p tp = wp->w_wndp ;
/* first clean up the windows */ free( wp) ;
wp = wheadp; wp = tp ;
while (wp) {
tp = wp->w_wndp;
free(wp);
wp = tp;
} }
wheadp = NULL;
wheadp = NULL ;
/* then the buffers */ /* then the buffers */
bp = bheadp; buffer_p bp ;
while (bp) { while( (bp = bheadp) != NULL) {
bp->b_nwnd = 0; bp->b_nwnd = 0 ;
bp->b_flag = 0; /* don't say anything about a changed buffer! */ bp->b_flag = 0 ; /* don't say anything about a changed buffer! */
zotbuf(bp); zotbuf( bp) ;
bp = bheadp;
} }
/* and the kill buffer */ /* and the kill buffer */
kdelete(); kdelete() ;
/* and the video buffers */ /* and the video buffers */
vtfree(); vtfree() ;
#undef exit (exit)( status) ;
exit(status);
} }
#endif #endif

View File

@ -2,7 +2,7 @@
#ifndef _PKLOCK_H_ #ifndef _PKLOCK_H_
#define _PKLOCK_H_ #define _PKLOCK_H_
#include "estruct.h" #include "defines.h" /* FILOCK, BSD, SVR4 */
#if (FILOCK && BSD) || SVR4 #if (FILOCK && BSD) || SVR4
char *dolock( const char *fname) ; char *dolock( const char *fname) ;

View File

@ -1,6 +1,7 @@
/* posix.c -- posix implementation of termio.h */ /* posix.c -- posix implementation of termio.h */
#include "termio.h" #include "termio.h"
#include "defines.h" /* POSIX */
#ifdef POSIX #ifdef POSIX
/* The functions in this file negotiate with the operating system for /* The functions in this file negotiate with the operating system for
@ -22,7 +23,6 @@
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
#include "estruct.h"
#include "retcode.h" #include "retcode.h"
#include "utf8.h" #include "utf8.h"

View File

@ -14,8 +14,8 @@
#include "basic.h" #include "basic.h"
#include "buffer.h" #include "buffer.h"
#include "defines.h"
#include "display.h" #include "display.h"
#include "estruct.h"
#include "execute.h" #include "execute.h"
#include "input.h" #include "input.h"
#include "line.h" #include "line.h"

View File

@ -12,7 +12,7 @@
#include <stddef.h> #include <stddef.h>
#include "buffer.h" #include "buffer.h"
#include "estruct.h" #include "defines.h"
#include "line.h" #include "line.h"
#include "mlout.h" #include "mlout.h"
#include "random.h" #include "random.h"

View File

@ -65,8 +65,8 @@
#include "basic.h" #include "basic.h"
#include "buffer.h" #include "buffer.h"
#include "defines.h"
#include "display.h" #include "display.h"
#include "estruct.h"
#include "input.h" #include "input.h"
#include "isa.h" #include "isa.h"
#include "line.h" #include "line.h"

View File

@ -12,11 +12,9 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "defines.h"
#include "buffer.h" #include "buffer.h"
#include "defines.h"
#include "display.h" #include "display.h"
#include "estruct.h"
#include "exec.h" #include "exec.h"
#include "file.h" #include "file.h"
#include "flook.h" #include "flook.h"
@ -27,8 +25,6 @@
#if USG | BSD #if USG | BSD
#include <signal.h> #include <signal.h>
#ifdef SIGWINCH
#endif
#endif #endif

2
tcap.c
View File

@ -20,8 +20,8 @@
#include <curses.h> #include <curses.h>
#include <term.h> #include <term.h>
#include "defines.h"
#include "display.h" #include "display.h"
#include "estruct.h"
#include "termio.h" #include "termio.h"
#if TERMCAP #if TERMCAP

View File

@ -1,6 +1,7 @@
/* termio.c -- implements termio.h */ /* termio.c -- implements termio.h */
#include "termio.h" #include "termio.h"
#include "defines.h" /* POSIX */
#ifndef POSIX #ifndef POSIX
/* The functions in this file negotiate with the operating system for /* The functions in this file negotiate with the operating system for
@ -13,7 +14,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "estruct.h"
#include "retcode.h" #include "retcode.h"
#include "utf8.h" #include "utf8.h"

View File

@ -9,8 +9,8 @@
#include "basic.h" #include "basic.h"
#include "buffer.h" #include "buffer.h"
#include "defines.h"
#include "display.h" /* upmode() */ #include "display.h" /* upmode() */
#include "estruct.h"
#include "execute.h" #include "execute.h"
#include "line.h" #include "line.h"
#include "mlout.h" #include "mlout.h"

2
word.c
View File

@ -14,7 +14,7 @@
#include "basic.h" #include "basic.h"
#include "buffer.h" #include "buffer.h"
#include "estruct.h" #include "defines.h"
#include "isa.h" #include "isa.h"
#include "line.h" #include "line.h"
#include "mlout.h" #include "mlout.h"