Add -c flag to fmt to center lines.
This commit is contained in:
parent
f7c176c92b
commit
3f8da92bc8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=18227
@ -39,6 +39,7 @@
|
|||||||
.Nd simple text formatter
|
.Nd simple text formatter
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm fmt
|
.Nm fmt
|
||||||
|
.Fl c
|
||||||
.Oo
|
.Oo
|
||||||
.Ar goal
|
.Ar goal
|
||||||
.Op Ar maximum
|
.Op Ar maximum
|
||||||
@ -58,6 +59,11 @@ to 65 and the maximum to 75. The spacing at the beginning of the
|
|||||||
input lines is preserved in the output, as are blank lines and
|
input lines is preserved in the output, as are blank lines and
|
||||||
interword spacing.
|
interword spacing.
|
||||||
.Pp
|
.Pp
|
||||||
|
.Fl c
|
||||||
|
instructs
|
||||||
|
.Nm fmt
|
||||||
|
to center the text.
|
||||||
|
.Pp
|
||||||
.Nm Fmt
|
.Nm Fmt
|
||||||
is meant to format mail messages prior to sending, but may also be useful
|
is meant to format mail messages prior to sending, but may also be useful
|
||||||
for other simple tasks.
|
for other simple tasks.
|
||||||
|
@ -68,6 +68,7 @@ int max_length; /* Max line length in output */
|
|||||||
int pfx; /* Current leading blank count */
|
int pfx; /* Current leading blank count */
|
||||||
int lineno; /* Current input line */
|
int lineno; /* Current input line */
|
||||||
int mark; /* Last place we saw a head line */
|
int mark; /* Last place we saw a head line */
|
||||||
|
int center;
|
||||||
|
|
||||||
char *malloc(); /* for lint . . . */
|
char *malloc(); /* for lint . . . */
|
||||||
char *headnames[] = {"To", "Subject", "Cc", 0};
|
char *headnames[] = {"To", "Subject", "Cc", 0};
|
||||||
@ -96,6 +97,11 @@ main(argc, argv)
|
|||||||
/*
|
/*
|
||||||
* LIZ@UOM 6/18/85 -- Check for goal and max length arguments
|
* LIZ@UOM 6/18/85 -- Check for goal and max length arguments
|
||||||
*/
|
*/
|
||||||
|
if (argc > 1 && !strcmp(argv[1], "-c")) {
|
||||||
|
center++;
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
if (argc > 1 && (1 == (sscanf(argv[1], "%d", &number)))) {
|
if (argc > 1 && (1 == (sscanf(argv[1], "%d", &number)))) {
|
||||||
argv++;
|
argv++;
|
||||||
argc--;
|
argc--;
|
||||||
@ -143,6 +149,27 @@ fmt(fi)
|
|||||||
#define CHUNKSIZE 1024
|
#define CHUNKSIZE 1024
|
||||||
static int lbufsize = 0, cbufsize = 0;
|
static int lbufsize = 0, cbufsize = 0;
|
||||||
|
|
||||||
|
if (center) {
|
||||||
|
linebuf = malloc(BUFSIZ);
|
||||||
|
while (1) {
|
||||||
|
cp = fgets(linebuf, BUFSIZ, fi);
|
||||||
|
if (!cp)
|
||||||
|
return;
|
||||||
|
while (*cp && isspace(*cp))
|
||||||
|
cp++;
|
||||||
|
cp2 = cp + strlen(cp) - 1;
|
||||||
|
while (cp2 > cp && isspace(*cp2))
|
||||||
|
cp2--;
|
||||||
|
if (cp == cp2)
|
||||||
|
putchar('\n');
|
||||||
|
col = cp2 - cp;
|
||||||
|
for (c = 0; c < (goal_length-col)/2; c++)
|
||||||
|
putchar(' ');
|
||||||
|
while (cp <= cp2)
|
||||||
|
putchar(*cp++);
|
||||||
|
putchar('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
c = getc(fi);
|
c = getc(fi);
|
||||||
while (c != EOF) {
|
while (c != EOF) {
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user