Small change to wc

Giorgos Keramidas keramida at freebsd.org
Sat Dec 6 04:09:06 PST 2008


On Fri, 5 Dec 2008 18:46:00 -0800, "Sheldon Givens" <sheldon at sigsegv.ca> wrote:
> On Fri, Dec 5, 2008 at 4:17 PM, Giorgos Keramidas <keramida at ceid.upatras.gr>wrote:
>> Adding the option to increase finger-compatibility and make shell
>> scripts a bit easier to port over sounds fine by me :)
>>
>> > My apologies if this is in the wrong format. I don't often post here.
>> > ---snip---
>> > [patch]
>> > ---unsnip---
>>
>> Can you post a `diff -u' or `diff -c' version of the patch?  I like the
>> idea of the new option but it would be easier to read in -u/-c format.
>
> New diff -u:

Excellent, thanks!  Other than a few minor style-bugs, which can be
fixed before committing it (see inline comments for details), the patch
looks great to me :-)

> --- /usr/src/usr.bin/wc/wc.c    2004-12-27 14:27:56.000000000 -0800
> +++ wc/wc.c     2008-12-05 14:33:21.000000000 -0800
> @@ -167,9 +172,13 @@
>                                         return (1);
>                                 }
>                                 charct += len;
> -                               for (p = buf; len--; ++p)
> -                                       if (*p == '\n')
> +                               for (p = buf; len--; ++p)
> +                                       if (*p == '\n') {
> +                                               if (tmpll > llcnt)
> +                                                       llcnt = tmpll;
> +                                               tmpll = 0;
>                                                 ++linect;
> +                                               } else {tmpll++;}

It's probably more 'stylish' to write the else part as:

                                       if (*p == '\n') {
                                               if (tmpll > llcnt)
                                                       llcnt = tmpll;
                                               tmpll = 0;
                                               ++linect;
                                       } else
                                               tmpll++;

> @@ -194,7 +207,7 @@
>                                 (void)printf(" %7lld", (long
> long)sb.st_size);
>                                 tcharct += sb.st_size;
>                                 (void)close(fd);
> -                               return (0);
> +                       return (0);

This change only removes indendation from a return statement.  We should
probably keep it out of the final commit.

Thanks for writing & posting the patch :-)



More information about the freebsd-hackers mailing list