X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ion3.git;a=blobdiff_plain;f=mod_query%2Fhistory.c;h=eae5b87af4f00b27eadcf9239ebceda66523aafc;hp=05b6aa51973275423ab708c65062fcd104bdf78e;hb=e3aec18706513a87eaa7839dfdaf7e0fcd0d8d2a;hpb=8366314611bf30a0f31d25bf5f5023186fa87692 diff --git a/mod_query/history.c b/mod_query/history.c index 05b6aa5..eae5b87 100644 --- a/mod_query/history.c +++ b/mod_query/history.c @@ -1,12 +1,9 @@ /* * 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 @@ -52,9 +49,10 @@ bool mod_query_history_push(const char *str) 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; @@ -110,7 +108,7 @@ void mod_query_history_clear() -static bool match(const char *h, const char *b) +static bool match(const char *h, const char *b, bool exact) { const char *h_; @@ -124,8 +122,10 @@ static bool match(const char *h, const char *b) 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); } @@ -140,17 +140,18 @@ static const char *skip_colon(const char *s) * 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--; @@ -172,7 +173,7 @@ uint mod_query_history_complete(const char *s, char ***h_ret) 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++;