]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - readline/examples/rltest.c
Import readline 8.0
[thirdparty/binutils-gdb.git] / readline / examples / rltest.c
CommitLineData
d60d9f65
SS
1/* **************************************************************** */
2/* */
3/* Testing Readline */
4/* */
5/* **************************************************************** */
9255ee31 6
cc88a640 7/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
9255ee31 8
cc88a640 9 This file is part of the GNU Readline Library (Readline), a library for
9255ee31
EZ
10 reading lines of text with interactive input and history editing.
11
cc88a640
JK
12 Readline is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
9255ee31
EZ
15 (at your option) any later version.
16
cc88a640
JK
17 Readline is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9255ee31
EZ
20 GNU General Public License for more details.
21
cc88a640
JK
22 You should have received a copy of the GNU General Public License
23 along with Readline. If not, see <http://www.gnu.org/licenses/>.
24*/
d60d9f65 25
d60d9f65
SS
26#if defined (HAVE_CONFIG_H)
27#include <config.h>
28#endif
29
30#include <stdio.h>
31#include <sys/types.h>
1b17e766 32
5bdf8622
DJ
33#ifdef HAVE_STDLIB_H
34# include <stdlib.h>
35#else
36extern void exit();
37#endif
38
1b17e766
EZ
39#ifdef READLINE_LIBRARY
40# include "readline.h"
41# include "history.h"
42#else
43# include <readline/readline.h>
44# include <readline/history.h>
45#endif
d60d9f65
SS
46
47extern HIST_ENTRY **history_list ();
48
cb41b9e7 49int
d60d9f65
SS
50main ()
51{
52 char *temp, *prompt;
53 int done;
54
55 temp = (char *)NULL;
56 prompt = "readline$ ";
57 done = 0;
58
59 while (!done)
60 {
61 temp = readline (prompt);
62
63 /* Test for EOF. */
64 if (!temp)
65 exit (1);
66
67 /* If there is anything on the line, print it and remember it. */
68 if (*temp)
69 {
70 fprintf (stderr, "%s\r\n", temp);
71 add_history (temp);
72 }
73
74 /* Check for `command' that we handle. */
75 if (strcmp (temp, "quit") == 0)
76 done = 1;
77
78 if (strcmp (temp, "list") == 0)
79 {
80 HIST_ENTRY **list;
81 register int i;
82
83 list = history_list ();
84 if (list)
85 {
86 for (i = 0; list[i]; i++)
87 fprintf (stderr, "%d: %s\r\n", i, list[i]->line);
88 }
89 }
90 free (temp);
91 }
92 exit (0);
93}