From owner-freebsd-hackers@FreeBSD.ORG Sat Dec 6 04:01:09 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 450411065672 for ; Sat, 6 Dec 2008 04:01:09 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.224]) by mx1.freebsd.org (Postfix) with ESMTP id 0EEAA8FC0A for ; Sat, 6 Dec 2008 04:01:08 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: by rv-out-0506.google.com with SMTP id b25so291424rvf.43 for ; Fri, 05 Dec 2008 20:01:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=DqZp8PpE5SScEWzAAECzLj1AWm3qeARMnSQAcvygaHw=; b=uswgT1dRRGfXReY5EAuETwjXztfbj7wACKx6dCCcU9oFVdTHco80Jn0rlj18pMIfWc dzNhJ4YtHXCky9Nig31pT6bu0YiUg4EzRpv9Uw8yXRx1ho6pd2hLorrwQai0ShAgtTQX mbffznJJpt+ZEE5NFto4KCHngwb7XyEgQOw/M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=vr0lAzWvAnHHLu37r5UYxLz5UnRMOEU3mQXY5Vj7oey11bJ8fTsN6dwaMdc/FNFfTr mNiMhd+8jRs59YRTeQ0CdU0b6B6OWlxhW5K+a3hWeXH3cP7cghNv6rASsOs/mDQ0+KPn WN/7cMG5BrCNLSahWAd2c9zvJs9UkEtqrBVe0= Received: by 10.140.161.11 with SMTP id j11mr342766rve.292.1228536068676; Fri, 05 Dec 2008 20:01:08 -0800 (PST) Received: by 10.140.158.13 with HTTP; Fri, 5 Dec 2008 20:01:08 -0800 (PST) Message-ID: <7d6fde3d0812052001g4742c2l45cb830e1ea85c9@mail.gmail.com> Date: Fri, 5 Dec 2008 20:01:08 -0800 From: "Garrett Cooper" To: "Sheldon Givens" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <7d6fde3d0812051448r1581d666v50d162cae348982a@mail.gmail.com> <20081205231458.GY2038@deviant.kiev.zoral.com.ua> <7d6fde3d0812051523p6be3fc19re3322f3ddba78b1e@mail.gmail.com> Cc: 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: Sat, 06 Dec 2008 04:01:09 -0000 On Fri, Dec 5, 2008 at 3:28 PM, Sheldon Givens wrote: > I've successfully built it in multiple circumstances. The only thing I'm > worried about (I'm on the road now and can't test) is what will occur if wc > is fed a zero-length input... ie, a "touched" file or a echo "" | wc -L. > > On Fri, Dec 5, 2008 at 3:23 PM, Garrett Cooper wrote: >> >> On Fri, Dec 5, 2008 at 3:14 PM, Kostik Belousov >> wrote: >> > 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 >> >> the >> >> transition for others who are migrating from Linux. >> >> You're absolutely right in that it can be done with awk (fairly simply, >> >> too) >> >> 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 >> >> run >> >> wc -clw && awk '{if(length>x){x=length}}END{if(x>0){print x}else{print >> >> 0}}'`? >> >> >> >> Isn't wc -L a more elegant solution than awk >> >> '{if(length>x){x=length}}END{if(x>0){print x}else{print 0}}'`? >> >> >> >> 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. >> > >> >> >> >> On Fri, Dec 5, 2008 at 2:48 PM, 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. >> >> > -Garrett >> >> Very true. Ok, I've been easily won over :). >> The patch looks largely ok, but have you gone through compiling it in >> your own dev tree (vatting out possible warnings, etc). >> -Garrett 1. Please don't top-post. 2. Solving the problem is easy. Have the value default to something unrealistic (like -1) and simply, set the value to 0, if indeed the value is < 0. Cheers, -Garrett