tweaks: elide a variable, by using a reallocation instead

Also unwrap a line.
This commit is contained in:
Benno Schulenberg 2021-01-03 11:34:19 +01:00
parent 86c9b9b54e
commit a102e45e90

View File

@ -101,7 +101,7 @@ void make_new_buffer(void)
/* Return the given file name in a way that fits within the given space. */ /* Return the given file name in a way that fits within the given space. */
char *crop_to_fit(const char *name, int room) char *crop_to_fit(const char *name, int room)
{ {
char *fragment, *clipped; char *clipped;
if (breadth(name) <= room) if (breadth(name) <= room)
return display_string(name, 0, room, FALSE, FALSE); return display_string(name, 0, room, FALSE, FALSE);
@ -109,12 +109,11 @@ char *crop_to_fit(const char *name, int room)
if (room < 4) if (room < 4)
return copy_of("_"); return copy_of("_");
fragment = display_string(name, breadth(name) - room + 3, room, FALSE, FALSE); clipped = display_string(name, breadth(name) - room + 3, room, FALSE, FALSE);
clipped = nmalloc(strlen(fragment) + 4); clipped = nrealloc(clipped, strlen(clipped) + 4);
strcpy(clipped, "..."); memmove(clipped + 3, clipped, strlen(clipped) + 1);
strcat(clipped, fragment); clipped[0] = '.'; clipped[1] = '.'; clipped[2] = '.';
free(fragment);
return clipped; return clipped;
} }
@ -2239,8 +2238,7 @@ int do_writeout(bool exiting, bool withprompt)
if (name_exists) { if (name_exists) {
char *question = _("File \"%s\" exists; OVERWRITE? "); char *question = _("File \"%s\" exists; OVERWRITE? ");
char *name = crop_to_fit(answer, COLS - breadth(question) + 1); char *name = crop_to_fit(answer, COLS - breadth(question) + 1);
char *message = nmalloc(strlen(question) + char *message = nmalloc(strlen(question) + strlen(name) + 1);
strlen(name) + 1);
sprintf(message, question, name); sprintf(message, question, name);