Place shared modules into the common dir

git-svn-id: svn://svn.cc65.org/cc65/trunk@71 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2000-06-14 09:57:42 +00:00
parent 6a482b59fa
commit 2767f66146
17 changed files with 181 additions and 197 deletions

View File

@@ -37,9 +37,10 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "../common/xmalloc.h"
#include "global.h" #include "global.h"
#include "error.h" #include "error.h"
#include "mem.h"
#include "fileio.h" #include "fileio.h"
#include "segments.h" #include "segments.h"
#include "exports.h" #include "exports.h"
@@ -73,7 +74,7 @@ BinDesc* NewBinDesc (void)
/* Create a new binary format descriptor */ /* Create a new binary format descriptor */
{ {
/* Allocate memory for a new BinDesc struct */ /* Allocate memory for a new BinDesc struct */
BinDesc* D = Xmalloc (sizeof (BinDesc)); BinDesc* D = xmalloc (sizeof (BinDesc));
/* Initialize the fields */ /* Initialize the fields */
D->Undef = 0; D->Undef = 0;
@@ -89,7 +90,7 @@ BinDesc* NewBinDesc (void)
void FreeBinDesc (BinDesc* D) void FreeBinDesc (BinDesc* D)
/* Free a binary format descriptor */ /* Free a binary format descriptor */
{ {
Xfree (D); xfree (D);
} }

View File

@@ -39,9 +39,9 @@
#include <errno.h> #include <errno.h>
#include "../common/bitops.h" #include "../common/bitops.h"
#include "../common/xmalloc.h"
#include "error.h" #include "error.h"
#include "mem.h"
#include "global.h" #include "global.h"
#include "bin.h" #include "bin.h"
#include "o65.h" #include "o65.h"
@@ -125,7 +125,7 @@ static File* NewFile (const char* Name)
unsigned Len = strlen (Name); unsigned Len = strlen (Name);
/* Allocate memory */ /* Allocate memory */
File* F = Xmalloc (sizeof (File) + Len); File* F = xmalloc (sizeof (File) + Len);
/* Initialize the fields */ /* Initialize the fields */
F->Flags = 0; F->Flags = 0;
@@ -163,7 +163,7 @@ static Memory* NewMemory (const char* Name)
} }
/* Allocate memory */ /* Allocate memory */
M = Xmalloc (sizeof (Memory) + Len); M = xmalloc (sizeof (Memory) + Len);
/* Initialize the fields */ /* Initialize the fields */
M->Next = 0; M->Next = 0;
@@ -221,7 +221,7 @@ static SegDesc* NewSegDesc (const char* Name)
} }
/* Allocate memory */ /* Allocate memory */
S = Xmalloc (sizeof (SegDesc) + Len); S = xmalloc (sizeof (SegDesc) + Len);
/* Initialize the fields */ /* Initialize the fields */
S->Next = 0; S->Next = 0;
@@ -241,7 +241,7 @@ static SegDesc* NewSegDesc (const char* Name)
static void FreeSegDesc (SegDesc* S) static void FreeSegDesc (SegDesc* S)
/* Free a segment descriptor */ /* Free a segment descriptor */
{ {
Xfree (S); xfree (S);
} }
@@ -567,7 +567,7 @@ static void MemoryInsert (Memory* M, SegDesc* S)
/* Insert the segment descriptor into the memory area list */ /* Insert the segment descriptor into the memory area list */
{ {
/* Create a new node for the entry */ /* Create a new node for the entry */
MemListNode* N = Xmalloc (sizeof (MemListNode)); MemListNode* N = xmalloc (sizeof (MemListNode));
N->Seg = S; N->Seg = S;
N->Next = 0; N->Next = 0;

View File

@@ -36,9 +36,9 @@
#include <string.h> #include <string.h>
#include "../common/symdefs.h" #include "../common/symdefs.h"
#include "../common/xmalloc.h"
#include "global.h" #include "global.h"
#include "mem.h"
#include "error.h" #include "error.h"
#include "fileio.h" #include "fileio.h"
#include "objdata.h" #include "objdata.h"
@@ -73,7 +73,7 @@ static DbgSym* NewDbgSym (unsigned char Type, const char* Name, ObjData* O)
unsigned Len = strlen (Name); unsigned Len = strlen (Name);
/* Allocate memory */ /* Allocate memory */
DbgSym* D = Xmalloc (sizeof (DbgSym) + Len); DbgSym* D = xmalloc (sizeof (DbgSym) + Len);
/* Initialize the fields */ /* Initialize the fields */
D->Next = 0; D->Next = 0;

View File

@@ -39,9 +39,9 @@
#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 "mem.h"
#include "error.h" #include "error.h"
#include "fileio.h" #include "fileio.h"
#include "objdata.h" #include "objdata.h"
@@ -88,7 +88,7 @@ static Import* NewImport (unsigned char Type, ObjData* Obj)
/* Create a new import and initialize it */ /* Create a new import and initialize it */
{ {
/* Allocate memory */ /* Allocate memory */
Import* I = Xmalloc (sizeof (Import)); Import* I = xmalloc (sizeof (Import));
/* Initialize the fields */ /* Initialize the fields */
I->Next = 0; I->Next = 0;
@@ -152,7 +152,7 @@ void InsertImport (Import* I)
} }
/* Now free the name since it's no longer needed */ /* Now free the name since it's no longer needed */
Xfree (Name); xfree (Name);
} }
@@ -196,7 +196,7 @@ static Export* NewExport (unsigned char Type, const char* Name, ObjData* Obj)
unsigned Len = strlen (Name); unsigned Len = strlen (Name);
/* Allocate memory */ /* Allocate memory */
Export* E = Xmalloc (sizeof (Export) + Len); Export* E = xmalloc (sizeof (Export) + Len);
/* Initialize the fields */ /* Initialize the fields */
E->Next = 0; E->Next = 0;
@@ -250,7 +250,7 @@ void InsertExport (Export* E)
HashTab [HashVal] = E; HashTab [HashVal] = E;
} }
ImpOpen -= E->ImpCount; /* Decrease open imports now */ ImpOpen -= E->ImpCount; /* Decrease open imports now */
Xfree (L); xfree (L);
/* We must run through the import list and change the /* We must run through the import list and change the
* export pointer now. * export pointer now.
*/ */
@@ -493,9 +493,9 @@ static void CreateExportPool (void)
/* Allocate memory */ /* Allocate memory */
if (ExpPool) { if (ExpPool) {
Xfree (ExpPool); xfree (ExpPool);
} }
ExpPool = Xmalloc (ExpCount * sizeof (Export*)); ExpPool = xmalloc (ExpCount * sizeof (Export*));
/* Walk through the list and insert the exports */ /* Walk through the list and insert the exports */
for (I = 0, J = 0; I < sizeof (HashTab) / sizeof (HashTab [0]); ++I) { for (I = 0, J = 0; I < sizeof (HashTab) / sizeof (HashTab [0]); ++I) {

View File

@@ -34,10 +34,10 @@
#include "../common/exprdefs.h" #include "../common/exprdefs.h"
#include "../common/xmalloc.h"
#include "global.h" #include "global.h"
#include "error.h" #include "error.h"
#include "mem.h"
#include "fileio.h" #include "fileio.h"
#include "segments.h" #include "segments.h"
#include "expr.h" #include "expr.h"
@@ -54,7 +54,7 @@ static ExprNode* NewExprNode (ObjData* O)
/* Create a new expression node */ /* Create a new expression node */
{ {
/* Allocate fresh memory */ /* Allocate fresh memory */
ExprNode* N = Xmalloc (sizeof (ExprNode)); ExprNode* N = xmalloc (sizeof (ExprNode));
N->Op = EXPR_NULL; N->Op = EXPR_NULL;
N->Left = 0; N->Left = 0;
N->Right = 0; N->Right = 0;
@@ -70,7 +70,7 @@ static void FreeExprNode (ExprNode* E)
/* Free a node */ /* Free a node */
{ {
/* Free the memory */ /* Free the memory */
Xfree (E); xfree (E);
} }

View File

@@ -36,8 +36,8 @@
#include <string.h> #include <string.h>
#include "../common/hashstr.h" #include "../common/hashstr.h"
#include "../common/xmalloc.h"
#include "mem.h"
#include "error.h" #include "error.h"
#include "extsyms.h" #include "extsyms.h"
@@ -88,11 +88,11 @@ ExtSym* NewExtSym (ExtSymTab* Tab, const char* Name)
ExtSym* E = GetExtSym (Tab, Name); /* Don't care about duplicate hash here... */ ExtSym* E = GetExtSym (Tab, Name); /* Don't care about duplicate hash here... */
if (E != 0) { if (E != 0) {
/* We do already have a symbol with this name */ /* We do already have a symbol with this name */
Error ("Duplicate external symbol `%s'", Name); Error ("Duplicate external symbol `%s'", Name);
} }
/* Allocate memory for the structure */ /* Allocate memory for the structure */
E = Xmalloc (sizeof (ExtSym) + Len); E = xmalloc (sizeof (ExtSym) + Len);
/* Initialize the structure */ /* Initialize the structure */
E->List = 0; E->List = 0;
@@ -102,10 +102,10 @@ ExtSym* NewExtSym (ExtSymTab* Tab, const char* Name)
/* Insert the entry into the list of all symbols */ /* Insert the entry into the list of all symbols */
if (Tab->Last == 0) { if (Tab->Last == 0) {
/* List is empty */ /* List is empty */
Tab->Root = E; Tab->Root = E;
} else { } else {
/* List not empty */ /* List not empty */
Tab->Last->List = E; Tab->Last->List = E;
} }
Tab->Last = E; Tab->Last = E;
@@ -126,7 +126,7 @@ static void FreeExtSym (ExtSym* E)
* use only. * use only.
*/ */
{ {
Xfree (E); xfree (E);
} }
@@ -137,14 +137,14 @@ ExtSymTab* NewExtSymTab (void)
unsigned I; unsigned I;
/* Allocate memory */ /* Allocate memory */
ExtSymTab* Tab = Xmalloc (sizeof (ExtSymTab)); ExtSymTab* Tab = xmalloc (sizeof (ExtSymTab));
/* Initialize the fields */ /* Initialize the fields */
Tab->Root = 0; Tab->Root = 0;
Tab->Last = 0; Tab->Last = 0;
Tab->Count = 0; Tab->Count = 0;
for (I = 0; I < HASHTAB_SIZE; ++I) { for (I = 0; I < HASHTAB_SIZE; ++I) {
Tab->HashTab [I] = 0; Tab->HashTab [I] = 0;
} }
/* Done, return the hash table */ /* Done, return the hash table */
@@ -158,13 +158,13 @@ void FreeExtSymTab (ExtSymTab* Tab)
{ {
/* Free all entries */ /* Free all entries */
while (Tab->Root) { while (Tab->Root) {
ExtSym* E = Tab->Root; ExtSym* E = Tab->Root;
Tab->Root = E->Next; Tab->Root = E->Next;
FreeExtSym (E); FreeExtSym (E);
} }
/* Free the struct itself */ /* Free the struct itself */
Xfree (Tab); xfree (Tab);
} }

View File

@@ -35,8 +35,9 @@
#include <string.h> #include <string.h>
#include "../common/xmalloc.h"
#include "error.h" #include "error.h"
#include "mem.h"
#include "fileio.h" #include "fileio.h"
@@ -232,7 +233,7 @@ char* ReadMallocedStr (FILE* F)
unsigned Len = Read8 (F); unsigned Len = Read8 (F);
/* Allocate memory */ /* Allocate memory */
char* Str = Xmalloc (Len + 1); char* Str = xmalloc (Len + 1);
/* Read the string itself */ /* Read the string itself */
ReadData (F, Str, Len); ReadData (F, Str, Len);
@@ -267,3 +268,4 @@ void* ReadData (FILE* F, void* Data, unsigned Size)

View File

@@ -43,8 +43,6 @@
const char* ProgName = "ld65"; /* Program name */
const char* OutputName = "a.out"; /* Name of output file */ const char* OutputName = "a.out"; /* Name of output file */
unsigned long StartAddr = 0x200; /* Start address */ unsigned long StartAddr = 0x200; /* Start address */

View File

@@ -44,8 +44,6 @@
extern const char* ProgName; /* Program name */
extern const char* OutputName; /* Name of output file */ extern const char* OutputName; /* Name of output file */
extern unsigned long StartAddr; /* Start address */ extern unsigned long StartAddr; /* Start address */

View File

@@ -37,18 +37,18 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "../common/objdefs.h"
#include "../common/libdefs.h"
#include "../common/symdefs.h"
#include "../common/exprdefs.h" #include "../common/exprdefs.h"
#include "../common/filepos.h" #include "../common/filepos.h"
#include "../common/libdefs.h"
#include "../common/objdefs.h"
#include "../common/symdefs.h"
#include "../common/xmalloc.h"
#include "mem.h"
#include "error.h" #include "error.h"
#include "exports.h"
#include "fileio.h" #include "fileio.h"
#include "objdata.h" #include "objdata.h"
#include "objfile.h" #include "objfile.h"
#include "exports.h"
#include "library.h" #include "library.h"
@@ -120,7 +120,7 @@ static ObjData* ReadIndexEntry (void)
/* Skip the export size, then read the exports */ /* Skip the export size, then read the exports */
Read16 (Lib); Read16 (Lib);
O->ExportCount = Read16 (Lib); O->ExportCount = Read16 (Lib);
O->Exports = Xmalloc (O->ExportCount * sizeof (Export*)); O->Exports = xmalloc (O->ExportCount * sizeof (Export*));
for (I = 0; I < O->ExportCount; ++I) { for (I = 0; I < O->ExportCount; ++I) {
O->Exports [I] = ReadExport (Lib, O); O->Exports [I] = ReadExport (Lib, O);
} }
@@ -128,7 +128,7 @@ static ObjData* ReadIndexEntry (void)
/* Skip the import size, then read the imports */ /* Skip the import size, then read the imports */
Read16 (Lib); Read16 (Lib);
O->ImportCount = Read16 (Lib); O->ImportCount = Read16 (Lib);
O->Imports = Xmalloc (O->ImportCount * sizeof (Import*)); O->Imports = xmalloc (O->ImportCount * sizeof (Import*));
for (I = 0; I < O->ImportCount; ++I) { for (I = 0; I < O->ImportCount; ++I) {
O->Imports [I] = ReadImport (Lib, O); O->Imports [I] = ReadImport (Lib, O);
} }
@@ -146,7 +146,7 @@ static void ReadIndex (void)
/* Read the object file count and allocate memory */ /* Read the object file count and allocate memory */
ModuleCount = Read16 (Lib); ModuleCount = Read16 (Lib);
Index = Xmalloc (ModuleCount * sizeof (ObjData*)); Index = xmalloc (ModuleCount * sizeof (ObjData*));
/* Read all entries in the index */ /* Read all entries in the index */
for (I = 0; I < ModuleCount; ++I) { for (I = 0; I < ModuleCount; ++I) {
@@ -204,7 +204,7 @@ void LibAdd (FILE* F, const char* Name)
/* Store the parameters, so they're visible for other routines */ /* Store the parameters, so they're visible for other routines */
Lib = F; Lib = F;
LibName = StrDup (Name); LibName = xstrdup (Name);
/* Read the remaining header fields (magic is already read) */ /* Read the remaining header fields (magic is already read) */
Header.Magic = LIB_MAGIC; Header.Magic = LIB_MAGIC;
@@ -270,7 +270,7 @@ void LibAdd (FILE* F, const char* Name)
/* Done. Close the file, release allocated memory */ /* Done. Close the file, release allocated memory */
fclose (F); fclose (F);
Xfree (Index); xfree (Index);
Lib = 0; Lib = 0;
LibName = 0; LibName = 0;
ModuleCount = 0; ModuleCount = 0;

View File

@@ -38,13 +38,14 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "../common/cmdline.h"
#include "../common/libdefs.h" #include "../common/libdefs.h"
#include "../common/objdefs.h" #include "../common/objdefs.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"
#include "target.h" #include "target.h"
#include "fileio.h" #include "fileio.h"
#include "scanner.h" #include "scanner.h"
@@ -81,37 +82,23 @@ static void Usage (void)
{ {
fprintf (stderr, fprintf (stderr,
"Usage: %s [options] module ...\n" "Usage: %s [options] module ...\n"
"Options are:\n" "Short options:\n"
"\t-m name\t\tCreate a map file\n" " -h\t\t\tHelp (this text)\n"
"\t-o name\t\tName the default output file\n" " -m name\t\tCreate a map file\n"
"\t-t type\t\tType of target system\n" " -o name\t\tName the default output file\n"
"\t-v\t\tVerbose mode\n" " -t type\t\tType of target system\n"
"\t-vm\t\tVerbose map file\n" " -v\t\t\tVerbose mode\n"
"\t-C name\t\tUse linker config file\n" " -vm\t\t\tVerbose map file\n"
"\t-Ln name\tCreate a VICE label file\n" " -C name\t\tUse linker config file\n"
"\t-Lp\t\tMark write protected segments as such (VICE)\n" " -Ln name\t\tCreate a VICE label file\n"
"\t-S addr\t\tSet the default start address\n" " -Lp\t\t\tMark write protected segments as such (VICE)\n"
"\t-V\t\tPrint linker version\n", " -S addr\t\tSet the default start address\n"
" -V\t\t\tPrint the linker version\n"
"\n"
"Long options:\n"
" --help\t\tHelp (this text)\n"
" --version\t\tPrint the linker version\n",
ProgName); ProgName);
exit (EXIT_FAILURE);
}
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 InvNumber (const char* Arg)
/* Print an error about an unknown option. Print usage information and exit */
{
fprintf (stderr, "Invalid number given in argument: %s\n", Arg);
Usage ();
} }
@@ -122,17 +109,20 @@ static unsigned long CvtNumber (const char* Arg, const char* Number)
*/ */
{ {
unsigned long Val; unsigned long Val;
int Converted;
/* Convert */ /* Convert */
if (*Number == '$') { if (*Number == '$') {
++Number; ++Number;
if (sscanf (Number, "%lx", &Val) != 1) { Converted = sscanf (Number, "%lx", &Val);
InvNumber (Arg);
}
} else { } else {
if (sscanf (Number, "%li", (long*)&Val) != 1) { Converted = sscanf (Number, "%li", (long*)&Val);
InvNumber (Arg); }
}
/* Check if we do really have a number */
if (Converted != 1) {
fprintf (stderr, "Invalid number given in argument: %s\n", Arg);
exit (EXIT_FAILURE);
} }
/* Return the result */ /* Return the result */
@@ -141,37 +131,6 @@ static unsigned long CvtNumber (const char* Arg, const char* Number)
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 */
fprintf (stderr, "Option requires an argument: %s\n", argv [*ArgNum]);
exit (EXIT_FAILURE);
}
++(*ArgNum);
return Arg;
}
}
static void LongOption (int* Arg, char* argv [])
/* Handle a long command line option */
{
/* For now ... */
UnknownOption (argv [*Arg]);
}
static int HasPath (const char* Name) static int HasPath (const char* Name)
/* Check if the given Name has a path component */ /* Check if the given Name has a path component */
{ {
@@ -199,7 +158,7 @@ static void LinkFile (const char* Name)
* path separator character eventually needed. * path separator character eventually needed.
*/ */
Len = LibPathLen; Len = LibPathLen;
NewName = Xmalloc (strlen (Name) + Len + 2); NewName = xmalloc (strlen (Name) + Len + 2);
/* Build the new name */ /* Build the new name */
memcpy (NewName, LibPath, Len); memcpy (NewName, LibPath, Len);
if (NewName [Len-1] != '/' && NewName [Len-1] != '\\') { if (NewName [Len-1] != '/' && NewName [Len-1] != '\\') {
@@ -243,7 +202,26 @@ static void LinkFile (const char* Name)
* be freed if we run into an error, but that's no problem. Adding more * be freed if we run into an error, but that's no problem. Adding more
* code to work around it will use more memory than the chunk that's lost. * code to work around it will use more memory than the chunk that's lost.
*/ */
Xfree (NewName); xfree (NewName);
}
static void OptHelp (const char* Opt, const char* Arg)
/* Print usage information and exit */
{
Usage ();
exit (EXIT_SUCCESS);
}
static void OptVersion (const char* Opt, const char* Arg)
/* Print the assembler version */
{
fprintf (stderr,
"ld65 V%u.%u.%u - (C) Copyright 1998-2000 Ullrich von Bassewitz\n",
VER_MAJOR, VER_MINOR, VER_PATCH);
} }
@@ -251,8 +229,17 @@ static void LinkFile (const char* Name)
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[] = {
{ "--help", 0, OptHelp },
{ "--version", 0, OptVersion },
};
int I; int I;
/* Initialize the cmdline module */
InitCmdLine (argc, argv, "ld65");
/* Evaluate the CC65_LIB environment variable */ /* Evaluate the CC65_LIB environment variable */
LibPath = getenv ("CC65_LIB"); LibPath = getenv ("CC65_LIB");
if (LibPath == 0) { if (LibPath == 0) {
@@ -260,7 +247,7 @@ int main (int argc, char* argv [])
#ifdef CC65_LIB #ifdef CC65_LIB
LibPath = CC65_LIB; LibPath = CC65_LIB;
#else #else
LibPath = "/usr/lib/cc65/lib/"; LibPath = "/usr/lib/cc65/lib/";
#endif #endif
} }
LibPathLen = strlen (LibPath); LibPathLen = strlen (LibPath);
@@ -279,22 +266,22 @@ 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 'm': case 'm':
MapFileName = GetArg (&I, argv, 2); MapFileName = GetArg (&I, 2);
break; break;
case 'o': case 'o':
OutputName = GetArg (&I, argv, 2); OutputName = GetArg (&I, 2);
break; break;
case 't': case 't':
if (CfgAvail ()) { if (CfgAvail ()) {
Error ("Cannot use -C/-t twice"); Error ("Cannot use -C/-t twice");
} }
TgtSet (GetArg (&I, argv, 2)); TgtSet (GetArg (&I, 2));
break; break;
case 'v': case 'v':
@@ -309,25 +296,23 @@ int main (int argc, char* argv [])
if (CfgAvail ()) { if (CfgAvail ()) {
Error ("Cannot use -C/-t twice"); Error ("Cannot use -C/-t twice");
} }
CfgSetName (GetArg (&I, argv, 2)); CfgSetName (GetArg (&I, 2));
break; break;
case 'L': case 'L':
switch (Arg [2]) { switch (Arg [2]) {
case 'n': LabelFileName = GetArg (&I, argv, 3); break; case 'n': LabelFileName = GetArg (&I, 3); break;
case 'p': WProtSegs = 1; break; case 'p': WProtSegs = 1; break;
default: UnknownOption (Arg); default: UnknownOption (Arg); break;
} }
break; break;
case 'S': case 'S':
StartAddr = CvtNumber (Arg, GetArg (&I, argv, 2)); StartAddr = CvtNumber (Arg, GetArg (&I, 2));
break; break;
case 'V': case 'V':
fprintf (stderr, OptVersion (Arg, 0);
"ld65 V%u.%u.%u - (C) Copyright 1998-2000 Ullrich von Bassewitz\n",
VER_MAJOR, VER_MINOR, VER_PATCH);
break; break;
default: default:
@@ -349,13 +334,13 @@ int main (int argc, char* argv [])
/* Check if we had any object files */ /* Check if we had any object files */
if (ObjFiles == 0) { if (ObjFiles == 0) {
fprintf (stderr, "No object files to link\n"); fprintf (stderr, "No object files to link\n");
Usage (); exit (EXIT_FAILURE);
} }
/* Check if we have a valid configuration */ /* Check if we have a valid configuration */
if (!CfgAvail ()) { if (!CfgAvail ()) {
fprintf (stderr, "Memory configuration missing\n"); fprintf (stderr, "Memory configuration missing\n");
Usage (); exit (EXIT_FAILURE);
} }
/* Read the config file */ /* Read the config file */
@@ -389,3 +374,4 @@ int main (int argc, char* argv [])

View File

@@ -21,7 +21,6 @@ OBJS = bin.o \
library.o \ library.o \
main.o \ main.o \
mapfile.o \ mapfile.o \
mem.o \
o65.o \ o65.o \
objdata.o \ objdata.o \
objfile.o \ objfile.o \

View File

@@ -76,7 +76,6 @@ OBJS = bin.obj \
library.obj \ library.obj \
main.obj \ main.obj \
mapfile.obj \ mapfile.obj \
mem.obj \
o65.obj \ o65.obj \
objdata.obj \ objdata.obj \
objfile.obj \ objfile.obj \
@@ -117,7 +116,6 @@ FILE global.obj
FILE library.obj FILE library.obj
FILE main.obj FILE main.obj
FILE mapfile.obj FILE mapfile.obj
FILE mem.obj
FILE o65.obj FILE o65.obj
FILE objdata.obj FILE objdata.obj
FILE objfile.obj FILE objfile.obj

View File

@@ -39,13 +39,13 @@
#include <time.h> #include <time.h>
#include "../common/version.h" #include "../common/version.h"
#include "../common/xmalloc.h"
#include "global.h"
#include "error.h" #include "error.h"
#include "mem.h"
#include "fileio.h"
#include "exports.h" #include "exports.h"
#include "expr.h" #include "expr.h"
#include "fileio.h"
#include "global.h"
#include "o65.h" #include "o65.h"
@@ -281,12 +281,12 @@ static O65RelocTab* NewO65RelocTab (void)
/* Create a new relocation table */ /* Create a new relocation table */
{ {
/* Allocate a new structure */ /* Allocate a new structure */
O65RelocTab* R = Xmalloc (sizeof (O65RelocTab)); O65RelocTab* R = xmalloc (sizeof (O65RelocTab));
/* Initialize the data */ /* Initialize the data */
R->Size = RELOC_BLOCKSIZE; R->Size = RELOC_BLOCKSIZE;
R->Fill = 0; R->Fill = 0;
R->Buf = Xmalloc (RELOC_BLOCKSIZE); R->Buf = xmalloc (RELOC_BLOCKSIZE);
/* Return the created struct */ /* Return the created struct */
return R; return R;
@@ -297,8 +297,8 @@ static O65RelocTab* NewO65RelocTab (void)
static void FreeO65RelocTab (O65RelocTab* R) static void FreeO65RelocTab (O65RelocTab* R)
/* Free a relocation table */ /* Free a relocation table */
{ {
Xfree (R->Buf); xfree (R->Buf);
Xfree (R); xfree (R);
} }
@@ -309,9 +309,9 @@ static void O65RelocPutByte (O65RelocTab* R, unsigned B)
/* Do we have enough space in the buffer? */ /* Do we have enough space in the buffer? */
if (R->Fill == R->Size) { if (R->Fill == R->Size) {
/* We need to grow the buffer */ /* We need to grow the buffer */
unsigned char* NewBuf = Xmalloc (R->Size + RELOC_BLOCKSIZE); unsigned char* NewBuf = xmalloc (R->Size + RELOC_BLOCKSIZE);
memcpy (NewBuf, R->Buf, R->Size); memcpy (NewBuf, R->Buf, R->Size);
Xfree (R->Buf); xfree (R->Buf);
R->Buf = NewBuf; R->Buf = NewBuf;
} }
@@ -353,7 +353,7 @@ static O65Option* NewO65Option (unsigned Type, const void* Data, unsigned DataLe
CHECK (DataLen <= 253); CHECK (DataLen <= 253);
/* Allocate memory */ /* Allocate memory */
O = Xmalloc (sizeof (O65Option) - 1 + DataLen); O = xmalloc (sizeof (O65Option) - 1 + DataLen);
/* Initialize the structure */ /* Initialize the structure */
O->Next = 0; O->Next = 0;
@@ -370,7 +370,7 @@ static O65Option* NewO65Option (unsigned Type, const void* Data, unsigned DataLe
static void FreeO65Option (O65Option* O) static void FreeO65Option (O65Option* O)
/* Free an O65Option struct */ /* Free an O65Option struct */
{ {
Xfree (O); xfree (O);
} }
@@ -718,7 +718,7 @@ O65Desc* NewO65Desc (void)
/* Create, initialize and return a new O65 descriptor struct */ /* Create, initialize and return a new O65 descriptor struct */
{ {
/* Allocate a new structure */ /* Allocate a new structure */
O65Desc* D = Xmalloc (sizeof (O65Desc)); O65Desc* D = xmalloc (sizeof (O65Desc));
/* Initialize the header */ /* Initialize the header */
D->Header.Version = 0; D->Header.Version = 0;
@@ -761,10 +761,10 @@ void FreeO65Desc (O65Desc* D)
/* Delete the descriptor struct with cleanup */ /* Delete the descriptor struct with cleanup */
{ {
/* Free the segment arrays */ /* Free the segment arrays */
Xfree (D->ZPSeg); xfree (D->ZPSeg);
Xfree (D->BssSeg); xfree (D->BssSeg);
Xfree (D->DataSeg); xfree (D->DataSeg);
Xfree (D->TextSeg); xfree (D->TextSeg);
/* Free the relocation tables */ /* Free the relocation tables */
FreeO65RelocTab (D->DataReloc); FreeO65RelocTab (D->DataReloc);
@@ -782,7 +782,7 @@ void FreeO65Desc (O65Desc* D)
FreeExtSymTab (D->Imports); FreeExtSymTab (D->Imports);
/* Free the struct itself */ /* Free the struct itself */
Xfree (D); xfree (D);
} }
@@ -929,10 +929,10 @@ static void O65SetupSegments (O65Desc* D, Memory* M)
} }
/* Allocate memory according to the numbers */ /* Allocate memory according to the numbers */
D->TextSeg = Xmalloc (D->TextCount * sizeof (SegDesc*)); D->TextSeg = xmalloc (D->TextCount * sizeof (SegDesc*));
D->DataSeg = Xmalloc (D->DataCount * sizeof (SegDesc*)); D->DataSeg = xmalloc (D->DataCount * sizeof (SegDesc*));
D->BssSeg = Xmalloc (D->BssCount * sizeof (SegDesc*)); D->BssSeg = xmalloc (D->BssCount * sizeof (SegDesc*));
D->ZPSeg = Xmalloc (D->ZPCount * sizeof (SegDesc*)); D->ZPSeg = xmalloc (D->ZPCount * sizeof (SegDesc*));
/* Walk again through the list and setup the segment arrays */ /* Walk again through the list and setup the segment arrays */
TextIdx = DataIdx = BssIdx = ZPIdx = 0; TextIdx = DataIdx = BssIdx = ZPIdx = 0;

View File

@@ -35,7 +35,8 @@
#include <string.h> #include <string.h>
#include "mem.h" #include "../common/xmalloc.h"
#include "error.h" #include "error.h"
#include "objdata.h" #include "objdata.h"
@@ -65,7 +66,7 @@ ObjData* NewObjData (void)
/* Allocate a new structure on the heap, insert it into the list, return it */ /* Allocate a new structure on the heap, insert it into the list, return it */
{ {
/* Allocate memory */ /* Allocate memory */
ObjData* O = Xmalloc (sizeof (ObjData)); ObjData* O = xmalloc (sizeof (ObjData));
/* Initialize the data */ /* Initialize the data */
O->Next = 0; O->Next = 0;
@@ -82,11 +83,11 @@ ObjData* NewObjData (void)
/* Link it into the list */ /* Link it into the list */
if (ObjLast) { if (ObjLast) {
ObjLast->Next = O; ObjLast->Next = O;
ObjLast = O; ObjLast = O;
} else { } else {
/* First entry */ /* First entry */
ObjRoot = ObjLast = O; ObjRoot = ObjLast = O;
} }
/* One object file more now */ /* One object file more now */
@@ -101,11 +102,11 @@ ObjData* NewObjData (void)
void FreeObjData (ObjData* O) void FreeObjData (ObjData* O)
/* Free a complete struct */ /* Free a complete struct */
{ {
Xfree (O->Name); xfree (O->Name);
Xfree (O->Imports); xfree (O->Imports);
Xfree (O->Exports); xfree (O->Exports);
Xfree (O->DbgSyms); xfree (O->DbgSyms);
Xfree (O); xfree (O);
} }

View File

@@ -38,13 +38,14 @@
#include <time.h> #include <time.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "error.h" #include "../common/xmalloc.h"
#include "mem.h"
#include "objdata.h"
#include "fileio.h"
#include "segments.h"
#include "exports.h"
#include "dbgsyms.h" #include "dbgsyms.h"
#include "error.h"
#include "exports.h"
#include "fileio.h"
#include "objdata.h"
#include "segments.h"
#include "objfile.h" #include "objfile.h"
@@ -105,7 +106,7 @@ void ObjReadFiles (FILE* F, ObjData* O)
unsigned I; unsigned I;
O->FileCount = Read8 (F); O->FileCount = Read8 (F);
O->Files = Xmalloc (O->FileCount * sizeof (char*)); O->Files = xmalloc (O->FileCount * sizeof (char*));
for (I = 0; I < O->FileCount; ++I) { for (I = 0; I < O->FileCount; ++I) {
/* Skip MTime and size */ /* Skip MTime and size */
Read32 (F); Read32 (F);
@@ -123,7 +124,7 @@ void ObjReadImports (FILE* F, ObjData* O)
unsigned I; unsigned I;
O->ImportCount = Read16 (F); O->ImportCount = Read16 (F);
O->Imports = Xmalloc (O->ImportCount * sizeof (Import*)); O->Imports = xmalloc (O->ImportCount * sizeof (Import*));
for (I = 0; I < O->ImportCount; ++I) { for (I = 0; I < O->ImportCount; ++I) {
O->Imports [I] = ReadImport (F, O); O->Imports [I] = ReadImport (F, O);
InsertImport (O->Imports [I]); InsertImport (O->Imports [I]);
@@ -138,7 +139,7 @@ void ObjReadExports (FILE* F, ObjData* O)
unsigned I; unsigned I;
O->ExportCount = Read16 (F); O->ExportCount = Read16 (F);
O->Exports = Xmalloc (O->ExportCount * sizeof (Export*)); O->Exports = xmalloc (O->ExportCount * sizeof (Export*));
for (I = 0; I < O->ExportCount; ++I) { for (I = 0; I < O->ExportCount; ++I) {
O->Exports [I] = ReadExport (F, O); O->Exports [I] = ReadExport (F, O);
InsertExport (O->Exports [I]); InsertExport (O->Exports [I]);
@@ -153,7 +154,7 @@ void ObjReadDbgSyms (FILE* F, ObjData* O)
unsigned I; unsigned I;
O->DbgSymCount = Read16 (F); O->DbgSymCount = Read16 (F);
O->DbgSyms = Xmalloc (O->DbgSymCount * sizeof (DbgSym*)); O->DbgSyms = xmalloc (O->DbgSymCount * sizeof (DbgSym*));
for (I = 0; I < O->DbgSymCount; ++I) { for (I = 0; I < O->DbgSymCount; ++I) {
O->DbgSyms [I] = ReadDbgSym (F, O); O->DbgSyms [I] = ReadDbgSym (F, O);
} }
@@ -167,7 +168,7 @@ void ObjReadSections (FILE* F, ObjData* O)
unsigned I; unsigned I;
O->SectionCount = Read8 (F); O->SectionCount = Read8 (F);
O->Sections = Xmalloc (O->SectionCount * sizeof (Section*)); O->Sections = xmalloc (O->SectionCount * sizeof (Section*));
for (I = 0; I < O->SectionCount; ++I) { for (I = 0; I < O->SectionCount; ++I) {
O->Sections [I] = ReadSection (F, O); O->Sections [I] = ReadSection (F, O);
} }
@@ -188,7 +189,7 @@ void ObjAdd (FILE* Obj, const char* Name)
ObjReadHeader (Obj, &O->Header, Name); ObjReadHeader (Obj, &O->Header, Name);
/* Initialize the object module data structure */ /* Initialize the object module data structure */
O->Name = StrDup (GetModule (Name)); O->Name = xstrdup (GetModule (Name));
O->Flags = OBJ_HAVEDATA; O->Flags = OBJ_HAVEDATA;
/* Read the files list from the object file */ /* Read the files list from the object file */

View File

@@ -37,15 +37,15 @@
#include <string.h> #include <string.h>
#include "../common/exprdefs.h" #include "../common/exprdefs.h"
#include "../common/symdefs.h"
#include "../common/segdefs.h"
#include "../common/hashstr.h" #include "../common/hashstr.h"
#include "../common/segdefs.h"
#include "../common/symdefs.h"
#include "../common/xmalloc.h"
#include "mem.h"
#include "global.h"
#include "error.h" #include "error.h"
#include "fileio.h"
#include "expr.h" #include "expr.h"
#include "fileio.h"
#include "global.h"
#include "segments.h" #include "segments.h"
@@ -89,7 +89,7 @@ static Fragment* NewFragment (unsigned char Type, unsigned long Size, Section* S
/* Create a new fragment and insert it into the segment S */ /* Create a new fragment and insert it into the segment S */
{ {
/* Allocate memory */ /* Allocate memory */
Fragment* F = Xmalloc (sizeof (Fragment) - 1 + Size); /* Portable? */ Fragment* F = xmalloc (sizeof (Fragment) - 1 + Size); /* Portable? */
/* Initialize the data */ /* Initialize the data */
F->Next = 0; F->Next = 0;
@@ -121,7 +121,7 @@ static Segment* NewSegment (const char* Name, unsigned char Type)
unsigned Len = strlen (Name); unsigned Len = strlen (Name);
/* Allocate memory */ /* Allocate memory */
Segment* S = Xmalloc (sizeof (Segment) + Len); Segment* S = xmalloc (sizeof (Segment) + Len);
/* Initialize the fields */ /* Initialize the fields */
S->Next = 0; S->Next = 0;
@@ -155,7 +155,7 @@ static Section* NewSection (Segment* Seg, unsigned char Align, unsigned char Typ
/* Allocate memory */ /* Allocate memory */
Section* S = Xmalloc (sizeof (Segment)); Section* S = xmalloc (sizeof (Segment));
/* Initialize the data */ /* Initialize the data */
S->Next = 0; S->Next = 0;
@@ -600,7 +600,7 @@ void PrintSegmentMap (FILE* F)
Segment** SegPool; Segment** SegPool;
/* Allocate memory for the segment pool */ /* Allocate memory for the segment pool */
SegPool = Xmalloc (SegCount * sizeof (Segment*)); SegPool = xmalloc (SegCount * sizeof (Segment*));
/* Collect pointers to the segments */ /* Collect pointers to the segments */
I = 0; I = 0;
@@ -643,7 +643,7 @@ void PrintSegmentMap (FILE* F)
} }
/* Free the segment pool */ /* Free the segment pool */
Xfree (SegPool); xfree (SegPool);
} }