snes9x/gtk/src/sourcify.c

67 lines
1.5 KiB
C
Raw Normal View History

/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
2010-09-25 17:46:12 +02:00
#include <stdio.h>
#include <sys/stat.h>
int
main (int argc,
char *argv[])
{
FILE *infile, *outfile;
unsigned char inchar;
unsigned int counter;
struct stat file_info;
if (argc != 4)
2010-09-25 17:46:12 +02:00
{
fprintf (stderr, "Usage: %s infile outfile identifier\n", argv[0]);
return 1;
}
2010-09-25 17:46:12 +02:00
stat (argv[1], &file_info);
2010-09-25 17:46:12 +02:00
infile = fopen (argv[1], "r");
2010-09-25 17:46:12 +02:00
if (!infile)
{
fprintf (stderr, "Input file doesn't exist.\n");
return 2;
}
2010-09-25 17:46:12 +02:00
outfile = fopen (argv[2], "w+");
fprintf (outfile,
"int %s_size = %d;\n\n",
argv[3],
2010-09-25 17:46:12 +02:00
(int) file_info.st_size);
2010-09-26 11:19:15 +02:00
fprintf (outfile, "unsigned char %s [] = \n{\n ", argv[3]);
2010-09-25 17:46:12 +02:00
counter = 0;
2010-09-25 17:46:12 +02:00
while (fread (&inchar, 1, 1, infile))
{
if (counter >= 32)
{
counter = 0;
fprintf (outfile, "\n ");
}
2010-09-25 17:46:12 +02:00
fprintf (outfile, "%d,", inchar);
counter++;
}
2010-09-25 17:46:12 +02:00
/* Erase extra "," */
fseek (outfile, -1, SEEK_CUR);
2010-09-25 17:46:12 +02:00
fprintf (outfile, "\n};\n");
fclose (infile);
fclose (outfile);
2010-09-25 17:46:12 +02:00
return 0;
}