summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2016-09-15 17:02:15 -0400
committerChet Ramey <chet.ramey@case.edu>2016-09-15 17:02:15 -0400
commitd49a9082c0e15bba8cd3d8cc0a994409cf823cac (patch)
treef0737355f68bc024a31beb0a5dd3c0370f522071 /examples
parent96c967e80aeaeda3c06ab298de77efd41288bb86 (diff)
downloadreadline-d49a9082c0e15bba8cd3d8cc0a994409cf823cac.tar.gz
Readline-7.0 distribution sources and documentationreadline-7.0
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.in35
-rw-r--r--examples/fileman.c18
-rw-r--r--examples/hist_erasedups.c2
-rw-r--r--examples/hist_purgecmd.c2
-rw-r--r--examples/rl-callbacktest.c32
-rw-r--r--examples/rl.c1
-rw-r--r--examples/rlbasic.c29
-rw-r--r--examples/rlptytest.c8
-rw-r--r--examples/rlversion.c1
9 files changed, 106 insertions, 22 deletions
diff --git a/examples/Makefile.in b/examples/Makefile.in
index 04399ce..5094c6c 100644
--- a/examples/Makefile.in
+++ b/examples/Makefile.in
@@ -53,11 +53,9 @@ CPPFLAGS = @CPPFLAGS@
INCLUDES = -I$(srcdir) -I$(top_srcdir) -I..
-CCFLAGS = $(DEFS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(INCLUDES) $(CFLAGS)
+CCFLAGS = $(DEFS) $(LOCAL_CFLAGS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
LDFLAGS = -g -L.. @LDFLAGS@
-PURIFY = @PURIFY@
-
READLINE_LIB = ../libreadline.a
HISTORY_LIB = ../libhistory.a
@@ -68,16 +66,16 @@ TERMCAP_LIB = @TERMCAP_LIB@
$(CC) $(CCFLAGS) -c $<
SOURCES = excallback.c fileman.c histexamp.c manexamp.c rl-fgets.c rl.c \
- rlcat.c rlevent.c rlptytest.c rltest.c rlversion.c \
+ rlbasic.c rlcat.c rlevent.c rlptytest.c rltest.c rlversion.c \
rl-callbacktest.c hist_erasedups.c hist_purgecmd.c
EXECUTABLES = fileman$(EXEEXT) rltest$(EXEEXT) rl$(EXEEXT) rlcat$(EXEEXT) \
rlevent$(EXEEXT) rlversion$(EXEEXT) histexamp$(EXEEXT) \
- rl-callbacktest$(EXEEXT) \
+ rl-callbacktest$(EXEEXT) rlbasic$(EXEEXT) \
hist_erasedups$(EXEEXT) hist_purgecmd$(EXEEXT)
OBJECTS = fileman.o rltest.o rl.o rlevent.o rlcat.o rlversion.o histexamp.o \
- rl-callbacktest.o hist_erasedups.o hist_purgecmd.o
+ rl-callbacktest.o rlbasic.o hist_erasedups.o hist_purgecmd.o
OTHEREXE = rlptytest$(EXEEXT)
OTHEROBJ = rlptytest.o
@@ -104,37 +102,40 @@ uninstall:
-rmdir $(DESTDIR)$(installdir)
rl$(EXEEXT): rl.o $(READLINE_LIB)
- $(PURIFY) $(CC) $(LDFLAGS) -o $@ rl.o $(READLINE_LIB) $(TERMCAP_LIB)
+ $(CC) $(LDFLAGS) -o $@ rl.o $(READLINE_LIB) $(TERMCAP_LIB)
+
+rlbasic$(EXEEXT): rlbasic.o $(READLINE_LIB)
+ $(CC) $(LDFLAGS) -o $@ rlbasic.o $(READLINE_LIB) $(TERMCAP_LIB)
rlcat$(EXEEXT): rlcat.o $(READLINE_LIB)
- $(PURIFY) $(CC) $(LDFLAGS) -o $@ rlcat.o $(READLINE_LIB) $(TERMCAP_LIB)
+ $(CC) $(LDFLAGS) -o $@ rlcat.o $(READLINE_LIB) $(TERMCAP_LIB)
rlevent$(EXEEXT): rlevent.o $(READLINE_LIB)
- $(PURIFY) $(CC) $(LDFLAGS) -o $@ rlevent.o $(READLINE_LIB) $(TERMCAP_LIB)
+ $(CC) $(LDFLAGS) -o $@ rlevent.o $(READLINE_LIB) $(TERMCAP_LIB)
fileman$(EXEEXT): fileman.o $(READLINE_LIB)
- $(PURIFY) $(CC) $(LDFLAGS) -o $@ fileman.o $(READLINE_LIB) $(TERMCAP_LIB)
+ $(CC) $(LDFLAGS) -o $@ fileman.o $(READLINE_LIB) $(TERMCAP_LIB)
rltest$(EXEEXT): rltest.o $(READLINE_LIB)
- $(PURIFY) $(CC) $(LDFLAGS) -o $@ rltest.o $(READLINE_LIB) $(TERMCAP_LIB)
+ $(CC) $(LDFLAGS) -o $@ rltest.o $(READLINE_LIB) $(TERMCAP_LIB)
rl-callbacktest$(EXEEXT): rl-callbacktest.o $(READLINE_LIB)
- $(PURIFY) $(CC) $(LDFLAGS) -o $@ rl-callbacktest.o $(READLINE_LIB) $(TERMCAP_LIB)
+ $(CC) $(LDFLAGS) -o $@ rl-callbacktest.o $(READLINE_LIB) $(TERMCAP_LIB)
rlptytest$(EXEEXT): rlptytest.o $(READLINE_LIB)
- $(PURIFY) $(CC) $(LDFLAGS) -o $@ rlptytest.o $(READLINE_LIB) $(TERMCAP_LIB)
+ $(CC) $(LDFLAGS) -o $@ rlptytest.o $(READLINE_LIB) $(TERMCAP_LIB) $(LIBUTIL)
rlversion$(EXEEXT): rlversion.o $(READLINE_LIB)
$(CC) $(LDFLAGS) -o $@ rlversion.o $(READLINE_LIB) $(TERMCAP_LIB)
histexamp$(EXEEXT): histexamp.o $(HISTORY_LIB)
- $(PURIFY) $(CC) $(LDFLAGS) -o $@ histexamp.o -lhistory $(TERMCAP_LIB)
+ $(CC) $(LDFLAGS) -o $@ histexamp.o -lhistory $(TERMCAP_LIB)
hist_erasedups$(EXEEXT): hist_erasedups.o $(HISTORY_LIB)
- $(PURIFY) $(CC) $(LDFLAGS) -o $@ hist_erasedups.o -lhistory $(TERMCAP_LIB)
+ $(CC) $(LDFLAGS) -o $@ hist_erasedups.o -lhistory $(TERMCAP_LIB)
hist_purgecmd$(EXEEXT): hist_purgecmd.o $(HISTORY_LIB)
- $(PURIFY) $(CC) $(LDFLAGS) -o $@ hist_purgecmd.o -lhistory $(TERMCAP_LIB)
+ $(CC) $(LDFLAGS) -o $@ hist_purgecmd.o -lhistory $(TERMCAP_LIB)
clean mostlyclean:
$(RM) $(OBJECTS) $(OTHEROBJ)
@@ -150,6 +151,7 @@ rlversion.o: rlversion.c
histexamp.o: histexamp.c
hist_erasedups.o: hist_erasedups.c
hist_purgecmd.o: hist_purgecmd.c
+rlbasic.o: rlbasic.c
rlcat.o: rlcat.c
rlptytest.o: rlptytest.c
rl-callbacktest.o: rl-callbacktest.c
@@ -161,6 +163,7 @@ rlversion.o: $(top_srcdir)/readline.h
histexamp.o: $(top_srcdir)/history.h
hist_erasedups.o: $(top_srcdir)/history.h
hist_purgecmd.o: $(top_srcdir)/history.h
+rlbasic.o: $(top_srcdir)/readline.h $(top_srcdir)/history.h
rlcat.o: $(top_srcdir)/readline.h $(top_srcdir)/history.h
rlptytest.o: $(top_srcdir)/readline.h $(top_srcdir)/history.h
rl-callbacktest.o: $(top_srcdir)/readline.h $(top_srcdir)/history.h
diff --git a/examples/fileman.c b/examples/fileman.c
index f7eed8a..c821df0 100644
--- a/examples/fileman.c
+++ b/examples/fileman.c
@@ -63,6 +63,12 @@
extern char *xmalloc PARAMS((size_t));
+void initialize_readline PARAMS((void));
+void too_dangerous PARAMS((char *));
+
+int execute_line PARAMS((char *));
+int valid_argument PARAMS((char *, char *));
+
/* The names of functions that actually do the manipulation. */
int com_list PARAMS((char *));
int com_view PARAMS((char *));
@@ -119,6 +125,7 @@ dupstr (s)
return (r);
}
+int
main (argc, argv)
int argc;
char **argv;
@@ -241,6 +248,7 @@ 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
if not. */
+void
initialize_readline ()
{
/* Allow conditional parsing of the ~/.inputrc file. */
@@ -317,6 +325,7 @@ command_generator (text, state)
static char syscom[1024];
/* List the file(s) named in arg. */
+int
com_list (arg)
char *arg;
{
@@ -327,6 +336,7 @@ com_list (arg)
return (system (syscom));
}
+int
com_view (arg)
char *arg;
{
@@ -342,6 +352,7 @@ com_view (arg)
return (system (syscom));
}
+int
com_rename (arg)
char *arg;
{
@@ -349,6 +360,7 @@ com_rename (arg)
return (1);
}
+int
com_stat (arg)
char *arg;
{
@@ -377,6 +389,7 @@ com_stat (arg)
return (0);
}
+int
com_delete (arg)
char *arg;
{
@@ -386,6 +399,7 @@ com_delete (arg)
/* Print out help for ARG, or for all of the commands if ARG is
not present. */
+int
com_help (arg)
char *arg;
{
@@ -425,6 +439,7 @@ com_help (arg)
}
/* Change to the directory ARG. */
+int
com_cd (arg)
char *arg;
{
@@ -439,6 +454,7 @@ com_cd (arg)
}
/* Print out the current working directory. */
+int
com_pwd (ignore)
char *ignore;
{
@@ -456,6 +472,7 @@ com_pwd (ignore)
}
/* The user wishes to quit using this program. Just set DONE non-zero. */
+int
com_quit (arg)
char *arg;
{
@@ -464,6 +481,7 @@ com_quit (arg)
}
/* Function which tells you that you can't do this. */
+void
too_dangerous (caller)
char *caller;
{
diff --git a/examples/hist_erasedups.c b/examples/hist_erasedups.c
index 02d617e..2ecee89 100644
--- a/examples/hist_erasedups.c
+++ b/examples/hist_erasedups.c
@@ -38,8 +38,6 @@
#define STREQN(a, b, n) ((n == 0) ? (1) \
: ((a)[0] == (b)[0] && strncmp(a, b, n) == 0))
-extern int history_offset;
-
static void
usage()
{
diff --git a/examples/hist_purgecmd.c b/examples/hist_purgecmd.c
index 94becd8..d836d14 100644
--- a/examples/hist_purgecmd.c
+++ b/examples/hist_purgecmd.c
@@ -41,8 +41,6 @@
#define STREQN(a, b, n) ((n == 0) ? (1) \
: ((a)[0] == (b)[0] && strncmp(a, b, n) == 0))
-extern int history_offset;
-
#define PURGE_REGEXP 0x01
static void
diff --git a/examples/rl-callbacktest.c b/examples/rl-callbacktest.c
index 87a781d..3525ffd 100644
--- a/examples/rl-callbacktest.c
+++ b/examples/rl-callbacktest.c
@@ -2,11 +2,15 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#include <locale.h>
/* Used for select(2) */
#include <sys/types.h>
#include <sys/select.h>
+#include <signal.h>
+
+#include <errno.h>
#include <stdio.h>
/* Standard readline include files. */
@@ -18,11 +22,22 @@
# include <readline/history.h>
#endif
+extern int errno;
+
static void cb_linehandler (char *);
+static void signandler (int);
-int running;
+int running, sigwinch_received;
const char *prompt = "rltest$ ";
+/* Handle SIGWINCH and window size changes when readline is not active and
+ reading a character. */
+static void
+sighandler (int sig)
+{
+ sigwinch_received = 1;
+}
+
/* Callback function called for each line when accept-line executed, EOF
seen, or EOF character read. This sets a flag and returns; it could
also call exit(3). */
@@ -57,6 +72,12 @@ main (int c, char **v)
fd_set fds;
int r;
+
+ setlocale (LC_ALL, "");
+
+ /* Handle SIGWINCH */
+ signal (SIGWINCH, sighandler);
+
/* Install the line handler. */
rl_callback_handler_install (prompt, cb_linehandler);
@@ -71,12 +92,19 @@ main (int c, char **v)
FD_SET (fileno (rl_instream), &fds);
r = select (FD_SETSIZE, &fds, NULL, NULL, NULL);
- if (r < 0)
+ if (r < 0 && errno != EINTR)
{
perror ("rltest: select");
rl_callback_handler_remove ();
break;
}
+ if (sigwinch_received)
+ {
+ rl_resize_terminal ();
+ sigwinch_received = 0;
+ }
+ if (r < 0)
+ continue;
if (FD_ISSET (fileno (rl_instream), &fds))
rl_callback_read_char ();
diff --git a/examples/rl.c b/examples/rl.c
index 845a4b1..a5cf276 100644
--- a/examples/rl.c
+++ b/examples/rl.c
@@ -28,6 +28,7 @@
# include <config.h>
#endif
+#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
diff --git a/examples/rlbasic.c b/examples/rlbasic.c
new file mode 100644
index 0000000..6a9601f
--- /dev/null
+++ b/examples/rlbasic.c
@@ -0,0 +1,29 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+#if defined (READLINE_LIBRARY)
+# include "readline.h"
+# include "history.h"
+#else
+# include <readline/readline.h>
+# include <readline/history.h>
+#endif
+
+int
+main (int c, char **v)
+{
+ char *input;
+
+ for (;;) {
+ input = readline ((char *)NULL);
+ if (input == 0)
+ break;
+ printf ("%s\n", input);
+ if (strcmp (input, "exit") == 0)
+ break;
+ free (input);
+ }
+ exit (0);
+}
diff --git a/examples/rlptytest.c b/examples/rlptytest.c
index 0699e86..9c42f8a 100644
--- a/examples/rlptytest.c
+++ b/examples/rlptytest.c
@@ -48,6 +48,13 @@ sigint (s)
exit (0);
}
+void
+sigwinch (s)
+ int s;
+{
+ rl_resize_terminal ();
+}
+
static int
user_input()
{
@@ -316,6 +323,7 @@ main()
if (val == -1)
return -1;
+ signal (SIGWINCH, sigwinch);
signal (SIGINT, sigint);
val = init_readline (slavefd, slavefd);
diff --git a/examples/rlversion.c b/examples/rlversion.c
index 88f4cd7..f36567b 100644
--- a/examples/rlversion.c
+++ b/examples/rlversion.c
@@ -41,6 +41,7 @@ extern void exit();
# include <readline/readline.h>
#endif
+int
main()
{
printf ("%s\n", rl_library_version ? rl_library_version : "unknown");