Use new cmdline module
git-svn-id: svn://svn.cc65.org/cc65/trunk@64 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
150
src/ca65/main.c
150
src/ca65/main.c
@@ -39,6 +39,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "../common/cmdline.h"
|
||||||
#include "../common/version.h"
|
#include "../common/version.h"
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
@@ -88,6 +89,7 @@ static void Usage (void)
|
|||||||
" --auto-import\t\tMark unresolved symbols as import\n"
|
" --auto-import\t\tMark unresolved symbols as import\n"
|
||||||
" --cpu type\t\tSet cpu type\n"
|
" --cpu type\t\tSet cpu type\n"
|
||||||
" --debug-info\t\tAdd debug info to object file\n"
|
" --debug-info\t\tAdd debug info to object file\n"
|
||||||
|
" --help\t\tPrint this text\n"
|
||||||
" --ignore-case\t\tIgnore case of symbols\n"
|
" --ignore-case\t\tIgnore case of symbols\n"
|
||||||
" --include-dir dir\tSet an include directory search path\n"
|
" --include-dir dir\tSet an include directory search path\n"
|
||||||
" --listing\t\tCreate a listing if assembly was ok\n"
|
" --listing\t\tCreate a listing if assembly was ok\n"
|
||||||
@@ -101,54 +103,6 @@ static void Usage (void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void UnknownOption (const char* Arg)
|
|
||||||
/* Print an error about an unknown option. Print usage information and exit */
|
|
||||||
{
|
|
||||||
fprintf (stderr, "Unknown option: %s\n", Arg);
|
|
||||||
Usage ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void NeedArg (const char* Arg)
|
|
||||||
/* Print an error about a missing option argument and exit. */
|
|
||||||
{
|
|
||||||
fprintf (stderr, "Option requires an argument: %s\n", Arg);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void InvSym (const char* Def)
|
|
||||||
/* Print an error about an invalid symbol definition and die */
|
|
||||||
{
|
|
||||||
fprintf (stderr, "Invalid symbol definition: `%s'\n", Def);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const char* GetArg (int* ArgNum, char* argv [], unsigned Len)
|
|
||||||
/* Get an option argument */
|
|
||||||
{
|
|
||||||
const char* Arg = argv [*ArgNum];
|
|
||||||
if (Arg [Len] != '\0') {
|
|
||||||
/* Argument appended */
|
|
||||||
return Arg + Len;
|
|
||||||
} else {
|
|
||||||
/* Separate argument */
|
|
||||||
Arg = argv [*ArgNum + 1];
|
|
||||||
if (Arg == 0) {
|
|
||||||
/* End of arguments */
|
|
||||||
NeedArg (argv [*ArgNum]);
|
|
||||||
}
|
|
||||||
++(*ArgNum);
|
|
||||||
return Arg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void SetOptions (void)
|
static void SetOptions (void)
|
||||||
/* Set the option for the translator */
|
/* Set the option for the translator */
|
||||||
{
|
{
|
||||||
@@ -221,7 +175,7 @@ static void DefineSymbol (const char* Def)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptAutoImport (const char* Opt)
|
static void OptAutoImport (const char* Opt, const char* Arg)
|
||||||
/* Mark unresolved symbols as imported */
|
/* Mark unresolved symbols as imported */
|
||||||
{
|
{
|
||||||
AutoImport = 1;
|
AutoImport = 1;
|
||||||
@@ -253,7 +207,7 @@ static void OptCPU (const char* Opt, const char* Arg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptDebugInfo (const char* Opt)
|
static void OptDebugInfo (const char* Opt, const char* Arg)
|
||||||
/* Add debug info to the object file */
|
/* Add debug info to the object file */
|
||||||
{
|
{
|
||||||
DbgSyms = 1;
|
DbgSyms = 1;
|
||||||
@@ -261,7 +215,15 @@ static void OptDebugInfo (const char* Opt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptIgnoreCase (const char* Opt)
|
static void OptHelp (const char* Opt, const char* Arg)
|
||||||
|
/* Print usage information and exit */
|
||||||
|
{
|
||||||
|
Usage ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void OptIgnoreCase (const char* Opt, const char* Arg)
|
||||||
/* Ignore case on symbols */
|
/* Ignore case on symbols */
|
||||||
{
|
{
|
||||||
IgnoreCase = 1;
|
IgnoreCase = 1;
|
||||||
@@ -280,7 +242,7 @@ static void OptIncludeDir (const char* Opt, const char* Arg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptListing (const char* Opt)
|
static void OptListing (const char* Opt, const char* Arg)
|
||||||
/* Create a listing file */
|
/* Create a listing file */
|
||||||
{
|
{
|
||||||
Listing = 1;
|
Listing = 1;
|
||||||
@@ -305,7 +267,7 @@ static void OptPageLength (const char* Opt, const char* Arg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptSmart (const char* Opt)
|
static void OptSmart (const char* Opt, const char* Arg)
|
||||||
/* Handle the -s/--smart options */
|
/* Handle the -s/--smart options */
|
||||||
{
|
{
|
||||||
SmartMode = 1;
|
SmartMode = 1;
|
||||||
@@ -313,7 +275,7 @@ static void OptSmart (const char* Opt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptVerbose (const char* Opt)
|
static void OptVerbose (const char* Opt, const char* Arg)
|
||||||
/* Increase verbosity */
|
/* Increase verbosity */
|
||||||
{
|
{
|
||||||
++Verbose;
|
++Verbose;
|
||||||
@@ -321,7 +283,7 @@ static void OptVerbose (const char* Opt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptVersion (const char* Opt)
|
static void OptVersion (const char* Opt, const char* Arg)
|
||||||
/* Print the assembler version */
|
/* Print the assembler version */
|
||||||
{
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
@@ -331,42 +293,6 @@ static void OptVersion (const char* Opt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void LongOption (int* ArgNum, char* argv [])
|
|
||||||
/* Handle a long command line option */
|
|
||||||
{
|
|
||||||
const char* Opt = argv [*ArgNum];
|
|
||||||
const char* Arg = argv [*ArgNum+1];
|
|
||||||
|
|
||||||
if (strcmp (Opt, "--auto-import") == 0) {
|
|
||||||
OptAutoImport (Opt);
|
|
||||||
} else if (strcmp (Opt, "--cpu") == 0) {
|
|
||||||
OptCPU (Opt, Arg);
|
|
||||||
++(*ArgNum);
|
|
||||||
} else if (strcmp (Opt, "--debug-info") == 0) {
|
|
||||||
OptIgnoreCase (Opt);
|
|
||||||
} else if (strcmp (Opt, "--ignore-case") == 0) {
|
|
||||||
OptIgnoreCase (Opt);
|
|
||||||
} else if (strcmp (Opt, "--include-dir") == 0) {
|
|
||||||
OptIncludeDir (Opt, Arg);
|
|
||||||
++(*ArgNum);
|
|
||||||
} else if (strcmp (Opt, "--listing") == 0) {
|
|
||||||
OptListing (Opt);
|
|
||||||
} else if (strcmp (Opt, "--pagelength") == 0) {
|
|
||||||
OptPageLength (Opt, Arg);
|
|
||||||
++(*ArgNum);
|
|
||||||
} else if (strcmp (Opt, "--smart") == 0) {
|
|
||||||
OptSmart (Opt);
|
|
||||||
} else if (strcmp (Opt, "--verbose") == 0) {
|
|
||||||
OptVerbose (Opt);
|
|
||||||
} else if (strcmp (Opt, "--version") == 0) {
|
|
||||||
OptVersion (Opt);
|
|
||||||
} else {
|
|
||||||
UnknownOption (Opt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OneLine (void)
|
static void OneLine (void)
|
||||||
/* Assemble one line */
|
/* Assemble one line */
|
||||||
{
|
{
|
||||||
@@ -506,8 +432,26 @@ static void CreateObjFile (void)
|
|||||||
int main (int argc, char* argv [])
|
int main (int argc, char* argv [])
|
||||||
/* Assembler main program */
|
/* Assembler main program */
|
||||||
{
|
{
|
||||||
|
/* Program long options */
|
||||||
|
static const LongOpt OptTab[] = {
|
||||||
|
{ "--auto-import", 0, OptAutoImport },
|
||||||
|
{ "--cpu", 1, OptCPU },
|
||||||
|
{ "--debug-info", 0, OptDebugInfo },
|
||||||
|
{ "--help", 0, OptHelp },
|
||||||
|
{ "--ignore-case", 0, OptIgnoreCase },
|
||||||
|
{ "--include-dir", 1, OptIncludeDir },
|
||||||
|
{ "--listing", 0, OptListing },
|
||||||
|
{ "--pagelength", 1, OptPageLength },
|
||||||
|
{ "--smart", 0, OptSmart },
|
||||||
|
{ "--verbose", 0, OptVerbose },
|
||||||
|
{ "--version", 0, OptVersion },
|
||||||
|
};
|
||||||
|
|
||||||
int I;
|
int I;
|
||||||
|
|
||||||
|
/* Initialize the cmdline module */
|
||||||
|
InitCmdLine (argc, argv);
|
||||||
|
|
||||||
/* Set the program name */
|
/* Set the program name */
|
||||||
ProgName = argv [0];
|
ProgName = argv [0];
|
||||||
|
|
||||||
@@ -533,51 +477,51 @@ int main (int argc, char* argv [])
|
|||||||
switch (Arg [1]) {
|
switch (Arg [1]) {
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
LongOption (&I, argv);
|
LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
OptDebugInfo (Arg);
|
OptDebugInfo (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
OptIgnoreCase (Arg);
|
OptIgnoreCase (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
OptListing (Arg);
|
OptListing (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
OutFile = GetArg (&I, argv, 2);
|
OutFile = GetArg (&I, 2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
OptSmart (Arg);
|
OptSmart (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
OptVerbose (Arg);
|
OptVerbose (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
DefineSymbol (GetArg (&I, argv, 2));
|
DefineSymbol (GetArg (&I, 2));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'I':
|
case 'I':
|
||||||
OptIncludeDir (Arg, GetArg (&I, argv, 2));
|
OptIncludeDir (Arg, GetArg (&I, 2));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'U':
|
case 'U':
|
||||||
OptAutoImport (Arg);
|
OptAutoImport (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'V':
|
case 'V':
|
||||||
OptVersion (Arg);
|
OptVersion (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'W':
|
case 'W':
|
||||||
WarnLevel = atoi (GetArg (&I, argv, 2));
|
WarnLevel = atoi (GetArg (&I, 2));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user