2010-07-29 Ralf Corsépius <ralf.corsepius@rtems.org>

* rtems-bin2c.c: Add -C and -H options.
This commit is contained in:
Ralf Corsepius
2010-07-29 17:12:38 +00:00
parent 1813048180
commit bafe269d8e
2 changed files with 34 additions and 7 deletions

View File

@@ -1,3 +1,7 @@
2010-07-29 Ralf Corsépius <ralf.corsepius@rtems.org>
* rtems-bin2c.c: Add -C and -H options.
2010-03-12 Joel Sherrill <joel.sherrill@oarcorp.com>
* eolstrip.c: Readdress use of ctype methods per recommendation from

View File

@@ -38,6 +38,8 @@ int useconst = 1;
int usestatic = 0;
int verbose = 0;
int zeroterminated = 0;
int createC = 1;
int createH = 1;
int myfgetc(FILE *f)
{
@@ -91,17 +93,22 @@ void process(const char *ifname, const char *ofname)
fprintf(stderr, "cannot open %s for reading\n", ifname);
exit(1);
}
if ( createC ) {
ocfile = fopen(ocname, "wb");
if (ocfile == NULL) {
fprintf(stderr, "cannot open %s for writing\n", ocname);
exit(1);
}
}
if ( createH ) {
ohfile = fopen(ohname, "wb");
if (ohfile == NULL) {
fprintf(stderr, "cannot open %s for writing\n", ohname);
exit(1);
}
}
/* find basename */
if ((cp = strrchr(ifname, '/')) != NULL)
@@ -117,6 +124,7 @@ void process(const char *ifname, const char *ofname)
if (!isalnum(*p))
*p = '_';
if ( createC ) {
/* print C file header */
fprintf(
ocfile,
@@ -161,11 +169,13 @@ void process(const char *ifname, const char *ofname)
buf,
buf
);
} /* createC */
/*****************************************************************/
/****** END OF C FILE *****/
/*****************************************************************/
if ( createH ) {
/* print H file header */
fprintf(
ohfile,
@@ -208,21 +218,22 @@ void process(const char *ifname, const char *ofname)
"\n"
"#endif\n"
);
} /* createH */
/*****************************************************************/
/****** END OF H FILE *****/
/*****************************************************************/
fclose(ifile);
fclose(ocfile);
fclose(ohfile);
if ( createC ) { fclose(ocfile); }
if ( createH ) { fclose(ohfile); }
}
void usage(void)
{
fprintf(
stderr,
"usage: bin2c [-csvz] <input_file> <output_file>\n"
"usage: bin2c [-csvzCH] <input_file> <output_file>\n"
" <input_file> is the binary file to convert\n"
" <output_file> should not have a .c or .h extension\n"
"\n"
@@ -230,6 +241,8 @@ void usage(void)
" -s - do use static in declaration\n"
" -v - verbose\n"
" -z - add zero terminator\n"
" -H - create c-header only\n"
" -C - create c-source file only\n"
);
exit(1);
}
@@ -253,6 +266,16 @@ int main(int argc, char **argv)
zeroterminated = 1;
--argc;
++argv;
} else if (!strcmp(argv[1], "-C")) {
createH = 0;
createC = 1;
--argc;
++argv;
} else if (!strcmp(argv[1], "-H")) {
createC = 0;
createH = 1;
--argc;
++argv;
} else {
usage();
}