shithub: rgbds

Download patch

ref: 5d6559f15f549c117ef80cbe7f4cb93669a2e5e3
parent: b1a2c664a90c9ec52f02f6d8650ae87ae6517ec1
author: Anthony J. Bentley <[email protected]>
date: Thu Dec 1 20:23:23 EST 2011

Remove nonstandard <err.h>.

This provides some really nice functions, but does not exist in some
environments (particularly MinGW).

--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -5,7 +5,6 @@
  *
  */
 
-#include <err.h>
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -136,7 +135,9 @@
 			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 @@
 			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 @@
 
 			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 @@
 				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 @@
 				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 @@
 			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 @@
 					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);
--- a/src/asm/yaccprt1.y
+++ b/src/asm/yaccprt1.y
@@ -1,6 +1,5 @@
 %{
 #include <ctype.h>
-#include <err.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
--- a/src/fix/main.c
+++ b/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 @@
 	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 @@
 		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 @@
 			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 @@
 		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 @@
 			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 @@
 		 */
 
 		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 @@
 			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);
--- a/src/lib/library.c
+++ b/src/lib/library.c
@@ -1,4 +1,3 @@
-#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -88,14 +87,18 @@
 		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 @@
 				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 @@
 			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 @@
 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 @@
 	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 @@
 		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 @@
 	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 @@
 		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);
--- a/src/lib/main.c
+++ b/src/lib/main.c
@@ -1,5 +1,4 @@
 #include <ctype.h>
-#include <err.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -83,11 +82,16 @@
 						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;
--- a/src/link/assign.c
+++ b/src/link/assign.c
@@ -1,4 +1,3 @@
-#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -71,8 +70,11 @@
 						    size + pArea->nSize;
 
 						return (org);
-					} else
-						errx(5, "Out of memory!");
+					} else {
+						fprintf(stderr,
+						    "Out of memory!\n");
+						exit(1);
+					}
 				}
 			}
 		}
@@ -164,8 +166,11 @@
 			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 @@
 	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 @@
 				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 @@
 				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 @@
 				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 @@
 				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 @@
 								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 @@
 				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 @@
 				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 @@
 				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 @@
 				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 @@
 				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 @@
 				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 @@
 			case SECT_CODE:
 				break;
 			default:
-				errx(5, "(INTERNAL) Unknown section type!");
+				fprintf(stderr, "(INTERNAL) Unknown section type!\n");
+				exit(1);
 				break;
 			}
 		}
--- a/src/link/library.c
+++ b/src/link/library.c
@@ -1,4 +1,3 @@
-#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -92,8 +91,9 @@
 	}
 	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);
--- a/src/link/main.c
+++ b/src/link/main.c
@@ -1,4 +1,3 @@
-#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -72,10 +71,14 @@
 			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;
--- a/src/link/mapfile.c
+++ b/src/link/mapfile.c
@@ -1,4 +1,3 @@
-#include <err.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -20,8 +19,11 @@
 {
 	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 @@
 {
 	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");
 }
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -3,7 +3,6 @@
  *
  */
 
-#include <err.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -81,8 +80,8 @@
 
 	*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 @@
 	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 @@
 		 */
 		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 @@
 			 */
 			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 @@
 
 				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 @@
 
 	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 @@
 		 */
 		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 @@
 			 */
 			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 @@
 				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 @@
 
 	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_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 @@
 		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 @@
 	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 @@
 	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);
 }
--- a/src/link/patch.c
+++ b/src/link/patch.c
@@ -1,5 +1,5 @@
-#include <err.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "link/mylink.h"
@@ -46,7 +46,8 @@
 	default:
 		break;
 	}
-	errx(5, "*INTERNAL* UNKNOWN SYMBOL TYPE");
+	fprintf(stderr, "*INTERNAL* UNKNOWN SYMBOL TYPE\n");
+	exit(1);
 }
 
 SLONG 
@@ -63,7 +64,8 @@
 	default:
 		break;
 	}
-	errx(5, "*INTERNAL* UNKNOWN SYMBOL TYPE");
+	fprintf(stderr, "*INTERNAL* UNKNOWN SYMBOL TYPE\n");
+	exit(1);
 }
 
 SLONG 
@@ -157,9 +159,10 @@
 			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:
@@ -166,9 +169,10 @@
 			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 @@
 				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 @@
 					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 @@
 						    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:
--- a/src/link/symbol.c
+++ b/src/link/symbol.c
@@ -1,4 +1,3 @@
-#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -54,7 +53,8 @@
 			}
 		}
 
-		errx(5, "Unknown symbol '%s'", tzName);
+		fprintf(stderr, "Unknown symbol '%s'\n", tzName);
+		exit(1);
 	}
 }
 
@@ -72,7 +72,8 @@
 		}
 	}
 
-	errx(5, "Unknown symbol '%s'", tzName);
+	fprintf(stderr, "Unknown symbol '%s'\n", tzName);
+	exit(1);
 }
 
 void 
@@ -92,9 +93,10 @@
 			if (nBank == -1)
 				return;
 
-			errx(5,
+			fprintf(stderr,
 			    "Symbol '%s' defined more than once\n",
 			    tzName);
+			exit(1);
 		}
 	}