Remove nonstandard <err.h>.

This provides some really nice functions, but does not exist in some
environments (particularly MinGW).
This commit is contained in:
Anthony J. Bentley
2011-12-02 01:23:23 -07:00
parent b1a2c664a9
commit 5d6559f15f
12 changed files with 315 additions and 167 deletions

View File

@@ -5,7 +5,6 @@
* *
*/ */
#include <err.h>
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -136,7 +135,9 @@ opt_Parse(char *s)
newopt.gbgfx[2] = s[3]; newopt.gbgfx[2] = s[3];
newopt.gbgfx[3] = s[4]; newopt.gbgfx[3] = s[4];
} else { } 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; break;
case 'b': case 'b':
@@ -144,7 +145,9 @@ opt_Parse(char *s)
newopt.binary[0] = s[1]; newopt.binary[0] = s[1];
newopt.binary[1] = s[2]; newopt.binary[1] = s[2];
} else { } 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; break;
case 'z': case 'z':
@@ -153,10 +156,13 @@ opt_Parse(char *s)
result = sscanf(&s[1], "%lx", &newopt.fillchar); result = sscanf(&s[1], "%lx", &newopt.fillchar);
if (!((result == EOF) || (result == 1))) { if (!((result == EOF) || (result == 1))) {
errx(5, "Invalid argument for option 'z'"); fprintf(stderr,
"Invalid argument for option 'z'\n");
exit(1);
} }
} else { } else {
errx(5, "Invalid argument for option 'z'"); fprintf(stderr, "Invalid argument for option 'z'\n");
exit(1);
} }
break; break;
default: default:
@@ -273,7 +279,9 @@ main(int argc, char *argv[])
newopt.binary[0] = optarg[1]; newopt.binary[0] = optarg[1];
newopt.binary[1] = optarg[2]; newopt.binary[1] = optarg[2];
} else { } 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': case 'g':
if (strlen(optarg) == 4) { if (strlen(optarg) == 4) {
@@ -282,7 +290,9 @@ main(int argc, char *argv[])
newopt.gbgfx[2] = optarg[3]; newopt.gbgfx[2] = optarg[3];
newopt.gbgfx[3] = optarg[4]; newopt.gbgfx[3] = optarg[4];
} else { } 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; break;
case 'i': case 'i':
@@ -293,10 +303,16 @@ main(int argc, char *argv[])
break; break;
case 'p': case 'p':
newopt.fillchar = strtoul(optarg, &ep, 0); newopt.fillchar = strtoul(optarg, &ep, 0);
if (optarg[0] == '\0' || *ep != '\0') if (optarg[0] == '\0' || *ep != '\0') {
errx(1, "Invalid argument for option 'p'"); fprintf(stderr,
if (newopt.fillchar < 0 || newopt.fillchar > 0xFF) "Invalid argument for option 'p'\n");
errx(1, "Argument for option 'p' must be between 0 and 0xFF"); 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; break;
default: default:
PrintUsage(); PrintUsage();
@@ -374,14 +390,16 @@ main(int argc, char *argv[])
exit(5); exit(5);
} }
} else { } else {
errx(5, "Unterminated IF construct (%ld levels)!", fprintf(stderr,
"Unterminated IF construct (%ld levels)!\n",
nIFDepth); nIFDepth);
exit(5); exit(1);
} }
} else { } else {
printf("Assembly aborted in pass 1 (%ld errors)!\n", fprintf(stderr,
"Assembly aborted in pass 1 (%ld errors)!\n",
nErrors); nErrors);
exit(5); exit(1);
} }
} else { } else {
printf("File '%s' not found\n", tzMainfile); printf("File '%s' not found\n", tzMainfile);

View File

@@ -1,6 +1,5 @@
%{ %{
#include <ctype.h> #include <ctype.h>
#include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View File

@@ -14,7 +14,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <err.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -44,8 +43,11 @@ main(int argc, char *argv[])
if (argc < 2) if (argc < 2)
usage(); usage();
if ((rom = fopen(argv[argc - 1], "rb+")) == NULL) if ((rom = fopen(argv[argc - 1], "rb+")) == NULL) {
err(1, "Error opening file %s", argv[argc - 1]); fprintf(stderr, "Error opening file %s: \n", argv[argc - 1]);
perror(NULL);
exit(1);
}
/* /*
* Parse command-line options * Parse command-line options
@@ -88,9 +90,12 @@ main(int argc, char *argv[])
case 'k': case 'k':
setnewlicensee = true; setnewlicensee = true;
if (strlen(optarg) != 2) if (strlen(optarg) != 2) {
errx(1, "New licensee code %s is not the " fprintf(stderr,
"correct length of 2 characters", optarg); "New licensee code %s is not the correct "
"length of 2 characters\n", optarg);
exit(1);
}
newlicensee = optarg; newlicensee = optarg;
break; break;
@@ -98,51 +103,80 @@ main(int argc, char *argv[])
setlicensee = true; setlicensee = true;
licensee = strtoul(optarg, &ep, 0); licensee = strtoul(optarg, &ep, 0);
if (optarg[0] == '\0' || *ep != '\0') if (optarg[0] == '\0' || *ep != '\0') {
errx(1, "Invalid argument for option 'l'"); fprintf(stderr,
if (licensee < 0 || licensee > 0xFF) "Invalid argument for option 'l'\n");
errx(1, "Argument for option 'l' must be " exit(1);
"between 0 and 255"); }
if (licensee < 0 || licensee > 0xFF) {
fprintf(stderr,
"Argument for option 'l' must be "
"between 0 and 255\n");
exit(1);
}
break; break;
case 'm': case 'm':
setcartridge = true; setcartridge = true;
cartridge = strtoul(optarg, &ep, 0); cartridge = strtoul(optarg, &ep, 0);
if (optarg[0] == '\0' || *ep != '\0') if (optarg[0] == '\0' || *ep != '\0') {
errx(1, "Invalid argument for option 'm'"); fprintf(stderr,
if (cartridge < 0 || cartridge > 0xFF) "Invalid argument for option 'm'\n");
errx(1, "Argument for option 'm' must be " exit(1);
"between 0 and 255"); }
if (cartridge < 0 || cartridge > 0xFF) {
fprintf(stderr,
"Argument for option 'm' must be "
"between 0 and 255\n");
exit(1);
}
break; break;
case 'n': case 'n':
setversion = true; setversion = true;
version = strtoul(optarg, &ep, 0); version = strtoul(optarg, &ep, 0);
if (optarg[0] == '\0' || *ep != '\0') if (optarg[0] == '\0' || *ep != '\0') {
errx(1, "Invalid argument for option 'n'"); fprintf(stderr,
if (version < 0 || version > 0xFF) "Invalid argument for option 'n'\n");
errx(1, "Argument for option 'n' must be " exit(1);
"between 0 and 255"); }
if (version < 0 || version > 0xFF) {
fprintf(stderr,
"Argument for option 'n' must be "
"between 0 and 255\n");
exit(1);
}
break; break;
case 'p': case 'p':
resize = true; resize = true;
padvalue = strtoul(optarg, &ep, 0); padvalue = strtoul(optarg, &ep, 0);
if (optarg[0] == '\0' || *ep != '\0') if (optarg[0] == '\0' || *ep != '\0') {
errx(1, "Invalid argument for option 'p'"); fprintf(stderr,
if (padvalue < 0 || padvalue > 0xFF) "Invalid argument for option 'p'\n");
errx(1, "Argument for option 'p' must be " exit(1);
"between 0 and 255"); }
if (padvalue < 0 || padvalue > 0xFF) {
fprintf(stderr,
"Argument for option 'p' must be "
"between 0 and 255\n");
exit(1);
}
break; break;
case 'r': case 'r':
setramsize = true; setramsize = true;
ramsize = strtoul(optarg, &ep, 0); ramsize = strtoul(optarg, &ep, 0);
if (optarg[0] == '\0' || *ep != '\0') if (optarg[0] == '\0' || *ep != '\0') {
errx(1, "Invalid argument for option 'r'"); fprintf(stderr,
if (ramsize < 0 || ramsize > 0xFF) "Invalid argument for option 'r'\n");
errx(1, "Argument for option 'r' must be " }
"between 0 and 255"); if (ramsize < 0 || ramsize > 0xFF) {
fprintf(stderr,
"Argument for option 'r' must be "
"between 0 and 255\n");
exit(1);
}
break; break;
case 's': case 's':
super = true; super = true;
@@ -150,13 +184,16 @@ main(int argc, char *argv[])
case 't': case 't':
settitle = true; settitle = true;
if (strlen(optarg) > 16) if (strlen(optarg) > 16) {
errx(1, "Title %s is greater than the " fprintf(stderr, "Title %s is greater than the "
"maximum of 16 characters", optarg); "maximum of 16 characters\n", optarg);
exit(1);
}
if (strlen(optarg) == 16) if (strlen(optarg) == 16)
warnx("Title %s is 16 chars, it is best " fprintf(stderr,
"to keep it to 15 or fewer", optarg); "Title %s is 16 chars, it is best "
"to keep it to 15 or fewer\n", optarg);
title = optarg; title = optarg;
break; break;
@@ -246,7 +283,8 @@ main(int argc, char *argv[])
byte |= 1 << 6; byte |= 1 << 6;
if (byte & 0x3F) if (byte & 0x3F)
warnx("Color flag conflicts with game title"); fprintf(stderr,
"Color flag conflicts with game title\n");
fseek(rom, 0x143, SEEK_SET); fseek(rom, 0x143, SEEK_SET);
fputc(byte, rom); fputc(byte, rom);
@@ -283,8 +321,9 @@ main(int argc, char *argv[])
*/ */
if (!setlicensee) if (!setlicensee)
warnx("You should probably set both '-s' and " fprintf(stderr,
"'-l 0x33'"); "You should probably set both '-s' and "
"'-l 0x33'\n");
fseek(rom, 0x146, SEEK_SET); fseek(rom, 0x146, SEEK_SET);
fputc(3, rom); fputc(3, rom);
@@ -323,7 +362,7 @@ main(int argc, char *argv[])
fputc(padvalue, rom); fputc(padvalue, rom);
if (newsize > 0x800000) /* ROM is bigger than 8MiB */ 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); fseek(rom, 0x148, SEEK_SET);
fputc(headbyte, rom); fputc(headbyte, rom);

View File

@@ -1,4 +1,3 @@
#include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -88,14 +87,18 @@ lib_ReadLib0(FILE * f, SLONG size)
while (size > 0) { while (size > 0) {
if (l == NULL) { if (l == NULL) {
l = malloc(sizeof *l); l = malloc(sizeof *l);
if (!l) if (!l) {
errx(5, "Out of memory"); fprintf(stderr, "Out of memory\n");
exit(1);
}
first = l; first = l;
} else { } else {
l->pNext = malloc(sizeof *l->pNext); l->pNext = malloc(sizeof *l->pNext);
if (!l->pNext) if (!l->pNext) {
errx(5, "Out of memory"); fprintf(stderr, "Out of memory\n");
exit(1);
}
l = l->pNext; l = l->pNext;
} }
@@ -111,8 +114,10 @@ lib_ReadLib0(FILE * f, SLONG size)
fread(l->pData, sizeof(UBYTE), l->nByteLength, fread(l->pData, sizeof(UBYTE), l->nByteLength,
f); f);
size -= l->nByteLength; size -= l->nByteLength;
} else } else {
errx(5, "Out of memory"); fprintf(stderr, "Out of memory\n");
exit(1);
}
l->pNext = NULL; l->pNext = NULL;
} }
@@ -148,8 +153,8 @@ lib_Read(char *filename)
return (r); return (r);
} else { } else {
fclose(f); fclose(f);
errx(5, "Not a valid xLib library"); fprintf(stderr, "Not a valid xLib library\n");
return (NULL); exit(1);
} }
} else { } else {
printf printf
@@ -185,8 +190,10 @@ lib_Write(sLibrary * lib, char *filename)
sLibrary * sLibrary *
lib_Find(sLibrary * lib, char *filename) lib_Find(sLibrary * lib, char *filename)
{ {
if (strlen(filename) >= MAXNAMELENGTH) if (strlen(filename) >= MAXNAMELENGTH) {
errx(5, "Module name too long: %s", filename); fprintf(stderr, "Module name too long: %s\n", filename);
exit(1);
}
while (lib) { while (lib) {
if (strcmp(lib->tName, filename) == 0) if (strcmp(lib->tName, filename) == 0)
@@ -206,13 +213,18 @@ lib_AddReplace(sLibrary * lib, char *filename)
if ((f = fopen(filename, "rb"))) { if ((f = fopen(filename, "rb"))) {
sLibrary *module; sLibrary *module;
if (strlen(filename) >= MAXNAMELENGTH) if (strlen(filename) >= MAXNAMELENGTH) {
errx(5, "Module name too long: %s", filename); fprintf(stderr, "Module name too long: %s\n",
filename);
exit(1);
}
if ((module = lib_Find(lib, filename)) == NULL) { if ((module = lib_Find(lib, filename)) == NULL) {
module = malloc(sizeof *module); module = malloc(sizeof *module);
if (!module) if (!module) {
errx(5, "Out of memory"); fprintf(stderr, "Out of memory\n");
exit(1);
}
module->pNext = lib; module->pNext = lib;
lib = module; lib = module;
@@ -224,8 +236,10 @@ lib_AddReplace(sLibrary * lib, char *filename)
module->nByteLength = file_Length(f); module->nByteLength = file_Length(f);
strcpy(module->tName, filename); strcpy(module->tName, filename);
module->pData = malloc(module->nByteLength); module->pData = malloc(module->nByteLength);
if (!module->pData) if (!module->pData) {
errx(5, "Out of memory"); fprintf(stderr, "Out of memory\n");
exit(1);
}
fread(module->pData, sizeof(UBYTE), module->nByteLength, f); fread(module->pData, sizeof(UBYTE), module->nByteLength, f);
@@ -245,8 +259,10 @@ lib_DeleteModule(sLibrary * lib, char *filename)
pp = &lib; pp = &lib;
first = pp; first = pp;
if (strlen(filename) >= MAXNAMELENGTH) if (strlen(filename) >= MAXNAMELENGTH) {
errx(5, "Module name too long: %s", filename); fprintf(stderr, "Module name too long: %s\n", filename);
exit(1);
}
while ((*pp) && (!found)) { while ((*pp) && (!found)) {
if (strcmp((*pp)->tName, filename) == 0) { if (strcmp((*pp)->tName, filename) == 0) {
@@ -265,9 +281,10 @@ lib_DeleteModule(sLibrary * lib, char *filename)
pp = &((*pp)->pNext); pp = &((*pp)->pNext);
} }
if (!found) if (!found) {
errx(5, "Module not found"); fprintf(stderr, "Module not found\n");
else exit(1);
} else
printf("Module '%s' deleted from library\n", filename); printf("Module '%s' deleted from library\n", filename);
return (*first); return (*first);

View File

@@ -1,5 +1,4 @@
#include <ctype.h> #include <ctype.h>
#include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -83,11 +82,16 @@ main(int argc, char *argv[])
printf printf
("Extracted module '%s'\n", ("Extracted module '%s'\n",
argv[argn]); argv[argn]);
} else } else {
err(1, fprintf(stderr,
"Unable to write module '%s'", argv[argn]); "Unable to write module '%s': ", argv[argn]);
} else perror(NULL);
errx(1, "Module not found"); exit(1);
}
} else {
fprintf(stderr, "Module not found\n");
exit(1);
}
argn += 1; argn += 1;
argc -= 1; argc -= 1;

View File

@@ -1,4 +1,3 @@
#include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -71,8 +70,11 @@ area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
size + pArea->nSize; size + pArea->nSize;
return (org); return (org);
} else } else {
errx(5, "Out of memory!"); fprintf(stderr,
"Out of memory!\n");
exit(1);
}
} }
} }
} }
@@ -164,8 +166,11 @@ AssignCodeSections(void)
pSection->nBank = org >> 16; pSection->nBank = org >> 16;
pSection->oAssigned = 1; pSection->oAssigned = 1;
DOMAXBANK(pSection->nBank); DOMAXBANK(pSection->nBank);
} else } else {
errx(5, "Unable to place CODE section anywhere"); fprintf(stderr,
"Unable to place CODE section anywhere\n");
exit(1);
}
} }
} }
@@ -185,8 +190,10 @@ AssignSections(void)
for (i = 0; i < MAXBANKS; i += 1) { for (i = 0; i < MAXBANKS; i += 1) {
BankFree[i] = malloc(sizeof *BankFree[i]); BankFree[i] = malloc(sizeof *BankFree[i]);
if (!BankFree[i]) if (!BankFree[i]) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
exit(1);
}
if (i == 0) { if (i == 0) {
BankFree[i]->nOrg = 0x0000; BankFree[i]->nOrg = 0x0000;
@@ -244,7 +251,10 @@ 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) {
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->oAssigned = 1;
pSection->nBank = BANK_BSS; pSection->nBank = BANK_BSS;
@@ -253,7 +263,10 @@ 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) {
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->oAssigned = 1;
pSection->nBank = BANK_HRAM; pSection->nBank = BANK_HRAM;
@@ -262,7 +275,10 @@ 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) {
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->oAssigned = 1;
pSection->nBank = BANK_VRAM; pSection->nBank = BANK_VRAM;
@@ -271,7 +287,10 @@ 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) {
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->oAssigned = 1;
pSection->nBank = BANK_HOME; pSection->nBank = BANK_HOME;
@@ -316,13 +335,15 @@ AssignSections(void)
pSection-> pSection->
nByteSize) != nByteSize) !=
pSection->nOrg) { 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-> DOMAXBANK(pSection->
nBank); nBank);
pSection->oAssigned = 1; pSection->oAssigned = 1;
} else { } 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 = if ((pSection->nOrg =
area_Alloc(&BankFree[pSection->nBank], area_Alloc(&BankFree[pSection->nBank],
pSection->nByteSize)) == -1) { 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; pSection->oAssigned = 1;
DOMAXBANK(pSection->nBank); DOMAXBANK(pSection->nBank);
} else { } 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; pSection = pSection->pNext;
@@ -375,7 +398,8 @@ AssignSections(void)
area_AllocAbsCODEAnyBank(pSection->nOrg, area_AllocAbsCODEAnyBank(pSection->nOrg,
pSection->nByteSize)) == pSection->nByteSize)) ==
-1) { -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; pSection->oAssigned = 1;
DOMAXBANK(pSection->nBank); DOMAXBANK(pSection->nBank);
@@ -397,7 +421,8 @@ AssignSections(void)
if ((pSection->nOrg = if ((pSection->nOrg =
area_Alloc(&BankFree[BANK_BSS], area_Alloc(&BankFree[BANK_BSS],
pSection->nByteSize)) == -1) { pSection->nByteSize)) == -1) {
errx(5, "BSS section too large"); fprintf(stderr, "BSS section too large\n");
exit(1);
} }
pSection->nBank = BANK_BSS; pSection->nBank = BANK_BSS;
pSection->oAssigned = 1; pSection->oAssigned = 1;
@@ -406,7 +431,8 @@ AssignSections(void)
if ((pSection->nOrg = if ((pSection->nOrg =
area_Alloc(&BankFree[BANK_HRAM], area_Alloc(&BankFree[BANK_HRAM],
pSection->nByteSize)) == -1) { pSection->nByteSize)) == -1) {
errx(5, "HRAM section too large"); fprintf(stderr, "HRAM section too large\n");
exit(1);
} }
pSection->nBank = BANK_HRAM; pSection->nBank = BANK_HRAM;
pSection->oAssigned = 1; pSection->oAssigned = 1;
@@ -415,7 +441,8 @@ AssignSections(void)
if ((pSection->nOrg = if ((pSection->nOrg =
area_Alloc(&BankFree[BANK_VRAM], area_Alloc(&BankFree[BANK_VRAM],
pSection->nByteSize)) == -1) { pSection->nByteSize)) == -1) {
errx(5, "VRAM section too large"); fprintf(stderr, "VRAM section too large\n");
exit(1);
} }
pSection->nBank = BANK_VRAM; pSection->nBank = BANK_VRAM;
pSection->oAssigned = 1; pSection->oAssigned = 1;
@@ -424,7 +451,8 @@ AssignSections(void)
if ((pSection->nOrg = if ((pSection->nOrg =
area_Alloc(&BankFree[BANK_HOME], area_Alloc(&BankFree[BANK_HOME],
pSection->nByteSize)) == -1) { pSection->nByteSize)) == -1) {
errx(5, "HOME section too large"); fprintf(stderr, "HOME section too large\n");
exit(1);
} }
pSection->nBank = BANK_HOME; pSection->nBank = BANK_HOME;
pSection->oAssigned = 1; pSection->oAssigned = 1;
@@ -432,7 +460,8 @@ AssignSections(void)
case SECT_CODE: case SECT_CODE:
break; break;
default: default:
errx(5, "(INTERNAL) Unknown section type!"); fprintf(stderr, "(INTERNAL) Unknown section type!\n");
exit(1);
break; break;
} }
} }

