121308Sache/* **************************************************************** */ 221308Sache/* */ 321308Sache/* Testing Readline */ 421308Sache/* */ 521308Sache/* **************************************************************** */ 621308Sache 7119610Sache/* Copyright (C) 1987-2002 Free Software Foundation, Inc. 8119610Sache 9119610Sache This file is part of the GNU Readline Library, a library for 10119610Sache reading lines of text with interactive input and history editing. 11119610Sache 12119610Sache The GNU Readline Library is free software; you can redistribute it 13119610Sache and/or modify it under the terms of the GNU General Public License 14119610Sache as published by the Free Software Foundation; either version 2, or 15119610Sache (at your option) any later version. 16119610Sache 17119610Sache The GNU Readline Library is distributed in the hope that it will be 18119610Sache useful, but WITHOUT ANY WARRANTY; without even the implied warranty 19119610Sache of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20119610Sache GNU General Public License for more details. 21119610Sache 22119610Sache The GNU General Public License is often shipped with GNU software, and 23119610Sache is generally kept in a file called COPYING or LICENSE. If you do not 24119610Sache have a copy of the license, write to the Free Software Foundation, 25119610Sache 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ 26119610Sache 2726497Sache#if defined (HAVE_CONFIG_H) 2826497Sache#include <config.h> 2926497Sache#endif 3026497Sache 3121308Sache#include <stdio.h> 3221308Sache#include <sys/types.h> 3321308Sache 34157184Sache#ifdef HAVE_STDLIB_H 35157184Sache# include <stdlib.h> 36157184Sache#else 37157184Sacheextern void exit(); 38157184Sache#endif 39157184Sache 4058310Sache#ifdef READLINE_LIBRARY 4158310Sache# include "readline.h" 4258310Sache# include "history.h" 4358310Sache#else 4458310Sache# include <readline/readline.h> 4558310Sache# include <readline/history.h> 4658310Sache#endif 4758310Sache 4835486Sacheextern HIST_ENTRY **history_list (); 4935486Sache 5021308Sachemain () 5121308Sache{ 5235486Sache char *temp, *prompt; 5335486Sache int done; 5421308Sache 5535486Sache temp = (char *)NULL; 5635486Sache prompt = "readline$ "; 5735486Sache done = 0; 5835486Sache 5921308Sache while (!done) 6021308Sache { 6121308Sache temp = readline (prompt); 6221308Sache 6321308Sache /* Test for EOF. */ 6421308Sache if (!temp) 6521308Sache exit (1); 6621308Sache 6721308Sache /* If there is anything on the line, print it and remember it. */ 6821308Sache if (*temp) 6921308Sache { 7021308Sache fprintf (stderr, "%s\r\n", temp); 7121308Sache add_history (temp); 7221308Sache } 7321308Sache 7421308Sache /* Check for `command' that we handle. */ 7521308Sache if (strcmp (temp, "quit") == 0) 7621308Sache done = 1; 7721308Sache 7821308Sache if (strcmp (temp, "list") == 0) 7921308Sache { 8035486Sache HIST_ENTRY **list; 8121308Sache register int i; 8235486Sache 8335486Sache list = history_list (); 8421308Sache if (list) 8521308Sache { 8621308Sache for (i = 0; list[i]; i++) 8735486Sache fprintf (stderr, "%d: %s\r\n", i, list[i]->line); 8821308Sache } 8921308Sache } 9021308Sache free (temp); 9121308Sache } 9235486Sache exit (0); 9321308Sache} 94