aboutsummaryrefslogtreecommitdiff
path: root/readline/history.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-10-07 12:52:13 -0600
committerTom Tromey <tom@tromey.com>2019-08-12 10:57:56 -0600
commit775e241e9c5f2b2ff2b59972ab70e5f20763fae6 (patch)
tree597ab643dce69ee6e98e46ecac00ee85f447bb4b /readline/history.c
parent08132bdd876fa1825810f90ecc25390dd4ded457 (diff)
downloadgdb-775e241e9c5f2b2ff2b59972ab70e5f20763fae6.zip
gdb-775e241e9c5f2b2ff2b59972ab70e5f20763fae6.tar.gz
gdb-775e241e9c5f2b2ff2b59972ab70e5f20763fae6.tar.bz2
Import readline 7.0 (patch 5)
This imports readline 7.0 (up to patch 5) while preserving all gdb-local changes. This was done by checking out the readline git repository, making a branch based on the gdb baseline revision, applying the gdb changes to that branch, and then merging from readline 7. readline/ChangeLog.gdb 2019-08-12 Tom Tromey <tom@tromey.com> * Imported readline 7.0 patch 5.
Diffstat (limited to 'readline/history.c')
-rw-r--r--readline/history.c72
1 files changed, 59 insertions, 13 deletions
diff --git a/readline/history.c b/readline/history.c
index d7894cf..129c57a 100644
--- a/readline/history.c
+++ b/readline/history.c
@@ -1,6 +1,6 @@
/* history.c -- standalone history library */
-/* Copyright (C) 1989-2009 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2015 Free Software Foundation, Inc.
This file contains the GNU History Library (History), a set of
routines for managing the text of previously typed lines.
@@ -43,11 +43,22 @@
# include <unistd.h>
#endif
+#include <errno.h>
+
#include "history.h"
#include "histlib.h"
#include "xmalloc.h"
+#if !defined (errno)
+extern int errno;
+#endif
+
+/* How big to make the_history when we first allocate it. */
+#define DEFAULT_HISTORY_INITIAL_SIZE 502
+
+#define MAX_HISTORY_INITIAL_SIZE 8192
+
/* The number of slots to increase the_history by. */
#define DEFAULT_HISTORY_GROW_SIZE 50
@@ -236,7 +247,10 @@ history_get_time (hist)
ts = hist->timestamp;
if (ts[0] != history_comment_char)
return 0;
- t = (time_t) atol (ts + 1); /* XXX - should use strtol() here */
+ errno = 0;
+ t = (time_t) strtol (ts + 1, (char **)NULL, 10); /* XXX - should use strtol() here */
+ if (errno == ERANGE)
+ return (time_t)0;
return t;
}
@@ -265,6 +279,7 @@ add_history (string)
const char *string;
{
HIST_ENTRY *temp;
+ int new_length;
if (history_stifled && (history_length == history_max_entries))
{
@@ -279,19 +294,25 @@ add_history (string)
if (the_history[0])
(void) free_history_entry (the_history[0]);
- /* Copy the rest of the entries, moving down one slot. */
- for (i = 0; i < history_length; i++)
- the_history[i] = the_history[i + 1];
+ /* Copy the rest of the entries, moving down one slot. Copy includes
+ trailing NULL. */
+ memmove (the_history, the_history + 1, history_length * sizeof (HIST_ENTRY *));
+ new_length = history_length;
history_base++;
}
else
{
if (history_size == 0)
{
- history_size = DEFAULT_HISTORY_GROW_SIZE;
+ if (history_stifled && history_max_entries > 0)
+ history_size = (history_max_entries > MAX_HISTORY_INITIAL_SIZE)
+ ? MAX_HISTORY_INITIAL_SIZE
+ : history_max_entries + 2;
+ else
+ history_size = DEFAULT_HISTORY_INITIAL_SIZE;
the_history = (HIST_ENTRY **)xmalloc (history_size * sizeof (HIST_ENTRY *));
- history_length = 1;
+ new_length = 1;
}
else
{
@@ -301,14 +322,15 @@ add_history (string)
the_history = (HIST_ENTRY **)
xrealloc (the_history, history_size * sizeof (HIST_ENTRY *));
}
- history_length++;
+ new_length = history_length + 1;
}
}
- temp = alloc_history_entry (string, hist_inittime ());
+ temp = alloc_history_entry ((char *)string, hist_inittime ());
- the_history[history_length] = (HIST_ENTRY *)NULL;
- the_history[history_length - 1] = temp;
+ the_history[new_length] = (HIST_ENTRY *)NULL;
+ the_history[new_length - 1] = temp;
+ history_length = new_length;
}
/* Change the time stamp of the most recent history entry to STRING. */
@@ -318,7 +340,7 @@ add_history_time (string)
{
HIST_ENTRY *hs;
- if (string == 0)
+ if (string == 0 || history_length < 1)
return;
hs = the_history[history_length - 1];
FREE (hs->timestamp);
@@ -387,6 +409,30 @@ replace_history_entry (which, line, data)
return (old_value);
}
+/* Append LINE to the history line at offset WHICH, adding a newline to the
+ end of the current line first. This can be used to construct multi-line
+ history entries while reading lines from the history file. */
+void
+_hs_append_history_line (which, line)
+ int which;
+ const char *line;
+{
+ HIST_ENTRY *hent;
+ size_t newlen, curlen;
+ char *newline;
+
+ hent = the_history[which];
+ curlen = strlen (hent->line);
+ newlen = curlen + strlen (line) + 2;
+ newline = realloc (hent->line, newlen);
+ if (newline)
+ {
+ hent->line = newline;
+ hent->line[curlen++] = '\n';
+ strcpy (hent->line + curlen, line);
+ }
+}
+
/* Replace the DATA in the specified history entries, replacing OLD with
NEW. WHICH says which one(s) to replace: WHICH == -1 means to replace
all of the history entries where entry->data == OLD; WHICH == -2 means
@@ -394,7 +440,7 @@ replace_history_entry (which, line, data)
WHICH >= 0 means to replace that particular history entry's data, as
long as it matches OLD. */
void
-replace_history_data (which,old, new)
+_hs_replace_history_data (which, old, new)
int which;
histdata_t *old, *new;
{