Changeset 915:703a240ebe85 for alias.c

Show
Ignore:
Timestamp:
1999-07-20 00:14:43 (9 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
mutt-1-0-stable
Message:

patch-0.95.6.alias_compl.1.gz, from Gero Treuner

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • alias.c

    r703 r915  
    297297 * 
    298298 * given a partial alias, this routine attempts to fill in the alias 
    299  * from the alias list as much as possible 
     299 * from the alias list as much as possible. if given empty search string 
     300 * or found nothing, present all aliases 
    300301 */ 
    301302int mutt_alias_complete (char *s, size_t buflen) 
     
    306307  int i; 
    307308 
    308   memset (bestname, 0, sizeof (bestname)); 
    309  
    310309#define min(a,b)        ((a<b)?a:b) 
    311310 
    312   while (a) 
    313   { 
    314     if (a->name && strstr (a->name, s) == a->name) 
    315     { 
    316       if (!bestname[0]) /* init */ 
    317         strfcpy (bestname, a->name, min (mutt_strlen (a->name) + 1, sizeof (bestname))); 
    318       else 
     311  if (s[0] != 0) /* avoid empty string as strstr argument */ 
     312  { 
     313    memset (bestname, 0, sizeof (bestname)); 
     314 
     315    while (a) 
     316    { 
     317      if (a->name && strstr (a->name, s) == a->name) 
    319318      { 
    320         for (i = 0 ; a->name[i] && a->name[i] == bestname[i] ; i++) 
    321           ; 
    322         bestname[i] = 0; 
     319        if (!bestname[0]) /* init */ 
     320          strfcpy (bestname, a->name, 
     321                   min (mutt_strlen (a->name) + 1, sizeof (bestname))); 
     322        else 
     323        { 
     324          for (i = 0 ; a->name[i] && a->name[i] == bestname[i] ; i++) 
     325            ; 
     326          bestname[i] = 0; 
     327        } 
    323328      } 
    324     } 
    325     a = a->next; 
    326   } 
    327  
    328   if ((bestname[0] == 0) || /* if we didn't find anything */ 
    329       (s[0] == 0))          /* or we weren't given anything */ 
    330   { 
    331     mutt_alias_menu (s, buflen, Aliases); 
    332     return 0; 
    333   } 
    334   else 
    335   { 
    336     if (mutt_strcmp (bestname, s) == 0) /* add anything to the completion? */ 
    337     { 
     329      a = a->next; 
     330    } 
     331 
     332    if (bestname[0] != 0) 
     333    { 
     334      if (mutt_strcmp (bestname, s) != 0) 
     335      { 
     336        /* we are adding something to the completion */ 
     337        strfcpy (s, bestname, mutt_strlen (bestname) + 1); 
     338        return 1; 
     339      } 
     340 
    338341      /* build alias list and show it */ 
    339342      a = Aliases; 
     
    354357        a = a->next; 
    355358      } 
    356  
    357       s[0] = 0; /* reset string before passing to alias_menu */ 
    358       mutt_alias_menu (s, buflen, a_list); 
    359  
    360       /* free the alias list */ 
    361       while (a_list) 
    362       { 
    363         a_cur = a_list; 
    364         a_list = a_list->next; 
    365         safe_free ((void **) &a_cur); 
    366       } 
    367  
    368       return 0; 
    369     } 
    370     else /* we are adding something to the completion */ 
    371       strfcpy (s, bestname, mutt_strlen (bestname) + 1); 
    372   } 
    373  
    374   return 1; 
     359    } 
     360  } 
     361 
     362  bestname[0] = 0; 
     363  mutt_alias_menu (bestname, sizeof(bestname), a_list ? a_list : Aliases); 
     364  if (bestname[0] != 0) 
     365    strfcpy (s, bestname, buflen); 
     366 
     367  /* free the alias list */ 
     368  while (a_list) 
     369  { 
     370    a_cur = a_list; 
     371    a_list = a_list->next; 
     372    safe_free ((void **) &a_cur); 
     373  } 
     374 
     375  return 0; 
    375376} 
    376377