/*
- * Copyright (C) 2006-2007 Michael Buesch <mb@bu3sch.de>
+ * Copyright (C) 2006-2010 Michael Buesch <m@bues.ch>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
#include <unistd.h>
-int _debug;
-bool arg_print_sizes;
+struct cmdline_args cmdargs = {
+ .debug = 0,
+ .print_sizes = 0,
+ .initvals_fn_extension = ".initvals",
+ .outformat = FMT_B43,
+};
+
#define ARG_MATCH 0
#define ARG_NOMATCH 1
static int do_cmp_arg(char **argv, int *pos,
const char *template,
int allow_merged,
- char **param)
+ const char **param)
{
char *arg;
char *next_arg;
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;
}
static int cmp_arg(char **argv, int *pos,
const char *long_template,
const char *short_template,
- char **param)
+ const char **param)
{
int err;
return err;
}
-static void usage(int argc, char **argv)
+static void usage(void)
{
- fprintf(stderr, "Usage: %s INPUT_FILE OUTPUT_FILE [OPTIONS]\n", argv[0]);
- fprintf(stderr, " -h|--help Print this help\n");
- fprintf(stderr, " -d|--debug Print verbose debugging info\n");
- fprintf(stderr, " Repeat for more verbose debugging\n");
- fprintf(stderr, " -s|--psize Print the size of the code after assembling\n");
+ printf("Usage: b43-asm INPUT_FILE OUTPUT_FILE [OPTIONS]\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;
outfile_name = argv[2];
for (i = 3; i < argc; i++) {
- if ((res = cmp_arg(argv, &i, "--help", "-h", 0)) == ARG_MATCH) {
- usage(argc, argv);
+ if ((res = cmp_arg(argv, &i, "--help", "-h", NULL)) == ARG_MATCH) {
+ usage();
return 1;
- } else if ((res = cmp_arg(argv, &i, "--debug", "-d", 0)) == ARG_MATCH) {
- _debug++;
- } else if ((res = cmp_arg(argv, &i, "--psize", "-s", 0)) == ARG_MATCH) {
- arg_print_sizes = 1;
+ } else if ((res = cmp_arg(argv, &i, "--format", "-f", ¶m)) == ARG_MATCH) {
+ if (strcasecmp(param, "raw-le32") == 0)
+ cmdargs.outformat = FMT_RAW_LE32;
+ else if (strcasecmp(param, "raw-be32") == 0)
+ cmdargs.outformat = FMT_RAW_BE32;
+ else if (strcasecmp(param, "b43") == 0)
+ 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) {
+ cmdargs.debug++;
+ } else if ((res = cmp_arg(argv, &i, "--psize", "-s", NULL)) == ARG_MATCH) {
+ 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 (!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;
+ }
+
return 0;
out_usage:
- usage(argc, argv);
+ usage();
return -1;
}