From owner-freebsd-hackers@FreeBSD.ORG Fri Dec 5 23:20:02 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A88361065677 for ; Fri, 5 Dec 2008 23:20:02 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outZ.internet-mail-service.net (outz.internet-mail-service.net [216.240.47.249]) by mx1.freebsd.org (Postfix) with ESMTP id 8CD3D8FC0C for ; Fri, 5 Dec 2008 23:20:02 +0000 (UTC) (envelope-from julian@elischer.org) Received: from idiom.com (mx0.idiom.com [216.240.32.160]) by out.internet-mail-service.net (Postfix) with ESMTP id A5DB92517; Fri, 5 Dec 2008 15:05:07 -0800 (PST) X-Client-Authorized: MaGic Cook1e X-Client-Authorized: MaGic Cook1e X-Client-Authorized: MaGic Cook1e Received: from julian-mac.elischer.org (home.elischer.org [216.240.48.38]) by idiom.com (Postfix) with ESMTP id C74B72D6017; Fri, 5 Dec 2008 15:05:07 -0800 (PST) Message-ID: <4939B3A1.6060307@elischer.org> Date: Fri, 05 Dec 2008 15:05:05 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.18 (Macintosh/20081105) MIME-Version: 1.0 To: Garrett Cooper References: <7d6fde3d0812051448r1581d666v50d162cae348982a@mail.gmail.com> In-Reply-To: <7d6fde3d0812051448r1581d666v50d162cae348982a@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org, Sheldon Givens Subject: Re: Small change to wc X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Dec 2008 23:20:02 -0000 Garrett Cooper wrote: > On Fri, Dec 5, 2008 at 2:14 PM, Sheldon Givens wrote: >> Hello everyone, >> In the process of migrating the last of a few Linux servers to FreeBSD, we >> ran in to a bit of a snag with one of our scripts when BSD wc didn't have an >> equivalent to the Linux -L. This flag tells wc to keep track of the longest >> line in the input. >> >> Here's a little diff to add this functionality to BSD wc. >> >> With this patch, an additional parameter is added to output that shows the >> length of the longest line >> >> My apologies if this is in the wrong format. I don't often post here. >> >> Happy Holidays, >> >> Sheldon Givens >> >> >> ---snip--- >> 65,66c65,66 >> < uintmax_t tlinect, twordct, tcharct; >> < int doline, doword, dochar, domulti; >> --- >>> uintmax_t tlinect, twordct, tcharct, tlongline; >>> int doline, doword, dochar, domulti, dolongline; >> 78c78 >> < while ((ch = getopt(argc, argv, "clmw")) != -1) >> --- >>> while ((ch = getopt(argc, argv, "clmwL")) != -1) >> 93a94,96 >>> case 'L': >>> dolongline = 1; >>> break; >> 127a131,132 >>> if (dolongline) >>> (void)printf(" %7ju", tlongline); >> 137c142 >> < uintmax_t linect, wordct, charct; >> --- >>> uintmax_t linect, wordct, charct, llcnt, tmpll; >> 146c151 >> < linect = wordct = charct = 0; >> --- >>> linect = wordct = charct = llcnt = tmpll = 0; >> 171c176,179 >> < if (*p == '\n') >> --- >>> if (*p == '\n') { >>> if (tmpll > llcnt) >>> llcnt = tmpll; >>> tmpll = 0; >> 172a181 >>> } else { tmpll++; } >> 179a189,192 >>> if (dolongline) { >>> tlongline = llcnt; >>> (void)printf(" %7ju", tlongline); >>> } >> 197c210 >> < return (0); >> --- >>> return (0); >> 231a245 >>> tmpll++; >> 234c248,251 >> < if (wch == L'\n') >> --- >>> if (wch == L'\n') { >>> if (tmpll > llcnt) >>> llcnt = tmpll; >>> tmpll = 0; >> 235a253 >>> } >> 258a277,280 >>> if (dolongline) { >>> tlongline = llcnt; >>> (void)printf(" %7ju", llcnt - 1); >>> } >> 266c288 >> < (void)fprintf(stderr, "usage: wc [-clmw] [file ...]\n"); >> --- >>> (void)fprintf(stderr, "usage: wc [-clmwL] [file ...]\n"); >> ---unsnip--- > > What's the plus side of having this? I can accomplish the same with > something like awk without the additional overhead, which would be > guaranteed to be portable. true, but this is a well known extension that people use and to tell the truth, I have no idea how I would do it in awk without reading a lot where in wc it's obvious from the synopsis. > -Garrett > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"