View File

@@ -1,4 +1,3 @@
#include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -92,8 +91,9 @@ AddNeededModules(void)
} }
if (options & OPT_SMART_C_LINK) { if (options & OPT_SMART_C_LINK) {
if (!addmodulecontaining(smartlinkstartsymbol)) { if (!addmodulecontaining(smartlinkstartsymbol)) {
errx(5, "Can't find start symbol '%s'", fprintf(stderr, "Can't find start symbol '%s'\n",
smartlinkstartsymbol); smartlinkstartsymbol);
exit(1);
} else } else
printf("Smart linking with symbol '%s'\n", printf("Smart linking with symbol '%s'\n",
smartlinkstartsymbol); smartlinkstartsymbol);

View File

@@ -1,4 +1,3 @@
#include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -72,10 +71,14 @@ main(int argc, char *argv[])
break; break;
case 'p': case 'p':
fillchar = strtoul(optarg, &ep, 0); fillchar = strtoul(optarg, &ep, 0);
if (optarg[0] == '\0' || *ep != '\0') if (optarg[0] == '\0' || *ep != '\0') {
errx(1, "Invalid argument for option 'p'"); fprintf(stderr, "Invalid argument for option 'p'\n");
if (fillchar < 0 || fillchar > 0xFF) exit(1);
errx(1, "Argument for option 'p' must be between 0 and 0xFF"); }
if (fillchar < 0 || fillchar > 0xFF) {
fprintf(stderr, "Argument for option 'p' must be between 0 and 0xFF");
exit(1);
}
break; break;
case 's': case 's':
options |= OPT_SMART_C_LINK; options |= OPT_SMART_C_LINK;

View File

@@ -1,4 +1,3 @@
#include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -20,8 +19,11 @@ SetMapfileName(char *name)
{ {
mf = fopen(name, "w"); mf = fopen(name, "w");
if (mf == NULL) if (mf == NULL) {
err(1, "Cannot open mapfile '%s'", name); fprintf(stderr, "Cannot open mapfile '%s': ", name);
perror(NULL);
exit(1);
}
} }
void void
@@ -29,8 +31,10 @@ SetSymfileName(char *name)
{ {
sf = fopen(name, "w"); sf = fopen(name, "w");
if (sf == NULL) if (sf == NULL) {
errx(1, "Cannot open symfile '%s'", name); fprintf(stderr, "Cannot open symfile '%s'\n", name);
exit(1);
}
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n"); fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
} }

View File

@@ -3,7 +3,6 @@
* *
*/ */
#include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -81,8 +80,8 @@ AllocSection(void)
*ppSections = malloc(sizeof **ppSections); *ppSections = malloc(sizeof **ppSections);
if (!*ppSections) { if (!*ppSections) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
return NULL; exit(1);
} }
(*ppSections)->tSymbols = tSymbols; (*ppSections)->tSymbols = tSymbols;
(*ppSections)->pNext = NULL; (*ppSections)->pNext = NULL;
@@ -102,13 +101,17 @@ obj_ReadSymbol(FILE * f)
struct sSymbol *pSym; struct sSymbol *pSym;
pSym = malloc(sizeof *pSym); pSym = malloc(sizeof *pSym);
if (!pSym) if (!pSym) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
exit(1);
}
readasciiz(s, f); readasciiz(s, f);
pSym->pzName = malloc(strlen(s) + 1); pSym->pzName = malloc(strlen(s) + 1);
if (!pSym->pzName) if (!pSym->pzName) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
exit(1);
}
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) {
@@ -146,8 +149,9 @@ 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) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
}
SLONG nNumberOfPatches; SLONG nNumberOfPatches;
struct sPatch **ppPatch, *pPatch; struct sPatch **ppPatch, *pPatch;
@@ -164,15 +168,17 @@ obj_ReadRGB0Section(FILE * f)
*/ */
while (nNumberOfPatches--) { while (nNumberOfPatches--) {
pPatch = malloc(sizeof *pPatch); pPatch = malloc(sizeof *pPatch);
if (!pPatch) if (!pPatch) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
}
*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) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
}
strcpy(pPatch->pzFilename, s); strcpy(pPatch->pzFilename, s);
@@ -186,8 +192,10 @@ 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) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
exit(1);
}
fread(pPatch->pRPN, sizeof(UBYTE), fread(pPatch->pRPN, sizeof(UBYTE),
pPatch->nRPNSize, f); pPatch->nRPNSize, f);
@@ -219,8 +227,10 @@ obj_ReadRGB0(FILE * pObjfile)
if (nNumberOfSymbols) { if (nNumberOfSymbols) {
tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *)); tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
if (!tSymbols) if (!tSymbols) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
exit(1);
}
for (i = 0; i < nNumberOfSymbols; i += 1) for (i = 0; i < nNumberOfSymbols; i += 1)
tSymbols[i] = obj_ReadSymbol(pObjfile); tSymbols[i] = obj_ReadSymbol(pObjfile);
@@ -294,8 +304,10 @@ 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) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
exit(1);
}
SLONG nNumberOfPatches; SLONG nNumberOfPatches;
struct sPatch **ppPatch, *pPatch; struct sPatch **ppPatch, *pPatch;
@@ -312,14 +324,16 @@ obj_ReadRGB1Section(FILE * f)
*/ */
while (nNumberOfPatches--) { while (nNumberOfPatches--) {
pPatch = malloc(sizeof *pPatch); pPatch = malloc(sizeof *pPatch);
if (!pPatch) if (!pPatch) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
}
*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) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
}
strcpy(pPatch->pzFilename, s); strcpy(pPatch->pzFilename, s);
pPatch->nLineNo = readlong(f); pPatch->nLineNo = readlong(f);
@@ -327,8 +341,9 @@ obj_ReadRGB1Section(FILE * f)
pPatch->Type = (enum ePatchType) fgetc(f); pPatch->Type = (enum ePatchType) fgetc(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) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
}
fread(pPatch->pRPN, sizeof(UBYTE), fread(pPatch->pRPN, sizeof(UBYTE),
pPatch->nRPNSize, f); pPatch->nRPNSize, f);
@@ -360,8 +375,9 @@ obj_ReadRGB1(FILE * pObjfile)
if (nNumberOfSymbols) { if (nNumberOfSymbols) {
tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols); tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols);
if (!tSymbols) if (!tSymbols) {
errx(5, "Out of memory!"); fprintf(stderr, "Out of memory!\n");
}
for (i = 0; i < nNumberOfSymbols; i += 1) for (i = 0; i < nNumberOfSymbols; i += 1)
tSymbols[i] = obj_ReadSymbol(pObjfile); tSymbols[i] = obj_ReadSymbol(pObjfile);
@@ -424,12 +440,14 @@ obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
obj_ReadRGB1(pObjfile); obj_ReadRGB1(pObjfile);
break; break;
default: default:
errx(5, "'%s' is an unsupported version", fprintf(stderr, "'%s' is an unsupported version",
tzObjectfile); tzObjectfile);
exit(1);
break; break;
} }
} else { } 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; oReadLib = 0;
pObjfile = fopen(tzObjectfile, "rb"); pObjfile = fopen(tzObjectfile, "rb");
if (pObjfile == NULL) if (pObjfile == NULL) {
err(1, "Unable to open object '%s'", fprintf(stderr, "Unable to open object '%s': ",
tzObjectfile); tzObjectfile);
perror(NULL);
exit(1);
}
obj_ReadOpenFile(pObjfile, tzObjectfile); obj_ReadOpenFile(pObjfile, tzObjectfile);
fclose(pObjfile); fclose(pObjfile);
@@ -494,10 +515,14 @@ lib_Readfile(char *tzLibfile)
oReadLib = 1; oReadLib = 1;
pObjfile = fopen(tzLibfile, "rb"); pObjfile = fopen(tzLibfile, "rb");
if (pObjfile == NULL) if (pObjfile == NULL) {
err(1, "Unable to open object '%s'", tzLibfile); fprintf(stderr, "Unable to open object '%s': ", tzLibfile);
perror(NULL);
exit(1);
}
if (!pObjfile) { if (!pObjfile) {
errx(5, "Unable to open '%s'", tzLibfile); fprintf(stderr, "Unable to open '%s'\n", tzLibfile);
exit(1);
} }
char tzHeader[5]; char tzHeader[5];
@@ -506,8 +531,9 @@ lib_Readfile(char *tzLibfile)
if (strcmp(tzHeader, "XLB0") == 0) if (strcmp(tzHeader, "XLB0") == 0)
lib_ReadXLB0(pObjfile); lib_ReadXLB0(pObjfile);
else { else {
errx(5, "'%s' is an invalid library", fprintf(stderr, "'%s' is an invalid library\n",
tzLibfile); tzLibfile);
exit(1);
} }
fclose(pObjfile); fclose(pObjfile);
} }

