From owner-freebsd-hackers@FreeBSD.ORG Fri Dec 5 23:15:06 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 EEC7C1065673 for ; Fri, 5 Dec 2008 23:15:06 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.terabit.net.ua (mail.terabit.net.ua [195.137.202.147]) by mx1.freebsd.org (Postfix) with ESMTP id 807D08FC1C for ; Fri, 5 Dec 2008 23:15:06 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from skuns.zoral.com.ua ([91.193.166.194] helo=mail.zoral.com.ua) by mail.terabit.net.ua with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63 (FreeBSD)) (envelope-from ) id 1L8jt2-000Fr1-70; Sat, 06 Dec 2008 01:15:04 +0200 Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id mB5NEwMT001307 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 6 Dec 2008 01:14:58 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3) with ESMTP id mB5NEw0h059523; Sat, 6 Dec 2008 01:14:58 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3/Submit) id mB5NEwnL059522; Sat, 6 Dec 2008 01:14:58 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 6 Dec 2008 01:14:58 +0200 From: Kostik Belousov To: Sheldon Givens Message-ID: <20081205231458.GY2038@deviant.kiev.zoral.com.ua> References: <7d6fde3d0812051448r1581d666v50d162cae348982a@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="5cJDuji44TeXTx+X" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: ClamAV version 0.93.3, clamav-milter version 0.93.3 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua X-Virus-Scanned: mail.terabit.net.ua 1L8jt2-000Fr1-70 52070edf249592802480f7e900476c81 X-Terabit: YES Cc: Garrett Cooper , freebsd-hackers@freebsd.org 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:15:07 -0000 --5cJDuji44TeXTx+X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Dec 05, 2008 at 03:10:56PM -0800, Sheldon Givens wrote: > What's the problem having it? The total code is mere bytes and it eases t= he > transition for others who are migrating from Linux. > You're absolutely right in that it can be done with awk (fairly simply, t= oo) > but it doesn't hurt to explore options. Additionally, with awk, you can't > get other figures with the same command, which increases ease of use. > IE: What's the equivalent to "wc -clwL" in awk? Would you really rather r= un > wc -clw && awk '{if(length>x){x=3Dlength}}END{if(x>0){print x}else{print > 0}}'`? >=20 > Isn't wc -L a more elegant solution than awk > '{if(length>x){x=3Dlength}}END{if(x>0){print x}else{print 0}}'`? >=20 > Should I continue? Real argument pro is that you have one less thing to worry when you trying to run some script, written on Linux, on the FreeBSD system. >=20 > On Fri, Dec 5, 2008 at 2:48 PM, Garrett Cooper wrote: >=20 > > On Fri, Dec 5, 2008 at 2:14 PM, Sheldon Givens wro= te: > > > Hello everyone, > > > In the process of migrating the last of a few Linux servers to FreeBS= D, > > 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 =3D getopt(argc, argv, "clmw")) !=3D -1) > > > --- > > >> while ((ch =3D getopt(argc, argv, "clmwL")) !=3D -1) > > > 93a94,96 > > >> case 'L': > > >> dolongline =3D 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 =3D wordct =3D charct =3D 0; > > > --- > > >> linect =3D wordct =3D charct =3D llcnt =3D tmpll =3D 0; > > > 171c176,179 > > > < if (*p =3D=3D '\n') > > > --- > > >> if (*p =3D=3D '\n') { > > >> if (tmpll > llcnt) > > >> llcnt =3D tmpl= l; > > >> tmpll =3D 0; > > > 172a181 > > >> } else { tmpll++; } > > > 179a189,192 > > >> if (dolongline) { > > >> tlongline =3D llcnt; > > >> (void)printf(" %7ju", tlongline); > > >> } > > > 197c210 > > > < return (0); > > > --- > > >> return (0); > > > 231a245 > > >> tmpll++; > > > 234c248,251 > > > < if (wch =3D=3D L'\n') > > > --- > > >> if (wch =3D=3D L'\n') { > > >> if (tmpll > llcnt) > > >> llcnt =3D tmpll; > > >> tmpll =3D 0; > > > 235a253 > > >> } > > > 258a277,280 > > >> if (dolongline) { > > >> tlongline =3D 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. > > -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" --5cJDuji44TeXTx+X Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEUEARECAAYFAkk5tfEACgkQC3+MBN1Mb4hV3gCY9L1hZJBV9Q/KqadGOJu9wOCU HgCgj6Jn9mqz9V/6zBZUHnPGV2zn8Os= =6H/f -----END PGP SIGNATURE----- --5cJDuji44TeXTx+X--