rltest.c revision 26497
121308Sache/* **************************************************************** */ 221308Sache/* */ 321308Sache/* Testing Readline */ 421308Sache/* */ 521308Sache/* **************************************************************** */ 621308Sache 726497Sache/* 826497Sache * Remove the next line if you're compiling this against an installed 926497Sache * libreadline.a 1026497Sache */ 1126497Sache#define READLINE_LIBRARY 1226497Sache 1326497Sache#if defined (HAVE_CONFIG_H) 1426497Sache#include <config.h> 1526497Sache#endif 1626497Sache 1721308Sache#include <stdio.h> 1821308Sache#include <sys/types.h> 1926497Sache#include "readline.h" 2026497Sache#include "history.h" 2121308Sache 2221308Sachemain () 2321308Sache{ 2421308Sache HIST_ENTRY **history_list (); 2521308Sache char *temp = (char *)NULL; 2621308Sache char *prompt = "readline$ "; 2721308Sache int done = 0; 2821308Sache 2921308Sache while (!done) 3021308Sache { 3121308Sache temp = readline (prompt); 3221308Sache 3321308Sache /* Test for EOF. */ 3421308Sache if (!temp) 3521308Sache exit (1); 3621308Sache 3721308Sache /* If there is anything on the line, print it and remember it. */ 3821308Sache if (*temp) 3921308Sache { 4021308Sache fprintf (stderr, "%s\r\n", temp); 4121308Sache add_history (temp); 4221308Sache } 4321308Sache 4421308Sache /* Check for `command' that we handle. */ 4521308Sache if (strcmp (temp, "quit") == 0) 4621308Sache done = 1; 4721308Sache 4821308Sache if (strcmp (temp, "list") == 0) 4921308Sache { 5021308Sache HIST_ENTRY **list = history_list (); 5121308Sache register int i; 5221308Sache if (list) 5321308Sache { 5421308Sache for (i = 0; list[i]; i++) 5521308Sache { 5621308Sache fprintf (stderr, "%d: %s\r\n", i, list[i]->line); 5721308Sache free (list[i]->line); 5821308Sache } 5921308Sache free (list); 6021308Sache } 6121308Sache } 6221308Sache free (temp); 6321308Sache } 6421308Sache} 65