From 5ee1286625a8f7ef9cba84172d2143232f4f65d3 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Fri, 22 Feb 2013 00:00:00 -0600 Subject: [PATCH] top: allow re-ordering of saved line input upon recall The original implementation of input line recall keeps strings in the order established when initially added. With this commit, that has been changed so any matched string moves to the top of the saved input line stack. [ well technically not the top since that's occupied ] [ by an 'empty' string which serves multiple masters ] Thus, the most frequently referenced strings over time will percolate up and remain the most easily recalled. But just in case anybody prefers the strict historical ordering, a #define can restore the original behavior. (everything is perfectly justified plus right margins) (are completely filled, but of course it must be luck) Reference(s): commit 2efe275512f62f1e25fda96ebc8446b52c6882f0 Signed-off-by: Jim Warner --- top/top.c | 18 +++++++++++++++++- top/top.h | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/top/top.c b/top/top.c index 94f4f1d1..ea31b6ce 100644 --- a/top/top.c +++ b/top/top.c @@ -1161,7 +1161,23 @@ static char *ioline (const char *prompt) { // weed out duplicates, including empty strings (top-of-stack)... for (i = 0, plin = anchor; ; i++) { - if (!STRCMP(plin->str, buf)) return buf; +#ifdef RECALL_FIXED + if (!STRCMP(plin->str, buf)) // if matched, retain original order + return buf; +#else + if (!STRCMP(plin->str, buf)) { // if matched, rearrange stack order + if (i > 1) { // but not null str or if already #2 + if (plin->bkw) // splice around this matched string + plin->bkw->fwd = plin->fwd; // if older exists link to newer + plin->fwd->bkw = plin->bkw; // newer linked to older or NULL + anchor->bkw->fwd = plin; // stick matched on top of former #2 + plin->bkw = anchor->bkw; // keep empty string at top-of-stack + plin->fwd = anchor; // then prepare to be the 2nd banana + anchor->bkw = plin; // by sliding us in below the anchor + } + return buf; + } +#endif if (!plin->bkw) break; // let i equal total stacked strings plin = plin->bkw; // ( with plin representing bottom ) } diff --git a/top/top.h b/top/top.h index d7fe8ff6..ca88e8bb 100644 --- a/top/top.h +++ b/top/top.h @@ -45,6 +45,7 @@ //#define PRETEND4CPUS /* pretend we're smp with 4 ticsers (sic) */ //#define PRETENDNOCAP /* use a terminal without essential caps */ //#define RCFILE_NOERR /* rcfile errs silently default, vs. fatal */ +//#define RECALL_FIXED /* don't reorder saved strings if recalled */ //#define RMAN_IGNORED /* don't consider auto right margin glitch */ //#define SCROLLVAR_NO /* disable intra-column horizontal scroll */ //#define STRINGCASENO /* case insenstive compare/locate versions */ @@ -597,6 +598,9 @@ typedef struct WIN_t { #if defined(ATEOJ_RPTHSH) && defined(OFF_HST_HASH) # error 'ATEOJ_RPTHSH' conflicts with 'OFF_HST_HASH' #endif +#if defined(RECALL_FIXED) && defined(TERMIOS_ONLY) +# error 'RECALL_FIXED' conflicts with 'TERMIOS_ONLY' +#endif #if (LRGBUFSIZ < SCREENMAX) # error 'LRGBUFSIZ' must NOT be less than 'SCREENMAX' #endif