``man 1 cksum'' already does that for you.

2009/5/11 Peter J. Philipp <[email protected]>:
> Hi,
>
> I did some research on different operating systems regarding checksumming and
> found that solaris had a nice option called "digest -l" which prints the
> available algorithms and exits. B I wrote this functionality into cksum(1)
> that you can have if you want it. B Patch follows.
>
> -peter
>
>
> ? 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 B  B  8 Feb 2009 17:15:09 -0000 B  B  B  1.19
> +++ cksum.1 B  B  11 May 2009 08:07:36 -0000
> @@ -42,7 +42,7 @@
> B .Sh SYNOPSIS
> B .Nm cksum
> B .Bk -words
> -.Op Fl bpqrtx
> +.Op Fl blpqrtx
> B .Op Fl a Ar algorithms
> B .Op Fl c Op Ar checklist ...
> B .Op Fl o Ar 1 | 2
> @@ -162,6 +162,8 @@
> B option may not be used in conjunction with more than a single
> B .Fl a
> B option.
> +.It Fl l
> +outputs the algorithms available and exits.
> B .It Fl o Ar 1 | 2
> B Use historic algorithms instead of the (superior) default one
> B (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 B  B  B  6 Sep 2008 12:01:34 -0000 B  B  B  1.50
> +++ md5.c B  B  B  11 May 2009 08:07:36 -0000
> @@ -201,6 +201,7 @@
> B void usage(void) __attribute__((__noreturn__));
>
> B extern char *__progname;
> +extern int errno;
> B int qflag = 0;
>
> B int
> @@ -210,14 +211,14 @@
> B  B  B  B struct hash_list hl;
> B  B  B  B size_t len;
> B  B  B  B char *cp, *input_string;
> - B  B  B  int fl, error, base64;
> + B  B  B  int fl, error, base64, i;
> B  B  B  B int bflag, cflag, pflag, rflag, tflag, xflag;
>
> B  B  B  B static const char *optstr[5] = {
> B  B  B  B  B  B  B  B "bcpqrs:tx",
> B  B  B  B  B  B  B  B "bcpqrs:tx",
> B  B  B  B  B  B  B  B "bcpqrs:tx",
> - B  B  B  B  B  B  B  "a:bco:pqrs:tx",
> + B  B  B  B  B  B  B  "a:bco:lpqrs:tx",
> B  B  B  B  B  B  B  B "a:bco:pqrs:tx"
> B  B  B  B };
>
> @@ -315,6 +316,20 @@
> B  B  B  B  B  B  B  B  B  B  B  B if (hftmp == TAILQ_END(&hl))
> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B hash_insert(&hl, hf, 0);
> B  B  B  B  B  B  B  B  B  B  B  B break;
> + B  B  B  B  B  B  B  case 'l':
> + B  B  B  B  B  B  B  B  B  B  B  for (hf = functions; hf->name != NULL; 
> hf++) {
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  len = strlen(hf->name);
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  if ((cp = calloc(1, len + 1)) 
> == NULL)
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  errx(1, "malloc: 
> %s", strerror(errno));
> +
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  for (i = 0; i < len; i++) {
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  cp[i] = 
> tolower(*(hf->name + i));
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  }
> +
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  printf("%s\n", cp);
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  free(cp);
> + B  B  B  B  B  B  B  B  B  B  B  }
> + B  B  B  B  B  B  B  B  B  B  B  exit(0);
> B  B  B  B  B  B  B  B case 'p':
> B  B  B  B  B  B  B  B  B  B  B  B pflag = 1;
> B  B  B  B  B  B  B  B  B  B  B  B break;

Reply via email to