PR/4504: Tero Kivinen: Add DB_HISTORY_SIZE option to enable history in ddb
This commit is contained in:
parent
fd7ea84f27
commit
98ec14c8e6
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: db_input.c,v 1.7 1996/02/05 01:57:02 christos Exp $ */
|
||||
/* $NetBSD: db_input.c,v 1.8 1997/11/16 22:24:47 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Mach Operating System
|
||||
@ -41,6 +41,10 @@
|
||||
|
||||
#include <dev/cons.h>
|
||||
|
||||
#ifndef DB_HISTORY_SIZE
|
||||
#define DB_HISTORY_SIZE 0
|
||||
#endif /* DB_HISTORY_SIZE */
|
||||
|
||||
/*
|
||||
* Character input and editing.
|
||||
*/
|
||||
@ -54,6 +58,14 @@ char * db_lbuf_start; /* start of input line buffer */
|
||||
char * db_lbuf_end; /* end of input line buffer */
|
||||
char * db_lc; /* current character */
|
||||
char * db_le; /* one past last character */
|
||||
#if DB_HISTORY_SIZE != 0
|
||||
char db_history[DB_HISTORY_SIZE]; /* start of history buffer */
|
||||
int db_history_size = DB_HISTORY_SIZE;/* size of history buffer */
|
||||
char * db_history_curr = db_history; /* start of current line */
|
||||
char * db_history_last = db_history; /* start of last line */
|
||||
char * db_history_prev = (char *) 0; /* start of previous line */
|
||||
#endif
|
||||
|
||||
|
||||
#define CTRL(c) ((c) & 0x1f)
|
||||
#define isspace(c) ((c) == ' ' || (c) == '\t')
|
||||
@ -105,6 +117,31 @@ db_delete(n, bwd)
|
||||
db_le -= n;
|
||||
}
|
||||
|
||||
void
|
||||
db_delete_line()
|
||||
{
|
||||
db_delete(db_le - db_lc, DEL_FWD);
|
||||
db_delete(db_lc - db_lbuf_start, DEL_BWD);
|
||||
db_le = db_lc = db_lbuf_start;
|
||||
}
|
||||
|
||||
#if DB_HISTORY_SIZE != 0
|
||||
#define INC_DB_CURR() \
|
||||
do { \
|
||||
db_history_curr++; \
|
||||
if (db_history_curr > \
|
||||
db_history + db_history_size - 1) \
|
||||
db_history_curr = db_history; \
|
||||
} while (0)
|
||||
#define DEC_DB_CURR() \
|
||||
do { \
|
||||
db_history_curr--; \
|
||||
if (db_history_curr < db_history) \
|
||||
db_history_curr = db_history + \
|
||||
db_history_size - 1; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/* returns TRUE at end-of-line */
|
||||
int
|
||||
db_inputchar(c)
|
||||
@ -155,6 +192,10 @@ db_inputchar(c)
|
||||
if (db_lc < db_le)
|
||||
db_delete(db_le - db_lc, DEL_FWD);
|
||||
break;
|
||||
case CTRL('u'):
|
||||
/* delete line */
|
||||
db_delete_line();
|
||||
break;
|
||||
case CTRL('t'):
|
||||
/* twiddle last 2 characters */
|
||||
if (db_lc >= db_lbuf_start + 2) {
|
||||
@ -167,6 +208,57 @@ db_inputchar(c)
|
||||
cnputc(db_lc[-1]);
|
||||
}
|
||||
break;
|
||||
#if DB_HISTORY_SIZE != 0
|
||||
case CTRL('p'):
|
||||
DEC_DB_CURR();
|
||||
while (db_history_curr != db_history_last) {
|
||||
DEC_DB_CURR();
|
||||
if (*db_history_curr == '\0')
|
||||
break;
|
||||
}
|
||||
db_delete_line();
|
||||
if (db_history_curr == db_history_last) {
|
||||
INC_DB_CURR();
|
||||
db_le = db_lc = db_lbuf_start;
|
||||
} else {
|
||||
register char *p;
|
||||
INC_DB_CURR();
|
||||
for (p = db_history_curr, db_le = db_lbuf_start;
|
||||
*p; ) {
|
||||
*db_le++ = *p++;
|
||||
if (p == db_history + db_history_size) {
|
||||
p = db_history;
|
||||
}
|
||||
}
|
||||
db_lc = db_le;
|
||||
}
|
||||
db_putstring(db_lbuf_start, db_le - db_lbuf_start);
|
||||
break;
|
||||
case CTRL('n'):
|
||||
while (db_history_curr != db_history_last) {
|
||||
if (*db_history_curr == '\0')
|
||||
break;
|
||||
INC_DB_CURR();
|
||||
}
|
||||
if (db_history_curr != db_history_last) {
|
||||
INC_DB_CURR();
|
||||
db_delete_line();
|
||||
if (db_history_curr != db_history_last) {
|
||||
register char *p;
|
||||
for (p = db_history_curr,
|
||||
db_le = db_lbuf_start; *p;) {
|
||||
*db_le++ = *p++;
|
||||
if (p == db_history +
|
||||
db_history_size) {
|
||||
p = db_history;
|
||||
}
|
||||
}
|
||||
db_lc = db_le;
|
||||
}
|
||||
db_putstring(db_lbuf_start, db_le - db_lbuf_start);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case CTRL('r'):
|
||||
db_putstring("^R\n", 3);
|
||||
if (db_le > db_lbuf_start) {
|
||||
@ -176,6 +268,44 @@ db_inputchar(c)
|
||||
break;
|
||||
case '\n':
|
||||
case '\r':
|
||||
#if DB_HISTORY_SIZE != 0
|
||||
/* Check if it same than previous line */
|
||||
if (db_history_curr == db_history_prev) {
|
||||
register char *pp, *pc;
|
||||
|
||||
/* Is it unmodified */
|
||||
for (pp = db_history_prev, pc = db_lbuf_start;
|
||||
pc != db_le && *pp; pp++, pc++) {
|
||||
if (*pp != *pc)
|
||||
break;
|
||||
if (++pp == db_history + db_history_size) {
|
||||
pp = db_history;
|
||||
}
|
||||
if (++pc == db_history + db_history_size) {
|
||||
pc = db_history;
|
||||
}
|
||||
}
|
||||
if (!*pp && pc == db_le) {
|
||||
/* Repeted previous line, not saved */
|
||||
db_history_curr = db_history_last;
|
||||
*db_le++ = c;
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
if (db_le != db_lbuf_start) {
|
||||
register char *p;
|
||||
db_history_prev = db_history_last;
|
||||
for (p = db_lbuf_start; p != db_le; p++) {
|
||||
*db_history_last++ = *p;
|
||||
if (db_history_last == db_history +
|
||||
db_history_size) {
|
||||
db_history_last = db_history;
|
||||
}
|
||||
}
|
||||
*db_history_last++ = '\0';
|
||||
}
|
||||
db_history_curr = db_history_last;
|
||||
#endif
|
||||
*db_le++ = c;
|
||||
return (1);
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user