summaryrefslogtreecommitdiffstats
path: root/mbbsd/visio.c
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-04-18 13:49:40 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-04-18 13:49:40 +0800
commitc77c6cf22be895bb34192df420a9a141fe4a9d2c (patch)
treeffbb5a3bc61d8d8a181853ffceacb2eb7f8c59a0 /mbbsd/visio.c
parent18f83795218bf3ea80255e9e84781ffa306921c5 (diff)
downloadpttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar
pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar.gz
pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar.bz2
pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar.lz
pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar.xz
pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar.zst
pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.zip
- xchat: fix "waterball exists forever" issue, and prevent printing mail alerts all the time.
- visio: improve history navigation ordering git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4187 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/visio.c')
-rw-r--r--mbbsd/visio.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/mbbsd/visio.c b/mbbsd/visio.c
index 5a72b698..35384ab8 100644
--- a/mbbsd/visio.c
+++ b/mbbsd/visio.c
@@ -726,7 +726,8 @@ vs_cols(const VCOL *cols, const VCOLW *ws, int n, ...)
// History Helpers
////////////////////////////////////////////////////////////////////////
//
-#define IH_MAX_ENTRIES (12)
+#define IH_MAX_ENTRIES (12) // buffer size = approx. 1k
+#define IH_MIN_SIZE (2) // only keep string >= 2 bytes
typedef struct {
int icurr; // current retrival pointer
@@ -737,21 +738,42 @@ typedef struct {
static InputHistory ih; // everything intialized to zero.
int
-InputHistoryAdd(const char *s)
+InputHistoryExists(const char *s)
{
int i = 0;
- if (!s || !*s || !*(s+1))
- return 0;
- // TODO if already in queue, change order...?
for (i = 0; i < IH_MAX_ENTRIES; i++)
if (strcmp(s, ih.buf[i]) == 0)
- return 0;
+ return i+1;
+
+ return 0;
+}
+
+int
+InputHistoryAdd(const char *s)
+{
+ int i = 0;
+ int l = strlen(s);
+
+ if (l < IH_MIN_SIZE)
+ return 0;
+
+ i = InputHistoryExists(s);
+ if (i > 0) // found
+ {
+ i--; // i points to valid index
+ assert(i < IH_MAX_ENTRIES);
+ // change order: just delete it.
+ ih.buf[i][0] = 0;
+ }
+
+ // now append s.
strlcpy(ih.buf[ih.iappend], s, sizeof(ih.buf[ih.iappend]));
- ih.icurr = ih.iappend;
ih.iappend ++;
ih.iappend %= IH_MAX_ENTRIES;
+ ih.icurr = ih.iappend;
+
return 1;
}
@@ -901,7 +923,8 @@ vgetstring(char *_buf, int len, int flags, const char *defstr, const VGET_CALLBA
}
// NOECHO is already checked...
- InputHistoryAdd(buf);
+ if (!InputHistoryExists(buf))
+ InputHistoryAdd(buf);
if (c == KEY_DOWN)
InputHistoryNext(buf, len);