More cleanup. Added license blurb to top of all source files.

Remove all old $Id:$ and similar constructs, they don't provide any
additional benefit anymore.

Add configure options for toggling terminal bell and  toying with
SIGSTOP using Ctrl-Z.  Rename config option for ANSI keys to get
a consistent namespace.

Also did some work on ANSI-fication of function definitions, lot's
of that was still lingering around.
This commit is contained in:
Joachim Nilsson
2010-07-18 01:41:18 +02:00
parent 00dd651835
commit 3c4cf96bfc
13 changed files with 351 additions and 195 deletions

View File

@@ -1,7 +1,7 @@
AUTOMAKE_OPTIONS = foreign
lib_LTLIBRARIES = libeditline.la
libeditline_la_SOURCES = editline.c editline.h sysunix.c unix.h
if COMPLETE
if CONFIG_DEFAULT_COMPLETE
# Built-in completion handler.
libeditline_la_SOURCES += complete.c
AM_CPPFLAGS = -DCOMPLETE

View File

@@ -35,7 +35,7 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
# Built-in completion handler.
@COMPLETE_TRUE@am__append_1 = complete.c
@CONFIG_DEFAULT_COMPLETE_TRUE@am__append_1 = complete.c
subdir = src
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -75,7 +75,7 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
libeditline_la_LIBADD =
am__libeditline_la_SOURCES_DIST = editline.c editline.h sysunix.c \
unix.h complete.c
@COMPLETE_TRUE@am__objects_1 = complete.lo
@CONFIG_DEFAULT_COMPLETE_TRUE@am__objects_1 = complete.lo
am_libeditline_la_OBJECTS = editline.lo sysunix.lo $(am__objects_1)
libeditline_la_OBJECTS = $(am_libeditline_la_OBJECTS)
AM_V_lt = $(am__v_lt_$(V))
@@ -228,7 +228,7 @@ AUTOMAKE_OPTIONS = foreign
lib_LTLIBRARIES = libeditline.la
libeditline_la_SOURCES = editline.c editline.h sysunix.c unix.h \
$(am__append_1)
@COMPLETE_TRUE@AM_CPPFLAGS = -DCOMPLETE
@CONFIG_DEFAULT_COMPLETE_TRUE@AM_CPPFLAGS = -DCOMPLETE
all: all-am
.SUFFIXES:

View File

