mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
xlink: replace awkward fatalerror() with standard errx(3)
fatalerror() prints a given string to stdout and exits(5). It cannot format text, so there was a string temptext used with sprintf() to format text and pass it to fatalerror(). errx() can format text, and it prints to stderr. As a bonus, this fixes the linking warnings from use of sprintf().
This commit is contained in:
@@ -4,8 +4,6 @@
|
|||||||
#include "link/types.h"
|
#include "link/types.h"
|
||||||
|
|
||||||
extern void PrintUsage(void);
|
extern void PrintUsage(void);
|
||||||
extern void fatalerror(char *s);
|
|
||||||
extern char temptext[1024];
|
|
||||||
extern SLONG fillchar;
|
extern SLONG fillchar;
|
||||||
extern char smartlinkstartsymbol[256];
|
extern char smartlinkstartsymbol[256];
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
|
|||||||
|
|
||||||
return (org);
|
return (org);
|
||||||
} else
|
} else
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +165,7 @@ AssignCodeSections(void)
|
|||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
} else
|
} else
|
||||||
fatalerror("Unable to place CODE section anywhere");
|
errx(5, "Unable to place CODE section anywhere");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +186,7 @@ GBROM_AssignSections(void)
|
|||||||
BankFree[i] = malloc(sizeof *BankFree[i]);
|
BankFree[i] = malloc(sizeof *BankFree[i]);
|
||||||
|
|
||||||
if (!BankFree[i])
|
if (!BankFree[i])
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
BankFree[i]->nOrg = 0x0000;
|
BankFree[i]->nOrg = 0x0000;
|
||||||
@@ -243,10 +244,7 @@ GBROM_AssignSections(void)
|
|||||||
if (area_AllocAbs
|
if (area_AllocAbs
|
||||||
(&BankFree[BANK_BSS], pSection->nOrg,
|
(&BankFree[BANK_BSS], pSection->nOrg,
|
||||||
pSection->nByteSize) != pSection->nOrg) {
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
sprintf(temptext,
|
errx(5, "Unable to load fixed BSS section at $%lX", pSection->nOrg);
|
||||||
"Unable to load fixed BSS section at $%lX",
|
|
||||||
pSection->nOrg);
|
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank = BANK_BSS;
|
pSection->nBank = BANK_BSS;
|
||||||
@@ -255,10 +253,7 @@ GBROM_AssignSections(void)
|
|||||||
if (area_AllocAbs
|
if (area_AllocAbs
|
||||||
(&BankFree[BANK_HRAM], pSection->nOrg,
|
(&BankFree[BANK_HRAM], pSection->nOrg,
|
||||||
pSection->nByteSize) != pSection->nOrg) {
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
sprintf(temptext,
|
errx(5, "Unable to load fixed HRAM section at $%lX", pSection->nOrg);
|
||||||
"Unable to load fixed HRAM section at $%lX",
|
|
||||||
pSection->nOrg);
|
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank = BANK_HRAM;
|
pSection->nBank = BANK_HRAM;
|
||||||
@@ -267,10 +262,7 @@ GBROM_AssignSections(void)
|
|||||||
if (area_AllocAbs
|
if (area_AllocAbs
|
||||||
(&BankFree[BANK_VRAM], pSection->nOrg,
|
(&BankFree[BANK_VRAM], pSection->nOrg,
|
||||||
pSection->nByteSize) != pSection->nOrg) {
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
sprintf(temptext,
|
errx(5, "Unable to load fixed VRAM section at $%lX", pSection->nOrg);
|
||||||
"Unable to load fixed VRAM section at $%lX",
|
|
||||||
pSection->nOrg);
|
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank = BANK_VRAM;
|
pSection->nBank = BANK_VRAM;
|
||||||
@@ -279,10 +271,7 @@ GBROM_AssignSections(void)
|
|||||||
if (area_AllocAbs
|
if (area_AllocAbs
|
||||||
(&BankFree[BANK_HOME], pSection->nOrg,
|
(&BankFree[BANK_HOME], pSection->nOrg,
|
||||||
pSection->nByteSize) != pSection->nOrg) {
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
sprintf(temptext,
|
errx(5, "Unable to load fixed HOME section at $%lX", pSection->nOrg);
|
||||||
"Unable to load fixed HOME section at $%lX",
|
|
||||||
pSection->nOrg);
|
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank = BANK_HOME;
|
pSection->nBank = BANK_HOME;
|
||||||
@@ -327,26 +316,13 @@ GBROM_AssignSections(void)
|
|||||||
pSection->
|
pSection->
|
||||||
nByteSize) !=
|
nByteSize) !=
|
||||||
pSection->nOrg) {
|
pSection->nOrg) {
|
||||||
sprintf
|
errx(5, "Unable to load fixed CODE/DATA section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
(temptext,
|
|
||||||
"Unable to load fixed CODE/DATA section at $%lX in bank $%02lX",
|
|
||||||
pSection->
|
|
||||||
nOrg,
|
|
||||||
pSection->
|
|
||||||
nBank);
|
|
||||||
fatalerror
|
|
||||||
(temptext);
|
|
||||||
}
|
}
|
||||||
DOMAXBANK(pSection->
|
DOMAXBANK(pSection->
|
||||||
nBank);
|
nBank);
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
} else {
|
} else {
|
||||||
sprintf(temptext,
|
errx(5, "Unable to load fixed CODE/DATA section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
"Unable to load fixed CODE/DATA section at $%lX in bank $%02lX",
|
|
||||||
pSection->nOrg,
|
|
||||||
pSection->
|
|
||||||
nBank);
|
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,18 +348,12 @@ GBROM_AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[pSection->nBank],
|
area_Alloc(&BankFree[pSection->nBank],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
sprintf(temptext,
|
errx(5, "Unable to load fixed CODE/DATA section into bank $%02lX", pSection->nBank);
|
||||||
"Unable to load fixed CODE/DATA section into bank $%02lX",
|
|
||||||
pSection->nBank);
|
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
sprintf(temptext,
|
errx(5, "Unable to load fixed CODE/DATA section into bank $%02lX", pSection->nBank);
|
||||||
"Unable to load fixed CODE/DATA section into bank $%02lX",
|
|
||||||
pSection->nBank);
|
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pSection = pSection->pNext;
|
pSection = pSection->pNext;
|
||||||
@@ -405,10 +375,7 @@ GBROM_AssignSections(void)
|
|||||||
area_AllocAbsCODEAnyBank(pSection->nOrg,
|
area_AllocAbsCODEAnyBank(pSection->nOrg,
|
||||||
pSection->nByteSize)) ==
|
pSection->nByteSize)) ==
|
||||||
-1) {
|
-1) {
|
||||||
sprintf(temptext,
|
errx(5, "Unable to load fixed CODE/DATA section at $%lX into any bank", pSection->nOrg);
|
||||||
"Unable to load fixed CODE/DATA section at $%lX into any bank",
|
|
||||||
pSection->nOrg);
|
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
@@ -430,7 +397,7 @@ GBROM_AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[BANK_BSS],
|
area_Alloc(&BankFree[BANK_BSS],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fatalerror("BSS section too large\n");
|
errx(5, "BSS section too large");
|
||||||
}
|
}
|
||||||
pSection->nBank = BANK_BSS;
|
pSection->nBank = BANK_BSS;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
@@ -439,7 +406,7 @@ GBROM_AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[BANK_HRAM],
|
area_Alloc(&BankFree[BANK_HRAM],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fatalerror("HRAM section too large");
|
errx(5, "HRAM section too large");
|
||||||
}
|
}
|
||||||
pSection->nBank = BANK_HRAM;
|
pSection->nBank = BANK_HRAM;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
@@ -448,7 +415,7 @@ GBROM_AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[BANK_VRAM],
|
area_Alloc(&BankFree[BANK_VRAM],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fatalerror("VRAM section too large");
|
errx(5, "VRAM section too large");
|
||||||
}
|
}
|
||||||
pSection->nBank = BANK_VRAM;
|
pSection->nBank = BANK_VRAM;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
@@ -457,7 +424,7 @@ GBROM_AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[BANK_HOME],
|
area_Alloc(&BankFree[BANK_HOME],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fatalerror("HOME section too large");
|
errx(5, "HOME section too large");
|
||||||
}
|
}
|
||||||
pSection->nBank = BANK_HOME;
|
pSection->nBank = BANK_HOME;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
@@ -465,7 +432,7 @@ GBROM_AssignSections(void)
|
|||||||
case SECT_CODE:
|
case SECT_CODE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fatalerror("(INTERNAL) Unknown section type!");
|
errx(5, "(INTERNAL) Unknown section type!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -482,7 +449,7 @@ PSION2_AssignSections(void)
|
|||||||
|
|
||||||
BankFree[0] = malloc(sizeof *BankFree[0]);
|
BankFree[0] = malloc(sizeof *BankFree[0]);
|
||||||
if (!BankFree[0])
|
if (!BankFree[0])
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
BankFree[0]->nOrg = 0x0000;
|
BankFree[0]->nOrg = 0x0000;
|
||||||
BankFree[0]->nSize = 0x10000;
|
BankFree[0]->nSize = 0x10000;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -91,9 +92,8 @@ AddNeededModules(void)
|
|||||||
}
|
}
|
||||||
if (options & OPT_SMART_C_LINK) {
|
if (options & OPT_SMART_C_LINK) {
|
||||||
if (!addmodulecontaining(smartlinkstartsymbol)) {
|
if (!addmodulecontaining(smartlinkstartsymbol)) {
|
||||||
sprintf(temptext, "Can't find start symbol '%s'",
|
errx(5, "Can't find start symbol '%s'",
|
||||||
smartlinkstartsymbol);
|
smartlinkstartsymbol);
|
||||||
fatalerror(temptext);
|
|
||||||
} else
|
} else
|
||||||
printf("Smart linking with symbol '%s'\n",
|
printf("Smart linking with symbol '%s'\n",
|
||||||
smartlinkstartsymbol);
|
smartlinkstartsymbol);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -31,17 +32,6 @@ enum eOutputType outputtype = OUTPUT_GBROM;
|
|||||||
char temptext[1024];
|
char temptext[1024];
|
||||||
char smartlinkstartsymbol[256];
|
char smartlinkstartsymbol[256];
|
||||||
|
|
||||||
/*
|
|
||||||
* Print out an errormessage
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
|
||||||
fatalerror(char *s)
|
|
||||||
{
|
|
||||||
printf("*ERROR* : %s\n", s);
|
|
||||||
exit(5);
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* Print the usagescreen
|
* Print the usagescreen
|
||||||
*
|
*
|
||||||
@@ -76,8 +66,7 @@ ProcessLinkfile(char *tzLinkfile)
|
|||||||
|
|
||||||
pLinkfile = fopen(tzLinkfile, "rt");
|
pLinkfile = fopen(tzLinkfile, "rt");
|
||||||
if (!pLinkfile) {
|
if (!pLinkfile) {
|
||||||
sprintf(temptext, "Unable to find linkfile '%s'\n", tzLinkfile);
|
errx(5, "Unable to find linkfile '%s'", tzLinkfile);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
while (!feof(pLinkfile)) {
|
while (!feof(pLinkfile)) {
|
||||||
char tzLine[256];
|
char tzLine[256];
|
||||||
@@ -99,10 +88,9 @@ ProcessLinkfile(char *tzLinkfile)
|
|||||||
CurrentBlock = BLOCK_COMMENT;
|
CurrentBlock = BLOCK_COMMENT;
|
||||||
else {
|
else {
|
||||||
fclose(pLinkfile);
|
fclose(pLinkfile);
|
||||||
sprintf(temptext,
|
errx(5,
|
||||||
"Unknown block '%s'\n",
|
"Unknown block '%s'",
|
||||||
tzLine);
|
tzLine);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (CurrentBlock) {
|
switch (CurrentBlock) {
|
||||||
@@ -167,9 +155,8 @@ main(int argc, char *argv[])
|
|||||||
outputtype = OUTPUT_PSION2;
|
outputtype = OUTPUT_PSION2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sprintf(temptext, "Unknown option 't%c'\n",
|
errx(5, "Unknown option 't%c'",
|
||||||
opt);
|
opt);
|
||||||
fatalerror(temptext);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -184,12 +171,12 @@ main(int argc, char *argv[])
|
|||||||
sscanf(argv[argn - 1] + 2, "%lx",
|
sscanf(argv[argn - 1] + 2, "%lx",
|
||||||
&fillchar);
|
&fillchar);
|
||||||
if (!((result == EOF) || (result == 1))) {
|
if (!((result == EOF) || (result == 1))) {
|
||||||
fatalerror
|
errx(5,
|
||||||
("Invalid argument for option 'z'\n");
|
"Invalid argument for option 'z'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fatalerror("Invalid argument for option 'z'\n");
|
errx(5, "Invalid argument for option 'z'");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
@@ -197,8 +184,7 @@ main(int argc, char *argv[])
|
|||||||
strcpy(smartlinkstartsymbol, argv[argn - 1] + 2);
|
strcpy(smartlinkstartsymbol, argv[argn - 1] + 2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sprintf(temptext, "Unknown option '%c'\n", opt);
|
errx(5, "Unknown option '%c'", opt);
|
||||||
fatalerror(temptext);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ SetMapfileName(char *name)
|
|||||||
mf = fopen(name, "wt");
|
mf = fopen(name, "wt");
|
||||||
|
|
||||||
if (!mf)
|
if (!mf)
|
||||||
fatalerror("Unable to open mapfile for writing");
|
errx(5, "Unable to open mapfile for writing");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -28,7 +28,7 @@ SetSymfileName(char *name)
|
|||||||
sf = fopen(name, "wt");
|
sf = fopen(name, "wt");
|
||||||
|
|
||||||
if (!sf)
|
if (!sf)
|
||||||
fatalerror("Unable to open symfile for writing");
|
errx(5, "Unable to open symfile for writing");
|
||||||
|
|
||||||
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
|
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -79,7 +80,7 @@ AllocSection(void)
|
|||||||
|
|
||||||
*ppSections = malloc(sizeof **ppSections);
|
*ppSections = malloc(sizeof **ppSections);
|
||||||
if (!*ppSections) {
|
if (!*ppSections) {
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
(*ppSections)->tSymbols = tSymbols;
|
(*ppSections)->tSymbols = tSymbols;
|
||||||
@@ -101,12 +102,12 @@ obj_ReadSymbol(FILE * f)
|
|||||||
|
|
||||||
pSym = malloc(sizeof *pSym);
|
pSym = malloc(sizeof *pSym);
|
||||||
if (!pSym)
|
if (!pSym)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
readasciiz(s, f);
|
readasciiz(s, f);
|
||||||
pSym->pzName = malloc(strlen(s) + 1);
|
pSym->pzName = malloc(strlen(s) + 1);
|
||||||
if (!pSym->pzName)
|
if (!pSym->pzName)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
strcpy(pSym->pzName, s);
|
strcpy(pSym->pzName, s);
|
||||||
if ((pSym->Type = (enum eSymbolType) fgetc(f)) != SYM_IMPORT) {
|
if ((pSym->Type = (enum eSymbolType) fgetc(f)) != SYM_IMPORT) {
|
||||||
@@ -145,7 +146,7 @@ obj_ReadRGB0Section(FILE * f)
|
|||||||
if (pSection->nByteSize) {
|
if (pSection->nByteSize) {
|
||||||
pSection->pData = malloc(pSection->nByteSize);
|
pSection->pData = malloc(pSection->nByteSize);
|
||||||
if (!pSection->pData)
|
if (!pSection->pData)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
SLONG nNumberOfPatches;
|
SLONG nNumberOfPatches;
|
||||||
struct sPatch **ppPatch, *pPatch;
|
struct sPatch **ppPatch, *pPatch;
|
||||||
@@ -163,14 +164,14 @@ obj_ReadRGB0Section(FILE * f)
|
|||||||
while (nNumberOfPatches--) {
|
while (nNumberOfPatches--) {
|
||||||
pPatch = malloc(sizeof *pPatch);
|
pPatch = malloc(sizeof *pPatch);
|
||||||
if (!pPatch)
|
if (!pPatch)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
*ppPatch = pPatch;
|
*ppPatch = pPatch;
|
||||||
readasciiz(s, f);
|
readasciiz(s, f);
|
||||||
|
|
||||||
pPatch->pzFilename = malloc(strlen(s) + 1);
|
pPatch->pzFilename = malloc(strlen(s) + 1);
|
||||||
if (!pPatch->pzFilename)
|
if (!pPatch->pzFilename)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
strcpy(pPatch->pzFilename, s);
|
strcpy(pPatch->pzFilename, s);
|
||||||
|
|
||||||
@@ -185,7 +186,7 @@ obj_ReadRGB0Section(FILE * f)
|
|||||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||||
if (!pPatch->pRPN)
|
if (!pPatch->pRPN)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||||
pPatch->nRPNSize, f);
|
pPatch->nRPNSize, f);
|
||||||
@@ -218,7 +219,7 @@ obj_ReadRGB0(FILE * pObjfile)
|
|||||||
if (nNumberOfSymbols) {
|
if (nNumberOfSymbols) {
|
||||||
tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
|
tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
|
||||||
if (!tSymbols)
|
if (!tSymbols)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||||
@@ -293,7 +294,7 @@ obj_ReadRGB1Section(FILE * f)
|
|||||||
if (pSection->nByteSize) {
|
if (pSection->nByteSize) {
|
||||||
pSection->pData = malloc(pSection->nByteSize);
|
pSection->pData = malloc(pSection->nByteSize);
|
||||||
if (!pSection->pData)
|
if (!pSection->pData)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
SLONG nNumberOfPatches;
|
SLONG nNumberOfPatches;
|
||||||
struct sPatch **ppPatch, *pPatch;
|
struct sPatch **ppPatch, *pPatch;
|
||||||
@@ -311,13 +312,13 @@ obj_ReadRGB1Section(FILE * f)
|
|||||||
while (nNumberOfPatches--) {
|
while (nNumberOfPatches--) {
|
||||||
pPatch = malloc(sizeof *pPatch);
|
pPatch = malloc(sizeof *pPatch);
|
||||||
if (!pPatch)
|
if (!pPatch)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
*ppPatch = pPatch;
|
*ppPatch = pPatch;
|
||||||
readasciiz(s, f);
|
readasciiz(s, f);
|
||||||
pPatch->pzFilename = malloc(strlen(s) + 1);
|
pPatch->pzFilename = malloc(strlen(s) + 1);
|
||||||
if (!pPatch->pzFilename)
|
if (!pPatch->pzFilename)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
strcpy(pPatch->pzFilename, s);
|
strcpy(pPatch->pzFilename, s);
|
||||||
pPatch->nLineNo = readlong(f);
|
pPatch->nLineNo = readlong(f);
|
||||||
@@ -326,7 +327,7 @@ obj_ReadRGB1Section(FILE * f)
|
|||||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||||
if (!pPatch->pRPN)
|
if (!pPatch->pRPN)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||||
pPatch->nRPNSize, f);
|
pPatch->nRPNSize, f);
|
||||||
@@ -359,7 +360,7 @@ obj_ReadRGB1(FILE * pObjfile)
|
|||||||
if (nNumberOfSymbols) {
|
if (nNumberOfSymbols) {
|
||||||
tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols);
|
tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols);
|
||||||
if (!tSymbols)
|
if (!tSymbols)
|
||||||
fatalerror("Out of memory!");
|
errx(5, "Out of memory!");
|
||||||
|
|
||||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||||
@@ -422,14 +423,12 @@ obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
|||||||
obj_ReadRGB1(pObjfile);
|
obj_ReadRGB1(pObjfile);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sprintf(temptext, "'%s' is an unsupported version\n",
|
errx(5, "'%s' is an unsupported version",
|
||||||
tzObjectfile);
|
tzObjectfile);
|
||||||
fatalerror(temptext);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sprintf(temptext, "'%s' is not a valid object\n", tzObjectfile);
|
errx(5, "'%s' is not a valid object", tzObjectfile);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,8 +444,7 @@ obj_Readfile(char *tzObjectfile)
|
|||||||
|
|
||||||
pObjfile = fopen(tzObjectfile, "rb");
|
pObjfile = fopen(tzObjectfile, "rb");
|
||||||
if (!pObjfile) {
|
if (!pObjfile) {
|
||||||
sprintf(temptext, "Unable to open '%s'\n", tzObjectfile);
|
errx(5, "Unable to open '%s'", tzObjectfile);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
||||||
fclose(pObjfile);
|
fclose(pObjfile);
|
||||||
@@ -496,8 +494,7 @@ lib_Readfile(char *tzLibfile)
|
|||||||
|
|
||||||
pObjfile = fopen(tzLibfile, "rb");
|
pObjfile = fopen(tzLibfile, "rb");
|
||||||
if (!pObjfile) {
|
if (!pObjfile) {
|
||||||
sprintf(temptext, "Unable to open '%s'\n", tzLibfile);
|
errx(5, "Unable to open '%s'", tzLibfile);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
char tzHeader[5];
|
char tzHeader[5];
|
||||||
|
|
||||||
@@ -506,9 +503,8 @@ lib_Readfile(char *tzLibfile)
|
|||||||
if (strcmp(tzHeader, "XLB0") == 0)
|
if (strcmp(tzHeader, "XLB0") == 0)
|
||||||
lib_ReadXLB0(pObjfile);
|
lib_ReadXLB0(pObjfile);
|
||||||
else {
|
else {
|
||||||
sprintf(temptext, "'%s' is an invalid library\n",
|
errx(5, "'%s' is an invalid library",
|
||||||
tzLibfile);
|
tzLibfile);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
fclose(pObjfile);
|
fclose(pObjfile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -45,8 +46,7 @@ getsymvalue(SLONG symid)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fatalerror("*INTERNAL* UNKNOWN SYMBOL TYPE");
|
errx(5, "*INTERNAL* UNKNOWN SYMBOL TYPE");
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG
|
SLONG
|
||||||
@@ -63,8 +63,7 @@ getsymbank(SLONG symid)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fatalerror("*INTERNAL* UNKNOWN SYMBOL TYPE");
|
errx(5, "*INTERNAL* UNKNOWN SYMBOL TYPE");
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG
|
SLONG
|
||||||
@@ -158,20 +157,18 @@ calcrpn(struct sPatch * pPatch)
|
|||||||
t = rpnpop();
|
t = rpnpop();
|
||||||
rpnpush(t & 0xFF);
|
rpnpush(t & 0xFF);
|
||||||
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
|
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
|
||||||
sprintf(temptext,
|
errx(5,
|
||||||
"%s(%ld) : Value must be in the HRAM area",
|
"%s(%ld) : Value must be in the HRAM area",
|
||||||
pPatch->pzFilename, pPatch->nLineNo);
|
pPatch->pzFilename, pPatch->nLineNo);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RPN_PCEZP:
|
case RPN_PCEZP:
|
||||||
t = rpnpop();
|
t = rpnpop();
|
||||||
rpnpush(t & 0xFF);
|
rpnpush(t & 0xFF);
|
||||||
if (t < 0x2000 || t > 0x20FF) {
|
if (t < 0x2000 || t > 0x20FF) {
|
||||||
sprintf(temptext,
|
errx(5,
|
||||||
"%s(%ld) : Value must be in the ZP area",
|
"%s(%ld) : Value must be in the ZP area",
|
||||||
pPatch->pzFilename, pPatch->nLineNo);
|
pPatch->pzFilename, pPatch->nLineNo);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RPN_CONST:
|
case RPN_CONST:
|
||||||
@@ -216,11 +213,10 @@ calcrpn(struct sPatch * pPatch)
|
|||||||
high |= (*rpn++) << 24;
|
high |= (*rpn++) << 24;
|
||||||
t = rpnpop();
|
t = rpnpop();
|
||||||
if (t < low || t > high) {
|
if (t < low || t > high) {
|
||||||
sprintf(temptext,
|
errx(5,
|
||||||
"%s(%ld) : Value must be in the range [%ld;%ld]",
|
"%s(%ld) : Value must be in the range [%ld;%ld]",
|
||||||
pPatch->pzFilename,
|
pPatch->pzFilename,
|
||||||
pPatch->nLineNo, low, high);
|
pPatch->nLineNo, low, high);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
rpnpush(t);
|
rpnpush(t);
|
||||||
size -= 8;
|
size -= 8;
|
||||||
@@ -254,11 +250,10 @@ Patch(void)
|
|||||||
pSect->pData[pPatch->nOffset] =
|
pSect->pData[pPatch->nOffset] =
|
||||||
(UBYTE) t;
|
(UBYTE) t;
|
||||||
} else {
|
} else {
|
||||||
sprintf(temptext,
|
errx(5,
|
||||||
"%s(%ld) : Value must be 8-bit\n",
|
"%s(%ld) : Value must be 8-bit\n",
|
||||||
pPatch->pzFilename,
|
pPatch->pzFilename,
|
||||||
pPatch->nLineNo);
|
pPatch->nLineNo);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PATCH_WORD_L:
|
case PATCH_WORD_L:
|
||||||
@@ -279,11 +274,10 @@ Patch(void)
|
|||||||
1] = t & 0xFF;
|
1] = t & 0xFF;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sprintf(temptext,
|
errx(5,
|
||||||
"%s(%ld) : Value must be 16-bit\n",
|
"%s(%ld) : Value must be 16-bit\n",
|
||||||
pPatch->pzFilename,
|
pPatch->pzFilename,
|
||||||
pPatch->nLineNo);
|
pPatch->nLineNo);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PATCH_LONG_L:
|
case PATCH_LONG_L:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -53,9 +54,7 @@ sym_GetValue(char *tzName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(temptext, "Unknown symbol '%s'", tzName);
|
errx(5, "Unknown symbol '%s'", tzName);
|
||||||
fatalerror(temptext);
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,9 +72,7 @@ sym_GetBank(char *tzName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(temptext, "Unknown symbol '%s'", tzName);
|
errx(5, "Unknown symbol '%s'", tzName);
|
||||||
fatalerror(temptext);
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -95,10 +92,9 @@ sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
|
|||||||
if (nBank == -1)
|
if (nBank == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sprintf(temptext,
|
errx(5,
|
||||||
"Symbol '%s' defined more than once\n",
|
"Symbol '%s' defined more than once\n",
|
||||||
tzName);
|
tzName);
|
||||||
fatalerror(temptext);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user