| 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) |
| 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 | |
| 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; |