rltest.c 2.1 KB

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