=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/status.c,v retrieving revision 1.233 retrieving revision 1.234 diff -c -r1.233 -r1.234 *** src/usr.bin/tmux/status.c 2022/03/07 11:52:09 1.233 --- src/usr.bin/tmux/status.c 2022/05/30 13:07:46 1.234 *************** *** 1,4 **** ! /* $OpenBSD: status.c,v 1.233 2022/03/07 11:52:09 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: status.c,v 1.234 2022/05/30 13:07:46 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 1576,1586 **** status_prompt_hsize[type] = newsize; } /* Build completion list. */ static char ** status_prompt_complete_list(u_int *size, const char *s, int at_start) { ! char **list = NULL; const char **layout, *value, *cp; const struct cmd_entry **cmdent; const struct options_table_entry *oe; --- 1576,1600 ---- status_prompt_hsize[type] = newsize; } + /* Add to completion list. */ + static void + status_prompt_add_list(char ***list, u_int *size, const char *s) + { + u_int i; + + for (i = 0; i < *size; i++) { + if (strcmp((*list)[i], s) == 0) + return; + } + *list = xreallocarray(*list, (*size) + 1, sizeof **list); + (*list)[(*size)++] = xstrdup(s); + } + /* Build completion list. */ static char ** status_prompt_complete_list(u_int *size, const char *s, int at_start) { ! char **list = NULL, *tmp; const char **layout, *value, *cp; const struct cmd_entry **cmdent; const struct options_table_entry *oe; *************** *** 1594,1608 **** *size = 0; for (cmdent = cmd_table; *cmdent != NULL; cmdent++) { ! if (strncmp((*cmdent)->name, s, slen) == 0) { ! list = xreallocarray(list, (*size) + 1, sizeof *list); ! list[(*size)++] = xstrdup((*cmdent)->name); ! } if ((*cmdent)->alias != NULL && ! strncmp((*cmdent)->alias, s, slen) == 0) { ! list = xreallocarray(list, (*size) + 1, sizeof *list); ! list[(*size)++] = xstrdup((*cmdent)->alias); ! } } o = options_get_only(global_options, "command-alias"); if (o != NULL) { --- 1608,1618 ---- *size = 0; for (cmdent = cmd_table; *cmdent != NULL; cmdent++) { ! if (strncmp((*cmdent)->name, s, slen) == 0) ! status_prompt_add_list(&list, size, (*cmdent)->name); if ((*cmdent)->alias != NULL && ! strncmp((*cmdent)->alias, s, slen) == 0) ! status_prompt_add_list(&list, size, (*cmdent)->alias); } o = options_get_only(global_options, "command-alias"); if (o != NULL) { *************** *** 1615,1622 **** if (slen > valuelen || strncmp(value, s, slen) != 0) goto next; ! list = xreallocarray(list, (*size) + 1, sizeof *list); ! list[(*size)++] = xstrndup(value, valuelen); next: a = options_array_next(a); --- 1625,1633 ---- if (slen > valuelen || strncmp(value, s, slen) != 0) goto next; ! xasprintf(&tmp, "%.*s", (int)valuelen, value); ! status_prompt_add_list(&list, size, tmp); ! free(tmp); next: a = options_array_next(a); *************** *** 1624,1641 **** } if (at_start) return (list); - for (oe = options_table; oe->name != NULL; oe++) { ! if (strncmp(oe->name, s, slen) == 0) { ! list = xreallocarray(list, (*size) + 1, sizeof *list); ! list[(*size)++] = xstrdup(oe->name); ! } } for (layout = layouts; *layout != NULL; layout++) { ! if (strncmp(*layout, s, slen) == 0) { ! list = xreallocarray(list, (*size) + 1, sizeof *list); ! list[(*size)++] = xstrdup(*layout); ! } } return (list); } --- 1635,1647 ---- } if (at_start) return (list); for (oe = options_table; oe->name != NULL; oe++) { ! if (strncmp(oe->name, s, slen) == 0) ! status_prompt_add_list(&list, size, oe->name); } for (layout = layouts; *layout != NULL; layout++) { ! if (strncmp(*layout, s, slen) == 0) ! status_prompt_add_list(&list, size, *layout); } return (list); }