diff --git a/src/ChangeLog b/src/ChangeLog index 919a01eaf..f9581bad1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2002-09-10 Pavel Roskin + * util.c (trim): Handle short strings even better - don't use + dots unless necessary. + * main.c (load_prompt): Don't shorten the prompt if COLS is 8 or less. diff --git a/src/util.c b/src/util.c index 8d32ead6e..fed6cc551 100644 --- a/src/util.c +++ b/src/util.c @@ -117,18 +117,24 @@ trim (char *s, char *d, int len) { int source_len; - if (len < 3) { - len = max (len, 0); - memset (d, '.', len); - d[len] = 0; - return d; - } + /* Sanity check */ + len = max (len, 0); source_len = strlen (s); if (source_len > len) { - memset (d, '.', 3); - strcpy (d + 3, s + 3 + source_len - len); + /* Cannot fit the whole line */ + if (len <= 3) { + /* We only have room for the dots */ + memset (d, '.', len); + d[len] = 0; + return d; + } else { + /* Begin with ... and add the rest of the source string */ + memset (d, '.', 3); + strcpy (d + 3, s + 3 + source_len - len); + } } else + /* We can copy the whole line */ strcpy (d, s); return d; }