9 #define error_printf printf
10 #define debug_printf if( debugLevel>0 ) printf
17 void dummy_printf(
char *ptr,...);
29 const char *argerror =
"error: Two file arguments required";
30 const char commentLine[] =
"/************************************************************************/\n";
36 int filearg[ MAX_FILES ];
37 int optArg[ MAX_ARGS ];
44 float compressRatio = 0.0f;
58 int main(
int argc,
char *argv[]){
62 unsigned char ch=
'\0';
73 error_printf(
"Syntax: rfscreate [option] ... [option] <outputfile> <inputfiles>\n\n\r" );
74 error_printf(
" <outputfile> : Name of output file\n\r");
75 error_printf(
" <inputfiles> : List of input files to convert\n\r" );
76 error_printf(
" -c : Compress files\n\r");
77 error_printf(
" -d:<0-9> : Debug level\n\r" );
89 debug_printf(
"-------------------- Argument processing -------------------\n" );
96 debug_printf(
"option : %s\n", argv[i]);
101 if (argv[i][2] ==
'c'){
107 ret = sscanf( argv[i],
"-d:%d", &temp );
111 debug_printf(
"Debug level : %d\n", temp );
116 error_printf(
"Unknown option: %s\n",argv[i]);
126 filearg[fileargs] = i;
127 debug_printf(
"filearg[%d] = argv[%d]: %s\n", fileargs, filearg[fileargs], argv[i] );
138 error_printf(argerror);
142 debug_printf(
"------------------- /Argument processing -------------------\n" );
145 debug_printf(
"---------------- File information gathering ----------------\n" );
150 tptr = localtime(<);
151 printf(
"Local time : %s",asctime(tptr) );
154 error_printf(
"Error: Failed to get local time.\n");
159 outputFileName = argv[filearg[0]];
160 if( (fpout=fopen(outputFileName ,
"wb")) == NULL ){
161 error_printf(
"Error: File %s could not be opened for write.\n", outputFileName );
166 printf(
"Output file : %s\n", outputFileName );
170 inputFileCount = fileargs-1;
171 for( j=0; j<inputFileCount; j++ ){
173 inputFileName = argv[filearg[j+1]];
176 if( (fpin=fopen( inputFileName ,
"rb")) == NULL ){
177 error_printf(
"Error: File %s could not be opened for reading.\n", inputFileName );
183 fseek(fpin,0,SEEK_END);
184 fileLength = ftell(fpin);
185 fseek(fpin,0,SEEK_SET);
188 files[j].fileName = inputFileName;
189 files[j].fileLength = fileLength;
196 debug_printf(
"--------------- /File information gathering ----------------\n" );
199 fprintf( fpout,
"/************************************************************************/\n");
200 fprintf( fpout,
"/* Autogenerated file - DO NOT EDIT */\n");
201 fprintf( fpout,
"/* */\n");
202 fprintf( fpout,
"/* Date: %02d.%02d.%04d %02d:%02d:%02d */\n",
211 fprintf( fpout,
"/* */\n");
212 fprintf( fpout,
"/* Files embedded in this file; */\n");
213 fprintf( fpout,
"/* */\n");
214 fprintf( fpout,
"/* Length Index Name */\n");
215 fprintf( fpout,
"/*----------------------------------------------------------------------*/\n");
216 printf(
" Length Index Name\n");
217 printf(
"----------------------------------------------------------------------\n");
218 for( j=0; j<inputFileCount; j++ ){
219 printf(
" %8d %2d %s\n", files[j].fileLength, j, files[j].fileName );
220 sprintf( stringbuf,
"/* %8d %2d %s", files[j].fileLength, j, files[j].fileName );
221 len = strlen( stringbuf );
222 for( i=len; i<(
sizeof(commentLine)-4); i++ ) stringbuf[i] =
' ';
223 stringbuf[i++] =
'*';
224 stringbuf[i++] =
'/';
225 stringbuf[i++] =
'\n';
226 stringbuf[i ] = 0x00;
228 fprintf( fpout, stringbuf );
230 fprintf( fpout,
"/************************************************************************/\n");
231 fprintf( fpout,
"#ifndef __RFS_FILES_H_\n\n");
232 fprintf( fpout,
"#define __RFS_FILES_H_\n\n");
234 fprintf( fpout,
"#include <stdint.h>\n");
235 fprintf( fpout,
"\n");
238 fprintf( fpout,
"#define RFS_FILE_COUNT %d\n", inputFileCount );
239 fprintf( fpout,
"const uint32_t RFS_fileCount = RFS_FILE_COUNT;\n" );
240 fprintf( fpout,
"\n");
243 for( j=0; j<inputFileCount; j++ ){
244 fprintf( fpout,
"const uint8_t RFS_fileName%d[] = \"%s\";\n", j, files[j].fileName );
248 fprintf( fpout,
"\n");
249 fprintf( fpout,
"const uint8_t *RFS_fileNames[ RFS_FILE_COUNT ] = {\n" );
250 for( j=0; j<inputFileCount; j++ ){
251 fprintf( fpout,
" RFS_fileName%d", j );
252 if( j != (inputFileCount-1) ) fprintf( fpout,
",\n" );
254 fprintf( fpout,
"\n");
255 fprintf( fpout,
"};\n");
258 fprintf( fpout,
"\n");
259 fprintf( fpout,
"const uint32_t RFS_fileLength[ RFS_FILE_COUNT ] = {\n" );
260 for( j=0; j<inputFileCount; j++ ){
261 fprintf( fpout,
" %d", files[j].fileLength );
262 if( j != (inputFileCount-1) ) fprintf( fpout,
",\n" );
264 fprintf( fpout,
"\n");
265 fprintf( fpout,
"};\n");
268 fprintf( fpout,
"\n");
269 for( j=0; j<inputFileCount; j++ ){
270 fprintf( fpout,
"const uint8_t RFS_fileData%d[];\n",j );
274 fprintf( fpout,
"\n");
275 fprintf( fpout,
"const uint8_t *RFS_fileData[ RFS_FILE_COUNT ] = {\n" );
276 for( j=0; j<inputFileCount; j++ ){
277 fprintf( fpout,
" RFS_fileData%d", j );
278 if( j != (inputFileCount-1) ) fprintf( fpout,
",\n" );
280 fprintf( fpout,
"\n");
281 fprintf( fpout,
"};\n");
284 for( j=0; j<inputFileCount; j++ ){
287 if( (fpin=fopen( files[j].fileName ,
"rb")) == NULL ){
288 error_printf(
"Error: File %s could not be opened for reading.\n", files[j].fileName );
294 fprintf( fpout,
"\n");
295 fprintf( fpout,
"const uint8_t RFS_fileData%d[] = {\n",j );
298 fprintf( fpout,
"\n ");
299 for( i=0; i<files[j].fileLength; i++ ){
301 fprintf( fpout,
"0x%02x", (
unsigned int)ch );
302 if ( j != (files[j].fileLength-1) ) fprintf( fpout,
", " );
303 if ( (++count % 16) == 0 ) fprintf( fpout,
"\n ");
306 if( debugLevel>0) printf(
"last byte = %02Xh\n", (
unsigned int)ch );
307 temp = fgetc( fpin );
308 ch = (
unsigned char)temp;
310 printf(
"File %s contains more data than file length indicates! Bytes read = %d [%d]\n",
319 fprintf( fpout,
"\n");
320 fprintf( fpout,
"};\n");
324 fprintf( fpout,
"#endif\n");
334 debug_printf(
"Closing all open files\n");
341 void dummy_printf(
char *ptr,...){