Update .gitignore
[b43-tools.git] / assembler / args.c
index a6736543be537260748be9834ede60147ef49bd5..42d9c1809fca8b3658aed31264e34771174eaed7 100644 (file)
@@ -25,7 +25,8 @@
 int _debug;
 bool arg_print_sizes;
 const char *initvals_fn_extension = ".initvals";
-const char *real_infile_name;
+static const char *real_infile_name;
+enum fwformat output_format = FMT_B43;
 
 
 #define ARG_MATCH              0
@@ -64,7 +65,7 @@ static int do_cmp_arg(char **argv, int *pos,
                if (param) {
                        /* Skip the parameter on the next iteration. */
                        (*pos)++;
-                       if (*param == 0) {
+                       if (*param == NULL) {
                                fprintf(stderr, "%s needs a parameter\n", arg);
                                return ARG_ERROR;
                        }
@@ -97,17 +98,20 @@ static int cmp_arg(char **argv, int *pos,
 static void usage(int argc, char **argv)
 {
        printf("Usage: %s INPUT_FILE OUTPUT_FILE [OPTIONS]\n", argv[0]);
-       printf("  -h|--help           Print this help\n");
+       printf("  -f|--format FMT     Output file format. FMT must be one of:\n");
+       printf("                      raw-le32, raw-be32, b43\n");
        printf("  -d|--debug          Print verbose debugging info\n");
        printf("                      Repeat for more verbose debugging\n");
        printf("  -s|--psize          Print the size of the code after assembling\n");
        printf("  -e|--ivalext EXT    Filename extension for the initvals\n");
+       printf("  -h|--help           Print this help\n");
 }
 
 int parse_args(int argc, char **argv)
 {
        int i;
        int res;
+       const char *param;
 
        if (argc < 3)
                goto out_usage;
@@ -115,16 +119,27 @@ int parse_args(int argc, char **argv)
        outfile_name = argv[2];
 
        for (i = 3; i < argc; i++) {
-               if ((res = cmp_arg(argv, &i, "--help", "-h", 0)) == ARG_MATCH) {
+               if ((res = cmp_arg(argv, &i, "--help", "-h", NULL)) == ARG_MATCH) {
                        usage(argc, argv);
                        return 1;
-               } else if ((res = cmp_arg(argv, &i, "--debug", "-d", 0)) == ARG_MATCH) {
+               } else if ((res = cmp_arg(argv, &i, "--format", "-f", &param)) == ARG_MATCH) {
+                       if (strcasecmp(param, "raw-le32") == 0)
+                               output_format = FMT_RAW_LE32;
+                       else if (strcasecmp(param, "raw-be32") == 0)
+                               output_format = FMT_RAW_BE32;
+                       else if (strcasecmp(param, "b43") == 0)
+                               output_format = 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++;
-               } else if ((res = cmp_arg(argv, &i, "--psize", "-s", 0)) == ARG_MATCH) {
+               } 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", 0, &real_infile_name)) == ARG_MATCH) {
+               } else if ((res = cmp_arg(argv, &i, "--__real_infile", NULL, &real_infile_name)) == ARG_MATCH) {
                        /* real_infile_name is set. */
                } else {
                        fprintf(stderr, "Unrecognized argument: %s\n", argv[i]);