rltest.c revision 21308
1/* **************************************************************** */
2/*								    */
3/*			Testing Readline			    */
4/*								    */
5/* **************************************************************** */
6
7#include <stdio.h>
8#include <sys/types.h>
9#include "../readline.h"
10#include "../history.h"
11
12main ()
13{
14  HIST_ENTRY **history_list ();
15  char *temp = (char *)NULL;
16  char *prompt = "readline$ ";
17  int done = 0;
18
19  while (!done)
20    {
21      temp = readline (prompt);
22
23      /* Test for EOF. */
24      if (!temp)
25	exit (1);
26
27      /* If there is anything on the line, print it and remember it. */
28      if (*temp)
29	{
30	  fprintf (stderr, "%s\r\n", temp);
31	  add_history (temp);
32	}
33
34      /* Check for `command' that we handle. */
35      if (strcmp (temp, "quit") == 0)
36	done = 1;
37
38      if (strcmp (temp, "list") == 0)
39	{
40	  HIST_ENTRY **list = history_list ();
41	  register int i;
42	  if (list)
43	    {
44	      for (i = 0; list[i]; i++)
45		{
46		  fprintf (stderr, "%d: %s\r\n", i, list[i]->line);
47		  free (list[i]->line);
48		}
49	      free (list);
50	    }
51	}
52      free (temp);
53    }
54}
55