Initial compile under linux. Not yet tested

This commit is contained in:
gdr 1997-05-03 19:37:53 +00:00
parent 796a6ac638
commit c6828d9ec1
18 changed files with 313 additions and 36 deletions

View File

@ -1,11 +1,23 @@
# @(#)Makefile 8.1 (Berkeley) 6/4/93 # @(#)Makefile 8.1 (Berkeley) 6/4/93
LIB= edit LIB= libedit.a
AHDR = vi.h emacs.h common.h
ASRC = vi.c emacs.c common.c
GENSRCS = $(AHDR) fcns.h fcns.c help.c help.h editline.c
SH = /bin/sh
OSRCS= chared.c common.c el.c emacs.c hist.c key.c map.c parse.c \ OSRCS= chared.c common.c el.c emacs.c hist.c key.c map.c parse.c \
prompt.c read.c refresh.c search.c sig.c term.c tty.c vi.c \ prompt.c read.c refresh.c search.c sig.c term.c tty.c vi.c \
help.c fcns.c help.h help.c fcns.c help.h
SYS_ELL_H = sys.h el.h $(AHDR) fcns.h help.h
GENOBJS = help.o fcns.o
OBJS = chared.o common.o el.o emacs.o hist.o key.o map.o parse.o \
prompt.o read.o refresh.o search.o sig.o term.o tty.o vi.o \
history.o tokenizer.o \
$(GENOBJS)
LDADD+= -ltermcap LDADD+= -ltermcap
# For speed and debugging # For speed and debugging
@ -14,41 +26,66 @@ LDADD+= -ltermcap
SRCS= editline.c tokenizer.c history.c SRCS= editline.c tokenizer.c history.c
CLEANFILES+=common.h emacs.h fcns.h help.h vi.h help.c fcns.c editline.c CLEANFILES+=common.h emacs.h fcns.h help.h vi.h help.c fcns.c editline.c
CFLAGS+=-I. -I${.CURDIR} DEFINES = -Dlint
#CFLAGS += $(DEFINES) -I../../include -I.
CFLAGS += $(DEFINES) -I.
CFLAGS+=#-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG -DDEBUG_REFRESH CFLAGS+=#-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG -DDEBUG_REFRESH
CFLAGS+=#-DDEBUG_PASTE CFLAGS+=#-DDEBUG_PASTE
CFLAGS += -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror \
-Wshadow -Wmissing-declarations -Wnested-externs # -W
AHDR=vi.h emacs.h common.h build: $(LIB)
ASRC=${.CURDIR}/vi.c ${.CURDIR}/emacs.c ${.CURDIR}/common.c
$(LIB): $(GENSRCS) $(OBJS)
$(AR) -rcv $(LIB) $(OBJS)
clobber:
$(RM) -f $(GENSRCS) $(OBJS) $(LIB)
vi.h: vi.c makelist vi.h: vi.c makelist
sh ${.CURDIR}/makelist -h ${.CURDIR}/vi.c > ${.TARGET} $(SH) makelist -h vi.c > $@
emacs.h: emacs.c makelist emacs.h: emacs.c makelist
sh ${.CURDIR}/makelist -h ${.CURDIR}/emacs.c > ${.TARGET} $(SH) makelist -h emacs.c > $@
common.h: common.c makelist common.h: common.c makelist
sh ${.CURDIR}/makelist -h ${.CURDIR}/common.c > ${.TARGET} $(SH) makelist -h common.c > $@
fcns.h: ${AHDR} makelist fcns.h: ${AHDR} makelist
sh ${.CURDIR}/makelist -fh ${AHDR} > ${.TARGET} $(SH) makelist -fh ${AHDR} > $@
fcns.c: ${AHDR} fcns.h makelist fcns.c: ${AHDR} fcns.h makelist
sh ${.CURDIR}/makelist -fc ${AHDR} > ${.TARGET} $(SH) makelist -fc ${AHDR} > $@
help.c: ${ASRC} makelist help.c: ${ASRC} makelist
sh ${.CURDIR}/makelist -bc ${ASRC} > ${.TARGET} $(SH) makelist -bc ${ASRC} > $@
help.h: ${ASRC} makelist help.h: ${ASRC} makelist
sh ${.CURDIR}/makelist -bh ${ASRC} > ${.TARGET} $(SH) makelist -bh ${ASRC} > $@
editline.c: ${OSRCS} editline.c: ${OSRCS}
sh ${.CURDIR}/makelist -e ${.ALLSRC:T} > ${.TARGET} $(SH) makelist -e ${OSRCS} > $@
.depend: vi.h emacs.h common.h fcns.h help.h help.c chared.o:: $(SYS_ELL_H)
common.o:: $(SYS_ELL_H)
el.o:: $(SYS_ELL_H)
emacs.o:: $(SYS_ELL_H)
hist.o:: $(SYS_ELL_H)
key.o:: $(SYS_ELL_H)
map.o:: $(SYS_ELL_H)
parse.o:: $(SYS_ELL_H) tokenizer.h
prompt.o:: $(SYS_ELL_H)
read.o:: $(SYS_ELL_H)
refresh.o:: $(SYS_ELL_H)
search.o:: $(SYS_ELL_H)
sig.o:: $(SYS_ELL_H)
term.o:: $(SYS_ELL_H)
tty.o:: $(SYS_ELL_H) tty.h
vi.o:: $(SYS_ELL_H)
# .depend: vi.h emacs.h common.h fcns.h help.h help.c
test: test.o libedit.a ${DPADD} ${LIBTERMCAP} testit: TEST/test.o libedit.a ${DPADD} ${LIBTERMCAP}
${CC} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD} -ltermcap ${CC} ${CFLAGS} TEST/test.o ${DPADD} -o $@ libedit.a ${LDADD} -ltermcap
.include <bsd.lib.mk> # .include <bsd.lib.mk>

