On Sat, Nov 05, 2005 at 04:19:28PM +0100, Alain Bench wrote: > So it would seem perfectly natural to have a case-insensitive > completion. Now it may perhaps be a user preference, having "johnone" and > "JohnTwo", completing either j<Tab> or J<Tab> to full, instead of j<Tab> > giving "john" only and futher [ot]<Tab> required to full. I don't know? > Situation dependant pref? First pass attached. The code is almost certainly not as pretty as it could be, and I'm certain it wouldn't handle multi-byte strings, but I don't know how to do that properly. However, it gives me case-insensitive alias matching - I was reluctant to re-implement a standard string function, but there appears to be no other way to do it. :/ Please test and let me know if it gives you the "right" behaviour. -- Paul
diff -r 38ac88174436 PATCHES
--- a/PATCHES Tue Nov 1 08:43:14 2005
+++ b/PATCHES Mon Nov 7 00:37:22 2005
@@ -1,0 +1,1 @@
+patch-1.5.11.pw.alias_case.1
diff -r 38ac88174436 alias.c
--- a/alias.c Tue Nov 1 08:43:14 2005
+++ b/alias.c Mon Nov 7 00:37:22 2005
@@ -408,6 +408,52 @@
return 0;
}
+static char *mutt_strcasestr(const char *haystack, const char *needle)
+{
+ const char *src = haystack;
+ const char *start_cmp;
+ char *cmp, *target;
+
+ if ((NULL == needle) || (NULL == haystack))
+ return (char *)haystack;
+
+ /* Copy and convert this since we might need to read it many times. */
+ target = safe_strdup(needle);
+ mutt_strlower(target);
+ cmp = target;
+
+ start_cmp = NULL;
+ while ((*src) && (*cmp))
+ {
+ /* At most we'll have to convert each source character once; at best,
+ * no more than strlen(target) characters. So pre-converting could
+ * actually waste time.
+ */
+ if (tolower(*src) == *cmp)
+ {
+ if (NULL == start_cmp)
+ start_cmp = src;
+
+ cmp++;
+ if ('\0' == *cmp)
+ {
+ FREE(&target);
+ return (char *)start_cmp;
+ }
+ }
+ else
+ {
+ start_cmp = NULL;
+ cmp = target;
+ }
+
+ src++;
+ }
+
+ FREE(&target);
+ return NULL;
+}
+
/* alias_complete() -- alias completion routine
*
* given a partial alias, this routine attempts to fill in the alias
@@ -429,7 +475,7 @@
while (a)
{
- if (a->name && strstr (a->name, s) == a->name)
+ if (a->name && mutt_strcasestr (a->name, s) == a->name)
{
if (!bestname[0]) /* init */
strfcpy (bestname, a->name,
Attachment:
signature.asc
Description: Digital signature