From owner-freebsd-audit Wed Nov 28 13:34: 7 2001 Delivered-To: freebsd-audit@freebsd.org Received: from whale.sunbay.crimea.ua (whale.sunbay.crimea.ua [212.110.138.65]) by hub.freebsd.org (Postfix) with ESMTP id 914DA37B41B for ; Wed, 28 Nov 2001 13:33:55 -0800 (PST) Received: (from ru@localhost) by whale.sunbay.crimea.ua (8.11.6/8.11.2) id fASLXqR26002 for audit@FreeBSD.org; Wed, 28 Nov 2001 23:33:52 +0200 (EET) (envelope-from ru) Date: Wed, 28 Nov 2001 23:33:52 +0200 From: Ruslan Ermilov To: audit@FreeBSD.org Subject: fmt(1) patch Message-ID: <20011128233352.D16849@sunbay.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="DocE+STaALJfprDB" Content-Disposition: inline User-Agent: Mutt/1.3.23i Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi! The attached patch restores an undocumented feature of the old pre-4.4 fmt(1) to avoid formatting the troff requests (lines beginning with a dot character). There's an open PR on this subject, bin/31392. Also, the old fmt(1) did not do this quite right by expanding tabs into spaces and skipping non-printable characters in the troff requests. This patch fixes this as well. Comments, reviews? 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 --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=p Index: fmt.c =================================================================== RCS file: /home/ncvs/src/usr.bin/fmt/fmt.c,v retrieving revision 1.16 diff -u -p -r1.16 fmt.c --- fmt.c 2001/08/15 14:53:55 1.16 +++ fmt.c 2001/11/28 20:56:55 @@ -30,6 +30,8 @@ * preceded by a non-blank non-message-header line, is * taken to start a new paragraph, which also contains * any subsequent lines with non-empty leading whitespace. + * Unless the `-n' option is given, lines beginning with + * a . (dot) are not formatted. * 3. The "everything else" is split into words; a word * includes its trailing whitespace, and a word at the * end of a line is deemed to be followed by a single @@ -222,6 +224,7 @@ static int tab_width=8; /* Number of sp 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? */ +static int format_troff=0; /* Format troff? */ static int n_errors=0; /* Number of failed files. Return on exit. */ static char *output_buffer=0; /* Output line will be built here */ @@ -257,7 +260,7 @@ main(int argc, char *argv[]) { /* 1. Grok parameters. */ - while ((ch = getopt(argc, argv, "0123456789cd:hl:mpst:w:")) != -1) + while ((ch = getopt(argc, argv, "0123456789cd:hl:mnpst:w:")) != -1) switch(ch) { case 'c': centerP = 1; @@ -272,6 +275,9 @@ main(int argc, char *argv[]) { case 'm': grok_mail_headers = 1; continue; + case 'n': + format_troff = 1; + continue; case 'p': allow_indented_paragraphs = 1; continue; @@ -307,6 +313,7 @@ main(int argc, char *argv[]) { " -d double-space after at line end\n" " -l turn each spaces at start of line into a tab\n" " -m try to make sure mail header lines stay separate\n" +" -n format lines beginning with a dot\n" " -p allow indented paragraphs\n" " -s coalesce whitespace inside lines\n" " -t have tabs every columns\n" @@ -395,6 +402,7 @@ process_stream(FILE *stream, const char } /* We need a new paragraph if and only if: * this line is blank, + * OR it's a troff request, * OR it's a mail header, * OR it's not a mail header AND the last line was one, * OR the indentation has changed @@ -402,6 +410,7 @@ process_stream(FILE *stream, const char * AND this isn't the second line of an indented paragraph. */ if ( length==0 + || (line[0]=='.' && !format_troff) || header_type==hdr_Header || (header_type==hdr_NonHeader && prev_header_type>hdr_NonHeader) || (np!=last_indent @@ -411,6 +420,11 @@ process_stream(FILE *stream, const char para_line_number = 0; first_indent = np; last_indent = np; + /* nroff compatibility */ + if (length>0 && line[0]=='.' && !format_troff) { + printf("%.*s\n", (int)length, line); + continue; + } if (header_type==hdr_Header) last_indent=2; /* for cont. lines */ if (length==0) { putchar('\n'); @@ -594,11 +608,13 @@ get_line(FILE *stream, size_t *lengthp) size_t len=0; int ch; size_t spaces_pending=0; + int troff=0; if (buf==NULL) { length=100; buf=XMALLOC(length); } while ((ch=getc(stream)) != '\n' && ch != EOF) { + if (len+spaces_pending==0 && ch=='.' && !format_troff) troff=1; if (ch==' ') ++spaces_pending; - else if (isprint(ch)) { + else if (troff || isprint(ch)) { while (len+spaces_pending >= length) { length*=2; buf=xrealloc(buf, length); } Index: fmt.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/fmt/fmt.1,v retrieving revision 1.9 diff -u -r1.9 fmt.1 --- fmt.1 2001/08/15 14:53:55 1.9 +++ fmt.1 2001/11/28 21:23:59 @@ -42,7 +42,7 @@ .Nd simple text formatter .Sh SYNOPSIS .Nm fmt -.Op Fl cmps +.Op Fl cmnps .Op Fl d Ar chars .Op Fl l Ar num .Op Fl t Ar num @@ -88,6 +88,14 @@ options are ignored; no splitting or joining of lines is done. .It Fl m Try to format mail header lines contained in the input sensibly. +.It Fl n +Format lines beginning with a +.Ql \&. +(dot) character. +Normally, +.Nm +does not fill these lines, for compatibility with +.Xr nroff 1 . .It Fl p Allow indented paragraphs. Without the --DocE+STaALJfprDB-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message