From a900ab610c7ed54e52ae0d618f177817c54be77e Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 4 Apr 2013 02:01:07 +0200 Subject: file2c tool cleanup --- tools/file2c/binaries/file2c | Bin 10801 -> 0 bytes tools/file2c/binaries/file2c.exe | Bin 9728 -> 0 bytes tools/file2c/binaries/linux/file2c | Bin 0 -> 10801 bytes tools/file2c/binaries/windows/file2c.exe | Bin 0 -> 9728 bytes tools/file2c/source/Makefile | 15 -- tools/file2c/source/VS 2012 Project/file2c.sln | 22 --- tools/file2c/source/VS 2012 Project/file2c.v11.suo | Bin 25600 -> 0 bytes .../source/VS 2012 Project/file2c/file2c.vcxproj | 84 --------- .../VS 2012 Project/file2c/file2c.vcxproj.filters | 22 --- .../VS 2012 Project/file2c/file2c.vcxproj.user | 4 - tools/file2c/source/file2c.c | 194 --------------------- tools/file2c/src/Makefile | 15 ++ tools/file2c/src/VS 2012 Project/file2c.sln | 22 +++ tools/file2c/src/VS 2012 Project/file2c.v11.suo | Bin 0 -> 25600 bytes .../src/VS 2012 Project/file2c/file2c.vcxproj | 84 +++++++++ .../VS 2012 Project/file2c/file2c.vcxproj.filters | 22 +++ .../src/VS 2012 Project/file2c/file2c.vcxproj.user | 4 + tools/file2c/src/file2c.c | 194 +++++++++++++++++++++ 18 files changed, 341 insertions(+), 341 deletions(-) delete mode 100755 tools/file2c/binaries/file2c delete mode 100644 tools/file2c/binaries/file2c.exe create mode 100755 tools/file2c/binaries/linux/file2c create mode 100644 tools/file2c/binaries/windows/file2c.exe delete mode 100644 tools/file2c/source/Makefile delete mode 100644 tools/file2c/source/VS 2012 Project/file2c.sln delete mode 100644 tools/file2c/source/VS 2012 Project/file2c.v11.suo delete mode 100644 tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj delete mode 100644 tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj.filters delete mode 100644 tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj.user delete mode 100644 tools/file2c/source/file2c.c create mode 100644 tools/file2c/src/Makefile create mode 100644 tools/file2c/src/VS 2012 Project/file2c.sln create mode 100644 tools/file2c/src/VS 2012 Project/file2c.v11.suo create mode 100644 tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj create mode 100644 tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj.filters create mode 100644 tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj.user create mode 100644 tools/file2c/src/file2c.c (limited to 'tools') diff --git a/tools/file2c/binaries/file2c b/tools/file2c/binaries/file2c deleted file mode 100755 index 403c7d8f..00000000 Binary files a/tools/file2c/binaries/file2c and /dev/null differ diff --git a/tools/file2c/binaries/file2c.exe b/tools/file2c/binaries/file2c.exe deleted file mode 100644 index 333b1138..00000000 Binary files a/tools/file2c/binaries/file2c.exe and /dev/null differ diff --git a/tools/file2c/binaries/linux/file2c b/tools/file2c/binaries/linux/file2c new file mode 100755 index 00000000..403c7d8f Binary files /dev/null and b/tools/file2c/binaries/linux/file2c differ diff --git a/tools/file2c/binaries/windows/file2c.exe b/tools/file2c/binaries/windows/file2c.exe new file mode 100644 index 00000000..333b1138 Binary files /dev/null and b/tools/file2c/binaries/windows/file2c.exe differ diff --git a/tools/file2c/source/Makefile b/tools/file2c/source/Makefile deleted file mode 100644 index a6a7041c..00000000 --- a/tools/file2c/source/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -TARGET = file2c -SRCS = $(shell find -name '*.c') -OBJS = $(addsuffix .o,$(basename $(SRCS))) - -CFLAGS = -Wall -p - -CC = /usr/bin/gcc -RM = /bin/rm -f - -all: clean - $(CC) $(CFLAGS) -o $(TARGET) $(SRCS) - -clean: - $(RM) $(TARGET) $(OBJS) - diff --git a/tools/file2c/source/VS 2012 Project/file2c.sln b/tools/file2c/source/VS 2012 Project/file2c.sln deleted file mode 100644 index 5e067d5b..00000000 --- a/tools/file2c/source/VS 2012 Project/file2c.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "file2c", "file2c\file2c.vcxproj", "{16787B20-A841-4DC1-9C15-E6677A0D7342}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {16787B20-A841-4DC1-9C15-E6677A0D7342}.Debug|Win32.ActiveCfg = Debug|Win32 - {16787B20-A841-4DC1-9C15-E6677A0D7342}.Debug|Win32.Build.0 = Debug|Win32 - {16787B20-A841-4DC1-9C15-E6677A0D7342}.Debug|Win32.Deploy.0 = Debug|Win32 - {16787B20-A841-4DC1-9C15-E6677A0D7342}.Release|Win32.ActiveCfg = Release|Win32 - {16787B20-A841-4DC1-9C15-E6677A0D7342}.Release|Win32.Build.0 = Release|Win32 - {16787B20-A841-4DC1-9C15-E6677A0D7342}.Release|Win32.Deploy.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/tools/file2c/source/VS 2012 Project/file2c.v11.suo b/tools/file2c/source/VS 2012 Project/file2c.v11.suo deleted file mode 100644 index 38fa846c..00000000 Binary files a/tools/file2c/source/VS 2012 Project/file2c.v11.suo and /dev/null differ diff --git a/tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj b/tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj deleted file mode 100644 index b0b846c7..00000000 --- a/tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj +++ /dev/null @@ -1,84 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - - - - {16787B20-A841-4DC1-9C15-E6677A0D7342} - Win32Proj - file2c - - - - Application - true - v110 - Unicode - - - Application - false - v110 - true - Unicode - - - - - - - - - - - - - true - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - - \ No newline at end of file diff --git a/tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj.filters b/tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj.filters deleted file mode 100644 index 97daa75f..00000000 --- a/tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj.user b/tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj.user deleted file mode 100644 index a375ae35..00000000 --- a/tools/file2c/source/VS 2012 Project/file2c/file2c.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/tools/file2c/source/file2c.c b/tools/file2c/source/file2c.c deleted file mode 100644 index 29b9da2f..00000000 --- a/tools/file2c/source/file2c.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - ChibiOS/GFX - Copyright (C) 2012, 2013 - Joel Bodenmann aka Tectu - - This file is part of ChibiOS/GFX. - - ChibiOS/GFX is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/GFX is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include -#include -#include -#ifdef WIN32 - #include -#endif - -static unsigned char buf[1024]; - -static char *filenameof(char *fname) { - char *p; - -#ifdef WIN32 - if (fname[1] == ':') - fname = fname+2; - p = strrchr(fname, '\\'); - if (p) fname = p+1; -#endif - p = strrchr(fname, '/'); - if (p) fname = p+1; - p = strchr(fname, '.'); - if (p) *p = 0; - return fname; -} - -static char *clean4c(char *fname) { - char *p; - - while((p = strpbrk(fname, "-+ `~!@#$%^&*(){}[]|:;'\",<>?/|=.\\"))) *p = '_'; - return fname; -} - -int main(int argc, char * argv[]) -{ -char * opt_progname; -char * opt_inputfile; -char * opt_outputfile; -char * opt_arrayname; -int opt_breakblocks; -char * opt_static; -char * opt_const; -FILE * f_input; -FILE * f_output; -unsigned blocknum; -size_t len; -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 = ""; - - /* 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; - default: - fprintf(stderr, "Unknown flag -%c\n", argv[0][0]); - goto usage; - } - } - } else if (!opt_inputfile) - opt_inputfile = argv[0]; - else if (!opt_outputfile) - 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" - , opt_progname, opt_progname); - return 1; - } - nextarg: ; - } - - /* Open the input file */ - if (opt_inputfile) { - f_input = fopen(opt_inputfile, -#ifdef WIN32 - "rb"); -#else - "r"); -#endif - if (!f_input) { - fprintf(stderr, "Could not open input file '%s'\n", opt_inputfile); - goto usage; - } - } else { - f_input = stdin; -#ifdef WIN32 - _setmode(_fileno(stdin), _O_BINARY); -#endif - } - - /* Open the output file */ - if (opt_outputfile) { - f_output = fopen(opt_outputfile, "w"); - if (!f_output) { - fprintf(stderr, "Could not open output file '%s'\n", opt_outputfile); - goto usage; - } - } else - f_output = stdout; - - /* Print the comment header */ - 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) { - fprintf(f_output, " -"); - 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_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. - */ - if (!opt_arrayname) { - if (opt_inputfile) - opt_arrayname = filenameof(opt_inputfile); - if (!opt_arrayname || !opt_arrayname[0]) - opt_arrayname = "filearray"; - } - opt_arrayname = clean4c(opt_arrayname); - - /* Read the file processing 1K at a time */ - blocknum = 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); - else if (opt_breakblocks) - fprintf(f_output, "\n};\n%s%sunsigned char %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]); - } - } - fprintf(f_output, "\n};\n"); - - /* Clean up */ - if (ferror(f_input)) - fprintf(stderr, "Input file read error\n"); - if (ferror(f_output)) - fprintf(stderr, "Output file write error - disk full?\n"); - if (f_input != stdin) - fclose(f_input); - if (f_output != stdout) - fclose(f_output); - - return 0; -} - diff --git a/tools/file2c/src/Makefile b/tools/file2c/src/Makefile new file mode 100644 index 00000000..a6a7041c --- /dev/null +++ b/tools/file2c/src/Makefile @@ -0,0 +1,15 @@ +TARGET = file2c +SRCS = $(shell find -name '*.c') +OBJS = $(addsuffix .o,$(basename $(SRCS))) + +CFLAGS = -Wall -p + +CC = /usr/bin/gcc +RM = /bin/rm -f + +all: clean + $(CC) $(CFLAGS) -o $(TARGET) $(SRCS) + +clean: + $(RM) $(TARGET) $(OBJS) + diff --git a/tools/file2c/src/VS 2012 Project/file2c.sln b/tools/file2c/src/VS 2012 Project/file2c.sln new file mode 100644 index 00000000..5e067d5b --- /dev/null +++ b/tools/file2c/src/VS 2012 Project/file2c.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "file2c", "file2c\file2c.vcxproj", "{16787B20-A841-4DC1-9C15-E6677A0D7342}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {16787B20-A841-4DC1-9C15-E6677A0D7342}.Debug|Win32.ActiveCfg = Debug|Win32 + {16787B20-A841-4DC1-9C15-E6677A0D7342}.Debug|Win32.Build.0 = Debug|Win32 + {16787B20-A841-4DC1-9C15-E6677A0D7342}.Debug|Win32.Deploy.0 = Debug|Win32 + {16787B20-A841-4DC1-9C15-E6677A0D7342}.Release|Win32.ActiveCfg = Release|Win32 + {16787B20-A841-4DC1-9C15-E6677A0D7342}.Release|Win32.Build.0 = Release|Win32 + {16787B20-A841-4DC1-9C15-E6677A0D7342}.Release|Win32.Deploy.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/tools/file2c/src/VS 2012 Project/file2c.v11.suo b/tools/file2c/src/VS 2012 Project/file2c.v11.suo new file mode 100644 index 00000000..38fa846c Binary files /dev/null and b/tools/file2c/src/VS 2012 Project/file2c.v11.suo differ diff --git a/tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj b/tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj new file mode 100644 index 00000000..b0b846c7 --- /dev/null +++ b/tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj @@ -0,0 +1,84 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + {16787B20-A841-4DC1-9C15-E6677A0D7342} + Win32Proj + file2c + + + + Application + true + v110 + Unicode + + + Application + false + v110 + true + Unicode + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + \ No newline at end of file diff --git a/tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj.filters b/tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj.filters new file mode 100644 index 00000000..97daa75f --- /dev/null +++ b/tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj.user b/tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj.user new file mode 100644 index 00000000..a375ae35 --- /dev/null +++ b/tools/file2c/src/VS 2012 Project/file2c/file2c.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/tools/file2c/src/file2c.c b/tools/file2c/src/file2c.c new file mode 100644 index 00000000..29b9da2f --- /dev/null +++ b/tools/file2c/src/file2c.c @@ -0,0 +1,194 @@ +/* + ChibiOS/GFX - Copyright (C) 2012, 2013 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS/GFX. + + ChibiOS/GFX is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/GFX is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include +#ifdef WIN32 + #include +#endif + +static unsigned char buf[1024]; + +static char *filenameof(char *fname) { + char *p; + +#ifdef WIN32 + if (fname[1] == ':') + fname = fname+2; + p = strrchr(fname, '\\'); + if (p) fname = p+1; +#endif + p = strrchr(fname, '/'); + if (p) fname = p+1; + p = strchr(fname, '.'); + if (p) *p = 0; + return fname; +} + +static char *clean4c(char *fname) { + char *p; + + while((p = strpbrk(fname, "-+ `~!@#$%^&*(){}[]|:;'\",<>?/|=.\\"))) *p = '_'; + return fname; +} + +int main(int argc, char * argv[]) +{ +char * opt_progname; +char * opt_inputfile; +char * opt_outputfile; +char * opt_arrayname; +int opt_breakblocks; +char * opt_static; +char * opt_const; +FILE * f_input; +FILE * f_output; +unsigned blocknum; +size_t len; +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 = ""; + + /* 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; + default: + fprintf(stderr, "Unknown flag -%c\n", argv[0][0]); + goto usage; + } + } + } else if (!opt_inputfile) + opt_inputfile = argv[0]; + else if (!opt_outputfile) + 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" + , opt_progname, opt_progname); + return 1; + } + nextarg: ; + } + + /* Open the input file */ + if (opt_inputfile) { + f_input = fopen(opt_inputfile, +#ifdef WIN32 + "rb"); +#else + "r"); +#endif + if (!f_input) { + fprintf(stderr, "Could not open input file '%s'\n", opt_inputfile); + goto usage; + } + } else { + f_input = stdin; +#ifdef WIN32 + _setmode(_fileno(stdin), _O_BINARY); +#endif + } + + /* Open the output file */ + if (opt_outputfile) { + f_output = fopen(opt_outputfile, "w"); + if (!f_output) { + fprintf(stderr, "Could not open output file '%s'\n", opt_outputfile); + goto usage; + } + } else + f_output = stdout; + + /* Print the comment header */ + 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) { + fprintf(f_output, " -"); + 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_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. + */ + if (!opt_arrayname) { + if (opt_inputfile) + opt_arrayname = filenameof(opt_inputfile); + if (!opt_arrayname || !opt_arrayname[0]) + opt_arrayname = "filearray"; + } + opt_arrayname = clean4c(opt_arrayname); + + /* Read the file processing 1K at a time */ + blocknum = 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); + else if (opt_breakblocks) + fprintf(f_output, "\n};\n%s%sunsigned char %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]); + } + } + fprintf(f_output, "\n};\n"); + + /* Clean up */ + if (ferror(f_input)) + fprintf(stderr, "Input file read error\n"); + if (ferror(f_output)) + fprintf(stderr, "Output file write error - disk full?\n"); + if (f_input != stdin) + fclose(f_input); + if (f_output != stdout) + fclose(f_output); + + return 0; +} + -- cgit v1.2.3