/* */
/* */
/* */
-/* (C) 1999-2004 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1999-2005, Ullrich von Bassewitz */
+/* Römerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
+static void CmdExpand (CmdDesc* Cmd)
+/* Expand the argument vector */
+{
+ unsigned NewMax = Cmd->ArgMax + 10;
+ char** NewArgs = xmalloc (NewMax * sizeof (char*));
+ memcpy (NewArgs, Cmd->Args, Cmd->ArgMax * sizeof (char*));
+ xfree (Cmd->Args);
+ Cmd->Args = NewArgs;
+ Cmd->ArgMax = NewMax;
+}
+
+
+
static void CmdAddArg (CmdDesc* Cmd, const char* Arg)
/* Add a new argument to the command */
{
/* Expand the argument vector if needed */
- if (Cmd->ArgCount == Cmd->ArgMax) {
- unsigned NewMax = Cmd->ArgMax + 10;
- char** NewArgs = xmalloc (NewMax * sizeof (char*));
- memcpy (NewArgs, Cmd->Args, Cmd->ArgMax * sizeof (char*));
- xfree (Cmd->Args);
- Cmd->Args = NewArgs;
- Cmd->ArgMax = NewMax;
+ if (Cmd->ArgCount >= Cmd->ArgMax) {
+ CmdExpand (Cmd);
}
/* Add a copy of the new argument, allow a NULL pointer */
if (Arg) {
- Cmd->Args [Cmd->ArgCount++] = xstrdup (Arg);
+ Cmd->Args[Cmd->ArgCount++] = xstrdup (Arg);
} else {
- Cmd->Args [Cmd->ArgCount++] = 0;
+ Cmd->Args[Cmd->ArgCount++] = 0;
}
}
+static void CmdAddArgList (CmdDesc* Cmd, const char* ArgList)
+/* Add a list of arguments separated by commas */
+{
+ const char* Arg = ArgList;
+ const char* P = Arg;
+
+ while (1) {
+ if (*P == '\0' || *P == ',') {
+
+ /* End of argument, add it */
+ unsigned Len = P - Arg;
+
+ /* Expand the argument vector if needed */
+ if (Cmd->ArgCount >= Cmd->ArgMax) {
+ CmdExpand (Cmd);
+ }
+
+ /* Add the new argument */
+ Cmd->Args[Cmd->ArgCount] = memcpy (xmalloc (Len + 1), Arg, Len);
+ Cmd->Args[Cmd->ArgCount][Len] = '\0';
+ ++Cmd->ArgCount;
+
+ /* If the argument was terminated by a comma, skip it, otherwise
+ * we're done.
+ */
+ if (*P == ',') {
+ /* Start over at next char */
+ Arg = ++P;
+ } else {
+ break;
+ }
+ } else {
+ /* Skip other chars */
+ ++P;
+ }
+ }
+
+}
+
+
+
static void CmdDelArgs (CmdDesc* Cmd, unsigned LastValid)
/* Remove all arguments with an index greater than LastValid */
{
+static void OptAsmArgs (const char* Opt attribute ((unused)), const char* Arg)
+/* Pass arguments to the assembler */
+{
+ CmdAddArgList (&CA65, Arg);
+}
+
+
+
static void OptAsmDefine (const char* Opt attribute ((unused)), const char* Arg)
/* Define an assembler symbol (assembler) */
{
+static void OptLdArgs (const char* Opt attribute ((unused)), const char* Arg)
+/* Pass arguments to the linker */
+{
+ CmdAddArgList (&LD65, Arg);
+}
+
+
+
static void OptLib (const char* Opt attribute ((unused)), const char* Arg)
/* Library file follows (linker) */
{
/* Program long options */
static const LongOpt OptTab[] = {
{ "--add-source", 0, OptAddSource },
+ { "--asm-args", 1, OptAsmArgs },
{ "--asm-define", 1, OptAsmDefine },
{ "--asm-include-dir", 1, OptAsmIncludeDir },
{ "--bss-label", 1, OptBssLabel },
{ "--forget-inc-paths", 0, OptForgetIncPaths },
{ "--help", 0, OptHelp },
{ "--include-dir", 1, OptIncludeDir },
+ { "--ld-args", 1, OptLdArgs },
{ "--lib", 1, OptLib },
{ "--lib-path", 1, OptLibPath },
{ "--list-targets", 0, OptListTargets },
break;
case 'W':
- /* Suppress warnings - compiler and assembler */
- CmdAddArg (&CC65, "-W");
- CmdAddArg2 (&CA65, "-W", "0");
- break;
+ switch (Arg[2]) {
+
+ case 'a':
+ OptAsmArgs (Arg, GetArg (&I, 3));
+ break;
+
+ case 'l':
+ OptLdArgs (Arg, GetArg (&I, 3));
+ break;
+
+ case '\0':
+ /* Suppress warnings - compiler and assembler */
+ CmdAddArg (&CC65, "-W");
+ CmdAddArg2 (&CA65, "-W", "0");
+ break;
+
+ default:
+ UnknownOption (Arg);
+ break;
+ }
+ break;
case 'c':
/* Don't link the resulting files */