M.Z.
This commit is contained in:
15
tecs/term.c
15
tecs/term.c
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user