From 1e4e5d08e95b810dc5bcec9a3b9b296a0c3afa85 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Wed, 23 Nov 2011 19:10:13 -0500 Subject: Readline-4.3 import --- examples/Inputrc | 16 +++++ examples/Makefile.in | 13 ++-- examples/fileman.c | 20 ++++++ examples/histexamp.c | 20 ++++++ examples/manexamp.c | 20 ++++++ examples/rl.c | 20 ++++++ examples/rlcat.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++ examples/rltest.c | 20 ++++++ examples/rlversion.c | 20 ++++++ 9 files changed, 318 insertions(+), 5 deletions(-) create mode 100644 examples/rlcat.c (limited to 'examples') diff --git a/examples/Inputrc b/examples/Inputrc index 5b71bd7..d7fdb42 100644 --- a/examples/Inputrc +++ b/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/examples/Makefile.in b/examples/Makefile.in index f189664..72c9904 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -38,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 @@ -49,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/examples/fileman.c b/examples/fileman.c index 578491a..340eee7 100644 --- a/examples/fileman.c +++ b/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. */ diff --git a/examples/histexamp.c b/examples/histexamp.c index fa0de1b..45651df 100644 --- a/examples/histexamp.c +++ b/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/examples/manexamp.c b/examples/manexamp.c index 132e2bf..9c6cf2c 100644 --- a/examples/manexamp.c +++ b/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/examples/rl.c b/examples/rl.c index 8636184..d260489 100644 --- a/examples/rl.c +++ b/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/examples/rlcat.c b/examples/rlcat.c new file mode 100644 index 0000000..176b9f4 --- /dev/null +++ b/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/examples/rltest.c b/examples/rltest.c index 6250f90..99f083b 100644 --- a/examples/rltest.c +++ b/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/examples/rlversion.c b/examples/rlversion.c index 652d37c..53949d1 100644 --- a/examples/rlversion.c +++ b/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.2.1