190792Sgshapiro/* **************************************************************** */ 290792Sgshapiro/* */ 390792Sgshapiro/* Testing Readline */ 490792Sgshapiro/* */ 590792Sgshapiro/* **************************************************************** */ 690792Sgshapiro 790792Sgshapiro/* Copyright (C) 1987-2002 Free Software Foundation, Inc. 890792Sgshapiro 990792Sgshapiro This file is part of the GNU Readline Library, a library for 1090792Sgshapiro reading lines of text with interactive input and history editing. 1198121Sgshapiro 1290792Sgshapiro The GNU Readline Library is free software; you can redistribute it 1390792Sgshapiro and/or modify it under the terms of the GNU General Public License 1490792Sgshapiro as published by the Free Software Foundation; either version 2, or 1590792Sgshapiro (at your option) any later version. 1690792Sgshapiro 1790792Sgshapiro The GNU Readline Library is distributed in the hope that it will be 1890792Sgshapiro useful, but WITHOUT ANY WARRANTY; without even the implied warranty 1990792Sgshapiro of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2090792Sgshapiro GNU General Public License for more details. 2190792Sgshapiro 2290792Sgshapiro The GNU General Public License is often shipped with GNU software, and 2390792Sgshapiro is generally kept in a file called COPYING or LICENSE. If you do not 2490792Sgshapiro have a copy of the license, write to the Free Software Foundation, 2590792Sgshapiro 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ 2690792Sgshapiro 2790792Sgshapiro#if defined (HAVE_CONFIG_H) 2890792Sgshapiro#include <config.h> 2990792Sgshapiro#endif 3090792Sgshapiro 3190792Sgshapiro#include <stdio.h> 3290792Sgshapiro#include <sys/types.h> 3390792Sgshapiro 3490792Sgshapiro#ifdef HAVE_STDLIB_H 3590792Sgshapiro# include <stdlib.h> 3690792Sgshapiro#else 3790792Sgshapiroextern void exit(); 3890792Sgshapiro#endif 3990792Sgshapiro 4090792Sgshapiro#ifdef READLINE_LIBRARY 4190792Sgshapiro# include "readline.h" 4290792Sgshapiro# include "history.h" 4390792Sgshapiro#else 4490792Sgshapiro# include <readline/readline.h> 4590792Sgshapiro# include <readline/history.h> 4690792Sgshapiro#endif 4790792Sgshapiro 4890792Sgshapiroextern HIST_ENTRY **history_list (); 4990792Sgshapiro 5090792Sgshapiromain () 5190792Sgshapiro{ 5290792Sgshapiro char *temp, *prompt; 5390792Sgshapiro 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} 94