*** spice/common/src/lib/cp/history.c.orig Sat Jan 29 18:44:09 1994 --- spice/common/src/lib/cp/history.c Sun Dec 12 14:56:43 1999 *************** *** 11,16 **** --- 11,24 ---- #include "cpdefs.h" #include "suffix.h" + #ifdef HAS_GNUREADLINE + + /* Added GNU Readline Support -- Andrew Veliath */ + #include + #include + + #endif /* HAS_GNUREADLINE */ + static char *dohs(); static void freehist(); static wordlist *dohmod(); *************** *** 19,24 **** --- 27,33 ---- static wordlist *hpattern(); static wordlist *hprefix(); + struct histent *cp_lastone = NULL; int cp_maxhistlength = 1000; char cp_hat = '^'; *************** *** 345,352 **** --- 354,363 ---- cp_lastone->hi_next = NULL; cp_lastone->hi_event = event; cp_lastone->hi_wlist = wl_copy(wlist); + #ifndef HAS_GNUREADLINE freehist(histlength - cp_maxhistlength); histlength++; + #endif return; } *************** *** 483,492 **** --- 494,529 ---- wl = wl->wl_next; rev = true; } + #ifdef HAS_GNUREADLINE + /* Added GNU Readline Support -- Andrew Veliath */ + { + HIST_ENTRY *he; + int i, N; + + N = (wl == NULL) ? history_length : atoi(wl->wl_word); + + if (N < 0) N = 0; + if (N > history_length) N = history_length; + + if (rev) + for (i = history_length; i > 0 && N; --i, --N) { + he = history_get(i); + if (!he) return; + fprintf(cp_out, "%d\t%s\n", i, he->line); + } + else + for (i = history_length - N + 1; i <= history_length; ++i) { + he = history_get(i); + if (!he) return; + fprintf(cp_out, "%d\t%s\n", i, he->line); + } + } + #else if (wl == NULL) cp_hprint(cp_event - 1, cp_event - histlength, rev); else cp_hprint(cp_event - 1, cp_event - 1 - atoi(wl->wl_word), rev); + #endif /* ifelse HAS_GNUREADLINE */ return; }