TheGNUGeneralPublicLicenseisoftenshippedwithGNUsoftware,and isgenerallykeptinafilecalledCOPYINGorLICENSE.Ifyoudonot haveacopyofthelicense,writetotheFreeSoftwareFoundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA. */
/* The goal is to make the implementation transparent, so that you don'thavetoknowwhatdatatypesareused,justwhatfunctions
you can call. I think I have done that. */ #define READLINE_LIBRARY
#ifdefined (HAVE_CONFIG_H) # include "config_readline.h" #endif
#include <stdio.h>
#ifdefined (HAVE_STDLIB_H) # include <stdlib.h> #else # include "ansi_stdlib.h" #endif/* HAVE_STDLIB_H */
#ifdefined (HAVE_UNISTD_H) # ifdef _MINIX # include <sys/types.h> # endif # include <unistd.h> #endif
#include"history.h" #include"histlib.h"
#include"xmalloc.h"
/* The number of slots to increase the_history by. */ #define DEFAULT_HISTORY_GROW_SIZE 50
/* An array of HIST_ENTRY. This is where we store the history. */ static HIST_ENTRY **the_history = (HIST_ENTRY **)NULL;
/* Non-zero means that we have enforced a limit on the amount of
history that we save. */ staticint history_stifled;
/* The current number of slots allocated to the input_history. */ staticint history_size;
/* If HISTORY_STIFLED is non-zero, then this is the maximum number of
entries to remember. */ int history_max_entries; int max_input_history; /* backwards compatibility */
/* The current location of the interactive history pointer. Just makes
life easier for outside callers. */ int history_offset;
/* The number of strings currently stored in the history list. */ int history_length;
/* The logical `base' of the history array. It defaults to 1. */ int history_base = 1;
/* Return the current HISTORY_STATE of the history. */
HISTORY_STATE *
history_get_history_state ()
{
HISTORY_STATE *state;
/* Set the state of the current history array to STATE. */ void
history_set_history_state (state)
HISTORY_STATE *state;
{
the_history = state->entries;
history_offset = state->offset;
history_length = state->length;
history_size = state->size; if (state->flags & HS_STIFLED)
history_stifled = 1;
}
/* Begin a session in which the history functions might be used. This
initializes interactive variables. */ void
using_history ()
{
history_offset = history_length;
}
/* Return the number of bytes that the primary history entries are using. Thisjustaddsupthelengthsofthe_history->linesandtheassociated
timestamps. */ int
history_total_bytes ()
{ registerint i, result;
for (i = result = 0; the_history && the_history[i]; i++)
result += HISTENT_BYTES (the_history[i]);
return (result);
}
/* Returns the magic number which says what history element we are
looking at now. In this implementation, it returns history_offset. */ int
where_history ()
{ return (history_offset);
}
/* Make the current history item be the one at POS, an absolute index.
Returns zero if POS is out of range, else non-zero. */ int
history_set_pos (pos) int pos;
{ if (pos > history_length || pos < 0 || !the_history) return (0);
history_offset = pos; return (1);
}
/* Return the current history array. The caller has to be carefull, since this istheactualarrayofdata,andcouldbebashedormadecorrupteasily.
The array is terminated with a NULL pointer. */
HIST_ENTRY **
history_list ()
{ return (the_history);
}
/* Return the history entry at the current position, as determined by
history_offset. If there is no entry there, return a NULL pointer. */
HIST_ENTRY *
current_history ()
{ return ((history_offset == history_length) || the_history == 0)
? (HIST_ENTRY *)NULL
: the_history[history_offset];
}
/* Back up history_offset to the previous history entry, and return apointertothatentry.Ifthereisnopreviousentrythenreturn
a NULL pointer. */
HIST_ENTRY *
previous_history ()
{ return history_offset ? the_history[--history_offset] : (HIST_ENTRY *)NULL;
}
/* Move history_offset forward to the next history entry, and return apointertothatentry.Ifthereisnonextentrythenreturna
NULL pointer. */
HIST_ENTRY *
next_history ()
{ return (history_offset == history_length) ? (HIST_ENTRY *)NULL : the_history[++history_offset];
}
/* Return the history entry which is logically at OFFSET in the history array.
OFFSET is relative to history_base. */
HIST_ENTRY *
history_get (offset) int offset;
{ int local_index;
/* Free HIST and return the data so the calling application can free it
if necessary and desired. */
histdata_t
free_history_entry (hist)
HIST_ENTRY *hist;
{
histdata_t x;
if (hist == 0) return ((histdata_t) 0);
FREE (hist->line);
FREE (hist->timestamp);
x = hist->data;
free (hist); return (x);
}
/* Make the history entry at WHICH have LINE and DATA. This returns theoldentrysoyoucandisposeofthedata.Inthecaseofan
invalid WHICH, a NULL pointer is returned. */
HIST_ENTRY *
replace_history_entry (which, line, data) int which; constchar *line;
histdata_t data;
{
HIST_ENTRY *temp, *old_value;
if (which < 0 || which >= history_length) return ((HIST_ENTRY *)NULL);
/* Replace the DATA in the specified history entries, replacing OLD with NEW.WHICHsayswhichone(s)toreplace:WHICH==-1meanstoreplace allofthehistoryentrieswhereentry->data==OLD;WHICH==-2means toreplacethe`newest'historyentrywhereentry->data==OLD;and WHICH>=0meanstoreplacethatparticularhistoryentry'sdata,as
long as it matches OLD. */ void
replace_history_data (which,old, new) int which;
histdata_t *old, *new;
{
HIST_ENTRY *entry; registerint i, last;
if (which < -2 || which >= history_length || history_length == 0 || the_history == 0) return;
if (which >= 0)
{
entry = the_history[which]; if (entry && entry->data == old)
entry->data = new; return;
}
last = -1; for (i = 0; i < history_length; i++)
{
entry = the_history[i]; if (entry == 0) continue; if (entry->data == old)
{
last = i; if (which == -1)
entry->data = new;
}
} if (which == -2 && last >= 0)
{
entry = the_history[last];
entry->data = new; /* XXX - we don't check entry->old */
}
}
/* Remove history element WHICH from the history. The removed elementisreturnedtoyousoyoucanfreetheline,data,
and containing structure. */
HIST_ENTRY *
remove_history (which) int which;
{
HIST_ENTRY *return_value; registerint i;
if (which < 0 || which >= history_length || history_length == 0 || the_history == 0) return ((HIST_ENTRY *)NULL);
return_value = the_history[which];
for (i = which; i < history_length; i++)
the_history[i] = the_history[i + 1];
history_length--;
return (return_value);
}
/* Stifle the history list, remembering only MAX number of lines. */ void
stifle_history (max) int max;
{ registerint i, j;
if (max < 0)
max = 0;
if (history_length > max)
{ /* This loses because we cannot free the data. */ for (i = 0, j = history_length - max; i < j; i++)
free_history_entry (the_history[i]);
/* Stop stifling the history. This returns the previous maximum numberofhistoryentries.Thevalueispositiveifthehistory
was stifled, negative if it wasn't. */ int
unstifle_history ()
{ if (history_stifled)
{
history_stifled = 0; return (history_max_entries);
} else return (-history_max_entries);
}
int
history_is_stifled ()
{ return (history_stifled);
}
void
clear_history ()
{ registerint i;
/* This loses because we cannot free the data. */ for (i = 0; i < history_length; i++)
{
free_history_entry (the_history[i]);
the_history[i] = (HIST_ENTRY *)NULL;
}
history_offset = history_length = 0;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.25 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.