file2c copyright and add comment to output

ugfx_release_2.6
Andrew Hannam 2013-04-04 21:01:06 +10:00
parent ce9b930af0
commit 3473ad8820
3 changed files with 44 additions and 4 deletions

View File

@ -1,3 +1,22 @@
/*
ChibiOS/GFX - Copyright (C) 2012, 2013
Joel Bodenmann aka Tectu <joel@unormal.org>
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
@ -26,7 +45,7 @@ static char *filenameof(char *fname) {
static char *clean4c(char *fname) {
char *p;
while((p = strpbrk(fname, "-+ `~!@#$%^&*(){}[]|:;'\",<>?/|="))) *p = '_';
while((p = strpbrk(fname, "-+ `~!@#$%^&*(){}[]|:;'\",<>?/|=.\\"))) *p = '_';
return fname;
}
@ -46,7 +65,7 @@ size_t len;
size_t i;
/* Default values for our parameters */
opt_progname = argv[0];
opt_progname = filenameof(argv[0]);
opt_inputfile = 0;
opt_outputfile = 0;
opt_arrayname = 0;
@ -59,6 +78,7 @@ size_t i;
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;
@ -77,6 +97,7 @@ size_t i;
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"
@ -116,14 +137,33 @@ size_t i;
} else
f_output = stdout;
/* Set the array name */
/* 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);
}
opt_arrayname = clean4c(opt_arrayname);
/* Read the file processing 1K at a time */
blocknum = 0;