/*
* ion/mod_query/history.h
*
- * Copyright (c) Tuomo Valkonen 1999-2006.
+ * Copyright (c) Tuomo Valkonen 1999-2009.
*
- * Ion is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
+ * See the included file LICENSE for details.
*/
#include <string.h>
void mod_query_history_push_(char *str)
{
- int ndx=mod_query_history_search(str, 0, FALSE);
+ int ndx=mod_query_history_search(str, 0, FALSE, TRUE);
if(ndx==0){
+ free(str);
return; /* First entry already */
}else if(ndx>0){
int i, j;
-static bool match(const char *h, const char *b)
+static bool match(const char *h, const char *b, bool exact)
{
const char *h_;
if(h_!=NULL)
h=h_+1;
}
-
- return (strncmp(h, b, strlen(b))==0);
+
+ return (exact
+ ? strcmp(h, b)==0
+ : strncmp(h, b, strlen(b))==0);
}
* Try to find matching history entry. Returns -1 if none was
* found. The parameter \var{from} specifies where to start
* searching from, and \var{bwd} causes backward search from
- * that point.
+ * that point. If \var{exact} is not set, \var{s} only required
+ * to be a prefix of the match.
*/
EXTL_SAFE
EXTL_EXPORT
-int mod_query_history_search(const char *s, int from, bool bwd)
+int mod_query_history_search(const char *s, int from, bool bwd, bool exact)
{
while(1){
int i=get_index(from);
if(i<0)
return -1;
- if(match(hist[i], s))
+ if(match(hist[i], s, exact))
return from;
if(bwd)
from--;
int j=get_index(i);
if(j<0)
break;
- if(match(hist[j], s)){
+ if(match(hist[j], s, FALSE)){
h[n]=scopy(skip_colon(hist[j]));
if(h[n]!=NULL)
n++;