On Wed, May 13, 2009 at 12:11:35PM +0200, Peter J. Philipp wrote: > On Wed, May 13, 2009 at 10:40:13AM +0200, Otto Moerbeek wrote: > > Come to think of it, why don't you just putchar(tolower(hf->name[i])) > > in a loop? Saves you the calloc and error handling. > > > > Also, don't forget to fix usage(). > > > > -Otto > > Yeah, thanks. Well I got good and critical feedback and Otto's prodding was > good enough to make me rewrite this puny patch. Gone are errno, calloc() and > in is the putchar(). I stayed away from adding sthen's idea, perhaps he can > do > the patch for that. Patch follows:
You forgot to fix usage(). Also, I think it makes sense to allow -l for sum(1) too, so that both commands that take -a also take -l. -Otto > > > ? cksum.1-orig > ? cksum.patch > ? md5.c-orig > Index: cksum.1 > =================================================================== > RCS file: /cvs/src/bin/md5/cksum.1,v > retrieving revision 1.19 > diff -u -r1.19 cksum.1 > --- cksum.1 8 Feb 2009 17:15:09 -0000 1.19 > +++ cksum.1 13 May 2009 10:03:46 -0000 > @@ -42,7 +42,7 @@ > .Sh SYNOPSIS > .Nm cksum > .Bk -words > -.Op Fl bpqrtx > +.Op Fl blpqrtx > .Op Fl a Ar algorithms > .Op Fl c Op Ar checklist ... > .Op Fl o Ar 1 | 2 > @@ -162,6 +162,8 @@ > option may not be used in conjunction with more than a single > .Fl a > option. > +.It Fl l > +outputs the algorithms available and exits. > .It Fl o Ar 1 | 2 > Use historic algorithms instead of the (superior) default one > (see below). > Index: md5.c > =================================================================== > RCS file: /cvs/src/bin/md5/md5.c,v > retrieving revision 1.50 > diff -u -r1.50 md5.c > --- md5.c 6 Sep 2008 12:01:34 -0000 1.50 > +++ md5.c 13 May 2009 10:03:46 -0000 > @@ -210,14 +210,14 @@ > struct hash_list hl; > size_t len; > char *cp, *input_string; > - int fl, error, base64; > + int fl, error, base64, i; > int bflag, cflag, pflag, rflag, tflag, xflag; > > static const char *optstr[5] = { > "bcpqrs:tx", > "bcpqrs:tx", > "bcpqrs:tx", > - "a:bco:pqrs:tx", > + "a:bco:lpqrs:tx", > "a:bco:pqrs:tx" > }; > > @@ -315,6 +315,15 @@ > if (hftmp == TAILQ_END(&hl)) > hash_insert(&hl, hf, 0); > break; > + case 'l': > + for (hf = functions; hf->name != NULL; hf++) { > + len = strlen(hf->name); > + for (i = 0; i < len; i++) { > + putchar(tolower(hf->name[i])); > + } > + putchar('\n'); > + } > + exit(0); > case 'p': > pflag = 1; > break;