struct complete_data *cd = p->data;
struct mark *m;
struct mark *m2 = NULL;
- char *c;
+ const char *c;
int cnt = 0;
char *common = NULL;
+ /* common_pre is the longest common prefix to 'common' that
+ * appears in all matches in which 'common' appears. It is
+ * allocated with enough space to append 'common' after the
+ * prefix.
+ */
char *common_pre = NULL;
- int at_start = 0;
+ int best_match = 0;
if (!ci->str)
return Enoarg;
while (do_render_complete_prev(cd, m, p->parent, 1, &c) > 0 && c) {
int l;
- char *match;
- const char *match = c;
- if (!cd->prefix_only)
- match = strstr(match, cd->prefix);
++ const char *match;
+ int this_match = 0;
+
+ if (cd->prefix_only) {
+ match = c;
+ if (strncmp(c, cd->prefix, strlen(cd->prefix)) == 0)
+ this_match += 1;
+ } else {
+ match = strcasestr(c, cd->prefix);
+ if (strncasecmp(c, cd->prefix, strlen(cd->prefix)) == 0) {
+ this_match += 1;
+ if (strncmp(c, cd->prefix, strlen(cd->prefix)) == 0)
+ this_match += 1;
+ } else if (strstr(c, cd->prefix))
+ this_match += 1;
+ }
if (!match)
+ /* should be impossible */
break;
l = strlen(match);
if (l && match[l-1] == '\n')