snes9x/gtk/src/sourcify.c

62 lines
1.4 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[])
2010-09-25 17:46:12 +02:00
{
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]);
2010-09-25 17:46:12 +02:00
return 1;
}
stat(argv[1], &file_info);
infile = fopen(argv[1], "r");
2010-09-25 17:46:12 +02:00
if (!infile)
{
fprintf(stderr, "Input file doesn't exist.\n");
2010-09-25 17:46:12 +02:00
return 2;
}
outfile = fopen(argv[2], "w+");
fprintf(outfile, "int %s_size = %d;\n\n", argv[3], (int)file_info.st_size);
fprintf(outfile, "unsigned char %s [] = \n{\n ", argv[3]);
2010-09-25 17:46:12 +02:00
counter = 0;
while (fread(&inchar, 1, 1, infile))
2010-09-25 17:46:12 +02:00
{
if (counter >= 32)
{
counter = 0;
fprintf(outfile, "\n ");
2010-09-25 17:46:12 +02:00
}
fprintf(outfile, "%d,", inchar);
2010-09-25 17:46:12 +02:00
counter++;
}
2010-09-25 17:46:12 +02:00
/* Erase extra "," */
fseek(outfile, -1, SEEK_CUR);
fprintf(outfile, "\n};\n");
fclose(infile);
fclose(outfile);
2010-09-25 17:46:12 +02:00
return 0;
}