~ubuntu-branches/ubuntu/trusty/bash/trusty-security

« back to all changes in this revision

Viewing changes to lib/readline/examples/rltest.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-03-03 22:52:05 UTC
  • mfrom: (1.3.5) (2.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20140303225205-87ltrt5kspeq0g1b
Tags: 4.3-1ubuntu1
* Merge with Debian; remaining changes:
  - skel.bashrc:
    - Run lesspipe.
    - Enable ls aliases.
    - Set options in ll alias to -alF.
    - Define an alert alias.
    - Enabled colored grep aliases.
  - etc.bash.bashrc:
    - Add sudo hint.

Show diffs side-by-side

added added

removed removed

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