Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Dec 2008 15:10:56 -0800
From:      "Sheldon Givens" <sheldon@sigsegv.ca>
To:        "Garrett Cooper" <yanefbsd@gmail.com>, freebsd-hackers@freebsd.org
Subject:   Re: Small change to wc
Message-ID:  <f4ecc0930812051510v323ae95anccaca18d28fd174@mail.gmail.com>
In-Reply-To: <7d6fde3d0812051448r1581d666v50d162cae348982a@mail.gmail.com>
References:  <f4ecc0930812051414n17867e1fi80d6ed458e879bde@mail.gmail.com> <7d6fde3d0812051448r1581d666v50d162cae348982a@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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?

On Fri, Dec 5, 2008 at 2:48 PM, Garrett Cooper <yanefbsd@gmail.com> wrote:

> On Fri, Dec 5, 2008 at 2:14 PM, Sheldon Givens <sheldon@sigsegv.ca> 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
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?f4ecc0930812051510v323ae95anccaca18d28fd174>