1 /* **************************************************************** */ 2 /* */ 3 /* Testing Readline */ 4 /* */ 5 /* **************************************************************** */ 6 7 /* Copyright (C) 1987-2002 Free Software Foundation, Inc. 8 9 This file is part of the GNU Readline Library, a library for 10 reading lines of text with interactive input and history editing. 11 12 The GNU Readline Library is free software; you can redistribute it 13 and/or modify it under the terms of the GNU General Public License 14 as published by the Free Software Foundation; either version 2, or 15 (at your option) any later version. 16 17 The GNU Readline Library is distributed in the hope that it will be 18 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 19 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License for more details. 21 22 The GNU General Public License is often shipped with GNU software, and 23 is generally kept in a file called COPYING or LICENSE. If you do not 24 have a copy of the license, write to the Free Software Foundation, 25 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ 26 27 #if defined (HAVE_CONFIG_H) 28 #include <config.h> 29 #endif 30 31 #include <stdio.h> 32 #include <sys/types.h> 33 34 #ifdef READLINE_LIBRARY 35 # include "readline.h" 36 # include "history.h" 37 #else 38 # include <readline/readline.h> 39 # include <readline/history.h> 40 #endif 41 42 extern HIST_ENTRY **history_list (); 43 44 main () 45 { 46 char *temp, *prompt; 47 int done; 48 49 temp = (char *)NULL; 50 prompt = "readline$ "; 51 done = 0; 52 53 while (!done) 54 { 55 temp = readline (prompt); 56 57 /* Test for EOF. */ 58 if (!temp) 59 exit (1); 60 61 /* If there is anything on the line, print it and remember it. */ 62 if (*temp) 63 { 64 fprintf (stderr, "%s\r\n", temp); 65 add_history (temp); 66 } 67 68 /* Check for `command' that we handle. */ 69 if (strcmp (temp, "quit") == 0) 70 done = 1; 71 72 if (strcmp (temp, "list") == 0) 73 { 74 HIST_ENTRY **list; 75 register int i; 76 77 list = history_list (); 78 if (list) 79 { 80 for (i = 0; list[i]; i++) 81 fprintf (stderr, "%d: %s\r\n", i, list[i]->line); 82 } 83 } 84 free (temp); 85 } 86 exit (0); 87 } 88