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