home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / readline / examples / rltest.c < prev   
C/C++ Source or Header  |  2000-01-15  |  1KB  |  65 lines

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