From b3eed2c9f183c34458e0e2e40028990fd2173b86 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 7 May 2020 15:32:52 -0400 Subject: fussy formatting in usage() --- miragextract.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/miragextract.c b/miragextract.c index 25259da..571f39a 100644 --- a/miragextract.c +++ b/miragextract.c @@ -176,18 +176,28 @@ void set_auto_name(void) { outfilebase = autoname; } -void usage(int exit_code) { - fprintf(exit_code ? stderr : stdout, +void usage(void) { + char spaces[42]; + int i, count; + + count = strlen(self) + 8; + if(count >= 40) count = 40; + + for(i = 0; i < count; i++) + spaces[i] = ' '; + spaces[i] = '\0'; + + printf( "miragextract v" VERSION " by B. Watson, WTFPL\n" "Usage: %s [-l] [-s] [-n] [-a] [-d] [-t track] [-b base]\n" - " [-f fmt ] [-q quality ] image-file\n" - "See man page for details\n", self); - exit(exit_code); + "%s[-f fmt] [-q quality] image-file\n" + "See man page for details\n", self, spaces); + exit(0); } void parse_args(int argc, char **argv) { - if(argc == 1) usage(0); - if(argc > 1 && strcmp(argv[1], "--help") == 0) usage(0); + if(argc == 1) usage(); + if(argc > 1 && strcmp(argv[1], "--help") == 0) usage(); while(++argv, --argc) { if(argv[0][0] == '-') { -- cgit v1.2.3