diff options
| author | B. Watson <urchlay@slackware.uk> | 2025-11-18 06:57:14 -0500 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2025-11-18 06:57:14 -0500 |
| commit | ebfad791508af77f7f8e942c88a6f5dc88bd6d41 (patch) | |
| tree | c4414ef1e0fccc49c261dd5305dcdfb2feb53efc /src/alfsum.c | |
| parent | 7ec4a5150710643e99f982b5a82f8aeb49302d81 (diff) | |
| download | unalf-ebfad791508af77f7f8e942c88a6f5dc88bd6d41.tar.gz | |
Improve alfsum usage a bit.
Diffstat (limited to 'src/alfsum.c')
| -rw-r--r-- | src/alfsum.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/alfsum.c b/src/alfsum.c index 7f30c7c..2456e60 100644 --- a/src/alfsum.c +++ b/src/alfsum.c @@ -1,12 +1,9 @@ -#include <stdio.h> -#include <unistd.h> +#include "unalf.h" /* 20251104 bkw: implement the simple checksum used by ALF. Dumbest possible algo: all the bytes are added together and the bottom 16 bits of the result is the checksum. */ -char *self; - void alfsum(const char *file, FILE *f) { int c; unsigned long sum = 0; @@ -14,7 +11,7 @@ void alfsum(const char *file, FILE *f) { while((c = fgetc(f)) != EOF) sum += c; - printf("%8s\t%04x\n", file, (unsigned int)(sum & 0xffff)); + printf("%04x\t%s\n", (unsigned int)(sum & 0xffff), file); } int main(int argc, char **argv) { @@ -22,15 +19,19 @@ int main(int argc, char **argv) { char *file; FILE *f; - self = argv[0]; + set_self(argv[0]); - /* if the first arg is a - followed by anything at all, assume --help */ - if(argc < 2 || (argc == 2 && argv[1][0] == '-' && argv[1][1])) { - fprintf(stderr, - "usage: %s filename [filename ...]\n" + if(argc < 2 || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) { + printf("alfsum v" VERSION " by B. Watson. WTFPL.\n" + "Usage: %s filename [filename(s) ...]\n" "\t(use - to read from standard input)\n", self); - return -1; + return (argc < 2) ? -1 : 0; + } + + if(!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) { + puts(VERSION); + exit(0); } while((file = *++argv)) { |