View File

@@ -1,5 +1,5 @@
#include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include "link/mylink.h" #include "link/mylink.h"
@@ -46,7 +46,8 @@ getsymvalue(SLONG symid)
default: default:
break; break;
} }
errx(5, "*INTERNAL* UNKNOWN SYMBOL TYPE"); fprintf(stderr, "*INTERNAL* UNKNOWN SYMBOL TYPE\n");
exit(1);
} }
SLONG SLONG
@@ -63,7 +64,8 @@ getsymbank(SLONG symid)
default: default:
break; break;
} }
errx(5, "*INTERNAL* UNKNOWN SYMBOL TYPE"); fprintf(stderr, "*INTERNAL* UNKNOWN SYMBOL TYPE\n");
exit(1);
} }
SLONG SLONG
@@ -157,18 +159,20 @@ 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) {
errx(5, fprintf(stderr,
"%s(%ld) : Value must be in the HRAM area", "%s(%ld) : Value must be in the HRAM area\n",
pPatch->pzFilename, pPatch->nLineNo); pPatch->pzFilename, pPatch->nLineNo);
exit(1);
} }
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) {
errx(5, fprintf(stderr,
"%s(%ld) : Value must be in the ZP area", "%s(%ld) : Value must be in the ZP area\n",
pPatch->pzFilename, pPatch->nLineNo); pPatch->pzFilename, pPatch->nLineNo);
exit(1);
} }
break; break;
case RPN_CONST: case RPN_CONST:
@@ -213,10 +217,11 @@ calcrpn(struct sPatch * pPatch)
high |= (*rpn++) << 24; high |= (*rpn++) << 24;
t = rpnpop(); t = rpnpop();
if (t < low || t > high) { if (t < low || t > high) {
errx(5, fprintf(stderr,
"%s(%ld) : Value must be in the range [%ld;%ld]", "%s(%ld) : Value must be in the range [%ld;%ld]\n",
pPatch->pzFilename, pPatch->pzFilename,
pPatch->nLineNo, low, high); pPatch->nLineNo, low, high);
exit(1);
} }
rpnpush(t); rpnpush(t);
size -= 8; size -= 8;
@@ -250,10 +255,11 @@ Patch(void)
pSect->pData[pPatch->nOffset] = pSect->pData[pPatch->nOffset] =
(UBYTE) t; (UBYTE) t;
} else { } else {
errx(5, fprintf(stderr,
"%s(%ld) : Value must be 8-bit\n", "%s(%ld) : Value must be 8-bit\n",
pPatch->pzFilename, pPatch->pzFilename,
pPatch->nLineNo); pPatch->nLineNo);
exit(1);
} }
break; break;
case PATCH_WORD_L: case PATCH_WORD_L:
@@ -274,10 +280,11 @@ Patch(void)
1] = t & 0xFF; 1] = t & 0xFF;
} }
} else { } else {
errx(5, fprintf(stderr,
"%s(%ld) : Value must be 16-bit\n", "%s(%ld) : Value must be 16-bit\n",
pPatch->pzFilename, pPatch->pzFilename,
pPatch->nLineNo); pPatch->nLineNo);
exit(1);
} }
break; break;
case PATCH_LONG_L: case PATCH_LONG_L:

View File

@@ -1,4 +1,3 @@
#include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.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 void
@@ -92,9 +93,10 @@ sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
if (nBank == -1) if (nBank == -1)
return; return;
errx(5, fprintf(stderr,
"Symbol '%s' defined more than once\n", "Symbol '%s' defined more than once\n",
tzName); tzName);
exit(1);
} }
} }