@@ -1,31 +1,43 @@
/* $Revision: 5 $
**
** History and file completion functions for editline library.
*/
/* History and file completion functions for editline library.
*
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
*
* This software is not subject to any license of the American Telephone
* and Telegraph Company or of the Regents of the University of California.
*
* Permission is granted to anyone to use this software for any purpose on
* any computer system, and to alter it and redistribute it freely, subject
* to the following restrictions:
* 1. The authors are not responsible for the consequences of use of this
* software, no matter how awful, even if they arise from flaws in it.
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits must appear in the documentation.
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits must appear in the documentation.
* 4. This notice may not be removed or altered.
*/
#include "editline.h"
#define MAX_TOTAL_MATCHES (256 << sizeof(char *))
#if defined(NEED_STRDUP)
/*
** Return an allocated copy of a string.
*/
char *
strdup(p)
char *p;
#ifdef NEED_STRDUP
/* Return an allocated copy of a string. */
char *strdup(const char *p)
{
char *new;
char *new;
if ((new = NEW(char, strlen(p) + 1)) != NULL)
(void)strcpy(new, p);
return new;
}
#endif /* defined(NEED_STRDUP) */
#endif
/*
** strcmp-like sorting predicate for qsort.
*/
static int
compare(void *p1, void *p2)
/* Wrap strcmp() for qsort() */
static int compare(void *p1, void *p2)
{
char **v1 = (char **)p1;
char **v2 = (char **)p2;
@@ -33,15 +45,9 @@ compare(void *p1, void *p2)
return strcmp(*v1, *v2);
}
/*
** Fill in *avp with an array of names that match file, up to its length.
** Ignore . and .. .
*/
static int
FindMatches(dir, file, avp)
char *dir;
char *file;
char ***avp;
/* Fill in *avp with an array of names that match file, up to its length.
* Ignore . and .. . */
static int FindMatches(char *dir, char *file, char ***avp)
{
char **av;
char **new;
@@ -52,7 +58,6 @@ FindMatches(dir, file, avp)
SIZE_T len;
SIZE_T choices;
SIZE_T total;
#define MAX_TOTAL (256 << sizeof(char *))
if ((dp = opendir(dir)) == NULL)
return 0;
@@ -70,7 +75,7 @@ FindMatches(dir, file, avp)
continue;
choices++;
if ((total += strlen(p)) > MAX_TOTAL) {
if ((total += strlen(p)) > MAX_TOTAL_MATCHES) {
/* This is a bit too much. */
while (ac > 0) DISPOSE(av[--ac]);
continue;
@@ -98,8 +103,8 @@ FindMatches(dir, file, avp)
}
/* Clean up and return. */
(void)closedir(dp);
if (total > MAX_TOTAL) {
closedir(dp);
if (total > MAX_TOTAL_MATCHES) {
char many[sizeof(total) * 3];
p = many + sizeof(many);
*--p = '\0';
@@ -114,17 +119,12 @@ FindMatches(dir, file, avp)
if (ac)
qsort(av, ac, sizeof (char **), compare);
}
return ac;
}
/*
** Split a pathname into allocated directory and trailing filename parts.
*/
static int
SplitPath(path, dirpart, filepart)
char *path;
char **dirpart;
char **filepart;
/* Split a pathname into allocated directory and trailing filename parts. */
static int SplitPath(char *path, char **dirpart, char **filepart)
{
static char DOT[] = ".";
char *dpart;
@@ -149,17 +149,13 @@ SplitPath(path, dirpart, filepart)
}
*dirpart = dpart;
*filepart = fpart;
return 0;
}
/*
** Attempt to complete the pathname, returning an allocated copy.
** Fill in *unique if we completed it, or set it to 0 if ambiguous.
*/
char *
default_rl_complete(pathname, unique)
char *pathname;
int *unique;
/* Attempt to complete the pathname, returning an allocated copy.
* Fill in *unique if we completed it, or set it to 0 if ambiguous. */
char *default_rl_complete(char *pathname, int *unique)
{
char **av;
char *dir;
@@ -174,9 +170,11 @@ default_rl_complete(pathname, unique)
if (SplitPath(pathname, &dir, &file) < 0)
return NULL;
if ((ac = FindMatches(dir, file, &av)) == 0) {
DISPOSE(dir);
DISPOSE(file);
return NULL;
}
@@ -222,16 +220,12 @@ default_rl_complete(pathname, unique)
for (i = 0; i < ac; i++)
DISPOSE(av[i]);
DISPOSE(av);
return p;
}
/*
** Return all possible completions.
*/
int
default_rl_list_possib(pathname, avp)
char *pathname;
char ***avp;
/* Return all possible completions. */
int default_rl_list_possib(char *pathname, char ***avp)
{
char *dir;
char *file;
@@ -239,12 +233,10 @@ default_rl_list_possib(pathname, avp)
if (SplitPath(pathname, &dir, &file) < 0)
return 0;
ac = FindMatches(dir, file, avp);
DISPOSE(dir);
DISPOSE(file);
return ac;
}
/*
* $PchId: complete.c,v 1.3 1996/02/22 21:18:51 philip Exp $
*/

View File

@@ -1,7 +1,24 @@
/* $Revision: 2220 $
**
** Main editing routines for editline library.
*/
/* Main editing routines for editline library.
*
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
*
* This software is not subject to any license of the American Telephone
* and Telegraph Company or of the Regents of the University of California.
*
* Permission is granted to anyone to use this software for any purpose on
* any computer system, and to alter it and redistribute it freely, subject
* to the following restrictions:
* 1. The authors are not responsible for the consequences of use of this
* software, no matter how awful, even if they arise from flaws in it.
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits must appear in the documentation.
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits must appear in the documentation.
* 4. This notice may not be removed or altered.
*/
#include "editline.h"
#include <signal.h>
#include <errno.h>
@@ -64,9 +81,9 @@ int rl_erase;
int rl_intr;
int rl_kill;
int rl_quit;
#if defined(DO_SIGTSTP)
#ifdef CONFIG_SIGSTOP
int rl_susp;
#endif /* defined(DO_SIGTSTP) */
#endif
static const char NIL[] = "";
static const char *Input = NIL;
@@ -105,12 +122,12 @@ int (*rl_list_possib)(char *token, char ***av);
** Declarations.
*/
static char *editinput(void);
#if defined(USE_TERMCAP)
#ifdef USE_TERMCAP
extern char *getenv(void);
extern char *tgetstr(void);
extern int tgetent(void);
extern int tgetnum(void);
#endif /* defined(USE_TERMCAP) */
#endif
/*
** TTY input/output functions.
@@ -196,30 +213,30 @@ static void tty_backn(int n)
static void tty_info(void)
{
static int init;
#if defined(USE_TERMCAP)
#ifdef USE_TERMCAP
char *term;
char buff[2048];
char *bp;
#endif /* defined(USE_TERMCAP) */
#if defined(TIOCGWINSZ)
#endif
#ifdef TIOCGWINSZ
struct winsize W;
#endif /* defined(TIOCGWINSZ) */
#endif
if (init) {
#if defined(TIOCGWINSZ)
#ifdef TIOCGWINSZ
/* Perhaps we got resized. */
if (ioctl(0, TIOCGWINSZ, &W) >= 0
&& W.ws_col > 0 && W.ws_row > 0) {
tty_width = (int)W.ws_col;
tty_rows = (int)W.ws_row;
}
#endif /* defined(TIOCGWINSZ) */
#endif
return;
}
init++;
tty_width = tty_rows = 0;
#if defined(USE_TERMCAP)
#ifdef USE_TERMCAP
bp = &buff[0];
if ((term = getenv("TERM")) == NULL)
term = "dumb";
@@ -232,14 +249,14 @@ static void tty_info(void)
backspace = strdup(backspace);
tty_width = tgetnum("co");
tty_rows = tgetnum("li");
#endif /* defined(USE_TERMCAP) */
#endif
#if defined(TIOCGWINSZ)
#ifdef TIOCGWINSZ
if (ioctl(0, TIOCGWINSZ, &W) >= 0) {
tty_width = (int)W.ws_col;
tty_rows = (int)W.ws_row;
}
#endif /* defined(TIOCGWINSZ) */
#endif
if (tty_width <= 0 || tty_rows <= 0) {
tty_width = SCREEN_WIDTH;
@@ -323,7 +340,7 @@ static el_status_t ring_bell(void)
static el_status_t do_macro(int c)
{
char name[4];
char name[4];
name[0] = '_';
name[1] = c;
@@ -367,7 +384,7 @@ static el_status_t do_case(el_case_t type)
int count;
char *p;
(void)do_forward(CSstay);
do_forward(CSstay);
if (OldPoint != Point) {
if ((count = Point - OldPoint) < 0)
count = -count;
@@ -379,8 +396,9 @@ static el_status_t do_case(el_case_t type)
if (islower(*p))
*p = toupper(*p);
}
else if (isupper(*p))
else if (isupper(*p)) {
*p = tolower(*p);
}
right(CSmove);
}
}
@@ -496,7 +514,7 @@ static el_status_t do_insert_hist(const char *p)
return insert_string(p);
}
static el_status_t do_hist(const char *(*move)())
static el_status_t do_hist(const char *(*move)(void))
{
const char *p;
int i;
@@ -544,7 +562,7 @@ static int substrcmp(const char *text, const char *pat, size_t len)
return 1;
}
static const char *search_hist(const char *search, const char *(*move)())
static const char *search_hist(const char *search, const char *(*move)(void))
{
static char *old_search;
int len;
@@ -610,7 +628,7 @@ static el_status_t h_search(void)
p = search_hist(p, move);
clear_line();
if (p == NULL) {
(void)ring_bell();
ring_bell();
return redisplay();
}
return do_insert_hist(p);
@@ -723,11 +741,11 @@ static el_status_t kill_line(void)
i = Point;
Point = Repeat;
reposition();
(void)delete_string(i - Point);
delete_string(i - Point);
}
else if (Repeat > Point) {
right(CSmove);
(void)delete_string(Repeat - Point - 1);
delete_string(Repeat - Point - 1);
}
return CSmove;
}
@@ -794,7 +812,7 @@ static el_status_t meta(void)
if ((c = tty_get()) == EOF)
return CSeof;
#if defined(ANSI_ARROWS)
#ifdef CONFIG_ANSI_ARROWS
/* Also include VT-100 arrows. */
if (c == '[' || c == 'O') {
c = tty_get();
@@ -814,7 +832,7 @@ static el_status_t meta(void)
case 'H': return beg_line(); /* Home */
}
}
#endif /* defined(ANSI_ARROWS) */
#endif /* CONFIG_ANSI_ARROWS */
if (isdigit(c)) {
for (Repeat = c - '0'; (c = tty_get()) != EOF && isdigit(c); )
@@ -883,12 +901,12 @@ static el_status_t tty_special(int c)
Signal = SIGQUIT;
return CSeof;
}
#if defined(DO_SIGTSTP)
#ifdef CONFIG_SIGSTOP
if (c == rl_susp) {
Signal = SIGTSTP;
return CSsignal;
}
#endif /* defined(DO_SIGTSTP) */
#endif
return CSdispatch;
}
@@ -984,17 +1002,14 @@ static char *read_redirected(void)
return line;
}
/*
** For compatibility with FSF readline.
*/
/* ARGSUSED0 */
/* For compatibility with FSF readline. */
void rl_reset_terminal(char *p __attribute__((__unused__)))
{
}
void rl_initialize(void)
{
#ifdef COMPLETE
#ifdef CONFIG_DEFAULT_COMPLETE
int done = 0;
if (!done)
@@ -1057,7 +1072,7 @@ char *readline(const char *prompt)
if (Signal > 0) {
s = Signal;
Signal = 0;
(void)kill(getpid(), s);
kill(getpid(), s);
}
return (char *)line;
}
@@ -1170,9 +1185,9 @@ static el_status_t c_complete(void)
DISPOSE(word);
if (len > 0) {
s = insert_string(new);
#if ANNOYING_NOISE
#ifdef CONFIG_ANNOYING_NOISE
if (!unique)
(void)ring_bell();
ring_bell();
#endif
}
DISPOSE(new);
@@ -1294,7 +1309,7 @@ static el_status_t fd_kill_word(void)
{
int i;
(void)do_forward(CSstay);
do_forward(CSstay);
if (OldPoint != Point) {
i = Point - OldPoint;
Point = OldPoint;
@@ -1325,7 +1340,7 @@ static el_status_t bk_word(void)
static el_status_t bk_kill_word(void)
{
(void)bk_word();
bk_word();
if (OldPoint != Point)
return delete_string(OldPoint - Point);
return CSstay;
@@ -1452,6 +1467,3 @@ static el_keymap_t MetaMap[]= {
{ 0, NULL }
};
/*
* $PchId: editline.c,v 1.4 1996/02/22 21:16:56 philip Exp $
*/

View File

@@ -1,7 +1,24 @@
/* $Revision: 5 $
**
** Internal header file for editline library.
*/
/* Internal header file for editline library.
*
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
*
* This software is not subject to any license of the American Telephone
* and Telegraph Company or of the Regents of the University of California.
*
* Permission is granted to anyone to use this software for any purpose on
* any computer system, and to alter it and redistribute it freely, subject
* to the following restrictions:
* 1. The authors are not responsible for the consequences of use of this
* software, no matter how awful, even if they arise from flaws in it.
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits must appear in the documentation.
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits must appear in the documentation.
* 4. This notice may not be removed or altered.
*/
#ifndef __PRIVATE_EDITLINE_H__
#define __PRIVATE_EDITLINE_H__
@@ -51,10 +68,10 @@ extern int rl_erase;
extern int rl_intr;
extern int rl_kill;
extern int rl_quit;
#ifdef DO_SIGTSTP
#ifdef CONFIG_SIGSTOP
extern int rl_susp;
#endif
#ifdef COMPLETE
#ifdef CONFIG_DEFAULT_COMPLETE
extern char *default_rl_complete();
extern int default_rl_list_possib(char *pathname, char ***avp);
#endif
@@ -62,18 +79,18 @@ extern void rl_ttyset(int Reset);
extern void rl_add_slash(char *path, char *p);
#ifndef HAVE_STDLIB_H
extern char *getenv();
extern char *malloc();
extern char *realloc();
extern char *memcpy();
extern char *strcat();
extern char *strchr();
extern char *strrchr();
extern char *strcpy();
extern char *strdup();
extern int strcmp();
extern int strlen();
extern int strncmp();
extern char *getenv(const char *name);
extern char *malloc(size_t size);
extern char *realloc(void *ptr, size_t size);
extern char *memcpy(void *dest, const void *src, size_t n);
extern char *strcat(char *dest, const char *src);
extern char *strchr(const char *s, int c);
extern char *strrchr(const char *s, int c);
extern char *strcpy(char *dest, const char *src);
extern char *strdup(const char *s);
extern int strcmp(const char *s1, const char *s2);
extern int strlen(const char *s);
extern int strncmp(const char *s1, const char *s2, size_t n);
#endif/* !HAVE_STDLIB */
#ifdef NEED_STRDUP

View File

@@ -1,7 +1,23 @@
/* $Revision: 5 $
**
** Unix system-dependant routines for editline library.
*/
/* Unix system-dependant routines for editline library.
*
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
*
* This software is not subject to any license of the American Telephone
* and Telegraph Company or of the Regents of the University of California.
*
* Permission is granted to anyone to use this software for any purpose on
* any computer system, and to alter it and redistribute it freely, subject
* to the following restrictions:
* 1. The authors are not responsible for the consequences of use of this
* software, no matter how awful, even if they arise from flaws in it.
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits must appear in the documentation.
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits must appear in the documentation.
* 4. This notice may not be removed or altered.
*/
#include "editline.h"
#if defined(HAVE_TCGETATTR)
@@ -19,7 +35,7 @@ void rl_ttyset(int Reset)
rl_eof = old.c_cc[VEOF];
rl_intr = old.c_cc[VINTR];
rl_quit = old.c_cc[VQUIT];
#ifdef DO_SIGTSTP
#ifdef CONFIG_SIGSTOP
rl_susp = old.c_cc[VSUSP];
#endif
@@ -49,7 +65,7 @@ void rl_ttyset(int Reset)
rl_eof = old.c_cc[VEOF];
rl_intr = old.c_cc[VINTR];
rl_quit = old.c_cc[VQUIT];
#ifdef DO_SIGTSTP
#ifdef CONFIG_SIGSTOP
rl_susp = old.c_cc[VSUSP];
#endif
@@ -73,7 +89,7 @@ void rl_ttyset(int Reset)
static struct tchars old_tchars;
struct sgttyb new_sgttyb;
struct tchars new_tchars;
#ifdef DO_SIGTSTP
#ifdef CONFIG_SIGSTOP
struct ltchars old_ltchars;
#endif
@@ -87,7 +103,7 @@ void rl_ttyset(int Reset)
rl_intr = old_tchars.t_intrc;
rl_quit = old_tchars.t_quitc;
#ifdef DO_SIGTSTP
#ifdef CONFIG_SIGSTOP
(void)ioctl(0, TIOCGLTC, &old_ltchars);
rl_susp = old_ltchars.t_suspc;
#endif
@@ -119,6 +135,3 @@ void rl_add_slash(char *path, char *p)
(void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ");
}
/*
* $PchId: sysunix.c,v 1.4 1996/02/22 21:16:56 philip Exp $
*/

View File

@@ -1,7 +1,26 @@
/* $Revision: 5 $
**
** Editline system header file for Unix.
*/
/* Editline system header file for Unix.
*
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
*
* This software is not subject to any license of the American Telephone
* and Telegraph Company or of the Regents of the University of California.
*
* Permission is granted to anyone to use this software for any purpose on
* any computer system, and to alter it and redistribute it freely, subject
* to the following restrictions:
* 1. The authors are not responsible for the consequences of use of this
* software, no matter how awful, even if they arise from flaws in it.
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits must appear in the documentation.
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits must appear in the documentation.
* 4. This notice may not be removed or altered.
*/
#ifndef __EDITLINE_UNIX_H__
#define __EDITLINE_UNIX_H__
#define CRLF "\r\n"
#define FORWARD STATIC
@@ -10,18 +29,16 @@
#include <sys/stat.h>
#include <unistd.h>
#if defined(USE_DIRENT)
#ifdef USE_DIRENT
#include <dirent.h>
typedef struct dirent DIRENTRY;
#else
#include <sys/dir.h>
typedef struct direct DIRENTRY;
#endif /* defined(USE_DIRENT) */
#endif
#if !defined(S_ISDIR)
#ifndef S_ISDIR
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif /* !defined(S_ISDIR) */
#endif
/*
* $PchId: unix.h,v 1.3 1996/02/22 21:18:51 philip Exp $
*/
#endif /* __EDITLINE_UNIX_H__ */