aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2014-02-05 08:45:28 +1000
committerinmarket <andrewh@inmarket.com.au>2014-02-05 08:45:28 +1000
commit888a5d065640ff601e07bc35710daec2c4e6cc0b (patch)
tree339324ce752a0f2c7ab5b429aa48f7d3de08139d /tools
parent79d913f16dbaa17520521c645176cdbbffbb746a (diff)
downloaduGFX-888a5d065640ff601e07bc35710daec2c4e6cc0b.tar.gz
uGFX-888a5d065640ff601e07bc35710daec2c4e6cc0b.tar.bz2
uGFX-888a5d065640ff601e07bc35710daec2c4e6cc0b.zip
Update file2c tool to enable creation of directory entries for the ROM file system.
Diffstat (limited to 'tools')
-rw-r--r--tools/file2c/binaries/windows/file2c.exebin9728 -> 22030 bytes
-rw-r--r--tools/file2c/src/Makefile.mingw3210
-rw-r--r--tools/file2c/src/file2c.c95
3 files changed, 74 insertions, 31 deletions
diff --git a/tools/file2c/binaries/windows/file2c.exe b/tools/file2c/binaries/windows/file2c.exe
index 333b1138..dc530bf9 100644
--- a/tools/file2c/binaries/windows/file2c.exe
+++ b/tools/file2c/binaries/windows/file2c.exe
Binary files differ
diff --git a/tools/file2c/src/Makefile.mingw32 b/tools/file2c/src/Makefile.mingw32
new file mode 100644
index 00000000..470330bd
--- /dev/null
+++ b/tools/file2c/src/Makefile.mingw32
@@ -0,0 +1,10 @@
+
+CC = i686-pc-mingw32-gcc
+CFLAGS = -Wall -O2
+
+all:
+ $(CC) $(CFLAGS) -o file2c.exe file2c.c
+
+clean:
+ @rm file2c.exe
+
diff --git a/tools/file2c/src/file2c.c b/tools/file2c/src/file2c.c
index f7bc1e9c..1c279ff2 100644
--- a/tools/file2c/src/file2c.c
+++ b/tools/file2c/src/file2c.c
@@ -8,11 +8,14 @@
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
+#include <stdlib.h>
+#include <time.h>
#ifdef WIN32
#include <io.h>
#endif
-static unsigned char buf[1024];
+static unsigned char buf[1024];
+static char tname[FILENAME_MAX];
static char *filenameof(char *fname) {
char *p;
@@ -25,6 +28,13 @@ static char *filenameof(char *fname) {
#endif
p = strrchr(fname, '/');
if (p) fname = p+1;
+ return fname;
+}
+
+static char *basenameof(char *fname) {
+ char *p;
+
+ fname = filenameof(fname);
p = strchr(fname, '.');
if (p) *p = 0;
return fname;
@@ -43,34 +53,35 @@ char * opt_progname;
char * opt_inputfile;
char * opt_outputfile;
char * opt_arrayname;
+char * opt_dirname;
int opt_breakblocks;
+int opt_romdir;
char * opt_static;
char * opt_const;
FILE * f_input;
FILE * f_output;
unsigned blocknum;
-size_t len;
+size_t len, totallen;
size_t i;
/* Default values for our parameters */
- opt_progname = filenameof(argv[0]);
- opt_inputfile = 0;
- opt_outputfile = 0;
- opt_arrayname = 0;
- opt_breakblocks = 0;
- opt_static = "";
- opt_const = "";
+ opt_progname = basenameof(argv[0]);
+ opt_inputfile = opt_outputfile = opt_arrayname = opt_dirname = 0;
+ opt_breakblocks = opt_romdir = 0;
+ opt_static = opt_const = "";
/* Read the arguments */
while(*++argv) {
if (argv[0][0] == '-') {
while (*++(argv[0])) {
switch(argv[0][0]) {
- case '?': case 'h': goto usage;
- case 'b': opt_breakblocks = 1; break;
- case 'c': opt_const = "const "; break;
- case 's': opt_static = "static "; break;
- case 'n': opt_arrayname = *++argv; goto nextarg;
+ case '?': case 'h': goto usage;
+ case 'd': opt_romdir = 1; break;
+ case 'b': opt_breakblocks = 1; break;
+ case 'c': opt_const = "const "; break;
+ case 's': opt_static = "static "; break;
+ case 'n': opt_arrayname = *++argv; goto nextarg;
+ case 'f': opt_romdir = 1; opt_dirname = *++argv; goto nextarg;
default:
fprintf(stderr, "Unknown flag -%c\n", argv[0][0]);
goto usage;
@@ -82,20 +93,28 @@ size_t i;
opt_outputfile = argv[0];
else {
usage:
- fprintf(stderr, "Usage:\n\t%s -?\n"
- "\t%s [-bs] [-n name] [inputfile] [outputfile]\n"
- "\t\t-?\tThis help\n"
- "\t\t-h\tThis help\n"
- "\t\t-b\tBreak the arrays for compilers that won't handle large arrays\n"
- "\t\t-c\tDeclare the arrays as const (useful to ensure they end up in Flash)\n"
- "\t\t-s\tDeclare the arrays as static\n"
- "\t\t-n name\tUse \"name\" as the name of the array\n"
+ fprintf(stderr, "Usage:\n\n%s -?\n"
+ "%s [-dbcs] [-n name] [-f file] [inputfile] [outputfile]\n"
+ "\t-?\tThis help\n"
+ "\t-h\tThis help\n"
+ "\t-d\tAdd a directory entry for the ROM file system\n"
+ "\t-b\tBreak the arrays for compilers that won't handle large arrays\n"
+ "\t-c\tDeclare as const (useful to ensure they end up in Flash)\n"
+ "\t-s\tDeclare as static\n"
+ "\t-n name\tUse \"name\" as the name of the array\n"
+ "\t-f file\tUse \"file\" as the filename in the ROM directory entry\n"
, opt_progname, opt_progname);
return 1;
}
nextarg: ;
}
+ /* Make sure we can generate a default directory name if required */
+ if (opt_romdir && !opt_dirname && !opt_inputfile) {
+ fprintf(stderr, "If using -d you must either specify an input filename or use -f to specify a directory entry filename\n");
+ goto usage;
+ }
+
/* Open the input file */
if (opt_inputfile) {
f_input = fopen(opt_inputfile,
@@ -129,43 +148,57 @@ size_t i;
fprintf(f_output, "/**\n * This file was generated ");
if (opt_inputfile) fprintf(f_output, "from \"%s\" ", opt_inputfile);
fprintf(f_output, "using...\n *\n *\t%s", opt_progname);
- if (opt_arrayname || opt_static[0] || opt_const[0] || opt_breakblocks) {
+ if (opt_arrayname || opt_static[0] || opt_const[0] || opt_breakblocks || opt_romdir) {
fprintf(f_output, " -");
+ if (opt_romdir) fprintf(f_output, "b");
if (opt_breakblocks) fprintf(f_output, "b");
if (opt_const[0]) fprintf(f_output, "c");
if (opt_static[0]) fprintf(f_output, "s");
if (opt_arrayname) fprintf(f_output, "n %s", opt_arrayname);
+ if (opt_dirname) fprintf(f_output, (opt_arrayname ? " -f %s" : "f %s"), opt_dirname);
}
if (opt_inputfile) fprintf(f_output, " %s", opt_inputfile);
if (opt_outputfile) fprintf(f_output, " %s", opt_outputfile);
fprintf(f_output, "\n *\n */\n");
/*
- * Set the array name.
- * We do this after printing opt_inputfile for the last time as we
- * modify opt_inputfile in place to generate opt_arrayname.
+ * Set the array name and dir name
*/
if (!opt_arrayname) {
if (opt_inputfile)
- opt_arrayname = filenameof(opt_inputfile);
- if (!opt_arrayname || !opt_arrayname[0])
- opt_arrayname = "filearray";
+ opt_arrayname = basenameof(strcpy(tname, opt_inputfile));
+ if (!opt_arrayname || !opt_arrayname[0]) {
+ srand(time(NULL));
+ sprintf(tname, "filearray%u", rand());
+ opt_arrayname = tname;
+ }
}
opt_arrayname = clean4c(opt_arrayname);
+ if (opt_romdir && !opt_dirname)
+ opt_dirname = filenameof(opt_inputfile);
/* Read the file processing 1K at a time */
blocknum = 0;
+ totallen = 0;
while((len = fread(buf, 1, sizeof(buf), f_input))) {
if (!blocknum++)
- fprintf(f_output, "%s%sunsigned char %s[] = {", opt_static, opt_const, opt_arrayname);
+ fprintf(f_output, "%s%schar %s[] = {", opt_static, opt_const, opt_arrayname);
else if (opt_breakblocks)
- fprintf(f_output, "\n};\n%s%sunsigned char %s_p%u[] = {", opt_static, opt_const, opt_arrayname, blocknum);
+ fprintf(f_output, "\n};\n%s%schar %s_p%u[] = {", opt_static, opt_const, opt_arrayname, blocknum);
for(i = 0; i < len; i++) {
fprintf(f_output, (i & 0x0F) ? " 0x%02X," : "\n\t0x%02X,", buf[i]);
}
+ totallen += len;
}
fprintf(f_output, "\n};\n");
+ /* Add the directory entry if required */
+ if (opt_romdir) {
+ fprintf(f_output, "\n#ifdef ROMFS_DIRENTRY_HEAD\n");
+ fprintf(f_output, "\t%s%sROMFS_DIRENTRY %s_dir = { ROMFS_DIRENTRY_HEAD, \"%s\", %u, %s };\n", opt_static, opt_const, opt_arrayname, opt_dirname, totallen, opt_arrayname);
+ fprintf(f_output, "\t#undef ROMFS_DIRENTRY_HEAD\n\t#define ROMFS_DIRENTRY_HEAD &%s_dir\n#endif\n", opt_arrayname);
+ }
+
/* Clean up */
if (ferror(f_input))
fprintf(stderr, "Input file read error\n");