Remove insane centering code (that broke on strings of length 1) and
replace it with sane centering code. Fixes PR bin/38209, although with a different patch.
This commit is contained in:
parent
6fc636d882
commit
420b514ac8
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: fmt.c,v 1.29 2008/03/09 17:26:37 christos Exp $ */
|
||||
/* $NetBSD: fmt.c,v 1.30 2008/04/13 03:46:30 dholland Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
|
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)fmt.c 8.1 (Berkeley) 7/20/93";
|
||||
#endif
|
||||
__RCSID("$NetBSD: fmt.c,v 1.29 2008/03/09 17:26:37 christos Exp $");
|
||||
__RCSID("$NetBSD: fmt.c,v 1.30 2008/04/13 03:46:30 dholland Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <ctype.h>
|
||||
|
@ -211,26 +211,43 @@ fmt(FILE *fi)
|
|||
struct buffer lbuf, cbuf;
|
||||
char *cp, *cp2;
|
||||
int c, add_space;
|
||||
size_t len, col;
|
||||
size_t len, col, i;
|
||||
|
||||
if (center) {
|
||||
for (;;) {
|
||||
cp = fgetln(fi, &len);
|
||||
if (!cp)
|
||||
return;
|
||||
cp2 = cp + len - 1;
|
||||
while (len-- && isspace((unsigned char)*cp))
|
||||
|
||||
/* skip over leading space */
|
||||
while (len > 0) {
|
||||
if (!isspace((unsigned char)*cp))
|
||||
break;
|
||||
cp++;
|
||||
while (cp2 > cp && isspace((unsigned char)*cp2))
|
||||
cp2--;
|
||||
if (cp == cp2)
|
||||
len--;
|
||||
}
|
||||
|
||||
/* clear trailing space */
|
||||
while (len > 0) {
|
||||
if (!isspace((unsigned char)cp[len-1]))
|
||||
break;
|
||||
len--;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
/* blank line */
|
||||
(void)putchar('\n');
|
||||
col = cp2 - cp;
|
||||
if (goal_length > col)
|
||||
for (c = 0; c < (goal_length - col) / 2; c++)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (goal_length > len) {
|
||||
for (i = 0; i < (goal_length - len) / 2; i++) {
|
||||
(void)putchar(' ');
|
||||
while (cp <= cp2)
|
||||
(void)putchar(*cp++);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
(void)putchar(cp[i]);
|
||||
}
|
||||
(void)putchar('\n');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue