Changeset 1082:2c61ff42853a for alias.c

Show
Ignore:
Timestamp:
1999-06-14 11:11:15 (9 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
HEAD
Message:

Completion fixes from Gero Treuner <gero@…>.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • alias.c

    r1080 r1082  
    320320 * 
    321321 * given a partial alias, this routine attempts to fill in the alias 
    322  * from the alias list as much as possible 
     322 * from the alias list as much as possible. if given empty search string 
     323 * or found nothing, present all aliases 
    323324 */ 
    324325int mutt_alias_complete (char *s, size_t buflen) 
     
    329330  int i; 
    330331 
    331   memset (bestname, 0, sizeof (bestname)); 
    332  
    333332#define min(a,b)        ((a<b)?a:b) 
    334333 
    335   while (a) 
    336   { 
    337     if (a->name && strstr (a->name, s) == a->name) 
    338     { 
    339       if (!bestname[0]) /* init */ 
    340         strfcpy (bestname, a->name, min (mutt_strlen (a->name) + 1, sizeof (bestname))); 
    341       else 
     334  if (s[0] != 0) /* avoid empty string as strstr argument */ 
     335  { 
     336    memset (bestname, 0, sizeof (bestname)); 
     337 
     338    while (a) 
     339    { 
     340      if (a->name && strstr (a->name, s) == a->name) 
    342341      { 
    343         for (i = 0 ; a->name[i] && a->name[i] == bestname[i] ; i++) 
    344           ; 
    345         bestname[i] = 0; 
     342        if (!bestname[0]) /* init */ 
     343          strfcpy (bestname, a->name, 
     344                   min (mutt_strlen (a->name) + 1, sizeof (bestname))); 
     345        else 
     346        { 
     347          for (i = 0 ; a->name[i] && a->name[i] == bestname[i] ; i++) 
     348            ; 
     349          bestname[i] = 0; 
     350        } 
    346351      } 
    347     } 
    348     a = a->next; 
    349   } 
    350  
    351   if ((bestname[0] == 0) || /* if we didn't find anything */ 
    352       (s[0] == 0))          /* or we weren't given anything */ 
    353   { 
    354     mutt_alias_menu (s, buflen, Aliases); 
    355     return 0; 
    356   } 
    357   else 
    358   { 
    359     if (mutt_strcmp (bestname, s) == 0) /* add anything to the completion? */ 
    360     { 
     352      a = a->next; 
     353    } 
     354 
     355    if (bestname[0] != 0) 
     356    { 
     357      if (mutt_strcmp (bestname, s) != 0) 
     358      { 
     359        /* we are adding something to the completion */ 
     360        strfcpy (s, bestname, mutt_strlen (bestname) + 1); 
     361        return 1; 
     362      } 
     363 
    361364      /* build alias list and show it */ 
    362365      a = Aliases; 
     
    377380        a = a->next; 
    378381      } 
    379  
    380       s[0] = 0; /* reset string before passing to alias_menu */ 
    381       mutt_alias_menu (s, buflen, a_list); 
    382  
    383       /* free the alias list */ 
    384       while (a_list) 
    385       { 
    386         a_cur = a_list; 
    387         a_list = a_list->next; 
    388         safe_free ((void **) &a_cur); 
    389       } 
    390  
    391       return 0; 
    392     } 
    393     else /* we are adding something to the completion */ 
    394       strfcpy (s, bestname, mutt_strlen (bestname) + 1); 
    395   } 
    396  
    397   return 1; 
     382    } 
     383  } 
     384 
     385  bestname[0] = 0; 
     386  mutt_alias_menu (bestname, sizeof(bestname), a_list ? a_list : Aliases); 
     387  if (bestname[0] != 0) 
     388    strfcpy (s, bestname, buflen); 
     389 
     390  /* free the alias list */ 
     391  while (a_list) 
     392  { 
     393    a_cur = a_list; 
     394    a_list = a_list->next; 
     395    safe_free ((void **) &a_cur); 
     396  } 
     397 
     398  return 0; 
    398399} 
    399400