View File

@ -45,7 +45,11 @@
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#ifdef linux
#include "../../include/histedit.h"
#else
#include "histedit.h" #include "histedit.h"
#endif
#define EL_MAXMACRO 10 #define EL_MAXMACRO 10

View File

@ -54,6 +54,10 @@ static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#endif #endif
#include "el.h" #include "el.h"
#ifdef linux
extern char *fgetln __P((FILE *, size_t *));
#endif
/* el_init(): /* el_init():
* Initialize editline and set default parameters. * Initialize editline and set default parameters.
*/ */

View File

@ -42,7 +42,11 @@
#ifndef _h_el_hist #ifndef _h_el_hist
#define _h_el_hist #define _h_el_hist
#ifdef linux
#include "../../include/histedit.h"
#else
#include "histedit.h" #include "histedit.h"
#endif
typedef const HistEvent * (*hist_fun_t) __P((ptr_t, int, ...)); typedef const HistEvent * (*hist_fun_t) __P((ptr_t, int, ...));

View File

@ -51,7 +51,11 @@ static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
#include <varargs.h> #include <varargs.h>
#endif #endif
#ifdef linux
#include "unix/histedit.h"
#else
#include "histedit.h" #include "histedit.h"
#endif
typedef const HistEvent * (*history_gfun_t) __P((ptr_t)); typedef const HistEvent * (*history_gfun_t) __P((ptr_t));
typedef const HistEvent * (*history_efun_t) __P((ptr_t, const char *)); typedef const HistEvent * (*history_efun_t) __P((ptr_t, const char *));

View File

@ -56,7 +56,7 @@ case $FLAG in
-h) -h)
OIFS="$IFS" OIFS="$IFS"
IFS=".$IFS" IFS=".$IFS"
set - $FILES set -- $FILES
IFS="$OIFS" IFS="$OIFS"
hdr="_h_`basename $1`_$2" hdr="_h_`basename $1`_$2"
cat $FILES | $AWK ' cat $FILES | $AWK '

View File

