mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 12:31:45 +08:00
Restore add_history(), for compat and simplify code.
This commit is contained in:
parent
dde4471eda
commit
55aaddbc54
@ -52,6 +52,6 @@ extern void rl_reset_terminal(char *p);
|
|||||||
extern void rl_initialize(void);
|
extern void rl_initialize(void);
|
||||||
|
|
||||||
extern char *readline(const char *prompt);
|
extern char *readline(const char *prompt);
|
||||||
extern void add_history(char *line); /* OBSOLETE: Made part of readline(). -- kjb */
|
extern void add_history(const char *line);
|
||||||
|
|
||||||
#endif /* __EDITLINE_H__ */
|
#endif /* __EDITLINE_H__ */
|
||||||
|
@ -1000,19 +1000,27 @@ static char *editinput(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hist_add(char *p)
|
static void hist_add(const char *p)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
char *s;
|
||||||
|
|
||||||
if ((p = (char *)strdup((char *)p)) == NULL)
|
#ifdef CONFIG_UNIQUE_HISTORY
|
||||||
|
if (H.Pos && strcmp(p, H.Lines[H.Pos - 1]) == 0)
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
if (H.Size && strcmp(p, H.Lines[H.Size - 1]) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ((s = strdup(p)) == NULL)
|
||||||
return;
|
return;
|
||||||
if (H.Size < HIST_SIZE) {
|
if (H.Size < HIST_SIZE) {
|
||||||
H.Lines[H.Size++] = p;
|
H.Lines[H.Size++] = s;
|
||||||
} else {
|
} else {
|
||||||
free(H.Lines[0]);
|
free(H.Lines[0]);
|
||||||
for (i = 0; i < HIST_SIZE - 1; i++)
|
for (i = 0; i < HIST_SIZE - 1; i++)
|
||||||
H.Lines[i] = H.Lines[i + 1];
|
H.Lines[i] = H.Lines[i + 1];
|
||||||
H.Lines[i] = p;
|
H.Lines[i] = s;
|
||||||
}
|
}
|
||||||
H.Pos = H.Size - 1;
|
H.Pos = H.Size - 1;
|
||||||
}
|
}
|
||||||
@ -1115,14 +1123,9 @@ char *readline(const char *prompt)
|
|||||||
free(Screen);
|
free(Screen);
|
||||||
free(H.Lines[--H.Size]);
|
free(H.Lines[--H.Size]);
|
||||||
|
|
||||||
if (line != NULL && *line != '\0'
|
/* Always add history, if it's a sane line. */
|
||||||
#ifdef CONFIG_UNIQUE_HISTORY
|
if (line != NULL && *line != '\0')
|
||||||
&& !(H.Pos && strcmp(line, H.Lines[H.Pos - 1]) == 0)
|
|
||||||
#endif
|
|
||||||
&& !(H.Size && strcmp(line, H.Lines[H.Size - 1]) == 0)
|
|
||||||
) {
|
|
||||||
hist_add(line);
|
hist_add(line);
|
||||||
}
|
|
||||||
|
|
||||||
if (el_intr_pending > 0) {
|
if (el_intr_pending > 0) {
|
||||||
int s = el_intr_pending;
|
int s = el_intr_pending;
|
||||||
@ -1133,20 +1136,14 @@ char *readline(const char *prompt)
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_history(char *p __attribute__ ((unused)))
|
/* Even though readline() itself adds history automatically, the user can also add
|
||||||
|
* lines. This is for compat with GNU Readline. */
|
||||||
|
void add_history(const char *p)
|
||||||
{
|
{
|
||||||
#ifdef obsolete /* Made part of readline(). -- kjb */
|
|
||||||
if (p == NULL || *p == '\0')
|
if (p == NULL || *p == '\0')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef CONFIG_UNIQUE_HISTORY
|
hist_add(p);
|
||||||
if (H.Pos && strcmp(p, (char *) H.Lines[H.Pos - 1]) == 0)
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
if (H.Size && strcmp(p, (char *) H.Lines[H.Size - 1]) == 0)
|
|
||||||
return;
|
|
||||||
hist_add((char *)p);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user