From 3286d83fb8ddbcbbcde3adca2b41dbb3339daa02 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 24 Apr 2024 15:18:53 -0400 Subject: blob2xex: add -v -h/--help -V/--version options. --- blob2xex.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'blob2xex.c') diff --git a/blob2xex.c b/blob2xex.c index fb339e7..9740e45 100644 --- a/blob2xex.c +++ b/blob2xex.c @@ -121,7 +121,21 @@ int main(int argc, char **argv) { char *outfile = 0, *infile = 0; int i, loadaddr = -1, runaddr = -1, initaddr = -1, offset = 0, size = DEFAULT_SIZE, *param = 0; - xex_verbose = 1; + outfile = argv[1]; + if(!outfile || strcmp(outfile, "--help") == 0 || strcmp(outfile, "-h") == 0) { + usage(); + exit(0); + } + + if(strcmp(outfile, "--version") == 0 || strcmp(outfile, "-V") == 0) { + printf(SELF " " VERSION "\n"); + exit(0); + } + + if(outfile[0] == '-' && outfile[1] != '\0') { + fprintf(stderr, SELF ": output file must come before any options.\n"); + exit(1); + } if(argc < 5) { fprintf(stderr, SELF ": not enough arguments.\n"); @@ -129,8 +143,6 @@ int main(int argc, char **argv) { exit(1); } - outfile = argv[1]; - for(i = 2; i < argc; i++) { char *arg = argv[i]; @@ -153,6 +165,7 @@ int main(int argc, char **argv) { case 'i': param = &initaddr; break; case 'o': param = &offset; break; case 's': param = &size; break; + case 'v': xex_verbose = 1; break; default: fprintf(stderr, SELF ": unknown option '-%c'\n", arg[1]); usage(); -- cgit v1.2.3