1
/* histexamp.c - history library example program. */
3
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
5
This file is part of the GNU Readline Library (Readline), a library for
6
reading lines of text with interactive input and history editing.
8
Readline is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation, either version 3 of the License, or
11
(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.
18
You should have received a copy of the GNU General Public License
19
along with Readline. If not, see <http://www.gnu.org/licenses/>.
24
#ifdef READLINE_LIBRARY
27
# include <readline/history.h>
47
t = fgets (line, sizeof (line) - 1, stdin);
51
if (t[len - 1] == '\n')
56
strcpy (line, "quit");
65
result = history_expand (line, &expansion);
67
fprintf (stderr, "%s\n", expansion);
69
if (result < 0 || result == 2)
75
add_history (expansion);
76
strncpy (line, expansion, sizeof (line) - 1);
80
if (strcmp (line, "quit") == 0)
82
else if (strcmp (line, "save") == 0)
83
write_history ("history_file");
84
else if (strcmp (line, "read") == 0)
85
read_history ("history_file");
86
else if (strcmp (line, "list") == 0)
88
register HIST_ENTRY **the_list;
93
the_list = history_list ();
95
for (i = 0; the_list[i]; i++)
97
tt = history_get_time (the_list[i]);
99
strftime (timestr, sizeof (timestr), "%a %R", localtime(&tt));
101
strcpy (timestr, "??");
102
printf ("%d: %s: %s\n", i + history_base, timestr, the_list[i]->line);
105
else if (strncmp (line, "delete", 6) == 0)
108
if ((sscanf (line + 6, "%d", &which)) == 1)
110
HIST_ENTRY *entry = remove_history (which);
112
fprintf (stderr, "No such entry %d\n", which);
121
fprintf (stderr, "non-numeric arg given to `delete'\n");