From: Michael Buesch Date: Mon, 20 Sep 2010 20:53:52 +0000 (+0200) Subject: assembler: Put commandline args into structure X-Git-Tag: b43-fwcutter-014~24 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=b756ecc447336244a0340daaa821a12c2b8f7c61;p=b43-tools.git assembler: Put commandline args into structure Signed-off-by: Michael Buesch --- diff --git a/assembler/args.c b/assembler/args.c index 42d9c18..56707a1 100644 --- a/assembler/args.c +++ b/assembler/args.c @@ -22,11 +22,12 @@ #include -int _debug; -bool arg_print_sizes; -const char *initvals_fn_extension = ".initvals"; -static const char *real_infile_name; -enum fwformat output_format = FMT_B43; +struct cmdline_args cmdargs = { + .debug = 0, + .print_sizes = 0, + .initvals_fn_extension = ".initvals", + .outformat = FMT_B43, +}; #define ARG_MATCH 0 @@ -124,31 +125,31 @@ int parse_args(int argc, char **argv) return 1; } else if ((res = cmp_arg(argv, &i, "--format", "-f", ¶m)) == ARG_MATCH) { if (strcasecmp(param, "raw-le32") == 0) - output_format = FMT_RAW_LE32; + cmdargs.outformat = FMT_RAW_LE32; else if (strcasecmp(param, "raw-be32") == 0) - output_format = FMT_RAW_BE32; + cmdargs.outformat = FMT_RAW_BE32; else if (strcasecmp(param, "b43") == 0) - output_format = FMT_B43; + cmdargs.outformat = FMT_B43; else { fprintf(stderr, "Invalid -f|--format\n\n"); goto out_usage; } } else if ((res = cmp_arg(argv, &i, "--debug", "-d", NULL)) == ARG_MATCH) { - _debug++; + cmdargs.debug++; } else if ((res = cmp_arg(argv, &i, "--psize", "-s", NULL)) == ARG_MATCH) { - arg_print_sizes = 1; - } else if ((res = cmp_arg(argv, &i, "--ivalext", "-e", &initvals_fn_extension)) == ARG_MATCH) { - /* initvals_fn_extension is set to the extension. */ - } else if ((res = cmp_arg(argv, &i, "--__real_infile", NULL, &real_infile_name)) == ARG_MATCH) { - /* real_infile_name is set. */ + cmdargs.print_sizes = 1; + } else if ((res = cmp_arg(argv, &i, "--ivalext", "-e", ¶m)) == ARG_MATCH) { + cmdargs.initvals_fn_extension = param; + } else if ((res = cmp_arg(argv, &i, "--__real_infile", NULL, ¶m)) == ARG_MATCH) { + cmdargs.real_infile_name = param; } else { fprintf(stderr, "Unrecognized argument: %s\n", argv[i]); goto out_usage; } } - if (!real_infile_name) - real_infile_name = infile_name; - if (strcmp(real_infile_name, outfile_name) == 0) { + if (!cmdargs.real_infile_name) + cmdargs.real_infile_name = infile_name; + if (strcmp(cmdargs.real_infile_name, outfile_name) == 0) { fprintf(stderr, "Error: INPUT and OUTPUT filename must not be the same\n"); goto out_usage; } diff --git a/assembler/args.h b/assembler/args.h index fc3abc1..a2c86d1 100644 --- a/assembler/args.h +++ b/assembler/args.h @@ -10,17 +10,22 @@ enum fwformat { FMT_B43, /* b43/b43legacy headers. */ }; +struct cmdline_args { + int debug; /* Debug level. */ + bool print_sizes; /* Print sizes after assembling. */ + const char *initvals_fn_extension; /* Initvals filename extension. */ + const char *real_infile_name; /* The real input file name. */ + enum fwformat outformat; /* The output file format. */ +}; + int parse_args(int argc, char **argv); int open_input_file(void); void close_input_file(void); -extern int _debug; -extern bool arg_print_sizes; -extern const char *initvals_fn_extension; -extern enum fwformat output_format; +extern struct cmdline_args cmdargs; -#define IS_DEBUG (_debug > 0) -#define IS_VERBOSE_DEBUG (_debug > 1) -#define IS_INSANE_DEBUG (_debug > 2) +#define IS_DEBUG (cmdargs.debug > 0) +#define IS_VERBOSE_DEBUG (cmdargs.debug > 1) +#define IS_INSANE_DEBUG (cmdargs.debug > 2) #endif /* BCM43xx_ASM_ARGS_H_ */ diff --git a/assembler/initvals.c b/assembler/initvals.c index 5db74d1..5c968df 100644 --- a/assembler/initvals.c +++ b/assembler/initvals.c @@ -296,9 +296,9 @@ static void emit_ival_section(struct ivals_context *ctx) hdr.ver = FW_HDR_VER; hdr.size = cpu_to_be32(ctx->ivals_count); - fn_len = strlen(ctx->sect->name) + strlen(initvals_fn_extension ? : "") + 1; + fn_len = strlen(ctx->sect->name) + strlen(cmdargs.initvals_fn_extension ? : "") + 1; fn = xmalloc(fn_len); - snprintf(fn, fn_len, "%s%s", ctx->sect->name, initvals_fn_extension ? : ""); + snprintf(fn, fn_len, "%s%s", ctx->sect->name, cmdargs.initvals_fn_extension ? : ""); fd = fopen(fn, "w+"); if (!fd) { fprintf(stderr, "Could not open initval output file \"%s\"\n", fn); @@ -328,7 +328,7 @@ static void emit_ival_section(struct ivals_context *ctx) filesize += size; } - if (arg_print_sizes) { + if (cmdargs.print_sizes) { printf("%s: %d values (%u bytes)\n", fn, ctx->ivals_count, filesize); } diff --git a/assembler/main.c b/assembler/main.c index b262276..5981a42 100644 --- a/assembler/main.c +++ b/assembler/main.c @@ -1116,7 +1116,7 @@ static void emit_code(struct assembler_context *ctx) } } - switch (output_format) { + switch (cmdargs.outformat) { case FMT_RAW_LE32: case FMT_RAW_BE32: /* Nothing */ @@ -1179,7 +1179,7 @@ static void emit_code(struct assembler_context *ctx) ctx->arch); } - switch (output_format) { + switch (cmdargs.outformat) { case FMT_B43: case FMT_RAW_BE32: code = ((code & (uint64_t)0xFFFFFFFF00000000ULL) >> 32) | @@ -1215,7 +1215,7 @@ static void emit_code(struct assembler_context *ctx) } } - if (arg_print_sizes) { + if (cmdargs.print_sizes) { printf("%s: text = %u instructions (%u bytes)\n", fn, insn_count, (unsigned int)(insn_count * sizeof(uint64_t)));