commit 91ba76e1e0c807e2625d5369733644a1829d77e9
parent 3dcabd6d0314f24086af55f801d635abb310858e
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 21 Jun 2020 10:17:55 +0200
tweaks: normalize the indentation after the previous change
Also, improve five comments.
Diffstat:
M | src/files.c | | | 146 | +++++++++++++++++++++++++++++++++++++++---------------------------------------- |
1 file changed, 72 insertions(+), 74 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -2510,107 +2510,105 @@ char *input_tab(char *buf, size_t *place, void (*refresh_func)(void), bool *list
return buf;
}
- const char *lastslash = revstrstr(buf, "/", buf + *place);
- size_t length_of_path = (lastslash == NULL) ? 0 : lastslash - buf + 1;
- size_t match, common_len = 0;
- char *mzero, *glued;
- char char1[MAXCHARLEN], char2[MAXCHARLEN];
- int len1, len2;
-
- /* Get the number of characters that all matches have in common. */
- while (TRUE) {
- len1 = collect_char(matches[0] + common_len, char1);
-
- for (match = 1; match < num_matches; match++) {
- len2 = collect_char(matches[match] + common_len, char2);
-
- if (len1 != len2 || strncmp(char1, char2, len2) != 0)
- break;
- }
+ const char *lastslash = revstrstr(buf, "/", buf + *place);
+ size_t length_of_path = (lastslash == NULL) ? 0 : lastslash - buf + 1;
+ size_t match, common_len = 0;
+ char *mzero, *glued;
+ char char1[MAXCHARLEN], char2[MAXCHARLEN];
+ int len1, len2;
+
+ /* Determine the number of characters that all matches have in common. */
+ while (TRUE) {
+ len1 = collect_char(matches[0] + common_len, char1);
- if (match < num_matches || matches[0][common_len] == '\0')
- break;
+ for (match = 1; match < num_matches; match++) {
+ len2 = collect_char(matches[match] + common_len, char2);
- common_len += len1;
+ if (len1 != len2 || strncmp(char1, char2, len2) != 0)
+ break;
}
- mzero = charalloc(length_of_path + common_len + 1);
+ if (match < num_matches || matches[0][common_len] == '\0')
+ break;
- strncpy(mzero, buf, length_of_path);
- strncpy(mzero + length_of_path, matches[0], common_len);
+ common_len += len1;
+ }
- common_len += length_of_path;
- mzero[common_len] = '\0';
+ mzero = charalloc(length_of_path + common_len + 1);
- /* Cover also the case of the user specifying a relative path. */
- glued = charalloc(strlen(present_path) + strlen(mzero) + 1);
- sprintf(glued, "%s%s", present_path, mzero);
+ strncpy(mzero, buf, length_of_path);
+ strncpy(mzero + length_of_path, matches[0], common_len);
- if (num_matches == 1 && (is_dir(mzero) || is_dir(glued)))
- mzero[common_len++] = '/';
+ common_len += length_of_path;
+ mzero[common_len] = '\0';
- /* If the matches have something in common, show that part. */
- if (common_len != *place) {
- buf = charealloc(buf, common_len + 1);
- memmove(buf + common_len, buf + *place, 1);
- strncpy(buf, mzero, common_len);
- *place = common_len;
- }
+ /* Cover also the case of the user specifying a relative path. */
+ glued = charalloc(strlen(present_path) + strlen(mzero) + 1);
+ sprintf(glued, "%s%s", present_path, mzero);
- if (num_matches > 1) {
- size_t longest_name = 0, ncols;
- int row = 0;
+ if (num_matches == 1 && (is_dir(mzero) || is_dir(glued)))
+ mzero[common_len++] = '/';
- /* Sort the list of available choices. */
- qsort(matches, num_matches, sizeof(char *), diralphasort);
+ /* If the matches have something in common, copy that part. */
+ if (common_len != *place) {
+ buf = charealloc(buf, common_len + 1);
+ memmove(buf + common_len, buf + *place, 1);
+ strncpy(buf, mzero, common_len);
+ *place = common_len;
+ }
- /* Find the length of the longest among the choices. */
- for (match = 0; match < num_matches; match++) {
- size_t namelen = breadth(matches[match]);
+ /* If there is more than one possible completion, show a sorted list. */
+ if (num_matches > 1) {
+ size_t longest_name = 0, ncols;
+ int row = 0;
- if (namelen > longest_name)
- longest_name = namelen;
- }
+ qsort(matches, num_matches, sizeof(char *), diralphasort);
- if (longest_name > COLS - 1)
- longest_name = COLS - 1;
+ /* Find the length of the longest name among the matches. */
+ for (match = 0; match < num_matches; match++) {
+ size_t namelen = breadth(matches[match]);
- /* Each column will be (longest_name + 2) columns wide, i.e.
- * two spaces between columns, except that there will be
- * only one space after the last column. */
- ncols = (COLS + 1) / (longest_name + 2);
+ if (namelen > longest_name)
+ longest_name = namelen;
+ }
- /* Blank the edit window and hide the cursor. */
- blank_edit();
- curs_set(0);
+ if (longest_name > COLS - 1)
+ longest_name = COLS - 1;
- /* Now print the list of matches out there. */
- for (match = 0; match < num_matches; match++) {
- char *disp;
+ /* The columns of names will be separated by two spaces,
+ * but the last column will have just one space after it. */
+ ncols = (COLS + 1) / (longest_name + 2);
- wmove(edit, row, (longest_name + 2) * (match % ncols));
+ /* Blank the edit window and hide the cursor. */
+ blank_edit();
+ curs_set(0);
- if (row == editwinrows - 1 && num_matches - match > ncols) {
- waddstr(edit, _("(more)"));
- break;
- }
+ /* Now print the list of matches out there. */
+ for (match = 0; match < num_matches; match++) {
+ char *disp;
- disp = display_string(matches[match], 0, longest_name, FALSE, FALSE);
- waddstr(edit, disp);
- free(disp);
+ wmove(edit, row, (longest_name + 2) * (match % ncols));
- if ((match + 1) % ncols == 0)
- row++;
+ if (row == editwinrows - 1 && num_matches - match > ncols) {
+ waddstr(edit, _("(more)"));
+ break;
}
- wnoutrefresh(edit);
- *listed = TRUE;
+ disp = display_string(matches[match], 0, longest_name, FALSE, FALSE);
+ waddstr(edit, disp);
+ free(disp);
+
+ if ((match + 1) % ncols == 0)
+ row++;
}
- free(glued);
- free(mzero);
+ wnoutrefresh(edit);
+ *listed = TRUE;
+ }
free_chararray(matches, num_matches);
+ free(glued);
+ free(mzero);
return buf;
}