Use stuff from the common dir
git-svn-id: svn://svn.cc65.org/cc65/trunk@73 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -37,6 +37,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "../common/cmdline.h"
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,3 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char* ProgName = "cl65"; /* Program name */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,10 +44,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern const char* ProgName; /* Program name */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* End of global.h */
|
/* End of global.h */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
223
src/cl65/main.c
223
src/cl65/main.c
@@ -44,11 +44,13 @@
|
|||||||
# include "spawn.h" /* All others */
|
# include "spawn.h" /* All others */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "../common/cmdline.h"
|
||||||
|
#include "../common/fname.h"
|
||||||
#include "../common/version.h"
|
#include "../common/version.h"
|
||||||
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "mem.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -143,61 +145,6 @@ static char* TargetLib = 0;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* String handling */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const char* FindExt (const char* Name)
|
|
||||||
/* Return a pointer to the file extension in Name or NULL if there is none */
|
|
||||||
{
|
|
||||||
const char* S;
|
|
||||||
|
|
||||||
/* Get the length of the name */
|
|
||||||
unsigned Len = strlen (Name);
|
|
||||||
if (Len < 2) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get a pointer to the last character */
|
|
||||||
S = Name + Len - 1;
|
|
||||||
|
|
||||||
/* Search for the dot, beware of subdirectories */
|
|
||||||
while (S >= Name && *S != '.' && *S != '\\' && *S != '/') {
|
|
||||||
--S;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Did we find an extension? */
|
|
||||||
if (*S == '.') {
|
|
||||||
return S;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static char* ForceExt (const char* Name, const char* Ext)
|
|
||||||
/* Return a new filename with the new extension */
|
|
||||||
{
|
|
||||||
char* Out;
|
|
||||||
const char* P = FindExt (Name);
|
|
||||||
if (P == 0) {
|
|
||||||
/* No dot, add the extension */
|
|
||||||
Out = Xmalloc (strlen (Name) + strlen (Ext) + 1);
|
|
||||||
strcpy (Out, Name);
|
|
||||||
strcat (Out, Ext);
|
|
||||||
} else {
|
|
||||||
Out = Xmalloc (P - Name + strlen (Ext) + 1);
|
|
||||||
memcpy (Out, Name, P - Name);
|
|
||||||
strcpy (Out + (P - Name), Ext);
|
|
||||||
}
|
|
||||||
return Out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Determine a file type */
|
/* Determine a file type */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -257,16 +204,16 @@ static void CmdAddArg (CmdDesc* Cmd, const char* Arg)
|
|||||||
/* Expand the argument vector if needed */
|
/* Expand the argument vector if needed */
|
||||||
if (Cmd->ArgCount == Cmd->ArgMax) {
|
if (Cmd->ArgCount == Cmd->ArgMax) {
|
||||||
unsigned NewMax = Cmd->ArgMax + 10;
|
unsigned NewMax = Cmd->ArgMax + 10;
|
||||||
char** NewArgs = Xmalloc (NewMax * sizeof (char*));
|
char** NewArgs = xmalloc (NewMax * sizeof (char*));
|
||||||
memcpy (NewArgs, Cmd->Args, Cmd->ArgMax * sizeof (char*));
|
memcpy (NewArgs, Cmd->Args, Cmd->ArgMax * sizeof (char*));
|
||||||
Xfree (Cmd->Args);
|
xfree (Cmd->Args);
|
||||||
Cmd->Args = NewArgs;
|
Cmd->Args = NewArgs;
|
||||||
Cmd->ArgMax = NewMax;
|
Cmd->ArgMax = NewMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a copy of the new argument, allow a NULL pointer */
|
/* Add a copy of the new argument, allow a NULL pointer */
|
||||||
if (Arg) {
|
if (Arg) {
|
||||||
Cmd->Args [Cmd->ArgCount++] = StrDup (Arg);
|
Cmd->Args [Cmd->ArgCount++] = xstrdup (Arg);
|
||||||
} else {
|
} else {
|
||||||
Cmd->Args [Cmd->ArgCount++] = 0;
|
Cmd->Args [Cmd->ArgCount++] = 0;
|
||||||
}
|
}
|
||||||
@@ -279,7 +226,7 @@ static void CmdDelArgs (CmdDesc* Cmd, unsigned LastValid)
|
|||||||
{
|
{
|
||||||
while (Cmd->ArgCount > LastValid) {
|
while (Cmd->ArgCount > LastValid) {
|
||||||
Cmd->ArgCount--;
|
Cmd->ArgCount--;
|
||||||
Xfree (Cmd->Args [Cmd->ArgCount]);
|
xfree (Cmd->Args [Cmd->ArgCount]);
|
||||||
Cmd->Args [Cmd->ArgCount] = 0;
|
Cmd->Args [Cmd->ArgCount] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,16 +239,16 @@ static void CmdAddFile (CmdDesc* Cmd, const char* File)
|
|||||||
/* Expand the file vector if needed */
|
/* Expand the file vector if needed */
|
||||||
if (Cmd->FileCount == Cmd->FileMax) {
|
if (Cmd->FileCount == Cmd->FileMax) {
|
||||||
unsigned NewMax = Cmd->FileMax + 10;
|
unsigned NewMax = Cmd->FileMax + 10;
|
||||||
char** NewFiles = Xmalloc (NewMax * sizeof (char*));
|
char** NewFiles = xmalloc (NewMax * sizeof (char*));
|
||||||
memcpy (NewFiles, Cmd->Files, Cmd->FileMax * sizeof (char*));
|
memcpy (NewFiles, Cmd->Files, Cmd->FileMax * sizeof (char*));
|
||||||
Xfree (Cmd->Files);
|
xfree (Cmd->Files);
|
||||||
Cmd->Files = NewFiles;
|
Cmd->Files = NewFiles;
|
||||||
Cmd->FileMax = NewMax;
|
Cmd->FileMax = NewMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a copy of the file name, allow a NULL pointer */
|
/* Add a copy of the file name, allow a NULL pointer */
|
||||||
if (File) {
|
if (File) {
|
||||||
Cmd->Files [Cmd->FileCount++] = StrDup (File);
|
Cmd->Files [Cmd->FileCount++] = xstrdup (File);
|
||||||
} else {
|
} else {
|
||||||
Cmd->Files [Cmd->FileCount++] = 0;
|
Cmd->Files [Cmd->FileCount++] = 0;
|
||||||
}
|
}
|
||||||
@@ -313,7 +260,7 @@ static void CmdInit (CmdDesc* Cmd, const char* Path)
|
|||||||
/* Initialize the command using the given path to the executable */
|
/* Initialize the command using the given path to the executable */
|
||||||
{
|
{
|
||||||
/* Remember the command */
|
/* Remember the command */
|
||||||
Cmd->Name = StrDup (Path);
|
Cmd->Name = xstrdup (Path);
|
||||||
|
|
||||||
/* Use the command name as first argument */
|
/* Use the command name as first argument */
|
||||||
CmdAddArg (Cmd, Path);
|
CmdAddArg (Cmd, Path);
|
||||||
@@ -390,12 +337,12 @@ static void SetTargetFiles (void)
|
|||||||
unsigned TargetNameLen = strlen (TargetName);
|
unsigned TargetNameLen = strlen (TargetName);
|
||||||
|
|
||||||
/* Set the startup file */
|
/* Set the startup file */
|
||||||
TargetCRT0 = Xmalloc (TargetNameLen + 2 + 1);
|
TargetCRT0 = xmalloc (TargetNameLen + 2 + 1);
|
||||||
strcpy (TargetCRT0, TargetName);
|
strcpy (TargetCRT0, TargetName);
|
||||||
strcat (TargetCRT0, ".o");
|
strcat (TargetCRT0, ".o");
|
||||||
|
|
||||||
/* Set the library file */
|
/* Set the library file */
|
||||||
TargetLib = Xmalloc (TargetNameLen + 4 + 1);
|
TargetLib = xmalloc (TargetNameLen + 4 + 1);
|
||||||
strcpy (TargetLib, TargetName);
|
strcpy (TargetLib, TargetName);
|
||||||
strcat (TargetLib, ".lib");
|
strcat (TargetLib, ".lib");
|
||||||
|
|
||||||
@@ -468,10 +415,10 @@ static void Link (void)
|
|||||||
|
|
||||||
} else if (FirstInput && FindExt (FirstInput)) { /* Only if ext present! */
|
} else if (FirstInput && FindExt (FirstInput)) { /* Only if ext present! */
|
||||||
|
|
||||||
char* Output = ForceExt (FirstInput, "");
|
char* Output = MakeFilename (FirstInput, "");
|
||||||
CmdAddArg (&LD65, "-o");
|
CmdAddArg (&LD65, "-o");
|
||||||
CmdAddArg (&LD65, Output);
|
CmdAddArg (&LD65, Output);
|
||||||
Xfree (Output);
|
xfree (Output);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -515,9 +462,9 @@ static void Assemble (const char* File)
|
|||||||
* with .s replaced by ".o". Add this file to the list of
|
* with .s replaced by ".o". Add this file to the list of
|
||||||
* linker files.
|
* linker files.
|
||||||
*/
|
*/
|
||||||
char* ObjName = ForceExt (File, ".o");
|
char* ObjName = MakeFilename (File, ".o");
|
||||||
CmdAddFile (&LD65, ObjName);
|
CmdAddFile (&LD65, ObjName);
|
||||||
Xfree (ObjName);
|
xfree (ObjName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add the file as argument for the assembler */
|
/* Add the file as argument for the assembler */
|
||||||
@@ -555,7 +502,7 @@ static void Compile (const char* File)
|
|||||||
/* The assembler file name will be the name of the source file
|
/* The assembler file name will be the name of the source file
|
||||||
* with .c replaced by ".s".
|
* with .c replaced by ".s".
|
||||||
*/
|
*/
|
||||||
AsmName = ForceExt (File, ".s");
|
AsmName = MakeFilename (File, ".s");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add the file as argument for the compiler */
|
/* Add the file as argument for the compiler */
|
||||||
@@ -579,7 +526,7 @@ static void Compile (const char* File)
|
|||||||
Warning ("Cannot remove temporary file `%s': %s",
|
Warning ("Cannot remove temporary file `%s': %s",
|
||||||
AsmName, strerror (errno));
|
AsmName, strerror (errno));
|
||||||
}
|
}
|
||||||
Xfree (AsmName);
|
xfree (AsmName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,53 +574,15 @@ static void Usage (void)
|
|||||||
" --debug-info\t\tAdd debug info\n"
|
" --debug-info\t\tAdd debug info\n"
|
||||||
" --help\t\tHelp (this text)\n"
|
" --help\t\tHelp (this text)\n"
|
||||||
" --include-dir dir\tSet a compiler include directory path\n"
|
" --include-dir dir\tSet a compiler include directory path\n"
|
||||||
" --version\t\tPrint the version number\n"
|
|
||||||
" --target sys\t\tSet the target system\n"
|
" --target sys\t\tSet the target system\n"
|
||||||
|
" --version\t\tPrint the version number\n"
|
||||||
" --verbose\t\tVerbose mode\n",
|
" --verbose\t\tVerbose mode\n",
|
||||||
ProgName);
|
ProgName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const char* GetArg (int* ArgNum, char* argv [], unsigned Len)
|
static void OptAnsi (const char* Opt, const char* Arg)
|
||||||
/* 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 */
|
|
||||||
fprintf (stderr, "Option requires an argument: %s\n", argv [*ArgNum]);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
++(*ArgNum);
|
|
||||||
return Arg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void UnknownOption (const char* Arg)
|
|
||||||
/* Print an error about a wrong argument */
|
|
||||||
{
|
|
||||||
Error ("Unknown option: `%s', use -h for help", Arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void NeedArg (const char* Arg)
|
|
||||||
/* Print an error about a missing option argument and exit. */
|
|
||||||
{
|
|
||||||
Error ("Option requires an argument: %s\n", Arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptAnsi (const char* Opt)
|
|
||||||
/* Strict ANSI mode (compiler) */
|
/* Strict ANSI mode (compiler) */
|
||||||
{
|
{
|
||||||
CmdAddArg (&CC65, "-A");
|
CmdAddArg (&CC65, "-A");
|
||||||
@@ -693,7 +602,7 @@ static void OptAsmIncludeDir (const char* Opt, const char* Arg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptDebug (const char* Opt)
|
static void OptDebug (const char* Opt, const char* Arg)
|
||||||
/* Debug mode (compiler) */
|
/* Debug mode (compiler) */
|
||||||
{
|
{
|
||||||
CmdAddArg (&CC65, "-d");
|
CmdAddArg (&CC65, "-d");
|
||||||
@@ -701,7 +610,7 @@ static void OptDebug (const char* Opt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptDebugInfo (const char* Opt)
|
static void OptDebugInfo (const char* Opt, const char* Arg)
|
||||||
/* Debug Info - add to compiler and assembler */
|
/* Debug Info - add to compiler and assembler */
|
||||||
{
|
{
|
||||||
CmdAddArg (&CC65, "-g");
|
CmdAddArg (&CC65, "-g");
|
||||||
@@ -710,7 +619,7 @@ static void OptDebugInfo (const char* Opt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptHelp (const char* Opt)
|
static void OptHelp (const char* Opt, const char* Arg)
|
||||||
/* Print help - cl65 */
|
/* Print help - cl65 */
|
||||||
{
|
{
|
||||||
Usage ();
|
Usage ();
|
||||||
@@ -742,7 +651,7 @@ static void OptTarget (const char* Opt, const char* Arg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptVerbose (const char* Opt)
|
static void OptVerbose (const char* Opt, const char* Arg)
|
||||||
/* Verbose mode (compiler, assembler, linker) */
|
/* Verbose mode (compiler, assembler, linker) */
|
||||||
{
|
{
|
||||||
CmdAddArg (&CC65, "-v");
|
CmdAddArg (&CC65, "-v");
|
||||||
@@ -752,7 +661,7 @@ static void OptVerbose (const char* Opt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptVersion (const char* Opt)
|
static void OptVersion (const char* Opt, const char* Arg)
|
||||||
/* Print version number */
|
/* Print version number */
|
||||||
{
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
@@ -762,45 +671,27 @@ 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, "--ansi") == 0) {
|
|
||||||
OptAnsi (Opt);
|
|
||||||
} else if (strcmp (Opt, "--asm-include-dir") == 0) {
|
|
||||||
OptAsmIncludeDir (Opt, Arg);
|
|
||||||
++(*ArgNum);
|
|
||||||
} else if (strcmp (Opt, "--debug") == 0) {
|
|
||||||
OptDebug (Opt);
|
|
||||||
} else if (strcmp (Opt, "--debug-info") == 0) {
|
|
||||||
OptDebugInfo (Opt);
|
|
||||||
} else if (strcmp (Opt, "--help") == 0) {
|
|
||||||
OptHelp (Opt);
|
|
||||||
} else if (strcmp (Opt, "--include-dir") == 0) {
|
|
||||||
OptIncludeDir (Opt, Arg);
|
|
||||||
++(*ArgNum);
|
|
||||||
} else if (strcmp (Opt, "--target") == 0) {
|
|
||||||
OptTarget (Opt, Arg);
|
|
||||||
++(*ArgNum);
|
|
||||||
} else if (strcmp (Opt, "--verbose") == 0) {
|
|
||||||
OptVerbose (Opt);
|
|
||||||
} else if (strcmp (Opt, "--version") == 0) {
|
|
||||||
OptVersion (Opt);
|
|
||||||
} else {
|
|
||||||
UnknownOption (Opt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main (int argc, char* argv [])
|
int main (int argc, char* argv [])
|
||||||
/* Utility main program */
|
/* Utility main program */
|
||||||
{
|
{
|
||||||
|
/* Program long options */
|
||||||
|
static const LongOpt OptTab[] = {
|
||||||
|
{ "--ansi", 0, OptAnsi },
|
||||||
|
{ "--asm-include-dir", 1, OptAsmIncludeDir },
|
||||||
|
{ "--debug", 0, OptDebug },
|
||||||
|
{ "--debug-info", 0, OptDebugInfo },
|
||||||
|
{ "--help", 0, OptHelp },
|
||||||
|
{ "--include-dir", 1, OptIncludeDir },
|
||||||
|
{ "--target", 1, OptTarget },
|
||||||
|
{ "--verbose", 0, OptVerbose },
|
||||||
|
{ "--version", 0, OptVersion },
|
||||||
|
};
|
||||||
|
|
||||||
int I;
|
int I;
|
||||||
|
|
||||||
|
/* Initialize the cmdline module */
|
||||||
|
InitCmdLine (argc, argv, "cl65");
|
||||||
|
|
||||||
/* Initialize the command descriptors */
|
/* Initialize the command descriptors */
|
||||||
CmdInit (&CC65, "cc65");
|
CmdInit (&CC65, "cc65");
|
||||||
CmdInit (&CA65, "ca65");
|
CmdInit (&CA65, "ca65");
|
||||||
@@ -819,12 +710,12 @@ 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 'A':
|
case 'A':
|
||||||
/* Strict ANSI mode (compiler) */
|
/* Strict ANSI mode (compiler) */
|
||||||
OptAnsi (Arg);
|
OptAnsi (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
@@ -833,26 +724,26 @@ int main (int argc, char* argv [])
|
|||||||
CmdAddArg (&CC65, "-Cl");
|
CmdAddArg (&CC65, "-Cl");
|
||||||
} else {
|
} else {
|
||||||
/* Specify linker config file */
|
/* Specify linker config file */
|
||||||
LinkerConfig = GetArg (&I, argv, 2);
|
LinkerConfig = GetArg (&I, 2);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
/* Define a preprocessor symbol (compiler) */
|
/* Define a preprocessor symbol (compiler) */
|
||||||
CmdAddArg (&CC65, "-D");
|
CmdAddArg (&CC65, "-D");
|
||||||
CmdAddArg (&CC65, GetArg (&I, argv, 2));
|
CmdAddArg (&CC65, GetArg (&I, 2));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'I':
|
case 'I':
|
||||||
/* Include directory (compiler) */
|
/* Include directory (compiler) */
|
||||||
OptIncludeDir (Arg, GetArg (&I, argv, 2));
|
OptIncludeDir (Arg, GetArg (&I, 2));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'L':
|
case 'L':
|
||||||
if (Arg[2] == 'n') {
|
if (Arg[2] == 'n') {
|
||||||
/* VICE label file (linker) */
|
/* VICE label file (linker) */
|
||||||
CmdAddArg (&LD65, "-Ln");
|
CmdAddArg (&LD65, "-Ln");
|
||||||
CmdAddArg (&LD65, GetArg (&I, argv, 3));
|
CmdAddArg (&LD65, GetArg (&I, 3));
|
||||||
} else {
|
} else {
|
||||||
UnknownOption (Arg);
|
UnknownOption (Arg);
|
||||||
}
|
}
|
||||||
@@ -875,7 +766,7 @@ int main (int argc, char* argv [])
|
|||||||
|
|
||||||
case 'V':
|
case 'V':
|
||||||
/* Print version number */
|
/* Print version number */
|
||||||
OptVersion (Arg);
|
OptVersion (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'W':
|
case 'W':
|
||||||
@@ -892,34 +783,34 @@ int main (int argc, char* argv [])
|
|||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
/* Debug mode (compiler) */
|
/* Debug mode (compiler) */
|
||||||
OptDebug (Arg);
|
OptDebug (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
/* Debugging - add to compiler and assembler */
|
/* Debugging - add to compiler and assembler */
|
||||||
OptDebugInfo (Arg);
|
OptDebugInfo (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
case '?':
|
case '?':
|
||||||
/* Print help - cl65 */
|
/* Print help - cl65 */
|
||||||
OptHelp (Arg);
|
OptHelp (Arg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
/* Create a map file (linker) */
|
/* Create a map file (linker) */
|
||||||
CmdAddArg (&LD65, "-m");
|
CmdAddArg (&LD65, "-m");
|
||||||
CmdAddArg (&LD65, GetArg (&I, argv, 2));
|
CmdAddArg (&LD65, GetArg (&I, 2));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
/* Name the output file */
|
/* Name the output file */
|
||||||
OutputName = GetArg (&I, argv, 2);
|
OutputName = GetArg (&I, 2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
/* Set target system - compiler and linker */
|
/* Set target system - compiler and linker */
|
||||||
OptTarget (Arg, GetArg (&I, argv, 2));
|
OptTarget (Arg, GetArg (&I, 2));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
@@ -928,7 +819,7 @@ int main (int argc, char* argv [])
|
|||||||
CmdAddArg (&LD65, "-vm");
|
CmdAddArg (&LD65, "-vm");
|
||||||
} else {
|
} else {
|
||||||
/* Verbose mode (compiler, assembler, linker) */
|
/* Verbose mode (compiler, assembler, linker) */
|
||||||
OptVerbose (Arg);
|
OptVerbose (Arg, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ LDFLAGS=
|
|||||||
OBJS = error.o \
|
OBJS = error.o \
|
||||||
global.o \
|
global.o \
|
||||||
main.o \
|
main.o \
|
||||||
mem.o \
|
|
||||||
spawn.o
|
spawn.o
|
||||||
|
|
||||||
|
LIBS = ../common/common.a
|
||||||
|
|
||||||
EXECS = cl65
|
EXECS = cl65
|
||||||
|
|
||||||
|
|
||||||
@@ -25,8 +26,8 @@ all: depend
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
cl65: $(OBJS)
|
cl65: $(OBJS) $(LIBS)
|
||||||
$(CC) $(LDFLAGS) -o cl65 $(CFLAGS) $(OBJS)
|
$(CC) $(LDFLAGS) -o cl65 $(CFLAGS) $(OBJS) $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *~ core
|
rm -f *~ core
|
||||||
|
|||||||
@@ -65,8 +65,7 @@ CCCFG = -bt=$(TARGET) -d1 -onatx -zp4 -5 -zq -w2
|
|||||||
|
|
||||||
OBJS = error.obj \
|
OBJS = error.obj \
|
||||||
global.obj \
|
global.obj \
|
||||||
main.obj \
|
main.obj
|
||||||
mem.obj
|
|
||||||
|
|
||||||
.PRECIOUS $(OBJS:.obj=.c)
|
.PRECIOUS $(OBJS:.obj=.c)
|
||||||
|
|
||||||
@@ -90,7 +89,6 @@ NAME $<
|
|||||||
FILE error.obj
|
FILE error.obj
|
||||||
FILE global.obj
|
FILE global.obj
|
||||||
FILE main.obj
|
FILE main.obj
|
||||||
FILE mem.obj
|
|
||||||
|
|
|
|
||||||
|
|
||||||
|
|
||||||
@@ -99,6 +97,6 @@ clean:
|
|||||||
@if exist cl65.exe del cl65.exe
|
@if exist cl65.exe del cl65.exe
|
||||||
|
|
||||||
strip:
|
strip:
|
||||||
@-wstrip cl65.exe
|
@-wstrip cl65.exe
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
/*****************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* mem.c */
|
|
||||||
/* */
|
|
||||||
/* Memory allocation for the cl65 compile and link utility */
|
|
||||||
/* */
|
|
||||||
/* */
|
|
||||||
/* */
|
|
||||||
/* (C) 1998 Ullrich von Bassewitz */
|
|
||||||
/* Wacholderweg 14 */
|
|
||||||
/* D-70597 Stuttgart */
|
|
||||||
/* EMail: uz@musoftware.de */
|
|
||||||
/* */
|
|
||||||
/* */
|
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
|
||||||
/* warranty. In no event will the authors be held liable for any damages */
|
|
||||||
/* arising from the use of this software. */
|
|
||||||
/* */
|
|
||||||
/* Permission is granted to anyone to use this software for any purpose, */
|
|
||||||
/* including commercial applications, and to alter it and redistribute it */
|
|
||||||
/* freely, subject to the following restrictions: */
|
|
||||||
/* */
|
|
||||||
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
||||||
/* claim that you wrote the original software. If you use this software */
|
|
||||||
/* in a product, an acknowledgment in the product documentation would be */
|
|
||||||
/* appreciated but is not required. */
|
|
||||||
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
||||||
/* be misrepresented as being the original software. */
|
|
||||||
/* 3. This notice may not be removed or altered from any source */
|
|
||||||
/* distribution. */
|
|
||||||
/* */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "error.h"
|
|
||||||
#include "mem.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* code */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* Xmalloc (size_t size)
|
|
||||||
/* Allocate memory, check for out of memory condition. Do some debugging */
|
|
||||||
{
|
|
||||||
void* p;
|
|
||||||
|
|
||||||
p = malloc (size);
|
|
||||||
if (p == 0 && size != 0) {
|
|
||||||
Error ("Out of memory");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return a pointer to the block */
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Xfree (const void* block)
|
|
||||||
/* Free the block, do some debugging */
|
|
||||||
{
|
|
||||||
free ((void*) block);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char* StrDup (const char* s)
|
|
||||||
/* Duplicate a string on the heap. The function checks for out of memory */
|
|
||||||
{
|
|
||||||
unsigned len;
|
|
||||||
|
|
||||||
len = strlen (s) + 1;
|
|
||||||
return memcpy (Xmalloc (len), s, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
/*****************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* mem.h */
|
|
||||||
/* */
|
|
||||||
/* Memory allocation for the cl65 compile and link utility */
|
|
||||||
/* */
|
|
||||||
/* */
|
|
||||||
/* */
|
|
||||||
/* (C) 1998 Ullrich von Bassewitz */
|
|
||||||
/* Wacholderweg 14 */
|
|
||||||
/* D-70597 Stuttgart */
|
|
||||||
/* EMail: uz@musoftware.de */
|
|
||||||
/* */
|
|
||||||
/* */
|
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
|
||||||
/* warranty. In no event will the authors be held liable for any damages */
|
|
||||||
/* arising from the use of this software. */
|
|
||||||
/* */
|
|
||||||
/* Permission is granted to anyone to use this software for any purpose, */
|
|
||||||
/* including commercial applications, and to alter it and redistribute it */
|
|
||||||
/* freely, subject to the following restrictions: */
|
|
||||||
/* */
|
|
||||||
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
||||||
/* claim that you wrote the original software. If you use this software */
|
|
||||||
/* in a product, an acknowledgment in the product documentation would be */
|
|
||||||
/* appreciated but is not required. */
|
|
||||||
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
||||||
/* be misrepresented as being the original software. */
|
|
||||||
/* 3. This notice may not be removed or altered from any source */
|
|
||||||
/* distribution. */
|
|
||||||
/* */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MEM_H
|
|
||||||
#define MEM_H
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* Code */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* Xmalloc (size_t size);
|
|
||||||
/* Allocate memory, check for out of memory condition. Do some debugging */
|
|
||||||
|
|
||||||
void Xfree (const void* block);
|
|
||||||
/* Free the block, do some debugging */
|
|
||||||
|
|
||||||
char* StrDup (const char* s);
|
|
||||||
/* Duplicate a string on the heap. The function checks for out of memory */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* End of mem.h */
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user