mirror of
https://github.com/sheumann/hush.git
synced 2024-10-31 04:04:31 +00:00
lineedit: rename tmp -> chosen_match; small code shrink
function old new delta input_tab 1016 1012 -4 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
parent
9b56bf5416
commit
a46e16ef52
@ -1040,7 +1040,7 @@ static NOINLINE void input_tab(smallint *lastWasTab)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (!*lastWasTab) {
|
if (!*lastWasTab) {
|
||||||
char *tmp;
|
char *chosen_match;
|
||||||
size_t len_found;
|
size_t len_found;
|
||||||
/* char matchBuf[MAX_LINELEN]; */
|
/* char matchBuf[MAX_LINELEN]; */
|
||||||
#define matchBuf (S.input_tab__matchBuf)
|
#define matchBuf (S.input_tab__matchBuf)
|
||||||
@ -1067,8 +1067,6 @@ static NOINLINE void input_tab(smallint *lastWasTab)
|
|||||||
cursor_mb = strlen(matchBuf);
|
cursor_mb = strlen(matchBuf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
tmp = matchBuf;
|
|
||||||
|
|
||||||
find_type = build_match_prefix(matchBuf);
|
find_type = build_match_prefix(matchBuf);
|
||||||
|
|
||||||
/* Free up any memory already allocated */
|
/* Free up any memory already allocated */
|
||||||
@ -1104,38 +1102,39 @@ static NOINLINE void input_tab(smallint *lastWasTab)
|
|||||||
}
|
}
|
||||||
/* Did we find exactly one match? */
|
/* Did we find exactly one match? */
|
||||||
if (num_matches != 1) { /* no */
|
if (num_matches != 1) { /* no */
|
||||||
char *tmp1;
|
char *cp;
|
||||||
beep();
|
beep();
|
||||||
if (!matches)
|
if (!matches)
|
||||||
return; /* no matches at all */
|
return; /* no matches at all */
|
||||||
/* Find common prefix */
|
/* Find common prefix */
|
||||||
tmp1 = xstrdup(matches[0]);
|
chosen_match = xstrdup(matches[0]);
|
||||||
for (tmp = tmp1; *tmp; tmp++) {
|
for (cp = chosen_match; *cp; cp++) {
|
||||||
unsigned n;
|
unsigned n;
|
||||||
for (n = 1; n < num_matches; n++) {
|
for (n = 1; n < num_matches; n++) {
|
||||||
if (matches[n][tmp - tmp1] != *tmp) {
|
if (matches[n][cp - chosen_match] != *cp) {
|
||||||
goto stop;
|
goto stop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stop:
|
stop:
|
||||||
if (tmp1 == tmp) { /* have unique prefix? */
|
if (cp == chosen_match) { /* have unique prefix? */
|
||||||
free(tmp1); /* no */
|
free(chosen_match); /* no */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*tmp = '\0';
|
*cp = '\0';
|
||||||
tmp = add_quote_for_spec_chars(tmp1);
|
cp = add_quote_for_spec_chars(chosen_match);
|
||||||
free(tmp1);
|
free(chosen_match);
|
||||||
len_found = strlen(tmp);
|
chosen_match = cp;
|
||||||
|
len_found = strlen(chosen_match);
|
||||||
} else { /* exactly one match */
|
} else { /* exactly one match */
|
||||||
/* Next <tab> is not a double-tab */
|
/* Next <tab> is not a double-tab */
|
||||||
*lastWasTab = 0;
|
*lastWasTab = 0;
|
||||||
|
|
||||||
tmp = add_quote_for_spec_chars(matches[0]);
|
chosen_match = add_quote_for_spec_chars(matches[0]);
|
||||||
len_found = strlen(tmp);
|
len_found = strlen(chosen_match);
|
||||||
if (tmp[len_found-1] != '/') {
|
if (chosen_match[len_found-1] != '/') {
|
||||||
tmp[len_found] = ' ';
|
chosen_match[len_found] = ' ';
|
||||||
tmp[++len_found] = '\0';
|
chosen_match[++len_found] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1149,7 +1148,7 @@ static NOINLINE void input_tab(smallint *lastWasTab)
|
|||||||
/* save tail */
|
/* save tail */
|
||||||
strcpy(matchBuf, &command_ps[cursor]);
|
strcpy(matchBuf, &command_ps[cursor]);
|
||||||
/* add match and tail */
|
/* add match and tail */
|
||||||
sprintf(&command_ps[cursor], "%s%s", tmp + match_pfx_len, matchBuf);
|
sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, matchBuf);
|
||||||
command_len = strlen(command_ps);
|
command_len = strlen(command_ps);
|
||||||
/* new pos */
|
/* new pos */
|
||||||
pos = cursor + len_found - match_pfx_len;
|
pos = cursor + len_found - match_pfx_len;
|
||||||
@ -1167,10 +1166,10 @@ static NOINLINE void input_tab(smallint *lastWasTab)
|
|||||||
/* save tail */
|
/* save tail */
|
||||||
strcpy(matchBuf, &command[cursor_mb]);
|
strcpy(matchBuf, &command[cursor_mb]);
|
||||||
/* where do we want to have cursor after all? */
|
/* where do we want to have cursor after all? */
|
||||||
strcpy(&command[cursor_mb], tmp + match_pfx_len);
|
strcpy(&command[cursor_mb], chosen_match + match_pfx_len);
|
||||||
len = load_string(command, S.maxsize);
|
len = load_string(command, S.maxsize);
|
||||||
/* add match and tail */
|
/* add match and tail */
|
||||||
sprintf(&command[cursor_mb], "%s%s", tmp + match_pfx_len, matchBuf);
|
sprintf(&command[cursor_mb], "%s%s", chosen_match + match_pfx_len, matchBuf);
|
||||||
command_len = load_string(command, S.maxsize);
|
command_len = load_string(command, S.maxsize);
|
||||||
/* write out the matched command */
|
/* write out the matched command */
|
||||||
/* paranoia: load_string can return 0 on conv error,
|
/* paranoia: load_string can return 0 on conv error,
|
||||||
@ -1180,17 +1179,15 @@ static NOINLINE void input_tab(smallint *lastWasTab)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
free(tmp);
|
free(chosen_match);
|
||||||
#undef matchBuf
|
#undef matchBuf
|
||||||
} else {
|
} else {
|
||||||
/* Ok -- the last char was a TAB. Since they
|
/* Ok -- the last char was a TAB. Since they
|
||||||
* just hit TAB again, print a list of all the
|
* just hit TAB again, print a list of all the
|
||||||
* available choices... */
|
* available choices... */
|
||||||
if (matches && num_matches > 0) {
|
if (num_matches > 0) {
|
||||||
/* changed by goto_new_line() */
|
/* cursor will be changed by goto_new_line() */
|
||||||
int sav_cursor = cursor;
|
int sav_cursor = cursor;
|
||||||
|
|
||||||
/* Go to the next line */
|
|
||||||
goto_new_line();
|
goto_new_line();
|
||||||
showfiles();
|
showfiles();
|
||||||
redraw(0, command_len - sav_cursor);
|
redraw(0, command_len - sav_cursor);
|
||||||
|
Loading…
Reference in New Issue
Block a user