mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Remove nonstandard <err.h>.
This provides some really nice functions, but does not exist in some environments (particularly MinGW).
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -136,7 +135,9 @@ opt_Parse(char *s)
|
||||
newopt.gbgfx[2] = s[3];
|
||||
newopt.gbgfx[3] = s[4];
|
||||
} else {
|
||||
errx(1, "Must specify exactly 4 characters for option 'g'");
|
||||
fprintf(stderr, "Must specify exactly 4 characters "
|
||||
"for option 'g'\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
@@ -144,7 +145,9 @@ opt_Parse(char *s)
|
||||
newopt.binary[0] = s[1];
|
||||
newopt.binary[1] = s[2];
|
||||
} else {
|
||||
errx(5, "Must specify exactly 2 characters for option 'b'");
|
||||
fprintf(stderr, "Must specify exactly 2 characters "
|
||||
"for option 'b'\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 'z':
|
||||
@@ -153,10 +156,13 @@ opt_Parse(char *s)
|
||||
|
||||
result = sscanf(&s[1], "%lx", &newopt.fillchar);
|
||||
if (!((result == EOF) || (result == 1))) {
|
||||
errx(5, "Invalid argument for option 'z'");
|
||||
fprintf(stderr,
|
||||
"Invalid argument for option 'z'\n");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
errx(5, "Invalid argument for option 'z'");
|
||||
fprintf(stderr, "Invalid argument for option 'z'\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -273,7 +279,9 @@ main(int argc, char *argv[])
|
||||
newopt.binary[0] = optarg[1];
|
||||
newopt.binary[1] = optarg[2];
|
||||
} else {
|
||||
errx(1, "Must specify exactly 2 characters for option 'b'");
|
||||
fprintf(stderr, "Must specify exactly "
|
||||
"2 characters for option 'b'\n");
|
||||
exit(1);
|
||||
}
|
||||
case 'g':
|
||||
if (strlen(optarg) == 4) {
|
||||
@@ -282,7 +290,9 @@ main(int argc, char *argv[])
|
||||
newopt.gbgfx[2] = optarg[3];
|
||||
newopt.gbgfx[3] = optarg[4];
|
||||
} else {
|
||||
errx(1, "Must specify exactly 4 characters for option 'g'");
|
||||
fprintf(stderr, "Must specify exactly "
|
||||
"4 characters for option 'g'\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
@@ -293,10 +303,16 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
case 'p':
|
||||
newopt.fillchar = strtoul(optarg, &ep, 0);
|
||||
if (optarg[0] == '\0' || *ep != '\0')
|
||||
errx(1, "Invalid argument for option 'p'");
|
||||
if (newopt.fillchar < 0 || newopt.fillchar > 0xFF)
|
||||
errx(1, "Argument for option 'p' must be between 0 and 0xFF");
|
||||
if (optarg[0] == '\0' || *ep != '\0') {
|
||||
fprintf(stderr,
|
||||
"Invalid argument for option 'p'\n");
|
||||
exit(1);
|
||||
}
|
||||
if (newopt.fillchar < 0 || newopt.fillchar > 0xFF) {
|
||||
fprintf(stderr, "Argument for option 'p' "
|
||||
"must be between 0 and 0xFF\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
PrintUsage();
|
||||
@@ -374,14 +390,16 @@ main(int argc, char *argv[])
|
||||
exit(5);
|
||||
}
|
||||
} else {
|
||||
errx(5, "Unterminated IF construct (%ld levels)!",
|
||||
fprintf(stderr,
|
||||
"Unterminated IF construct (%ld levels)!\n",
|
||||
nIFDepth);
|
||||
exit(5);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
printf("Assembly aborted in pass 1 (%ld errors)!\n",
|
||||
fprintf(stderr,
|
||||
"Assembly aborted in pass 1 (%ld errors)!\n",
|
||||
nErrors);
|
||||
exit(5);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
printf("File '%s' not found\n", tzMainfile);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
%{
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
119
src/fix/main.c
119
src/fix/main.c
@@ -14,7 +14,6 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -44,8 +43,11 @@ main(int argc, char *argv[])
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
if ((rom = fopen(argv[argc - 1], "rb+")) == NULL)
|
||||
err(1, "Error opening file %s", argv[argc - 1]);
|
||||
if ((rom = fopen(argv[argc - 1], "rb+")) == NULL) {
|
||||
fprintf(stderr, "Error opening file %s: \n", argv[argc - 1]);
|
||||
perror(NULL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse command-line options
|
||||
@@ -88,9 +90,12 @@ main(int argc, char *argv[])
|
||||
case 'k':
|
||||
setnewlicensee = true;
|
||||
|
||||
if (strlen(optarg) != 2)
|
||||
errx(1, "New licensee code %s is not the "
|
||||
"correct length of 2 characters", optarg);
|
||||
if (strlen(optarg) != 2) {
|
||||
fprintf(stderr,
|
||||
"New licensee code %s is not the correct "
|
||||
"length of 2 characters\n", optarg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
newlicensee = optarg;
|
||||
break;
|
||||
@@ -98,51 +103,80 @@ main(int argc, char *argv[])
|
||||
setlicensee = true;
|
||||
|
||||
licensee = strtoul(optarg, &ep, 0);
|
||||
if (optarg[0] == '\0' || *ep != '\0')
|
||||
errx(1, "Invalid argument for option 'l'");
|
||||
if (licensee < 0 || licensee > 0xFF)
|
||||
errx(1, "Argument for option 'l' must be "
|
||||
"between 0 and 255");
|
||||
if (optarg[0] == '\0' || *ep != '\0') {
|
||||
fprintf(stderr,
|
||||
"Invalid argument for option 'l'\n");
|
||||
exit(1);
|
||||
}
|
||||
if (licensee < 0 || licensee > 0xFF) {
|
||||
fprintf(stderr,
|
||||
"Argument for option 'l' must be "
|
||||
"between 0 and 255\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
setcartridge = true;
|
||||
|
||||
cartridge = strtoul(optarg, &ep, 0);
|
||||
if (optarg[0] == '\0' || *ep != '\0')
|
||||
errx(1, "Invalid argument for option 'm'");
|
||||
if (cartridge < 0 || cartridge > 0xFF)
|
||||
errx(1, "Argument for option 'm' must be "
|
||||
"between 0 and 255");
|
||||
if (optarg[0] == '\0' || *ep != '\0') {
|
||||
fprintf(stderr,
|
||||
"Invalid argument for option 'm'\n");
|
||||
exit(1);
|
||||
}
|
||||
if (cartridge < 0 || cartridge > 0xFF) {
|
||||
fprintf(stderr,
|
||||
"Argument for option 'm' must be "
|
||||
"between 0 and 255\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
setversion = true;
|
||||
|
||||
version = strtoul(optarg, &ep, 0);
|
||||
if (optarg[0] == '\0' || *ep != '\0')
|
||||
errx(1, "Invalid argument for option 'n'");
|
||||
if (version < 0 || version > 0xFF)
|
||||
errx(1, "Argument for option 'n' must be "
|
||||
"between 0 and 255");
|
||||
if (optarg[0] == '\0' || *ep != '\0') {
|
||||
fprintf(stderr,
|
||||
"Invalid argument for option 'n'\n");
|
||||
exit(1);
|
||||
}
|
||||
if (version < 0 || version > 0xFF) {
|
||||
fprintf(stderr,
|
||||
"Argument for option 'n' must be "
|
||||
"between 0 and 255\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
resize = true;
|
||||
|
||||
padvalue = strtoul(optarg, &ep, 0);
|
||||
if (optarg[0] == '\0' || *ep != '\0')
|
||||
errx(1, "Invalid argument for option 'p'");
|
||||
if (padvalue < 0 || padvalue > 0xFF)
|
||||
errx(1, "Argument for option 'p' must be "
|
||||
"between 0 and 255");
|
||||
if (optarg[0] == '\0' || *ep != '\0') {
|
||||
fprintf(stderr,
|
||||
"Invalid argument for option 'p'\n");
|
||||
exit(1);
|
||||
}
|
||||
if (padvalue < 0 || padvalue > 0xFF) {
|
||||
fprintf(stderr,
|
||||
"Argument for option 'p' must be "
|
||||
"between 0 and 255\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
setramsize = true;
|
||||
|
||||
ramsize = strtoul(optarg, &ep, 0);
|
||||
if (optarg[0] == '\0' || *ep != '\0')
|
||||
errx(1, "Invalid argument for option 'r'");
|
||||
if (ramsize < 0 || ramsize > 0xFF)
|
||||
errx(1, "Argument for option 'r' must be "
|
||||
"between 0 and 255");
|
||||
if (optarg[0] == '\0' || *ep != '\0') {
|
||||
fprintf(stderr,
|
||||
"Invalid argument for option 'r'\n");
|
||||
}
|
||||
if (ramsize < 0 || ramsize > 0xFF) {
|
||||
fprintf(stderr,
|
||||
"Argument for option 'r' must be "
|
||||
"between 0 and 255\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
super = true;
|
||||
@@ -150,13 +184,16 @@ main(int argc, char *argv[])
|
||||
case 't':
|
||||
settitle = true;
|
||||
|
||||
if (strlen(optarg) > 16)
|
||||
errx(1, "Title %s is greater than the "
|
||||
"maximum of 16 characters", optarg);
|
||||
if (strlen(optarg) > 16) {
|
||||
fprintf(stderr, "Title %s is greater than the "
|
||||
"maximum of 16 characters\n", optarg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (strlen(optarg) == 16)
|
||||
warnx("Title %s is 16 chars, it is best "
|
||||
"to keep it to 15 or fewer", optarg);
|
||||
fprintf(stderr,
|
||||
"Title %s is 16 chars, it is best "
|
||||
"to keep it to 15 or fewer\n", optarg);
|
||||
|
||||
title = optarg;
|
||||
break;
|
||||
@@ -246,7 +283,8 @@ main(int argc, char *argv[])
|
||||
byte |= 1 << 6;
|
||||
|
||||
if (byte & 0x3F)
|
||||
warnx("Color flag conflicts with game title");
|
||||
fprintf(stderr,
|
||||
"Color flag conflicts with game title\n");
|
||||
|
||||
fseek(rom, 0x143, SEEK_SET);
|
||||
fputc(byte, rom);
|
||||
@@ -283,8 +321,9 @@ main(int argc, char *argv[])
|
||||
*/
|
||||
|
||||
if (!setlicensee)
|
||||
warnx("You should probably set both '-s' and "
|
||||
"'-l 0x33'");
|
||||
fprintf(stderr,
|
||||
"You should probably set both '-s' and "
|
||||
"'-l 0x33'\n");
|
||||
|
||||
fseek(rom, 0x146, SEEK_SET);
|
||||
fputc(3, rom);
|
||||
@@ -323,7 +362,7 @@ main(int argc, char *argv[])
|
||||
fputc(padvalue, rom);
|
||||
|
||||
if (newsize > 0x800000) /* ROM is bigger than 8MiB */
|
||||
warnx("ROM size is bigger than 8MiB");
|
||||
fprintf(stderr, "ROM size is bigger than 8MiB\n");
|
||||
|
||||
fseek(rom, 0x148, SEEK_SET);
|
||||
fputc(headbyte, rom);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -88,14 +87,18 @@ lib_ReadLib0(FILE * f, SLONG size)
|
||||
while (size > 0) {
|
||||
if (l == NULL) {
|
||||
l = malloc(sizeof *l);
|
||||
if (!l)
|
||||
errx(5, "Out of memory");
|
||||
if (!l) {
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
first = l;
|
||||
} else {
|
||||
l->pNext = malloc(sizeof *l->pNext);
|
||||
if (!l->pNext)
|
||||
errx(5, "Out of memory");
|
||||
if (!l->pNext) {
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
l = l->pNext;
|
||||
}
|
||||
@@ -111,8 +114,10 @@ lib_ReadLib0(FILE * f, SLONG size)
|
||||
fread(l->pData, sizeof(UBYTE), l->nByteLength,
|
||||
f);
|
||||
size -= l->nByteLength;
|
||||
} else
|
||||
errx(5, "Out of memory");
|
||||
} else {
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
l->pNext = NULL;
|
||||
}
|
||||
@@ -148,8 +153,8 @@ lib_Read(char *filename)
|
||||
return (r);
|
||||
} else {
|
||||
fclose(f);
|
||||
errx(5, "Not a valid xLib library");
|
||||
return (NULL);
|
||||
fprintf(stderr, "Not a valid xLib library\n");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
printf
|
||||
@@ -185,8 +190,10 @@ lib_Write(sLibrary * lib, char *filename)
|
||||
sLibrary *
|
||||
lib_Find(sLibrary * lib, char *filename)
|
||||
{
|
||||
if (strlen(filename) >= MAXNAMELENGTH)
|
||||
errx(5, "Module name too long: %s", filename);
|
||||
if (strlen(filename) >= MAXNAMELENGTH) {
|
||||
fprintf(stderr, "Module name too long: %s\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (lib) {
|
||||
if (strcmp(lib->tName, filename) == 0)
|
||||
@@ -206,13 +213,18 @@ lib_AddReplace(sLibrary * lib, char *filename)
|
||||
if ((f = fopen(filename, "rb"))) {
|
||||
sLibrary *module;
|
||||
|
||||
if (strlen(filename) >= MAXNAMELENGTH)
|
||||
errx(5, "Module name too long: %s", filename);
|
||||
if (strlen(filename) >= MAXNAMELENGTH) {
|
||||
fprintf(stderr, "Module name too long: %s\n",
|
||||
filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((module = lib_Find(lib, filename)) == NULL) {
|
||||
module = malloc(sizeof *module);
|
||||
if (!module)
|
||||
errx(5, "Out of memory");
|
||||
if (!module) {
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
module->pNext = lib;
|
||||
lib = module;
|
||||
@@ -224,8 +236,10 @@ lib_AddReplace(sLibrary * lib, char *filename)
|
||||
module->nByteLength = file_Length(f);
|
||||
strcpy(module->tName, filename);
|
||||
module->pData = malloc(module->nByteLength);
|
||||
if (!module->pData)
|
||||
errx(5, "Out of memory");
|
||||
if (!module->pData) {
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fread(module->pData, sizeof(UBYTE), module->nByteLength, f);
|
||||
|
||||
@@ -245,8 +259,10 @@ lib_DeleteModule(sLibrary * lib, char *filename)
|
||||
pp = &lib;
|
||||
first = pp;
|
||||
|
||||
if (strlen(filename) >= MAXNAMELENGTH)
|
||||
errx(5, "Module name too long: %s", filename);
|
||||
if (strlen(filename) >= MAXNAMELENGTH) {
|
||||
fprintf(stderr, "Module name too long: %s\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while ((*pp) && (!found)) {
|
||||
if (strcmp((*pp)->tName, filename) == 0) {
|
||||
@@ -265,9 +281,10 @@ lib_DeleteModule(sLibrary * lib, char *filename)
|
||||
pp = &((*pp)->pNext);
|
||||
}
|
||||
|
||||
if (!found)
|
||||
errx(5, "Module not found");
|
||||
else
|
||||
if (!found) {
|
||||
fprintf(stderr, "Module not found\n");
|
||||
exit(1);
|
||||
} else
|
||||
printf("Module '%s' deleted from library\n", filename);
|
||||
|
||||
return (*first);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -83,11 +82,16 @@ main(int argc, char *argv[])
|
||||
printf
|
||||
("Extracted module '%s'\n",
|
||||
argv[argn]);
|
||||
} else
|
||||
err(1,
|
||||
"Unable to write module '%s'", argv[argn]);
|
||||
} else
|
||||
errx(1, "Module not found");
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"Unable to write module '%s': ", argv[argn]);
|
||||
perror(NULL);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Module not found\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
argn += 1;
|
||||
argc -= 1;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -71,8 +70,11 @@ area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
|
||||
size + pArea->nSize;
|
||||
|
||||
return (org);
|
||||
} else
|
||||
errx(5, "Out of memory!");
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"Out of memory!\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,8 +166,11 @@ AssignCodeSections(void)
|
||||
pSection->nBank = org >> 16;
|
||||
pSection->oAssigned = 1;
|
||||
DOMAXBANK(pSection->nBank);
|
||||
} else
|
||||
errx(5, "Unable to place CODE section anywhere");
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"Unable to place CODE section anywhere\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,8 +190,10 @@ AssignSections(void)
|
||||
for (i = 0; i < MAXBANKS; i += 1) {
|
||||
BankFree[i] = malloc(sizeof *BankFree[i]);
|
||||
|
||||
if (!BankFree[i])
|
||||
errx(5, "Out of memory!");
|
||||
if (!BankFree[i]) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
BankFree[i]->nOrg = 0x0000;
|
||||
@@ -244,7 +251,10 @@ AssignSections(void)
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_BSS], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
errx(5, "Unable to load fixed BSS section at $%lX", pSection->nOrg);
|
||||
fprintf(stderr,
|
||||
"Unable to load fixed BSS section "
|
||||
"at $%lX\n", pSection->nOrg);
|
||||
exit(1);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = BANK_BSS;
|
||||
@@ -253,7 +263,10 @@ AssignSections(void)
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_HRAM], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
errx(5, "Unable to load fixed HRAM section at $%lX", pSection->nOrg);
|
||||
fprintf(stderr, "Unable to load fixed "
|
||||
"HRAM section at $%lX\n",
|
||||
pSection->nOrg);
|
||||
exit(1);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = BANK_HRAM;
|
||||
@@ -262,7 +275,10 @@ AssignSections(void)
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_VRAM], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
errx(5, "Unable to load fixed VRAM section at $%lX", pSection->nOrg);
|
||||
fprintf(stderr, "Unable to load fixed "
|
||||
"VRAM section at $%lX\n",
|
||||
pSection->nOrg);
|
||||
exit(1);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = BANK_VRAM;
|
||||
@@ -271,7 +287,10 @@ AssignSections(void)
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_HOME], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
errx(5, "Unable to load fixed HOME section at $%lX", pSection->nOrg);
|
||||
fprintf(stderr, "Unable to load fixed "
|
||||
"HOME section at $%lX\n",
|
||||
pSection->nOrg);
|
||||
exit(1);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = BANK_HOME;
|
||||
@@ -316,13 +335,15 @@ AssignSections(void)
|
||||
pSection->
|
||||
nByteSize) !=
|
||||
pSection->nOrg) {
|
||||
errx(5, "Unable to load fixed CODE/DATA section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||
fprintf(stderr, "Unable to load fixed CODE/DATA section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
||||
exit(1);
|
||||
}
|
||||
DOMAXBANK(pSection->
|
||||
nBank);
|
||||
pSection->oAssigned = 1;
|
||||
} else {
|
||||
errx(5, "Unable to load fixed CODE/DATA section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||
fprintf(stderr, "Unable to load fixed CODE/DATA section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,12 +369,14 @@ AssignSections(void)
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[pSection->nBank],
|
||||
pSection->nByteSize)) == -1) {
|
||||
errx(5, "Unable to load fixed CODE/DATA section into bank $%02lX", pSection->nBank);
|
||||
fprintf(stderr, "Unable to load fixed CODE/DATA section into bank $%02lX\n", pSection->nBank);
|
||||
exit(1);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
DOMAXBANK(pSection->nBank);
|
||||
} else {
|
||||
errx(5, "Unable to load fixed CODE/DATA section into bank $%02lX", pSection->nBank);
|
||||
fprintf(stderr, "Unable to load fixed CODE/DATA section into bank $%02lX\n", pSection->nBank);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
pSection = pSection->pNext;
|
||||
@@ -375,7 +398,8 @@ AssignSections(void)
|
||||
area_AllocAbsCODEAnyBank(pSection->nOrg,
|
||||
pSection->nByteSize)) ==
|
||||
-1) {
|
||||
errx(5, "Unable to load fixed CODE/DATA section at $%lX into any bank", pSection->nOrg);
|
||||
fprintf(stderr, "Unable to load fixed CODE/DATA section at $%lX into any bank\n", pSection->nOrg);
|
||||
exit(1);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
DOMAXBANK(pSection->nBank);
|
||||
@@ -397,7 +421,8 @@ AssignSections(void)
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_BSS],
|
||||
pSection->nByteSize)) == -1) {
|
||||
errx(5, "BSS section too large");
|
||||
fprintf(stderr, "BSS section too large\n");
|
||||
exit(1);
|
||||
}
|
||||
pSection->nBank = BANK_BSS;
|
||||
pSection->oAssigned = 1;
|
||||
@@ -406,7 +431,8 @@ AssignSections(void)
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_HRAM],
|
||||
pSection->nByteSize)) == -1) {
|
||||
errx(5, "HRAM section too large");
|
||||
fprintf(stderr, "HRAM section too large\n");
|
||||
exit(1);
|
||||
}
|
||||
pSection->nBank = BANK_HRAM;
|
||||
pSection->oAssigned = 1;
|
||||
@@ -415,7 +441,8 @@ AssignSections(void)
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_VRAM],
|
||||
pSection->nByteSize)) == -1) {
|
||||
errx(5, "VRAM section too large");
|
||||
fprintf(stderr, "VRAM section too large\n");
|
||||
exit(1);
|
||||
}
|
||||
pSection->nBank = BANK_VRAM;
|
||||
pSection->oAssigned = 1;
|
||||
@@ -424,7 +451,8 @@ AssignSections(void)
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_HOME],
|
||||
pSection->nByteSize)) == -1) {
|
||||
errx(5, "HOME section too large");
|
||||
fprintf(stderr, "HOME section too large\n");
|
||||
exit(1);
|
||||
}
|
||||
pSection->nBank = BANK_HOME;
|
||||
pSection->oAssigned = 1;
|
||||
@@ -432,7 +460,8 @@ AssignSections(void)
|
||||
case SECT_CODE:
|
||||
break;
|
||||
default:
|
||||
errx(5, "(INTERNAL) Unknown section type!");
|
||||
fprintf(stderr, "(INTERNAL) Unknown section type!\n");
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -92,8 +91,9 @@ AddNeededModules(void)
|
||||
}
|
||||
if (options & OPT_SMART_C_LINK) {
|
||||
if (!addmodulecontaining(smartlinkstartsymbol)) {
|
||||
errx(5, "Can't find start symbol '%s'",
|
||||
fprintf(stderr, "Can't find start symbol '%s'\n",
|
||||
smartlinkstartsymbol);
|
||||
exit(1);
|
||||
} else
|
||||
printf("Smart linking with symbol '%s'\n",
|
||||
smartlinkstartsymbol);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -72,10 +71,14 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
case 'p':
|
||||
fillchar = strtoul(optarg, &ep, 0);
|
||||
if (optarg[0] == '\0' || *ep != '\0')
|
||||
errx(1, "Invalid argument for option 'p'");
|
||||
if (fillchar < 0 || fillchar > 0xFF)
|
||||
errx(1, "Argument for option 'p' must be between 0 and 0xFF");
|
||||
if (optarg[0] == '\0' || *ep != '\0') {
|
||||
fprintf(stderr, "Invalid argument for option 'p'\n");
|
||||
exit(1);
|
||||
}
|
||||
if (fillchar < 0 || fillchar > 0xFF) {
|
||||
fprintf(stderr, "Argument for option 'p' must be between 0 and 0xFF");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
options |= OPT_SMART_C_LINK;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -20,8 +19,11 @@ SetMapfileName(char *name)
|
||||
{
|
||||
mf = fopen(name, "w");
|
||||
|
||||
if (mf == NULL)
|
||||
err(1, "Cannot open mapfile '%s'", name);
|
||||
if (mf == NULL) {
|
||||
fprintf(stderr, "Cannot open mapfile '%s': ", name);
|
||||
perror(NULL);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -29,8 +31,10 @@ SetSymfileName(char *name)
|
||||
{
|
||||
sf = fopen(name, "w");
|
||||
|
||||
if (sf == NULL)
|
||||
errx(1, "Cannot open symfile '%s'", name);
|
||||
if (sf == NULL) {
|
||||
fprintf(stderr, "Cannot open symfile '%s'\n", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -81,8 +80,8 @@ AllocSection(void)
|
||||
|
||||
*ppSections = malloc(sizeof **ppSections);
|
||||
if (!*ppSections) {
|
||||
errx(5, "Out of memory!");
|
||||
return NULL;
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
exit(1);
|
||||
}
|
||||
(*ppSections)->tSymbols = tSymbols;
|
||||
(*ppSections)->pNext = NULL;
|
||||
@@ -102,13 +101,17 @@ obj_ReadSymbol(FILE * f)
|
||||
struct sSymbol *pSym;
|
||||
|
||||
pSym = malloc(sizeof *pSym);
|
||||
if (!pSym)
|
||||
errx(5, "Out of memory!");
|
||||
if (!pSym) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
readasciiz(s, f);
|
||||
pSym->pzName = malloc(strlen(s) + 1);
|
||||
if (!pSym->pzName)
|
||||
errx(5, "Out of memory!");
|
||||
if (!pSym->pzName) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
strcpy(pSym->pzName, s);
|
||||
if ((pSym->Type = (enum eSymbolType) fgetc(f)) != SYM_IMPORT) {
|
||||
@@ -146,8 +149,9 @@ obj_ReadRGB0Section(FILE * f)
|
||||
*/
|
||||
if (pSection->nByteSize) {
|
||||
pSection->pData = malloc(pSection->nByteSize);
|
||||
if (!pSection->pData)
|
||||
errx(5, "Out of memory!");
|
||||
if (!pSection->pData) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
}
|
||||
|
||||
SLONG nNumberOfPatches;
|
||||
struct sPatch **ppPatch, *pPatch;
|
||||
@@ -164,15 +168,17 @@ obj_ReadRGB0Section(FILE * f)
|
||||
*/
|
||||
while (nNumberOfPatches--) {
|
||||
pPatch = malloc(sizeof *pPatch);
|
||||
if (!pPatch)
|
||||
errx(5, "Out of memory!");
|
||||
if (!pPatch) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
}
|
||||
|
||||
*ppPatch = pPatch;
|
||||
readasciiz(s, f);
|
||||
|
||||
pPatch->pzFilename = malloc(strlen(s) + 1);
|
||||
if (!pPatch->pzFilename)
|
||||
errx(5, "Out of memory!");
|
||||
if (!pPatch->pzFilename) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
}
|
||||
|
||||
strcpy(pPatch->pzFilename, s);
|
||||
|
||||
@@ -186,8 +192,10 @@ obj_ReadRGB0Section(FILE * f)
|
||||
|
||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||
if (!pPatch->pRPN)
|
||||
errx(5, "Out of memory!");
|
||||
if (!pPatch->pRPN) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||
pPatch->nRPNSize, f);
|
||||
@@ -219,8 +227,10 @@ obj_ReadRGB0(FILE * pObjfile)
|
||||
|
||||
if (nNumberOfSymbols) {
|
||||
tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
|
||||
if (!tSymbols)
|
||||
errx(5, "Out of memory!");
|
||||
if (!tSymbols) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||
@@ -294,8 +304,10 @@ obj_ReadRGB1Section(FILE * f)
|
||||
*/
|
||||
if (pSection->nByteSize) {
|
||||
pSection->pData = malloc(pSection->nByteSize);
|
||||
if (!pSection->pData)
|
||||
errx(5, "Out of memory!");
|
||||
if (!pSection->pData) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
SLONG nNumberOfPatches;
|
||||
struct sPatch **ppPatch, *pPatch;
|
||||
@@ -312,14 +324,16 @@ obj_ReadRGB1Section(FILE * f)
|
||||
*/
|
||||
while (nNumberOfPatches--) {
|
||||
pPatch = malloc(sizeof *pPatch);
|
||||
if (!pPatch)
|
||||
errx(5, "Out of memory!");
|
||||
if (!pPatch) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
}
|
||||
|
||||
*ppPatch = pPatch;
|
||||
readasciiz(s, f);
|
||||
pPatch->pzFilename = malloc(strlen(s) + 1);
|
||||
if (!pPatch->pzFilename)
|
||||
errx(5, "Out of memory!");
|
||||
if (!pPatch->pzFilename) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
}
|
||||
|
||||
strcpy(pPatch->pzFilename, s);
|
||||
pPatch->nLineNo = readlong(f);
|
||||
@@ -327,8 +341,9 @@ obj_ReadRGB1Section(FILE * f)
|
||||
pPatch->Type = (enum ePatchType) fgetc(f);
|
||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||
if (!pPatch->pRPN)
|
||||
errx(5, "Out of memory!");
|
||||
if (!pPatch->pRPN) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
}
|
||||
|
||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||
pPatch->nRPNSize, f);
|
||||
@@ -360,8 +375,9 @@ obj_ReadRGB1(FILE * pObjfile)
|
||||
|
||||
if (nNumberOfSymbols) {
|
||||
tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols);
|
||||
if (!tSymbols)
|
||||
errx(5, "Out of memory!");
|
||||
if (!tSymbols) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
}
|
||||
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||
@@ -424,12 +440,14 @@ obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
||||
obj_ReadRGB1(pObjfile);
|
||||
break;
|
||||
default:
|
||||
errx(5, "'%s' is an unsupported version",
|
||||
fprintf(stderr, "'%s' is an unsupported version",
|
||||
tzObjectfile);
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
errx(5, "'%s' is not a valid object", tzObjectfile);
|
||||
fprintf(stderr, "'%s' is not a valid object\n", tzObjectfile);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,9 +462,12 @@ obj_Readfile(char *tzObjectfile)
|
||||
oReadLib = 0;
|
||||
|
||||
pObjfile = fopen(tzObjectfile, "rb");
|
||||
if (pObjfile == NULL)
|
||||
err(1, "Unable to open object '%s'",
|
||||
if (pObjfile == NULL) {
|
||||
fprintf(stderr, "Unable to open object '%s': ",
|
||||
tzObjectfile);
|
||||
perror(NULL);
|
||||
exit(1);
|
||||
}
|
||||
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
||||
fclose(pObjfile);
|
||||
|
||||
@@ -494,10 +515,14 @@ lib_Readfile(char *tzLibfile)
|
||||
oReadLib = 1;
|
||||
|
||||
pObjfile = fopen(tzLibfile, "rb");
|
||||
if (pObjfile == NULL)
|
||||
err(1, "Unable to open object '%s'", tzLibfile);
|
||||
if (pObjfile == NULL) {
|
||||
fprintf(stderr, "Unable to open object '%s': ", tzLibfile);
|
||||
perror(NULL);
|
||||
exit(1);
|
||||
}
|
||||
if (!pObjfile) {
|
||||
errx(5, "Unable to open '%s'", tzLibfile);
|
||||
fprintf(stderr, "Unable to open '%s'\n", tzLibfile);
|
||||
exit(1);
|
||||
}
|
||||
char tzHeader[5];
|
||||
|
||||
@@ -506,8 +531,9 @@ lib_Readfile(char *tzLibfile)
|
||||
if (strcmp(tzHeader, "XLB0") == 0)
|
||||
lib_ReadXLB0(pObjfile);
|
||||
else {
|
||||
errx(5, "'%s' is an invalid library",
|
||||
fprintf(stderr, "'%s' is an invalid library\n",
|
||||
tzLibfile);
|
||||
exit(1);
|
||||
}
|
||||
fclose(pObjfile);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "link/mylink.h"
|
||||
@@ -46,7 +46,8 @@ getsymvalue(SLONG symid)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
errx(5, "*INTERNAL* UNKNOWN SYMBOL TYPE");
|
||||
fprintf(stderr, "*INTERNAL* UNKNOWN SYMBOL TYPE\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
SLONG
|
||||
@@ -63,7 +64,8 @@ getsymbank(SLONG symid)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
errx(5, "*INTERNAL* UNKNOWN SYMBOL TYPE");
|
||||
fprintf(stderr, "*INTERNAL* UNKNOWN SYMBOL TYPE\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
SLONG
|
||||
@@ -157,18 +159,20 @@ calcrpn(struct sPatch * pPatch)
|
||||
t = rpnpop();
|
||||
rpnpush(t & 0xFF);
|
||||
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
|
||||
errx(5,
|
||||
"%s(%ld) : Value must be in the HRAM area",
|
||||
fprintf(stderr,
|
||||
"%s(%ld) : Value must be in the HRAM area\n",
|
||||
pPatch->pzFilename, pPatch->nLineNo);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case RPN_PCEZP:
|
||||
t = rpnpop();
|
||||
rpnpush(t & 0xFF);
|
||||
if (t < 0x2000 || t > 0x20FF) {
|
||||
errx(5,
|
||||
"%s(%ld) : Value must be in the ZP area",
|
||||
fprintf(stderr,
|
||||
"%s(%ld) : Value must be in the ZP area\n",
|
||||
pPatch->pzFilename, pPatch->nLineNo);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case RPN_CONST:
|
||||
@@ -213,10 +217,11 @@ calcrpn(struct sPatch * pPatch)
|
||||
high |= (*rpn++) << 24;
|
||||
t = rpnpop();
|
||||
if (t < low || t > high) {
|
||||
errx(5,
|
||||
"%s(%ld) : Value must be in the range [%ld;%ld]",
|
||||
fprintf(stderr,
|
||||
"%s(%ld) : Value must be in the range [%ld;%ld]\n",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo, low, high);
|
||||
exit(1);
|
||||
}
|
||||
rpnpush(t);
|
||||
size -= 8;
|
||||
@@ -250,10 +255,11 @@ Patch(void)
|
||||
pSect->pData[pPatch->nOffset] =
|
||||
(UBYTE) t;
|
||||
} else {
|
||||
errx(5,
|
||||
fprintf(stderr,
|
||||
"%s(%ld) : Value must be 8-bit\n",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case PATCH_WORD_L:
|
||||
@@ -274,10 +280,11 @@ Patch(void)
|
||||
1] = t & 0xFF;
|
||||
}
|
||||
} else {
|
||||
errx(5,
|
||||
fprintf(stderr,
|
||||
"%s(%ld) : Value must be 16-bit\n",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case PATCH_LONG_L:
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -54,7 +53,8 @@ sym_GetValue(char *tzName)
|
||||
}
|
||||
}
|
||||
|
||||
errx(5, "Unknown symbol '%s'", tzName);
|
||||
fprintf(stderr, "Unknown symbol '%s'\n", tzName);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,8 @@ sym_GetBank(char *tzName)
|
||||
}
|
||||
}
|
||||
|
||||
errx(5, "Unknown symbol '%s'", tzName);
|
||||
fprintf(stderr, "Unknown symbol '%s'\n", tzName);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -92,9 +93,10 @@ sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
|
||||
if (nBank == -1)
|
||||
return;
|
||||
|
||||
errx(5,
|
||||
fprintf(stderr,
|
||||
"Symbol '%s' defined more than once\n",
|
||||
tzName);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user