rgbfix: use mkstemp() instead of tmpnam() and fix coding style issues

Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
This commit is contained in:
Vegard Nossum
2009-06-11 08:59:03 +02:00
parent bc6b2fe005
commit c6d8069eed

View File

@@ -27,12 +27,12 @@ unsigned long ulOptions;
*/ */
unsigned char NintendoChar[48] = { unsigned char NintendoChar[48] = {
0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B, 0x03, 0x73, 0x00, 0x83, 0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B,
0x00, 0x0C, 0x00, 0x0D, 0x03, 0x73, 0x00, 0x83, 0x00, 0x0C, 0x00, 0x0D,
0x00, 0x08, 0x11, 0x1F, 0x88, 0x89, 0x00, 0x0E, 0xDC, 0xCC, 0x6E, 0xE6, 0x00, 0x08, 0x11, 0x1F, 0x88, 0x89, 0x00, 0x0E,
0xDD, 0xDD, 0xD9, 0x99, 0xDC, 0xCC, 0x6E, 0xE6, 0xDD, 0xDD, 0xD9, 0x99,
0xBB, 0xBB, 0x67, 0x63, 0x6E, 0x0E, 0xEC, 0xCC, 0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xBB, 0x67, 0x63, 0x6E, 0x0E, 0xEC, 0xCC,
0xBB, 0xB9, 0x33, 0x3E 0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E,
}; };
/* /*
@@ -42,19 +42,18 @@ unsigned char NintendoChar[48] = {
void PrintUsage(void) void PrintUsage(void)
{ {
printf("RGBFix v" RGBFIX_VERSION " (part of ASMotor " ASMOTOR_VERSION printf("RGBFix v" RGBFIX_VERSION
")\n\n"); " (part of ASMotor " ASMOTOR_VERSION ")\n\n");
printf("Usage: rgbfix [options] image[.gb]\n"); printf("Usage: rgbfix [options] image[.gb]\n");
printf("Options:\n"); printf("Options:\n");
printf("\t-h\t\tThis text\n"); printf("\t-h\t\tThis text\n");
printf("\t-d\t\tDebug: Don't change image\n"); printf("\t-d\t\tDebug: Don't change image\n");
printf printf("\t-p\t\tPad image to valid size\n\t\t\tPads to 32/64/128/256/512kB as appropriate\n");
("\t-p\t\tPad image to valid size\n\t\t\tPads to 32/64/128/256/512kB as appropriate\n"); printf("\t-r\t\ttRuncate image to valid size\n\t\t\tTruncates to 32/64/128/256/512kB as appropriate\n");
printf
("\t-r\t\ttRuncate image to valid size\n\t\t\tTruncates to 32/64/128/256/512kB as appropriate\n");
printf("\t-t<name>\tChange cartridge title field (16 characters)\n"); printf("\t-t<name>\tChange cartridge title field (16 characters)\n");
printf printf("\t-v\t\tValidate header\n\t\t\tCorrects - Nintendo Character Area (0x0104)\n\t\t\t\t - ROM type (0x0147)\n\t\t\t\t - ROM size (0x0148)\n\t\t\t\t - Checksums (0x014D-0x014F)\n");
("\t-v\t\tValidate header\n\t\t\tCorrects - Nintendo Character Area (0x0104)\n\t\t\t\t - ROM type (0x0147)\n\t\t\t\t - ROM size (0x0148)\n\t\t\t\t - Checksums (0x014D-0x014F)\n");
exit(0); exit(0);
} }
@@ -136,7 +135,10 @@ int main(int argc, char *argv[])
if (!FileExists(filename)) if (!FileExists(filename))
strcat(filename, ".gb"); strcat(filename, ".gb");
if ((f = fopen(filename, "rb+")) != NULL) { f = fopen(filename, "rb+");
if (!f)
FatalError("Unable to open file");
/* /*
* -d (Debug) option code * -d (Debug) option code
* *
@@ -195,7 +197,7 @@ int main(int argc, char *argv[])
if (ulOptions & OPTF_TRUNCATE) { if (ulOptions & OPTF_TRUNCATE) {
long size, padto; long size, padto;
char tempfile[512]; char tempfile[] = "/tmp/rgbfix-XXXXXX";
FILE *tf; FILE *tf;
size = FileSize(f); size = FileSize(f);
@@ -205,7 +207,7 @@ int main(int argc, char *argv[])
printf("Truncating to %ldkB:\n", padto / 1024); printf("Truncating to %ldkB:\n", padto / 1024);
tmpnam(tempfile); mkstemp(tempfile);
if ((ulOptions & OPTF_DEBUG) == 0) { if ((ulOptions & OPTF_DEBUG) == 0) {
if ((tf = fopen(tempfile, "wb")) != NULL) { if ((tf = fopen(tempfile, "wb")) != NULL) {
@@ -303,8 +305,7 @@ int main(int argc, char *argv[])
fputc(calcromsize, f); fputc(calcromsize, f);
fflush(f); fflush(f);
} }
printf printf("\tChanged ROM size byte from 0x%02lX (%ldkB) to 0x%02lX (%ldkB)\n",
("\tChanged ROM size byte from 0x%02lX (%ldkB) to 0x%02lX (%ldkB)\n",
cartromsize, cartromsize,
(0x8000L << cartromsize) / 1024, (0x8000L << cartromsize) / 1024,
calcromsize, calcromsize,
@@ -393,10 +394,8 @@ int main(int argc, char *argv[])
printf("\tCompChecksum is OK\n"); printf("\tCompChecksum is OK\n");
} }
fclose(f); fclose(f);
} else {
FatalError("Unable to open file");
}
return (0); return (0);
} }