More common subroutines
git-svn-id: svn://svn.cc65.org/cc65/trunk@69 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -34,11 +34,11 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "../common/exprdefs.h"
|
#include "../common/exprdefs.h"
|
||||||
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "instr.h"
|
#include "instr.h"
|
||||||
#include "mem.h"
|
|
||||||
#include "nexttok.h"
|
#include "nexttok.h"
|
||||||
#include "objcode.h"
|
#include "objcode.h"
|
||||||
#include "objfile.h"
|
#include "objfile.h"
|
||||||
@@ -85,7 +85,7 @@ static ExprNode* NewExprNode (void)
|
|||||||
FreeExprNodes = N->Left;
|
FreeExprNodes = N->Left;
|
||||||
} else {
|
} else {
|
||||||
/* Allocate fresh memory */
|
/* Allocate fresh memory */
|
||||||
N = Xmalloc (sizeof (ExprNode));
|
N = xmalloc (sizeof (ExprNode));
|
||||||
}
|
}
|
||||||
N->Op = EXPR_NULL;
|
N->Op = EXPR_NULL;
|
||||||
N->Left = N->Right = 0;
|
N->Left = N->Right = 0;
|
||||||
@@ -106,7 +106,7 @@ static void FreeExprNode (ExprNode* E)
|
|||||||
FreeExprNodes = E;
|
FreeExprNodes = E;
|
||||||
} else {
|
} else {
|
||||||
/* Free the memory */
|
/* Free the memory */
|
||||||
Xfree (E);
|
xfree (E);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,10 +114,10 @@ static void FreeExprNode (ExprNode* E)
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Dump an expression tree on stdout for debugging */
|
/* Dump an expression tree on stdout for debugging */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void InternalDumpExpr (ExprNode* Expr)
|
static void InternalDumpExpr (ExprNode* Expr)
|
||||||
/* Dump an expression in UPN */
|
/* Dump an expression in UPN */
|
||||||
|
|||||||
@@ -43,8 +43,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char* ProgName = "ca65"; /* Program name */
|
|
||||||
|
|
||||||
/* File names */
|
/* File names */
|
||||||
const char* InFile = 0; /* Name of input file */
|
const char* InFile = 0; /* Name of input file */
|
||||||
const char* OutFile = 0; /* Name of output file */
|
const char* OutFile = 0; /* Name of output file */
|
||||||
@@ -70,7 +68,7 @@ unsigned char NoColonLabels = 0; /* Allow labels without a colon */
|
|||||||
unsigned char LooseStringTerm = 0; /* Allow ' as string terminator */
|
unsigned char LooseStringTerm = 0; /* Allow ' as string terminator */
|
||||||
unsigned char AtInIdents = 0; /* Allow '@' in identifiers */
|
unsigned char AtInIdents = 0; /* Allow '@' in identifiers */
|
||||||
unsigned char DollarInIdents = 0; /* Allow '$' in identifiers */
|
unsigned char DollarInIdents = 0; /* Allow '$' in identifiers */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,8 +44,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern const char* ProgName; /* Program name */
|
|
||||||
|
|
||||||
/* File names */
|
/* File names */
|
||||||
extern const char* InFile; /* Name of input file */
|
extern const char* InFile; /* Name of input file */
|
||||||
extern const char* OutFile; /* Name of output file */
|
extern const char* OutFile; /* Name of output file */
|
||||||
|
|||||||
@@ -44,7 +44,8 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "mem.h"
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "incpath.h"
|
#include "incpath.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ static char* Add (char* Orig, const char* New)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate memory for the new string */
|
/* Allocate memory for the new string */
|
||||||
NewPath = Xmalloc (OrigLen + NewLen + 2);
|
NewPath = xmalloc (OrigLen + NewLen + 2);
|
||||||
|
|
||||||
/* Copy the strings */
|
/* Copy the strings */
|
||||||
memcpy (NewPath, Orig, OrigLen);
|
memcpy (NewPath, Orig, OrigLen);
|
||||||
@@ -92,7 +93,7 @@ static char* Add (char* Orig, const char* New)
|
|||||||
NewPath [OrigLen+NewLen+1] = '\0';
|
NewPath [OrigLen+NewLen+1] = '\0';
|
||||||
|
|
||||||
/* Delete the original path */
|
/* Delete the original path */
|
||||||
Xfree (Orig);
|
xfree (Orig);
|
||||||
|
|
||||||
/* Return the new path */
|
/* Return the new path */
|
||||||
return NewPath;
|
return NewPath;
|
||||||
@@ -138,8 +139,8 @@ static char* Find (const char* Path, const char* File)
|
|||||||
/* Check if this file exists */
|
/* Check if this file exists */
|
||||||
if (access (PathName, R_OK) == 0) {
|
if (access (PathName, R_OK) == 0) {
|
||||||
/* The file exists */
|
/* The file exists */
|
||||||
return StrDup (PathName);
|
return xstrdup (PathName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip a list separator if we have one */
|
/* Skip a list separator if we have one */
|
||||||
if (*P == ';') {
|
if (*P == ';') {
|
||||||
|
|||||||
@@ -33,8 +33,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "mem.h"
|
|
||||||
#include "istack.h"
|
#include "istack.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ void PushInput (int (*Func) (void*), void* Data, const char* Desc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create a new stack element */
|
/* Create a new stack element */
|
||||||
E = Xmalloc (sizeof (*E));
|
E = xmalloc (sizeof (*E));
|
||||||
|
|
||||||
/* Initialize it */
|
/* Initialize it */
|
||||||
E->Func = Func;
|
E->Func = Func;
|
||||||
@@ -109,7 +110,7 @@ void PopInput (void)
|
|||||||
IStack = IStack->Next;
|
IStack = IStack->Next;
|
||||||
|
|
||||||
/* And delete it */
|
/* And delete it */
|
||||||
Xfree (E);
|
xfree (E);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,13 +37,13 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "../common/fname.h"
|
||||||
#include "../common/segdefs.h"
|
#include "../common/segdefs.h"
|
||||||
#include "../common/version.h"
|
#include "../common/version.h"
|
||||||
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "fname.h"
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "mem.h"
|
|
||||||
#include "objcode.h"
|
#include "objcode.h"
|
||||||
#include "listing.h"
|
#include "listing.h"
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ void NewListingLine (const char* Line, unsigned char File, unsigned char Depth)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
L = Xmalloc (sizeof (ListLine) + Len);
|
L = xmalloc (sizeof (ListLine) + Len);
|
||||||
|
|
||||||
/* Initialize the fields. */
|
/* Initialize the fields. */
|
||||||
L->Next = 0;
|
L->Next = 0;
|
||||||
@@ -201,7 +201,7 @@ static void PrintPageHeader (FILE* F, const ListLine* L)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
/* Print the header on the new page */
|
/* Print the header on the new page */
|
||||||
fprintf (F,
|
fprintf (F,
|
||||||
"ca65 V%u.%u.%u - (C) Copyright 1998-2000 Ullrich von Bassewitz\n"
|
"ca65 V%u.%u.%u - (C) Copyright 1998-2000 Ullrich von Bassewitz\n"
|
||||||
"Main file : %s\n"
|
"Main file : %s\n"
|
||||||
"Current file: %s\n"
|
"Current file: %s\n"
|
||||||
@@ -328,7 +328,7 @@ void CreateListing (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate memory for the given number of bytes */
|
/* Allocate memory for the given number of bytes */
|
||||||
Buf = Xmalloc (Count*2+1);
|
Buf = xmalloc (Count*2+1);
|
||||||
|
|
||||||
/* Copy an ASCII representation of the bytes into the buffer */
|
/* Copy an ASCII representation of the bytes into the buffer */
|
||||||
B = Buf;
|
B = Buf;
|
||||||
@@ -422,7 +422,7 @@ void CreateListing (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Delete the temporary buffer */
|
/* Delete the temporary buffer */
|
||||||
Xfree (Buf);
|
xfree (Buf);
|
||||||
|
|
||||||
/* Next line */
|
/* Next line */
|
||||||
L = L->Next;
|
L = L->Next;
|
||||||
|
|||||||
@@ -37,11 +37,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "../common/hashstr.h"
|
#include "../common/hashstr.h"
|
||||||
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "condasm.h"
|
#include "condasm.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "istack.h"
|
#include "istack.h"
|
||||||
#include "mem.h"
|
|
||||||
#include "nexttok.h"
|
#include "nexttok.h"
|
||||||
#include "pseudo.h"
|
#include "pseudo.h"
|
||||||
#include "toklist.h"
|
#include "toklist.h"
|
||||||
@@ -123,7 +123,7 @@ static IdDesc* NewIdDesc (const char* Id)
|
|||||||
{
|
{
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
unsigned Len = strlen (Id);
|
unsigned Len = strlen (Id);
|
||||||
IdDesc* I = Xmalloc (sizeof (IdDesc) + Len);
|
IdDesc* I = xmalloc (sizeof (IdDesc) + Len);
|
||||||
|
|
||||||
/* Initialize the struct */
|
/* Initialize the struct */
|
||||||
I->Next = 0;
|
I->Next = 0;
|
||||||
@@ -141,7 +141,7 @@ static Macro* NewMacro (const char* Name, unsigned HashVal, unsigned char Style)
|
|||||||
{
|
{
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
unsigned Len = strlen (Name);
|
unsigned Len = strlen (Name);
|
||||||
Macro* M = Xmalloc (sizeof (Macro) + Len);
|
Macro* M = xmalloc (sizeof (Macro) + Len);
|
||||||
|
|
||||||
/* Initialize the macro struct */
|
/* Initialize the macro struct */
|
||||||
M->LocalCount = 0;
|
M->LocalCount = 0;
|
||||||
@@ -174,7 +174,7 @@ static MacExp* NewMacExp (Macro* M)
|
|||||||
unsigned I;
|
unsigned I;
|
||||||
|
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
MacExp* E = Xmalloc (sizeof (MacExp));
|
MacExp* E = xmalloc (sizeof (MacExp));
|
||||||
|
|
||||||
/* Initialize the data */
|
/* Initialize the data */
|
||||||
E->M = M;
|
E->M = M;
|
||||||
@@ -184,7 +184,7 @@ static MacExp* NewMacExp (Macro* M)
|
|||||||
E->LocalStart = LocalName;
|
E->LocalStart = LocalName;
|
||||||
LocalName += M->LocalCount;
|
LocalName += M->LocalCount;
|
||||||
E->ParamCount = 0;
|
E->ParamCount = 0;
|
||||||
E->Params = Xmalloc (M->ParamCount * sizeof (TokNode*));
|
E->Params = xmalloc (M->ParamCount * sizeof (TokNode*));
|
||||||
E->ParamExp = 0;
|
E->ParamExp = 0;
|
||||||
for (I = 0; I < M->ParamCount; ++I) {
|
for (I = 0; I < M->ParamCount; ++I) {
|
||||||
E->Params [I] = 0;
|
E->Params [I] = 0;
|
||||||
@@ -209,9 +209,9 @@ static void FreeMacExp (MacExp* E)
|
|||||||
|
|
||||||
/* Free the parameter list */
|
/* Free the parameter list */
|
||||||
for (I = 0; I < E->ParamCount; ++I) {
|
for (I = 0; I < E->ParamCount; ++I) {
|
||||||
Xfree (E->Params [I]);
|
xfree (E->Params [I]);
|
||||||
}
|
}
|
||||||
Xfree (E->Params);
|
xfree (E->Params);
|
||||||
|
|
||||||
/* Free the final token if we have one */
|
/* Free the final token if we have one */
|
||||||
if (E->Final) {
|
if (E->Final) {
|
||||||
@@ -219,7 +219,7 @@ static void FreeMacExp (MacExp* E)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Free the structure itself */
|
/* Free the structure itself */
|
||||||
Xfree (E);
|
xfree (E);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
#include "instr.h"
|
#include "instr.h"
|
||||||
#include "listing.h"
|
#include "listing.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
#include "mem.h"
|
/*#include "mem.h"*/
|
||||||
#include "nexttok.h"
|
#include "nexttok.h"
|
||||||
#include "objcode.h"
|
#include "objcode.h"
|
||||||
#include "objfile.h"
|
#include "objfile.h"
|
||||||
@@ -89,7 +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"
|
" --help\t\tHelp (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"
|
||||||
@@ -98,7 +98,6 @@ static void Usage (void)
|
|||||||
" --verbose\t\tIncrease verbosity\n"
|
" --verbose\t\tIncrease verbosity\n"
|
||||||
" --version\t\tPrint the assembler version\n",
|
" --version\t\tPrint the assembler version\n",
|
||||||
ProgName);
|
ProgName);
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -128,7 +127,7 @@ static void DefineSymbol (const char* Def)
|
|||||||
|
|
||||||
/* The symbol must start with a character or underline */
|
/* The symbol must start with a character or underline */
|
||||||
if (Def [0] != '_' && !isalpha (Def [0])) {
|
if (Def [0] != '_' && !isalpha (Def [0])) {
|
||||||
InvSym (Def);
|
InvDef (Def);
|
||||||
}
|
}
|
||||||
P = Def;
|
P = Def;
|
||||||
|
|
||||||
@@ -145,7 +144,7 @@ static void DefineSymbol (const char* Def)
|
|||||||
/* Do we have a value given? */
|
/* Do we have a value given? */
|
||||||
if (*P != '=') {
|
if (*P != '=') {
|
||||||
if (*P != '\0') {
|
if (*P != '\0') {
|
||||||
InvSym (Def);
|
InvDef (Def);
|
||||||
}
|
}
|
||||||
Val = 0;
|
Val = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -154,11 +153,11 @@ static void DefineSymbol (const char* Def)
|
|||||||
if (*P == '$') {
|
if (*P == '$') {
|
||||||
++P;
|
++P;
|
||||||
if (sscanf (P, "%lx", &Val) != 1) {
|
if (sscanf (P, "%lx", &Val) != 1) {
|
||||||
InvSym (Def);
|
InvDef (Def);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (sscanf (P, "%li", &Val) != 1) {
|
if (sscanf (P, "%li", &Val) != 1) {
|
||||||
InvSym (Def);
|
InvDef (Def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,6 +218,7 @@ static void OptHelp (const char* Opt, const char* Arg)
|
|||||||
/* Print usage information and exit */
|
/* Print usage information and exit */
|
||||||
{
|
{
|
||||||
Usage ();
|
Usage ();
|
||||||
|
exit (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -450,15 +450,7 @@ int main (int argc, char* argv [])
|
|||||||
int I;
|
int I;
|
||||||
|
|
||||||
/* Initialize the cmdline module */
|
/* Initialize the cmdline module */
|
||||||
InitCmdLine (argc, argv);
|
InitCmdLine (argc, argv, "ca65");
|
||||||
|
|
||||||
/* Set the program name */
|
|
||||||
ProgName = argv [0];
|
|
||||||
|
|
||||||
/* We must have a file name */
|
|
||||||
if (argc < 2) {
|
|
||||||
Usage ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enter the base lexical level. We must do that here, since we may
|
/* Enter the base lexical level. We must do that here, since we may
|
||||||
* define symbols using -D.
|
* define symbols using -D.
|
||||||
@@ -532,8 +524,9 @@ int main (int argc, char* argv [])
|
|||||||
} else {
|
} else {
|
||||||
/* Filename. Check if we already had one */
|
/* Filename. Check if we already had one */
|
||||||
if (InFile) {
|
if (InFile) {
|
||||||
fprintf (stderr, "Don't know what to do with `%s'\n", Arg);
|
fprintf (stderr, "%s: Don't know what to do with `%s'\n",
|
||||||
Usage ();
|
ProgName, Arg);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
} else {
|
} else {
|
||||||
InFile = Arg;
|
InFile = Arg;
|
||||||
}
|
}
|
||||||
@@ -545,7 +538,7 @@ int main (int argc, char* argv [])
|
|||||||
|
|
||||||
/* Do we have an input file? */
|
/* Do we have an input file? */
|
||||||
if (InFile == 0) {
|
if (InFile == 0) {
|
||||||
fprintf (stderr, "No input file\n");
|
fprintf (stderr, "%s: No input files\n", ProgName);
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ OBJS = condasm.o \
|
|||||||
ea.o \
|
ea.o \
|
||||||
error.o \
|
error.o \
|
||||||
expr.o \
|
expr.o \
|
||||||
fname.o \
|
|
||||||
fragment.o \
|
fragment.o \
|
||||||
global.o \
|
global.o \
|
||||||
incpath.o \
|
incpath.o \
|
||||||
@@ -20,7 +19,6 @@ OBJS = condasm.o \
|
|||||||
macpack.o \
|
macpack.o \
|
||||||
macro.o \
|
macro.o \
|
||||||
main.o \
|
main.o \
|
||||||
mem.o \
|
|
||||||
nexttok.o \
|
nexttok.o \
|
||||||
objcode.o \
|
objcode.o \
|
||||||
objfile.o \
|
objfile.o \
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ OBJS = condasm.obj \
|
|||||||
ea.obj \
|
ea.obj \
|
||||||
error.obj \
|
error.obj \
|
||||||
expr.obj \
|
expr.obj \
|
||||||
fname.obj \
|
|
||||||
fragment.obj \
|
fragment.obj \
|
||||||
global.obj \
|
global.obj \
|
||||||
incpath.obj \
|
incpath.obj \
|
||||||
@@ -77,7 +76,6 @@ OBJS = condasm.obj \
|
|||||||
macpack.obj \
|
macpack.obj \
|
||||||
macro.obj \
|
macro.obj \
|
||||||
main.obj \
|
main.obj \
|
||||||
mem.obj \
|
|
||||||
nexttok.obj \
|
nexttok.obj \
|
||||||
objcode.obj \
|
objcode.obj \
|
||||||
objfile.obj \
|
objfile.obj \
|
||||||
@@ -113,7 +111,6 @@ FILE condasm.obj
|
|||||||
FILE ea.obj
|
FILE ea.obj
|
||||||
FILE error.obj
|
FILE error.obj
|
||||||
FILE expr.obj
|
FILE expr.obj
|
||||||
FILE fname.obj
|
|
||||||
FILE fragment.obj
|
FILE fragment.obj
|
||||||
FILE global.obj
|
FILE global.obj
|
||||||
FILE incpath.obj
|
FILE incpath.obj
|
||||||
@@ -123,7 +120,6 @@ FILE listing.obj
|
|||||||
FILE macpack.obj
|
FILE macpack.obj
|
||||||
FILE macro.obj
|
FILE macro.obj
|
||||||
FILE main.obj
|
FILE main.obj
|
||||||
FILE mem.obj
|
|
||||||
FILE nexttok.obj
|
FILE nexttok.obj
|
||||||
FILE objcode.obj
|
FILE objcode.obj
|
||||||
FILE objfile.obj
|
FILE objfile.obj
|
||||||
|
|||||||
@@ -38,12 +38,12 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "../common/segdefs.h"
|
#include "../common/segdefs.h"
|
||||||
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "fragment.h"
|
#include "fragment.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "listing.h"
|
#include "listing.h"
|
||||||
#include "mem.h"
|
|
||||||
#include "objfile.h"
|
#include "objfile.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
@@ -140,7 +140,7 @@ static Segment* NewSegment (const char* Name, unsigned SegType)
|
|||||||
} while (*N);
|
} while (*N);
|
||||||
|
|
||||||
/* Create a new segment */
|
/* Create a new segment */
|
||||||
S = Xmalloc (sizeof (*S));
|
S = xmalloc (sizeof (*S));
|
||||||
|
|
||||||
/* Initialize it */
|
/* Initialize it */
|
||||||
S->List = 0;
|
S->List = 0;
|
||||||
@@ -150,7 +150,7 @@ static Segment* NewSegment (const char* Name, unsigned SegType)
|
|||||||
S->SegType = SegType;
|
S->SegType = SegType;
|
||||||
S->PC = 0;
|
S->PC = 0;
|
||||||
S->Num = SegmentCount++;
|
S->Num = SegmentCount++;
|
||||||
S->Name = StrDup (Name);
|
S->Name = xstrdup (Name);
|
||||||
|
|
||||||
/* Insert it into the segment list */
|
/* Insert it into the segment list */
|
||||||
SegmentLast->List = S;
|
SegmentLast->List = S;
|
||||||
@@ -599,7 +599,7 @@ static Fragment* NewFragment (unsigned char Type, unsigned short Len)
|
|||||||
Fragment* F;
|
Fragment* F;
|
||||||
|
|
||||||
/* Create a new fragment */
|
/* Create a new fragment */
|
||||||
F = Xmalloc (sizeof (*F));
|
F = xmalloc (sizeof (*F));
|
||||||
|
|
||||||
/* Initialize it */
|
/* Initialize it */
|
||||||
F->List = 0;
|
F->List = 0;
|
||||||
@@ -631,7 +631,7 @@ static Fragment* NewFragment (unsigned char Type, unsigned short Len)
|
|||||||
LineCur->FragList = F;
|
LineCur->FragList = F;
|
||||||
/* First fragment - set the PC
|
/* First fragment - set the PC
|
||||||
LineCur->PC = GetPC ();
|
LineCur->PC = GetPC ();
|
||||||
LineCur->Reloc = RelocMode;
|
LineCur->Reloc = RelocMode;
|
||||||
*/
|
*/
|
||||||
} else {
|
} else {
|
||||||
LineCur->FragLast->LineList = F;
|
LineCur->FragLast->LineList = F;
|
||||||
|
|||||||
@@ -38,12 +38,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "../common/fname.h"
|
||||||
#include "../common/objdefs.h"
|
#include "../common/objdefs.h"
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "fname.h"
|
|
||||||
#include "mem.h"
|
|
||||||
#include "objfile.h"
|
#include "objfile.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "../common/optdefs.h"
|
#include "../common/optdefs.h"
|
||||||
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "mem.h"
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "objfile.h"
|
#include "objfile.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
@@ -67,7 +67,7 @@ static Option* NewOption (unsigned char Type)
|
|||||||
Option* Opt;
|
Option* Opt;
|
||||||
|
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
Opt = Xmalloc (sizeof (*Opt));
|
Opt = xmalloc (sizeof (*Opt));
|
||||||
|
|
||||||
/* Initialize fields */
|
/* Initialize fields */
|
||||||
Opt->Next = 0;
|
Opt->Next = 0;
|
||||||
@@ -101,7 +101,7 @@ void OptStr (unsigned char Type, const char* Text)
|
|||||||
Fatal (FAT_STRING_TOO_LONG);
|
Fatal (FAT_STRING_TOO_LONG);
|
||||||
}
|
}
|
||||||
O = NewOption (Type);
|
O = NewOption (Type);
|
||||||
O->V.Str = StrDup (Text);
|
O->V.Str = xstrdup (Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,16 +40,17 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "../common/fname.h"
|
||||||
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "condasm.h"
|
#include "condasm.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "fname.h"
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "incpath.h"
|
#include "incpath.h"
|
||||||
#include "instr.h"
|
#include "instr.h"
|
||||||
#include "istack.h"
|
#include "istack.h"
|
||||||
#include "listing.h"
|
#include "listing.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
#include "mem.h"
|
|
||||||
#include "objfile.h"
|
#include "objfile.h"
|
||||||
#include "toklist.h"
|
#include "toklist.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
@@ -353,7 +354,7 @@ void NewInputFile (const char* Name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Free the allocated memory */
|
/* Free the allocated memory */
|
||||||
Xfree (PathName);
|
xfree (PathName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,11 +368,11 @@ void NewInputFile (const char* Name)
|
|||||||
}
|
}
|
||||||
Files [FileCount].MTime = Buf.st_mtime;
|
Files [FileCount].MTime = Buf.st_mtime;
|
||||||
Files [FileCount].Size = Buf.st_size;
|
Files [FileCount].Size = Buf.st_size;
|
||||||
Files [FileCount].Name = StrDup (Name);
|
Files [FileCount].Name = xstrdup (Name);
|
||||||
++FileCount;
|
++FileCount;
|
||||||
|
|
||||||
/* Create a new state variable and initialize it */
|
/* Create a new state variable and initialize it */
|
||||||
I = Xmalloc (sizeof (*I));
|
I = xmalloc (sizeof (*I));
|
||||||
I->F = F;
|
I->F = F;
|
||||||
I->Pos.Line = 0;
|
I->Pos.Line = 0;
|
||||||
I->Pos.Col = 0;
|
I->Pos.Col = 0;
|
||||||
@@ -407,7 +408,7 @@ void DoneInputFile (void)
|
|||||||
|
|
||||||
/* Cleanup the current stuff */
|
/* Cleanup the current stuff */
|
||||||
fclose (I->F);
|
fclose (I->F);
|
||||||
Xfree (I);
|
xfree (I);
|
||||||
--ICount;
|
--ICount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,7 +420,7 @@ void NewInputData (const char* Data, int Malloced)
|
|||||||
InputData* I;
|
InputData* I;
|
||||||
|
|
||||||
/* Create a new state variable and initialize it */
|
/* Create a new state variable and initialize it */
|
||||||
I = Xmalloc (sizeof (*I));
|
I = xmalloc (sizeof (*I));
|
||||||
I->Data = Data;
|
I->Data = Data;
|
||||||
I->Pos = Data;
|
I->Pos = Data;
|
||||||
I->Malloced = Malloced;
|
I->Malloced = Malloced;
|
||||||
@@ -451,9 +452,9 @@ static void DoneInputData (void)
|
|||||||
|
|
||||||
/* Cleanup the current stuff */
|
/* Cleanup the current stuff */
|
||||||
if (I->Malloced) {
|
if (I->Malloced) {
|
||||||
Xfree (I->Data);
|
xfree (I->Data);
|
||||||
}
|
}
|
||||||
Xfree (I);
|
xfree (I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,10 +37,10 @@
|
|||||||
|
|
||||||
#include "../common/symdefs.h"
|
#include "../common/symdefs.h"
|
||||||
#include "../common/hashstr.h"
|
#include "../common/hashstr.h"
|
||||||
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "mem.h"
|
|
||||||
#include "expr.h"
|
#include "expr.h"
|
||||||
#include "objfile.h"
|
#include "objfile.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
@@ -146,7 +146,7 @@ static SymEntry* NewSymEntry (const char* Name)
|
|||||||
Len = strlen (Name);
|
Len = strlen (Name);
|
||||||
|
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
S = Xmalloc (sizeof (SymEntry) + Len);
|
S = xmalloc (sizeof (SymEntry) + Len);
|
||||||
|
|
||||||
/* Initialize the entry */
|
/* Initialize the entry */
|
||||||
S->Left = 0;
|
S->Left = 0;
|
||||||
@@ -174,7 +174,7 @@ static SymTable* NewSymTable (unsigned Size)
|
|||||||
SymTable* S;
|
SymTable* S;
|
||||||
|
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
S = Xmalloc (sizeof (SymTable) + (Size-1) * sizeof (SymEntry*));
|
S = xmalloc (sizeof (SymTable) + (Size-1) * sizeof (SymEntry*));
|
||||||
|
|
||||||
/* Set variables and clear hash table entries */
|
/* Set variables and clear hash table entries */
|
||||||
S->TableSlots = Size;
|
S->TableSlots = Size;
|
||||||
|
|||||||
@@ -35,7 +35,8 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "mem.h"
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "toklist.h"
|
#include "toklist.h"
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ TokNode* NewTokNode (void)
|
|||||||
|
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
unsigned Len = TokHasSVal (Tok)? strlen (SVal) : 0;
|
unsigned Len = TokHasSVal (Tok)? strlen (SVal) : 0;
|
||||||
T = Xmalloc (sizeof (TokNode) + Len);
|
T = xmalloc (sizeof (TokNode) + Len);
|
||||||
|
|
||||||
/* Initialize the token contents */
|
/* Initialize the token contents */
|
||||||
T->Next = 0;
|
T->Next = 0;
|
||||||
@@ -73,7 +74,7 @@ TokNode* NewTokNode (void)
|
|||||||
void FreeTokNode (TokNode* T)
|
void FreeTokNode (TokNode* T)
|
||||||
/* Free the given token node */
|
/* Free the given token node */
|
||||||
{
|
{
|
||||||
Xfree (T);
|
xfree (T);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -132,7 +133,7 @@ TokList* NewTokList (void)
|
|||||||
/* Create a new, empty token list */
|
/* Create a new, empty token list */
|
||||||
{
|
{
|
||||||
/* Allocate memory for the list structure */
|
/* Allocate memory for the list structure */
|
||||||
TokList* T = Xmalloc (sizeof (TokList));
|
TokList* T = xmalloc (sizeof (TokList));
|
||||||
|
|
||||||
/* Initialize the fields */
|
/* Initialize the fields */
|
||||||
InitTokList (T);
|
InitTokList (T);
|
||||||
@@ -155,7 +156,7 @@ void FreeTokList (TokList* List)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Free the list structure itself */
|
/* Free the list structure itself */
|
||||||
Xfree (List);
|
xfree (List);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -168,9 +169,9 @@ void AddCurTok (TokList* List)
|
|||||||
|
|
||||||
/* Insert the node into the list */
|
/* Insert the node into the list */
|
||||||
if (List->Root == 0) {
|
if (List->Root == 0) {
|
||||||
List->Root = T;
|
List->Root = T;
|
||||||
} else {
|
} else {
|
||||||
List->Last->Next = T;
|
List->Last->Next = T;
|
||||||
}
|
}
|
||||||
List->Last = T;
|
List->Last = T;
|
||||||
|
|
||||||
@@ -180,6 +181,3 @@ void AddCurTok (TokList* List)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,10 +34,10 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "../common/filepos.h"
|
#include "../common/filepos.h"
|
||||||
|
#include "../common/xmalloc.h"
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "expr.h"
|
#include "expr.h"
|
||||||
#include "mem.h"
|
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "ulabel.h"
|
#include "ulabel.h"
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ static ULabel* NewULabel (ExprNode* Val)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
/* Allocate memory for the ULabel structure */
|
/* Allocate memory for the ULabel structure */
|
||||||
ULabel* L = Xmalloc (sizeof (ULabel));
|
ULabel* L = xmalloc (sizeof (ULabel));
|
||||||
|
|
||||||
/* Initialize the fields */
|
/* Initialize the fields */
|
||||||
L->Pos = CurPos;
|
L->Pos = CurPos;
|
||||||
@@ -227,7 +227,7 @@ void ULabCheck (void)
|
|||||||
*/
|
*/
|
||||||
if (ULabCount) {
|
if (ULabCount) {
|
||||||
unsigned I = 0;
|
unsigned I = 0;
|
||||||
ULabList = Xmalloc (ULabCount * sizeof (ULabel*));
|
ULabList = xmalloc (ULabCount * sizeof (ULabel*));
|
||||||
L = ULabRoot;
|
L = ULabRoot;
|
||||||
while (L) {
|
while (L) {
|
||||||
ULabList[I] = L;
|
ULabList[I] = L;
|
||||||
|
|||||||
74
src/common/abend.c
Normal file
74
src/common/abend.c
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* abend.c */
|
||||||
|
/* */
|
||||||
|
/* Abnormal program end */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 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 <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "cmdline.h"
|
||||||
|
#include "abend.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AbEnd (const char* Format, ...)
|
||||||
|
/* Print a message preceeded by the program name and terminate the program
|
||||||
|
* with an error exit code.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
/* Print the program name */
|
||||||
|
fprintf (stderr, "%s: ", ProgName);
|
||||||
|
|
||||||
|
/* Format the given message and print it */
|
||||||
|
va_start (ap, Format);
|
||||||
|
vfprintf (stderr, Format, ap);
|
||||||
|
va_end (ap);
|
||||||
|
|
||||||
|
/* Add a newline */
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
/* Terminate the program */
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
59
src/common/abend.h
Normal file
59
src/common/abend.h
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* abend.h */
|
||||||
|
/* */
|
||||||
|
/* Abnormal program end */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 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 ABEND_H
|
||||||
|
#define ABEND_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AbEnd (const char* Format, ...);
|
||||||
|
/* Print a message preceeded by the program name and terminate the program
|
||||||
|
* with an error exit code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of abend.h */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -33,9 +33,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
|
#include "abend.h"
|
||||||
#include "cmdline.h"
|
#include "cmdline.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -46,25 +46,50 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Program name - is set after call to InitCmdLine */
|
||||||
|
const char* ProgName;
|
||||||
|
|
||||||
|
/* The program argument vector */
|
||||||
static char** ArgVec = 0;
|
static char** ArgVec = 0;
|
||||||
static unsigned ArgCount = 0;
|
static unsigned ArgCount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Code */
|
/* Code */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void InitCmdLine (unsigned aArgCount, char* aArgVec[])
|
void InitCmdLine (unsigned aArgCount, char* aArgVec[], const char* aProgName)
|
||||||
/* Initialize command line parsing. aArgVec is the argument array terminated by
|
/* Initialize command line parsing. aArgVec is the argument array terminated by
|
||||||
* a NULL pointer (as usual), ArgCount is the number of valid arguments in the
|
* a NULL pointer (as usual), ArgCount is the number of valid arguments in the
|
||||||
* array. Both arguments are remembered in static storage.
|
* array. Both arguments are remembered in static storage.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
|
/* Remember the argument vector */
|
||||||
ArgCount = aArgCount;
|
ArgCount = aArgCount;
|
||||||
ArgVec = aArgVec;
|
ArgVec = aArgVec;
|
||||||
|
|
||||||
|
/* Get the program name from argv[0] but strip a path */
|
||||||
|
if (ArgVec[0] == 0) {
|
||||||
|
/* Use the default name given */
|
||||||
|
ProgName = aProgName;
|
||||||
|
} else {
|
||||||
|
/* Strip a path */
|
||||||
|
ProgName = strchr (ArgVec[0], '\0');
|
||||||
|
while (ProgName > ArgVec[0]) {
|
||||||
|
--ProgName;
|
||||||
|
if (*ProgName == '/' || *ProgName == '\\') {
|
||||||
|
++ProgName;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ProgName[0] == '\0') {
|
||||||
|
/* Use the default */
|
||||||
|
ProgName = aProgName;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,8 +97,7 @@ void InitCmdLine (unsigned aArgCount, char* aArgVec[])
|
|||||||
void UnknownOption (const char* Opt)
|
void UnknownOption (const char* Opt)
|
||||||
/* Print an error about an unknown option. */
|
/* Print an error about an unknown option. */
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Unknown option: %s\n", Opt);
|
AbEnd ("Unknown option: %s\n", Opt);
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -81,8 +105,7 @@ void UnknownOption (const char* Opt)
|
|||||||
void NeedArg (const char* Opt)
|
void NeedArg (const char* Opt)
|
||||||
/* Print an error about a missing option argument and exit. */
|
/* Print an error about a missing option argument and exit. */
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Option requires an argument: %s\n", Opt);
|
AbEnd ("Option requires an argument: %s\n", Opt);
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,8 +113,7 @@ void NeedArg (const char* Opt)
|
|||||||
void InvDef (const char* Def)
|
void InvDef (const char* Def)
|
||||||
/* Print an error about an invalid definition and die */
|
/* Print an error about an invalid definition and die */
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Invalid definition: `%s'\n", Def);
|
AbEnd ("Invalid definition: `%s'\n", Def);
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -130,9 +152,9 @@ void LongOption (int* ArgNum, const LongOpt* OptTab, unsigned OptCount)
|
|||||||
if (strcmp (Opt, OptTab->Option) == 0) {
|
if (strcmp (Opt, OptTab->Option) == 0) {
|
||||||
/* Found, call the function */
|
/* Found, call the function */
|
||||||
if (OptTab->ArgCount > 0) {
|
if (OptTab->ArgCount > 0) {
|
||||||
OptTab->Func (Opt, ArgVec[++(*ArgNum)]);
|
OptTab->Func (Opt, ArgVec[++(*ArgNum)]);
|
||||||
} else {
|
} else {
|
||||||
OptTab->Func (Opt, 0);
|
OptTab->Func (Opt, 0);
|
||||||
}
|
}
|
||||||
/* Done */
|
/* Done */
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -44,6 +44,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Program name - is set after call to InitCmdLine */
|
||||||
|
extern const char* ProgName;
|
||||||
|
|
||||||
/* Structure defining a long option */
|
/* Structure defining a long option */
|
||||||
typedef struct LongOpt LongOpt;
|
typedef struct LongOpt LongOpt;
|
||||||
struct LongOpt {
|
struct LongOpt {
|
||||||
@@ -60,7 +63,7 @@ struct LongOpt {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void InitCmdLine (unsigned aArgCount, char* aArgVec[]);
|
void InitCmdLine (unsigned aArgCount, char* aArgVec[], const char* aProgName);
|
||||||
/* Initialize command line parsing. aArgVec is the argument array terminated by
|
/* Initialize command line parsing. aArgVec is the argument array terminated by
|
||||||
* a NULL pointer (as usual), ArgCount is the number of valid arguments in the
|
* a NULL pointer (as usual), ArgCount is the number of valid arguments in the
|
||||||
* array. Both arguments are remembered in static storage.
|
* array. Both arguments are remembered in static storage.
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "mem.h"
|
#include "xmalloc.h"
|
||||||
#include "fname.h"
|
#include "fname.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -58,11 +58,11 @@ char* MakeFilename (const char* Origin, const char* Ext)
|
|||||||
const char* P = strrchr (Origin, '.');
|
const char* P = strrchr (Origin, '.');
|
||||||
if (P == 0) {
|
if (P == 0) {
|
||||||
/* No dot, add the extension */
|
/* No dot, add the extension */
|
||||||
Result = Xmalloc (strlen (Origin) + strlen (Ext) + 1);
|
Result = xmalloc (strlen (Origin) + strlen (Ext) + 1);
|
||||||
strcpy (Result, Origin);
|
strcpy (Result, Origin);
|
||||||
strcat (Result, Ext);
|
strcat (Result, Ext);
|
||||||
} else {
|
} else {
|
||||||
Result = Xmalloc (P - Origin + strlen (Ext) + 1);
|
Result = xmalloc (P - Origin + strlen (Ext) + 1);
|
||||||
memcpy (Result, Origin, P - Origin);
|
memcpy (Result, Origin, P - Origin);
|
||||||
strcpy (Result + (P - Origin), Ext);
|
strcpy (Result + (P - Origin), Ext);
|
||||||
}
|
}
|
||||||
@@ -71,4 +71,3 @@ char* MakeFilename (const char* Origin, const char* Ext)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
61
src/common/fname.h
Normal file
61
src/common/fname.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* fname.h */
|
||||||
|
/* */
|
||||||
|
/* File name handling utilities */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 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 FNAME_H
|
||||||
|
#define FNAME_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char* MakeFilename (const char* Origin, const char* Ext);
|
||||||
|
/* Make a new file name from Origin and Ext. If Origin has an extension, it
|
||||||
|
* is removed and Ext is appended. If Origin has no extension, Ext is simply
|
||||||
|
* appended. The result is placed in a malloc'ed buffer and returned.
|
||||||
|
* The function may be used to create "foo.o" from "foo.s".
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of fname.h */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -9,9 +9,12 @@ LIB = common.a
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
OBJS = bitops.o \
|
OBJS = abend.o \
|
||||||
|
bitops.o \
|
||||||
cmdline.o \
|
cmdline.o \
|
||||||
|
fname.o \
|
||||||
hashstr.o \
|
hashstr.o \
|
||||||
|
xmalloc.o \
|
||||||
xsprintf.o
|
xsprintf.o
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -65,10 +65,13 @@ CCCFG = -bt=$(TARGET) -d1 -onatx -zp4 -5 -zq -w2
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# All library OBJ files
|
# All library OBJ files
|
||||||
|
|
||||||
OBJS = bitops.obj \
|
OBJS = abend.obj \
|
||||||
|
bitops.obj \
|
||||||
cmdline.obj \
|
cmdline.obj \
|
||||||
|
fname.obj \
|
||||||
hashstr.obj \
|
hashstr.obj \
|
||||||
wildargv.obj \
|
wildargv.obj \
|
||||||
|
xmalloc.obj \
|
||||||
xsprintf.obj
|
xsprintf.obj
|
||||||
|
|
||||||
|
|
||||||
@@ -92,3 +95,5 @@ clean:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* mem.c */
|
/* xmalloc.c */
|
||||||
/* */
|
/* */
|
||||||
/* Memory allocation for the ca65 macroassembler */
|
/* Memory allocation subroutines */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998 Ullrich von Bassewitz */
|
/* (C) 2000 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* Wacholderweg 14 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70597 Stuttgart */
|
||||||
/* EMail: uz@musoftware.de */
|
/* EMail: uz@musoftware.de */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
/* warranty. In no event will the authors be held liable for any damages */
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
/* arising from the use of this software. */
|
/* arising from the use of this software. */
|
||||||
/* */
|
/* */
|
||||||
/* Permission is granted to anyone to use this software for any purpose, */
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
/* including commercial applications, and to alter it and redistribute it */
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
/* freely, subject to the following restrictions: */
|
/* freely, subject to the following restrictions: */
|
||||||
/* */
|
/* */
|
||||||
/* 1. The origin of this software must not be misrepresented; you must not */
|
/* 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 */
|
/* claim that you wrote the original software. If you use this software */
|
||||||
/* in a product, an acknowledgment in the product documentation would be */
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
/* be misrepresented as being the original software. */
|
/* be misrepresented as being the original software. */
|
||||||
/* 3. This notice may not be removed or altered from any source */
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
/* distribution. */
|
/* distribution. */
|
||||||
/* */
|
/* */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
@@ -36,49 +36,52 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "error.h"
|
#include "abend.h"
|
||||||
#include "mem.h"
|
#include "xmalloc.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* code */
|
/* code */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* Xmalloc (size_t size)
|
void* xmalloc (size_t Size)
|
||||||
/* Allocate memory, check for out of memory condition. Do some debugging */
|
/* Allocate memory, check for out of memory condition. Do some debugging */
|
||||||
{
|
{
|
||||||
void* p;
|
/* Allocate memory */
|
||||||
|
void* P = malloc (Size);
|
||||||
|
|
||||||
p = malloc (size);
|
/* Check for errors */
|
||||||
if (p == 0 && size != 0) {
|
if (P == 0 && Size != 0) {
|
||||||
Fatal (FAT_OUT_OF_MEMORY);
|
AbEnd ("Out of memory - requested block size = %lu", (unsigned long) Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return a pointer to the block */
|
/* Return a pointer to the block */
|
||||||
return p;
|
return P;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Xfree (const void* block)
|
void xfree (const void* Block)
|
||||||
/* Free the block, do some debugging */
|
/* Free the block, do some debugging */
|
||||||
{
|
{
|
||||||
free ((void*) block);
|
free ((void*) Block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char* StrDup (const char* s)
|
char* xstrdup (const char* S)
|
||||||
/* Duplicate a string on the heap. The function checks for out of memory */
|
/* Duplicate a string on the heap. The function checks for out of memory */
|
||||||
{
|
{
|
||||||
unsigned len;
|
/* Get the length of the string */
|
||||||
|
unsigned Len = strlen (S) + 1;
|
||||||
|
|
||||||
len = strlen (s) + 1;
|
/* Allocate memory and return a copy */
|
||||||
return memcpy (Xmalloc (len), s, len);
|
return memcpy (xmalloc (Len), S, Len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* mem.h */
|
/* xmalloc.h */
|
||||||
/* */
|
/* */
|
||||||
/* Memory allocation for the ca65 macroassembler */
|
/* Memory allocation subroutines */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998 Ullrich von Bassewitz */
|
/* (C) 2000 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* Wacholderweg 14 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70597 Stuttgart */
|
||||||
/* EMail: uz@musoftware.de */
|
/* EMail: uz@musoftware.de */
|
||||||
@@ -33,8 +33,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MEM_H
|
#ifndef XMALLOC_H
|
||||||
#define MEM_H
|
#define XMALLOC_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -43,23 +43,23 @@
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Code */
|
/* Code */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* Xmalloc (size_t size);
|
void* xmalloc (size_t Size);
|
||||||
/* Allocate memory, check for out of memory condition. Do some debugging */
|
/* Allocate memory, check for out of memory condition. Do some debugging */
|
||||||
|
|
||||||
void Xfree (const void* block);
|
void xfree (const void* Block);
|
||||||
/* Free the block, do some debugging */
|
/* Free the block, do some debugging */
|
||||||
|
|
||||||
char* StrDup (const char* s);
|
char* xstrdup (const char* S);
|
||||||
/* Duplicate a string on the heap. The function checks for out of memory */
|
/* Duplicate a string on the heap. The function checks for out of memory */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* End of mem.h */
|
/* End of xmalloc.h */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Reference in New Issue
Block a user