summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2011-11-23 19:10:13 -0500
committerChet Ramey <chet.ramey@case.edu>2011-11-23 19:10:13 -0500
commit1e4e5d08e95b810dc5bcec9a3b9b296a0c3afa85 (patch)
tree3972ebdded0214475d2a402a1cd836da41f7bf2b /examples
parentabde3125f6228a63e22de708b9edaef62cab0ac3 (diff)
downloadreadline-1e4e5d08e95b810dc5bcec9a3b9b296a0c3afa85.tar.gz
Readline-4.3 import
Diffstat (limited to 'examples')
-rw-r--r--examples/Inputrc16
-rw-r--r--examples/Makefile.in13
-rw-r--r--examples/fileman.c20
-rw-r--r--examples/histexamp.c20
-rw-r--r--examples/manexamp.c20
-rw-r--r--examples/rl.c20
-rw-r--r--examples/rlcat.c174
-rw-r--r--examples/rltest.c20
-rw-r--r--examples/rlversion.c20
9 files changed, 318 insertions, 5 deletions
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 <stdio.h>
#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 <stdio.h>
#include <readline/readline.h>
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 <config.h>
#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 <config.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include <sys/types.h>
+#include "posixstat.h"
+
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <errno.h>
+
+#ifndef errno
+extern int errno;
+#endif
+
+#if defined (READLINE_LIBRARY)
+# include "readline.h"
+# include "history.h"
+#else
+# include <readline/readline.h>
+# include <readline/history.h>
+#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 <config.h>
#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 <config.h>
#endif