@ -1213,6 +1213,10 @@ map_print_all_keys(el)
/* map_bind(): /* map_bind():
* Add/remove/change bindings * Add/remove/change bindings
*/ */
/* don't shadow stdlib.h decl */
#define REMOVE localRemove
protected int protected int
map_bind(el, argc, argv) map_bind(el, argc, argv)
EditLine *el; EditLine *el;
@ -1220,7 +1224,7 @@ map_bind(el, argc, argv)
char **argv; char **argv;
{ {
el_action_t *map; el_action_t *map;
int ntype, remove; int ntype, REMOVE;
char *p; char *p;
char inbuf[EL_BUFSIZ]; char inbuf[EL_BUFSIZ];
char outbuf[EL_BUFSIZ]; char outbuf[EL_BUFSIZ];
@ -1235,7 +1239,7 @@ map_bind(el, argc, argv)
map = el->el_map.key; map = el->el_map.key;
ntype = XK_CMD; ntype = XK_CMD;
key = remove = 0; key = REMOVE = 0;
for (argc = 1; (p = argv[argc]) != NULL; argc++) for (argc = 1; (p = argv[argc]) != NULL; argc++)
if (p[0] == '-') if (p[0] == '-')
switch (p[1]) { switch (p[1]) {
@ -1256,7 +1260,7 @@ map_bind(el, argc, argv)
break; break;
case 'r': case 'r':
remove = 1; REMOVE = 1;
break; break;
case 'v': case 'v':
@ -1293,7 +1297,7 @@ map_bind(el, argc, argv)
return -1; return -1;
} }
if (remove) { if (REMOVE) {
if (key) { if (key) {
(void) term_clear_arrow(el, in); (void) term_clear_arrow(el, in);
return -1; return -1;

View File

@ -42,7 +42,11 @@
#ifndef _h_el_prompt #ifndef _h_el_prompt
#define _h_el_prompt #define _h_el_prompt
#ifdef linux
#include "../../include/histedit.h"
#else
#include "histedit.h" #include "histedit.h"
#endif
typedef char * (*el_pfunc_t) __P((EditLine*)); typedef char * (*el_pfunc_t) __P((EditLine*));

View File

@ -46,11 +46,16 @@ static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
#include <sys/errno.h> #include <sys/errno.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/ioctl.h>
extern int errno; extern int errno;
#include "el.h" #include "el.h"
#define OKCMD -1 #define OKCMD -1
#ifndef MIN
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#endif
private int read__fixio __P((int, int)); private int read__fixio __P((int, int));
private int read_preread __P((EditLine *)); private int read_preread __P((EditLine *));
private int read_getcmd __P((EditLine *, el_action_t *, char *)); private int read_getcmd __P((EditLine *, el_action_t *, char *));
@ -131,8 +136,7 @@ read__fixio(fd, e)
* Try to read the stuff in the input queue; * Try to read the stuff in the input queue;
*/ */
private int private int
read_preread(el) read_preread(EditLine *el)
EditLine *el;
{ {
int chrs = 0; int chrs = 0;
@ -153,7 +157,12 @@ read_preread(el)
if (chrs > 0) { if (chrs > 0) {
buf[chrs] = '\0'; buf[chrs] = '\0';
el->el_chared.c_macro.nline = strdup(buf); el->el_chared.c_macro.nline = strdup(buf);
#if 0
/* gdr: original version */
el_push(el->el_chared.c_macro.nline); el_push(el->el_chared.c_macro.nline);
#else
el_push(el, el->el_chared.c_macro.nline);
#endif
} }
} }
#endif /* FIONREAD */ #endif /* FIONREAD */
@ -245,9 +254,7 @@ read_getcmd(el, cmdnum, ch)
* Read a character * Read a character
*/ */
public int public int
el_getc(el, cp) el_getc(EditLine *el, char *cp)
EditLine *el;
char *cp;
{ {
int num_read; int num_read;
unsigned char tcp; unsigned char tcp;
@ -301,14 +308,16 @@ el_getc(el, cp)
public const char * public const char *
el_gets(el, nread) el_gets(EditLine *el, int *nread)
EditLine *el;
int *nread;
{ {
int retval; int retval;
el_action_t cmdnum = 0; el_action_t cmdnum = 0;
int num; /* how many chars we have read at NL */ int num; /* how many chars we have read at NL */
char ch; char ch;
#if 1
/* gdr: this wasn't here in the original. cut&paste from above */
c_macro_t *ma = &el->el_chared.c_macro;
#endif
if (el->el_flags & HANDLE_SIGNALS) if (el->el_flags & HANDLE_SIGNALS)
sig_set(el); sig_set(el);
@ -316,6 +325,7 @@ el_gets(el, nread)
re_clear_display(el); /* reset the display stuff */ re_clear_display(el); /* reset the display stuff */
ch_reset(el); ch_reset(el);
#ifdef FIONREAD #ifdef FIONREAD
if (el->el_tty.t_mode == EX_IO && ma->level < 0) { if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
long chrs = 0; long chrs = 0;

View File

@ -42,7 +42,11 @@
#ifndef _h_el_refresh #ifndef _h_el_refresh
#define _h_el_refresh #define _h_el_refresh
#ifdef linux
#include "../../include/histedit.h"
#else
#include "histedit.h" #include "histedit.h"
#endif
typedef struct { typedef struct {
coord_t r_cursor; /* Refresh cursor position */ coord_t r_cursor; /* Refresh cursor position */

View File

@ -42,7 +42,11 @@
#ifndef _h_el_search #ifndef _h_el_search
#define _h_el_search #define _h_el_search
#ifdef linux
#include "../../include/histedit.h"
#else
#include "histedit.h" #include "histedit.h"
#endif
typedef struct el_search_t { typedef struct el_search_t {
char *patbuf; /* The pattern buffer */ char *patbuf; /* The pattern buffer */

View File

@ -44,7 +44,11 @@
#include <signal.h> #include <signal.h>
#ifdef linux
#include "../../include/histedit.h"
#else
#include "histedit.h" #include "histedit.h"
#endif
/* /*
* Define here all the signals we are going to handle * Define here all the signals we are going to handle
@ -60,6 +64,10 @@
_DO(SIGCONT) \ _DO(SIGCONT) \
_DO(SIGWINCH) _DO(SIGWINCH)
#ifdef linux
typedef void (*sig_t) __P((int));
#endif
typedef sig_t *el_signal_t; typedef sig_t *el_signal_t;
protected void sig_end __P((EditLine*)); protected void sig_end __P((EditLine*));

View File

@ -51,8 +51,10 @@ static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
#include <unistd.h> #include <unistd.h>
#include <termcap.h> #include <termcap.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/ioctl.h>
#include "el.h" #include "el.h"
#include "term.h"
/* /*
* IMPORTANT NOTE: these routines are allowed to look at the current screen * IMPORTANT NOTE: these routines are allowed to look at the current screen
@ -187,8 +189,7 @@ private FILE *term_outfile = NULL; /* XXX: How do we fix that? */
* Set the terminal capability flags * Set the terminal capability flags
*/ */
private void private void
term_setflags(el) term_setflags(EditLine *el)
EditLine *el;
{ {
EL_FLAGS = 0; EL_FLAGS = 0;
if (el->el_tty.t_tabs) if (el->el_tty.t_tabs)
@ -1249,7 +1250,13 @@ term_echotc(el, argc, argv)
} }
#endif #endif
else if (strcmp(*argv, "baud") == 0) { else if (strcmp(*argv, "baud") == 0) {
(void) fprintf(el->el_outfile, "%ld\n", el->el_tty.t_speed); (void) fprintf(el->el_outfile,
#if defined(linux) || defined(__GNO__)
"%d\n",
#else
"%ld\n",
#endif
el->el_tty.t_speed);
return 0; return 0;
} }
else if (strcmp(*argv, "rows") == 0 || strcmp(*argv, "lines") == 0) { else if (strcmp(*argv, "rows") == 0 || strcmp(*argv, "lines") == 0) {

View File

@ -42,7 +42,11 @@
#ifndef _h_el_term #ifndef _h_el_term
#define _h_el_term #define _h_el_term
#ifdef linux
#include "../../include/histedit.h"
#else
#include "histedit.h" #include "histedit.h"
#endif
typedef struct { /* Symbolic function key bindings */ typedef struct { /* Symbolic function key bindings */
char *name; /* name of the key */ char *name; /* name of the key */

View File

@ -47,6 +47,10 @@ char *tgetstr __P((char *, char **));
int tgetflag __P((char *)); int tgetflag __P((char *));
int tgetnum __P((char *)); int tgetnum __P((char *));
char *tgoto __P((char *, int, int)); char *tgoto __P((char *, int, int));
char *tputs __P((char *, int, void (*)(int))); #if 0
char *tputs __P((char *, int, void (*)(int))); /* original */
#else
char *tputs __P((char *, int, int (*)(int)));
#endif
#endif /* _h_termcap */ #endif /* _h_termcap */

View File

@ -42,7 +42,11 @@
#ifndef _h_el_tty #ifndef _h_el_tty
#define _h_el_tty #define _h_el_tty
#ifdef linux
#include "../../include/histedit.h"
#else
#include "histedit.h" #include "histedit.h"
#endif
#include <termios.h> #include <termios.h>
/* Define our own since everyone gets it wrong! */ /* Define our own since everyone gets it wrong! */

172
lib/libedit/unix/histedit.h Normal file
View File

@ -0,0 +1,172 @@
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Christos Zoulas of Cornell University.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)histedit.h 8.2 (Berkeley) 1/3/94
*/
/*
* histedit.h: Line editor and history interface.
*/
#ifndef _h_editline
#define _h_editline
#include <sys/types.h>
#include <stdio.h>
/*
* ==== Editing ====
*/
typedef struct editline EditLine;
/*
* For user-defined function interface
*/
typedef struct lineinfo {
__const char *buffer;
__const char *cursor;
__const char *lastchar;
} LineInfo;
/*
* EditLine editor function return codes.
* For user-defined function interface
*/
#define CC_NORM 0
#define CC_NEWLINE 1
#define CC_EOF 2
#define CC_ARGHACK 3
#define CC_REFRESH 4
#define CC_CURSOR 5
#define CC_ERROR 6
#define CC_FATAL 7
/*
* Initialization, cleanup, and resetting
*/
EditLine *el_init __P((const char *, FILE *, FILE *));
void el_reset __P((EditLine *));
void el_end __P((EditLine *));
/*
* Get a line, a character or push a string back in the input queue
*/
__const char *el_gets __P((EditLine *, int *));
int el_getc __P((EditLine *, char *));
void el_push __P((EditLine *, const char *));
/*
* High level function internals control
* Parses argc, argv array and executes builtin editline commands
*/
int el_parse __P((EditLine *, int, char **));
/*
* Low level editline access function
*/
int el_set __P((EditLine *, int, ...));
/*
* el_set/el_get parameters
*/
#define EL_PROMPT 0 /* , el_pfunc_t); */
#define EL_TERMINAL 1 /* , const char *); */
#define EL_EDITOR 2 /* , const char *); */
#define EL_SIGNAL 3 /* , int); */
#define EL_BIND 4 /* , const char *, ..., NULL); */
#define EL_TELLTC 5 /* , const char *, ..., NULL); */
#define EL_SETTC 6 /* , const char *, ..., NULL); */
#define EL_ECHOTC 7 /* , const char *, ..., NULL); */
#define EL_SETTY 8 /* , const char *, ..., NULL); */
#define EL_ADDFN 9 /* , const char *, const char * */
/* , el_func_t); */
#define EL_HIST 10 /* , hist_fun_t, const char *); */
/*
* Source named file or $PWD/.editrc or $HOME/.editrc
*/
int el_source __P((EditLine *, const char *));
/*
* Must be called when the terminal changes size; If EL_SIGNAL
* is set this is done automatically otherwise it is the responsibility
* of the application
*/
void el_resize __P((EditLine *));
/*
* User-defined function interface.
*/
__const LineInfo *el_line __P((EditLine *));
int el_insertstr __P((EditLine *, char *));
void el_deletestr __P((EditLine *, int));
/*
* ==== History ====
*/
typedef struct history History;
typedef struct HistEvent {
int num;
__const char *str;
} HistEvent;
/*
* History access functions.
*/
History * history_init __P((void));
void history_end __P((History *));
__const HistEvent * history __P((History *, int, ...));
#define H_FUNC 0 /* , UTSL */
#define H_EVENT 1 /* , const int); */
#define H_FIRST 2 /* , void); */
#define H_LAST 3 /* , void); */
#define H_PREV 4 /* , void); */
#define H_NEXT 5 /* , void); */
#define H_CURR 6 /* , void); */
#define H_ADD 7 /* , const char*); */
#define H_ENTER 8 /* , const char*); */
#define H_END 9 /* , void); */
#define H_NEXT_STR 10 /* , const char*); */
#define H_PREV_STR 11 /* , const char*); */
#define H_NEXT_EVENT 12 /* , const int); */
#define H_PREV_EVENT 13 /* , const int); */
#endif /* _h_editline */

View File

@ -45,6 +45,7 @@ static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
#include "el.h" #include "el.h"
private el_action_t cv_action __P((EditLine *, int)); private el_action_t cv_action __P((EditLine *, int));
protected el_action_t cv_paste __P((EditLine *el, int c));
/* cv_action(): /* cv_action():
* Handle vi actions. * Handle vi actions.
@ -104,9 +105,7 @@ cv_action(el, c)
* Paste previous deletion before or after the cursor * Paste previous deletion before or after the cursor
*/ */
protected el_action_t protected el_action_t
cv_paste(el, c) cv_paste(EditLine *el, int c)
EditLine *el;
int c;
{ {
char *ptr; char *ptr;
c_undo_t *un = &el->el_chared.c_undo; c_undo_t *un = &el->el_chared.c_undo;