summaryrefslogtreecommitdiffstats
path: root/usr.bin/fmt
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2001-08-15 14:53:55 +0000
committerru <ru@FreeBSD.org>2001-08-15 14:53:55 +0000
commitc14d208cbde9ca7e7d4a7be9aef46db162c46ff6 (patch)
tree9828b0d985eb96d81835453c8ba2eb90e959c82a /usr.bin/fmt
parent839c5a13326aca13093860164f18e9875972e237 (diff)
downloadFreeBSD-src-c14d208cbde9ca7e7d4a7be9aef46db162c46ff6.zip
FreeBSD-src-c14d208cbde9ca7e7d4a7be9aef46db162c46ff6.tar.gz
The old fmt(1) always did what the new ``-l 8'' option does.
POLA: Changed the default to ``-l 8'' while still providing a way to disable this feature with ``-l 0''. PR: bin/29247 Reviewed by: iedowse
Diffstat (limited to 'usr.bin/fmt')
-rw-r--r--usr.bin/fmt/fmt.15
-rw-r--r--usr.bin/fmt/fmt.c13
2 files changed, 16 insertions, 2 deletions
diff --git a/usr.bin/fmt/fmt.1 b/usr.bin/fmt/fmt.1
index 63d89f7..b1333ae 100644
--- a/usr.bin/fmt/fmt.1
+++ b/usr.bin/fmt/fmt.1
@@ -115,8 +115,13 @@ escaped to protect them from your shell.
.It Fl l Ar number
Replace multiple spaces with tabs at the start of each output
line, if possible.
+Each
.Ar number
spaces will be replaced with one tab.
+The default is 8.
+If
+.Ar number
+is 0, spaces are preserved.
.It Fl t Ar number
Assume that the input files' tabs assume
.Ar number
diff --git a/usr.bin/fmt/fmt.c b/usr.bin/fmt/fmt.c
index c601c4d..a40e2fe 100644
--- a/usr.bin/fmt/fmt.c
+++ b/usr.bin/fmt/fmt.c
@@ -202,6 +202,15 @@ get_positive(const char *s, const char *err_mess, int fussyP) {
return (size_t) result;
}
+static size_t
+get_nonnegative(const char *s, const char *err_mess, int fussyP) {
+ char *t;
+ long result = strtol(s,&t,0);
+ if (*t) { if (fussyP) goto Lose; else return 0; }
+ if (result<0) { Lose: errx(EX_USAGE, "%s", err_mess); }
+ return (size_t) result;
+}
+
/* Global variables */
static int centerP=0; /* Try to center lines? */
@@ -210,7 +219,7 @@ static size_t max_length=0; /* Maximum length for output lines */
static int coalesce_spaces_P=0; /* Coalesce multiple whitespace -> ' ' ? */
static int allow_indented_paragraphs=0; /* Can first line have diff. ind.? */
static int tab_width=8; /* Number of spaces per tab stop */
-static size_t output_tab_width=0; /* Ditto, when squashing leading spaces */
+static size_t output_tab_width=8; /* Ditto, when squashing leading spaces */
static const char *sentence_enders=".?!"; /* Double-space after these */
static int grok_mail_headers=0; /* treat embedded mail headers magically? */
@@ -258,7 +267,7 @@ main(int argc, char *argv[]) {
continue;
case 'l':
output_tab_width
- = get_positive(optarg, "output tab width must be positive", 1);
+ = get_nonnegative(optarg, "output tab width must be non-negative", 1);
continue;
case 'm':
grok_mail_headers = 1;
OpenPOWER on IntegriCloud