From owner-freebsd-bugs Tue Aug 14 6:30:13 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 6F4C137B405 for ; Tue, 14 Aug 2001 06:30:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f7EDU2259139; Tue, 14 Aug 2001 06:30:02 -0700 (PDT) (envelope-from gnats) Date: Tue, 14 Aug 2001 06:30:02 -0700 (PDT) Message-Id: <200108141330.f7EDU2259139@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Ruslan Ermilov Subject: Re: bin/29247: fmt should not expand tabs. Reply-To: Ruslan Ermilov Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/29247; it has been noted by GNATS. From: Ruslan Ermilov To: Ian Dowse Cc: bug-followup@FreeBSD.org Subject: Re: bin/29247: fmt should not expand tabs. Date: Tue, 14 Aug 2001 16:20:18 +0300 --7JfCtLOvnd9MIVvH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Aug 06, 2001 at 03:40:35PM +0100, Ian Dowse wrote: > In message <20010806170033.A44549@sunbay.com>, Ruslan Ermilov writes: > >Ah, that. That could be achieved by `fmt -l 8'. Don't take it wrong! > >fmt(1) always replaces spaces by tabs first. The old fmt(1) then did > >what new `-l 8' currently does, unconditionally, i.e., replaces every > >8 leading spaces by a single tab character. > > Ok, I didn't understand fully why it worked, but a "!}fmt" in vi > has always left a tab-indented paragraph with tabs in the indentation, > and now it doesn't. This is the only way I ever use fmt, so the > new behaviour is quite annoying, and I don't think I'll just get > used to typing "!}fmt -l 8" instead :-). > > I agree that the old behaviour was not an ideal way to achieve the > effect of keeping tab indents, but the outcome for me was the same > as if it had not expanded the tabs in the first place. I think that > to avoid this unwanted change in behaviour, either fmt needs to > remember whether the indentation used tabs, or it should default > to -l 8... > OK, how about the following? Cheers, -- Ruslan Ermilov Oracle Developer/DBA, ru@sunbay.com Sunbay Software AG, ru@FreeBSD.org FreeBSD committer, +380.652.512.251 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age --7JfCtLOvnd9MIVvH Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=p Index: fmt.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/fmt/fmt.1,v retrieving revision 1.8 diff -u -p -r1.8 fmt.1 --- fmt.1 2001/06/06 10:17:05 1.8 +++ fmt.1 2001/08/14 13:20:10 @@ -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 Index: fmt.c =================================================================== RCS file: /home/ncvs/src/usr.bin/fmt/fmt.c,v retrieving revision 1.15 diff -u -p -r1.15 fmt.c --- fmt.c 2001/08/11 00:49:11 1.15 +++ fmt.c 2001/08/14 13:20:11 @@ -202,6 +202,15 @@ get_positive(const char *s, const char * 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 l 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; --7JfCtLOvnd9MIVvH-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message