This commit is contained in:
cvs
2003-03-13 14:03:07 +00:00
parent 9a5bd901d8
commit 731e48d920
6 changed files with 121 additions and 103 deletions

View File

@@ -5,6 +5,7 @@
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "myc_mem.h"
#include "sys_select.h"
#define ESC_TMO 1000
@@ -133,8 +134,8 @@ static int hist_pos=0; /* position when scrolling through the history */
static int hist_end=0; /* end of history. Always history[hist_end]==NULL */
int term_get_line(char *buf, int size, int *pos, char *prompt, fd_set *mask) {
char key;
int i,j,l,iret;
char key, *lin;
int i,j,l,iret,buflen;
char tmp[512];
buf[size-1]='\0'; /* make sure buf is null terminated */
@@ -174,10 +175,14 @@ int term_get_line(char *buf, int size, int *pos, char *prompt, fd_set *mask) {
/* fputs("\r\033[K", stdout); */
i=hist_end-1; if (i<0) i=HISTORY_LINES-1;
if ((history[i]==NULL || 0!=strcmp(history[i], buf)) && buf[0]!='\0') { /* do not save equal and empty lines */
history[hist_end]=malloc(strlen(buf)+1);
strncpy(history[hist_end], buf, size);
buflen=strlen(buf)+1;
lin=MALLOC(buflen);
strncpy(lin, buf, buflen);
history[hist_end]=lin;
hist_end++; if (hist_end>=HISTORY_LINES) hist_end=0;
if (history[hist_end]!=NULL) free(history[hist_end]); /* clear line at end of history */
if (history[hist_end]!=NULL) {
FREE(history[hist_end]); /* clear line at end of history */
}
history[hist_end]==NULL;
}
hist_pos=hist_end;