From ab304301db89e3906744fb6a81655b9598764582 Mon Sep 17 00:00:00 2001 From: ache Date: Sun, 31 Aug 2003 17:55:46 +0000 Subject: Virgin import of GNU Readline 4.3 --- contrib/libreadline/examples/Inputrc | 16 +++ contrib/libreadline/examples/Makefile.in | 16 ++- contrib/libreadline/examples/fileman.c | 42 +++++-- contrib/libreadline/examples/histexamp.c | 20 ++++ contrib/libreadline/examples/manexamp.c | 20 ++++ contrib/libreadline/examples/readlinebuf.h | 139 +++++++++++++++++++++++ contrib/libreadline/examples/rl.c | 20 ++++ contrib/libreadline/examples/rlcat.c | 174 +++++++++++++++++++++++++++++ contrib/libreadline/examples/rltest.c | 20 ++++ contrib/libreadline/examples/rlversion.c | 20 ++++ 10 files changed, 471 insertions(+), 16 deletions(-) create mode 100644 contrib/libreadline/examples/readlinebuf.h create mode 100644 contrib/libreadline/examples/rlcat.c (limited to 'contrib/libreadline/examples') diff --git a/contrib/libreadline/examples/Inputrc b/contrib/libreadline/examples/Inputrc index 5b71bd7..d7fdb42 100644 --- a/contrib/libreadline/examples/Inputrc +++ b/contrib/libreadline/examples/Inputrc @@ -4,6 +4,22 @@ # on which program is running, or what terminal is active. # +# Copyright (C) 1989-2002 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. + # In all programs, all terminals, make sure this is bound. "\C-x\C-r": re-read-init-file diff --git a/contrib/libreadline/examples/Makefile.in b/contrib/libreadline/examples/Makefile.in index 1e90f8a..72c9904 100644 --- a/contrib/libreadline/examples/Makefile.in +++ b/contrib/libreadline/examples/Makefile.in @@ -26,6 +26,9 @@ VPATH = .:@srcdir@ top_srcdir = @top_srcdir@ BUILD_DIR = . +# Support an alternate destination root directory for package building +DESTDIR = + DEFS = @DEFS@ CC = @CC@ CFLAGS = @CFLAGS@ @@ -35,7 +38,7 @@ CPPFLAGS = @CPPFLAGS@ INCLUDES = -I$(srcdir) -I$(top_srcdir) -I.. CCFLAGS = $(DEFS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(INCLUDES) $(CFLAGS) -LDFLAGS = -g -L.. +LDFLAGS = -g -L.. @LDFLAGS@ READLINE_LIB = ../libreadline.a HISTORY_LIB = ../libhistory.a @@ -46,19 +49,22 @@ TERMCAP_LIB = @TERMCAP_LIB@ ${RM} $@ $(CC) $(CCFLAGS) -c $< -EXECUTABLES = fileman rltest rl rlversion histexamp +EXECUTABLES = fileman rltest rl rlcat rlversion histexamp OBJECTS = fileman.o rltest.o rl.o rlversion.o histexamp.o all: $(EXECUTABLES) everything: all rlfe -rl: rl.o +rl: rl.o $(READLINE_LIB) $(CC) $(LDFLAGS) -o $@ rl.o -lreadline $(TERMCAP_LIB) -fileman: fileman.o +rlcat: rlcat.o $(READLINE_LIB) + $(CC) $(LDFLAGS) -o $@ rlcat.o -lreadline $(TERMCAP_LIB) + +fileman: fileman.o $(READLINE_LIB) $(CC) $(LDFLAGS) -o $@ fileman.o -lreadline $(TERMCAP_LIB) -rltest: rltest.o +rltest: rltest.o $(READLINE_LIB) $(CC) $(LDFLAGS) -o $@ rltest.o -lreadline $(TERMCAP_LIB) rlversion: rlversion.o $(READLINE_LIB) diff --git a/contrib/libreadline/examples/fileman.c b/contrib/libreadline/examples/fileman.c index e976848..340eee7 100644 --- a/contrib/libreadline/examples/fileman.c +++ b/contrib/libreadline/examples/fileman.c @@ -1,3 +1,23 @@ +/* Copyright (C) 1987-2002 Free Software Foundation, Inc. + + This file is part of the GNU Readline Library, a library for + reading lines of text with interactive input and history editing. + + The GNU Readline Library is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2, or + (at your option) any later version. + + The GNU Readline Library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + The GNU General Public License is often shipped with GNU software, and + is generally kept in a file called COPYING or LICENSE. If you do not + have a copy of the license, write to the Free Software Foundation, + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + /* fileman.c -- A tiny application which demonstrates how to use the GNU Readline library. This application interactively allows users to manipulate files and their modes. */ @@ -41,15 +61,15 @@ extern char *xmalloc (); /* The names of functions that actually do the manipulation. */ -int com_list __P((char *)); -int com_view __P((char *)); -int com_rename __P((char *)); -int com_stat __P((char *)); -int com_pwd __P((char *)); -int com_delete __P((char *)); -int com_help __P((char *)); -int com_cd __P((char *)); -int com_quit __P((char *)); +int com_list PARAMS((char *)); +int com_view PARAMS((char *)); +int com_rename PARAMS((char *)); +int com_stat PARAMS((char *)); +int com_pwd PARAMS((char *)); +int com_delete PARAMS((char *)); +int com_help PARAMS((char *)); +int com_cd PARAMS((char *)); +int com_quit PARAMS((char *)); /* A structure which contains information on the commands this program can understand. */ @@ -212,8 +232,8 @@ stripwhite (string) /* */ /* **************************************************************** */ -char *command_generator __P((const char *, int)); -char **fileman_completion __P((const char *, int, int)); +char *command_generator PARAMS((const char *, int)); +char **fileman_completion PARAMS((const char *, int, int)); /* Tell the GNU Readline library how to complete. We want to try to complete on command names if this is the first word in the line, or on filenames diff --git a/contrib/libreadline/examples/histexamp.c b/contrib/libreadline/examples/histexamp.c index fa0de1b..45651df 100644 --- a/contrib/libreadline/examples/histexamp.c +++ b/contrib/libreadline/examples/histexamp.c @@ -1,3 +1,23 @@ +/* Copyright (C) 1987-2002 Free Software Foundation, Inc. + + This file is part of the GNU Readline Library, a library for + reading lines of text with interactive input and history editing. + + The GNU Readline Library is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2, or + (at your option) any later version. + + The GNU Readline Library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + The GNU General Public License is often shipped with GNU software, and + is generally kept in a file called COPYING or LICENSE. If you do not + have a copy of the license, write to the Free Software Foundation, + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + #include #ifdef READLINE_LIBRARY diff --git a/contrib/libreadline/examples/manexamp.c b/contrib/libreadline/examples/manexamp.c index 132e2bf..9c6cf2c 100644 --- a/contrib/libreadline/examples/manexamp.c +++ b/contrib/libreadline/examples/manexamp.c @@ -1,5 +1,25 @@ /* manexamp.c -- The examples which appear in the documentation are here. */ +/* Copyright (C) 1987-2002 Free Software Foundation, Inc. + + This file is part of the GNU Readline Library, a library for + reading lines of text with interactive input and history editing. + + The GNU Readline Library is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2, or + (at your option) any later version. + + The GNU Readline Library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + The GNU General Public License is often shipped with GNU software, and + is generally kept in a file called COPYING or LICENSE. If you do not + have a copy of the license, write to the Free Software Foundation, + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + #include #include diff --git a/contrib/libreadline/examples/readlinebuf.h b/contrib/libreadline/examples/readlinebuf.h new file mode 100644 index 0000000..a8af52c --- /dev/null +++ b/contrib/libreadline/examples/readlinebuf.h @@ -0,0 +1,139 @@ +/******************************************************************************* + * $Revision: 1.2 $ + * $Date: 2001/09/11 06:19:36 $ + * $Author: vyzo $ + * + * Contents: A streambuf which uses the GNU readline library for line I/O + * (c) 2001 by Dimitris Vyzovitis [vyzo@media.mit.edu] + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ******************************************************************************/ + +#ifndef _READLINEBUF_H_ +#define _READLINEBUF_H_ + +#include +#include +#include +#include +#include + +#include +#include + +#if (defined __GNUC__) && (__GNUC__ < 3) +#include +#else +#include +using std::streamsize; +using std::streambuf; +#endif + +class readlinebuf : public streambuf { +public: +#if (defined __GNUC__) && (__GNUC__ < 3) + typedef char char_type; + typedef int int_type; + typedef streampos pos_type; + typedef streamoff off_type; +#endif + static const int_type eof = EOF; // this is -1 + static const int_type not_eof = 0; + +private: + const char* prompt_; + bool history_; + char* line_; + int low_; + int high_; + +protected: + + virtual int_type showmanyc() const { return high_ - low_; } + + virtual streamsize xsgetn( char_type* buf, streamsize n ) { + int rd = n > (high_ - low_)? (high_ - low_) : n; + memcpy( buf, line_, rd ); + low_ += rd; + + if ( rd < n ) { + low_ = high_ = 0; + free( line_ ); // free( NULL ) is a noop + line_ = readline( prompt_ ); + if ( line_ ) { + high_ = strlen( line_ ); + if ( history_ && high_ ) add_history( line_ ); + rd += xsgetn( buf + rd, n - rd ); + } + } + + return rd; + } + + virtual int_type underflow() { + if ( high_ == low_ ) { + low_ = high_ = 0; + free( line_ ); // free( NULL ) is a noop + line_ = readline( prompt_ ); + if ( line_ ) { + high_ = strlen( line_ ); + if ( history_ && high_ ) add_history( line_ ); + } + } + + if ( low_ < high_ ) return line_[low_]; + else return eof; + } + + virtual int_type uflow() { + int_type c = underflow(); + if ( c != eof ) ++low_; + return c; + } + + virtual int_type pbackfail( int_type c = eof ) { + if ( low_ > 0 ) --low_; + else if ( c != eof ) { + if ( high_ > 0 ) { + char* nl = (char*)realloc( line_, high_ + 1 ); + if ( nl ) { + line_ = (char*)memcpy( nl + 1, line_, high_ ); + high_ += 1; + line_[0] = char( c ); + } else return eof; + } else { + assert( !line_ ); + line_ = (char*)malloc( sizeof( char ) ); + *line_ = char( c ); + high_ = 1; + } + } else return eof; + + return not_eof; + } + +public: + readlinebuf( const char* prompt = NULL, bool history = true ) + : prompt_( prompt ), history_( history ), + line_( NULL ), low_( 0 ), high_( 0 ) { + setbuf( 0, 0 ); + } + + +}; + +#endif diff --git a/contrib/libreadline/examples/rl.c b/contrib/libreadline/examples/rl.c index 8636184..d260489 100644 --- a/contrib/libreadline/examples/rl.c +++ b/contrib/libreadline/examples/rl.c @@ -5,6 +5,26 @@ * usage: rl [-p prompt] [-u unit] [-d default] [-n nchars] */ +/* Copyright (C) 1987-2002 Free Software Foundation, Inc. + + This file is part of the GNU Readline Library, a library for + reading lines of text with interactive input and history editing. + + The GNU Readline Library is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2, or + (at your option) any later version. + + The GNU Readline Library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + The GNU General Public License is often shipped with GNU software, and + is generally kept in a file called COPYING or LICENSE. If you do not + have a copy of the license, write to the Free Software Foundation, + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + #if defined (HAVE_CONFIG_H) # include #endif diff --git a/contrib/libreadline/examples/rlcat.c b/contrib/libreadline/examples/rlcat.c new file mode 100644 index 0000000..176b9f4 --- /dev/null +++ b/contrib/libreadline/examples/rlcat.c @@ -0,0 +1,174 @@ +/* + * rlcat - cat(1) using readline + * + * usage: rlcat + */ + +/* Copyright (C) 1987-2002 Free Software Foundation, Inc. + + This file is part of the GNU Readline Library, a library for + reading lines of text with interactive input and history editing. + + The GNU Readline Library is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2, or + (at your option) any later version. + + The GNU Readline Library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + The GNU General Public License is often shipped with GNU software, and + is generally kept in a file called COPYING or LICENSE. If you do not + have a copy of the license, write to the Free Software Foundation, + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + +#if defined (HAVE_CONFIG_H) +# include +#endif + +#ifdef HAVE_UNISTD_H +# include +#endif + +#include +#include "posixstat.h" + +#include +#include +#include +#include + +#ifndef errno +extern int errno; +#endif + +#if defined (READLINE_LIBRARY) +# include "readline.h" +# include "history.h" +#else +# include +# include +#endif + +extern int optind; +extern char *optarg; + +static int stdcat(); + +static char *progname; +static int vflag; + +static void +usage() +{ + fprintf (stderr, "%s: usage: %s [-vEVN] [filename]\n", progname, progname); +} + +int +main (argc, argv) + int argc; + char **argv; +{ + char *temp; + int opt, Vflag, Nflag; + + progname = strrchr(argv[0], '/'); + if (progname == 0) + progname = argv[0]; + else + progname++; + + vflag = Vflag = Nflag = 0; + while ((opt = getopt(argc, argv, "vEVN")) != EOF) + { + switch (opt) + { + case 'v': + vflag = 1; + break; + case 'V': + Vflag = 1; + break; + case 'E': + Vflag = 0; + break; + case 'N': + Nflag = 1; + break; + default: + usage (); + exit (2); + } + } + + argc -= optind; + argv += optind; + + if (isatty(0) == 0 || argc || Nflag) + return stdcat(argc, argv); + + rl_variable_bind ("editing-mode", Vflag ? "vi" : "emacs"); + while (temp = readline ("")) + { + if (*temp) + add_history (temp); + printf ("%s\n", temp); + } + + return (ferror (stdout)); +} + +static int +fcopy(fp) + FILE *fp; +{ + int c; + char *x; + + while ((c = getc(fp)) != EOF) + { + if (vflag && isascii ((unsigned char)c) && isprint((unsigned char)c) == 0) + { + x = rl_untranslate_keyseq (c); + if (fputs (x, stdout) != 0) + return 1; + } + else if (putchar (c) == EOF) + return 1; + } + return (ferror (stdout)); +} + +int +stdcat (argc, argv) + int argc; + char **argv; +{ + int i, fd, r; + char *s; + FILE *fp; + + if (argc == 0) + return (fcopy(stdin)); + + for (i = 0, r = 1; i < argc; i++) + { + if (*argv[i] == '-' && argv[i][1] == 0) + fp = stdin; + else + { + fp = fopen (argv[i], "r"); + if (fp == 0) + { + fprintf (stderr, "%s: %s: cannot open: %s\n", progname, argv[i], strerror(errno)); + continue; + } + } + r = fcopy (fp); + if (fp != stdin) + fclose(fp); + } + return r; +} diff --git a/contrib/libreadline/examples/rltest.c b/contrib/libreadline/examples/rltest.c index 6250f90..99f083b 100644 --- a/contrib/libreadline/examples/rltest.c +++ b/contrib/libreadline/examples/rltest.c @@ -4,6 +4,26 @@ /* */ /* **************************************************************** */ +/* Copyright (C) 1987-2002 Free Software Foundation, Inc. + + This file is part of the GNU Readline Library, a library for + reading lines of text with interactive input and history editing. + + The GNU Readline Library is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2, or + (at your option) any later version. + + The GNU Readline Library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + The GNU General Public License is often shipped with GNU software, and + is generally kept in a file called COPYING or LICENSE. If you do not + have a copy of the license, write to the Free Software Foundation, + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + #if defined (HAVE_CONFIG_H) #include #endif diff --git a/contrib/libreadline/examples/rlversion.c b/contrib/libreadline/examples/rlversion.c index 652d37c..53949d1 100644 --- a/contrib/libreadline/examples/rlversion.c +++ b/contrib/libreadline/examples/rlversion.c @@ -2,6 +2,26 @@ * rlversion -- print out readline's version number */ +/* Copyright (C) 1987-2002 Free Software Foundation, Inc. + + This file is part of the GNU Readline Library, a library for + reading lines of text with interactive input and history editing. + + The GNU Readline Library is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2, or + (at your option) any later version. + + The GNU Readline Library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + The GNU General Public License is often shipped with GNU software, and + is generally kept in a file called COPYING or LICENSE. If you do not + have a copy of the license, write to the Free Software Foundation, + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + #if defined (HAVE_CONFIG_H) # include #endif -- cgit v1.1