/* alias_complete() -- alias completion routine
*
* given a partial alias, this routine attempts to fill in the alias
- * from the alias list as much as possible
+ * from the alias list as much as possible. if given empty search string
+ * or found nothing, present all aliases
*/
int mutt_alias_complete (char *s, size_t buflen)
{
char bestname[STRING];
int i;
- memset (bestname, 0, sizeof (bestname));
-
#define min(a,b) ((a<b)?a:b)
- while (a)
+ if (s[0] != 0) /* avoid empty string as strstr argument */
{
- if (a->name && strstr (a->name, s) == a->name)
+ memset (bestname, 0, sizeof (bestname));
+
+ while (a)
{
- if (!bestname[0]) /* init */
- strfcpy (bestname, a->name, min (mutt_strlen (a->name) + 1, sizeof (bestname)));
- else
+ if (a->name && strstr (a->name, s) == a->name)
{
- for (i = 0 ; a->name[i] && a->name[i] == bestname[i] ; i++)
- ;
- bestname[i] = 0;
+ if (!bestname[0]) /* init */
+ strfcpy (bestname, a->name,
+ min (mutt_strlen (a->name) + 1, sizeof (bestname)));
+ else
+ {
+ for (i = 0 ; a->name[i] && a->name[i] == bestname[i] ; i++)
+ ;
+ bestname[i] = 0;
+ }
}
+ a = a->next;
}
- a = a->next;
- }
- if ((bestname[0] == 0) || /* if we didn't find anything */
- (s[0] == 0)) /* or we weren't given anything */
- {
- mutt_alias_menu (s, buflen, Aliases);
- return 0;
- }
- else
- {
- if (mutt_strcmp (bestname, s) == 0) /* add anything to the completion? */
+ if (bestname[0] != 0)
{
+ if (mutt_strcmp (bestname, s) != 0)
+ {
+ /* we are adding something to the completion */
+ strfcpy (s, bestname, mutt_strlen (bestname) + 1);
+ return 1;
+ }
+
/* build alias list and show it */
a = Aliases;
while (a)
}
a = a->next;
}
+ }
+ }
- s[0] = 0; /* reset string before passing to alias_menu */
- mutt_alias_menu (s, buflen, a_list);
-
- /* free the alias list */
- while (a_list)
- {
- a_cur = a_list;
- a_list = a_list->next;
- safe_free ((void **) &a_cur);
- }
+ bestname[0] = 0;
+ mutt_alias_menu (bestname, sizeof(bestname), a_list ? a_list : Aliases);
+ if (bestname[0] != 0)
+ strfcpy (s, bestname, buflen);
- return 0;
- }
- else /* we are adding something to the completion */
- strfcpy (s, bestname, mutt_strlen (bestname) + 1);
+ /* free the alias list */
+ while (a_list)
+ {
+ a_cur = a_list;
+ a_list = a_list->next;
+ safe_free ((void **) &a_cur);
}
- return 1;
+ return 0;
}
static int string_is_address(const char *str, const char *u, const char *d)
{
/* invoke the alias-menu to get more addresses */
buf[curpos] = 0;
- if (curpos)
+ for (j = curpos - 1 ; j >= 0 && buf[j] != ',' ; j--);
+ for (++j; buf[j] == ' '; j++)
+ ;
+ if (mutt_alias_complete ((char *) buf + j, buflen - j))
{
- for (j = curpos - 1 ; j >= 0 && buf[j] != ',' ; j--);
- for (++j; buf[j] == ' '; j++)
- ;
- if (mutt_alias_complete ((char *) buf + j, buflen - j))
- {
- redraw = M_REDRAW_INIT;
- continue;
- }
+ redraw = M_REDRAW_INIT;
+ continue;
}
- else
- mutt_alias_menu ((char *) buf, buflen, Aliases);
return (1);
}
else if (flags & M_COMMAND)