2018-11-16 00:42:29 +01:00
|
|
|
/*****************************************************************************\
|
|
|
|
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>
|
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
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;
|
2016-09-27 22:25:37 +02:00
|
|
|
|
|
|
|
if (argc != 4)
|
2010-09-25 17:46:12 +02:00
|
|
|
{
|
2020-07-05 00:53:38 +02:00
|
|
|
fprintf(stderr, "Usage: %s infile outfile identifier\n", argv[0]);
|
2010-09-25 17:46:12 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
stat(argv[1], &file_info);
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
infile = fopen(argv[1], "r");
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2010-09-25 17:46:12 +02:00
|
|
|
if (!infile)
|
|
|
|
{
|
2020-07-05 00:53:38 +02:00
|
|
|
fprintf(stderr, "Input file doesn't exist.\n");
|
2010-09-25 17:46:12 +02:00
|
|
|
return 2;
|
|
|
|
}
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
outfile = fopen(argv[2], "w+");
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
fprintf(outfile, "int %s_size = %d;\n\n", argv[3], (int)file_info.st_size);
|
|
|
|
fprintf(outfile, "unsigned char %s [] = \n{\n ", argv[3]);
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2010-09-25 17:46:12 +02:00
|
|
|
counter = 0;
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
while (fread(&inchar, 1, 1, infile))
|
2010-09-25 17:46:12 +02:00
|
|
|
{
|
|
|
|
if (counter >= 32)
|
|
|
|
{
|
|
|
|
counter = 0;
|
2020-07-05 00:53:38 +02:00
|
|
|
fprintf(outfile, "\n ");
|
2010-09-25 17:46:12 +02:00
|
|
|
}
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
fprintf(outfile, "%d,", inchar);
|
2010-09-25 17:46:12 +02:00
|
|
|
counter++;
|
|
|
|
}
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2010-09-25 17:46:12 +02:00
|
|
|
/* Erase extra "," */
|
2020-07-05 00:53:38 +02:00
|
|
|
fseek(outfile, -1, SEEK_CUR);
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
fprintf(outfile, "\n};\n");
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
fclose(infile);
|
|
|
|
fclose(outfile);
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2010-09-25 17:46:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|