assembler: Put commandline args into structure
authorMichael Buesch <mb@bu3sch.de>
Mon, 20 Sep 2010 20:53:52 +0000 (22:53 +0200)
committerMichael Buesch <mb@bu3sch.de>
Mon, 20 Sep 2010 20:53:52 +0000 (22:53 +0200)
Signed-off-by: Michael Buesch <mb@bu3sch.de>
assembler/args.c
assembler/args.h
assembler/initvals.c
assembler/main.c

index 42d9c1809fca8b3658aed31264e34771174eaed7..56707a1ac9e9d61e44f8879d63ff41679a939234 100644 (file)
 #include <unistd.h>
 
 
-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", &param)) == 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", &param)) == ARG_MATCH) {
+                       cmdargs.initvals_fn_extension = param;
+               } else if ((res = cmp_arg(argv, &i, "--__real_infile", NULL, &param)) == 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;
        }
index fc3abc1b46947174dede81da0928166e1271c3d6..a2c86d160f27efcf21a259d67fee428057946b56 100644 (file)
@@ -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_ */
index 5db74d149d7cb58246c8a13212ab67d60b9216cc..5c968dff4666d4f44fbb1aeb875ebed98a274817 100644 (file)
@@ -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);
        }
index b262276d2ee800305d6a192b42fd1e73b80cfdb3..5981a42bc5b8a998f34c5aa5b62d4a497aab1eaf 100644 (file)
@@ -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)));