From ebfad791508af77f7f8e942c88a6f5dc88bd6d41 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 18 Nov 2025 06:57:14 -0500 Subject: Improve alfsum usage a bit. --- src/alfsum.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/alfsum.c') 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 -#include +#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)) { -- cgit v1.2.3