2 * rl - command-line interface to read a line from the standard input
3 * (or another fd) using readline.
5 * usage: rl [-p prompt] [-u unit] [-d default] [-n nchars]
8 #if defined (HAVE_CONFIG_H)
13 #include <sys/types.h>
14 #include "posixstat.h"
16 #if defined (READLINE_LIBRARY)
17 # include "readline.h"
20 # include <readline/readline.h>
21 # include <readline/history.h>
27 #if !defined (strchr) && !defined (__STDC__)
28 extern char *strrchr();
31 static char *progname;
39 rl_insert_text (deftext);
40 deftext = (char *)NULL;
41 rl_startup_hook = (Function *)NULL;
49 fprintf (stderr, "%s: usage: %s [-p prompt] [-u unit] [-d default] [-n nchars]\n",
63 progname = strrchr(argv[0], '/');
70 prompt = "readline$ ";
74 while ((opt = getopt(argc, argv, "p:u:d:n:")) != EOF)
85 fprintf (stderr, "%s: bad file descriptor `%s'\n", progname, optarg);
96 fprintf (stderr, "%s: bad value for -n: `%s'\n", progname, optarg);
108 if (fstat (fd, &sb) < 0)
110 fprintf (stderr, "%s: %d: bad file descriptor\n", progname, fd);
113 ifp = fdopen (fd, "r");
117 if (deftext && *deftext)
118 rl_startup_hook = set_deftext;
121 rl_num_chars_to_read = nch;
123 temp = readline (prompt);