forked from Imagelibrary/rtems
2010-07-29 Ralf Corsépius <ralf.corsepius@rtems.org>
* rtems-bin2c.c: Add -C and -H options.
This commit is contained in:
@@ -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>
|
2010-03-12 Joel Sherrill <joel.sherrill@oarcorp.com>
|
||||||
|
|
||||||
* eolstrip.c: Readdress use of ctype methods per recommendation from
|
* eolstrip.c: Readdress use of ctype methods per recommendation from
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ int useconst = 1;
|
|||||||
int usestatic = 0;
|
int usestatic = 0;
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
int zeroterminated = 0;
|
int zeroterminated = 0;
|
||||||
|
int createC = 1;
|
||||||
|
int createH = 1;
|
||||||
|
|
||||||
int myfgetc(FILE *f)
|
int myfgetc(FILE *f)
|
||||||
{
|
{
|
||||||
@@ -91,18 +93,23 @@ void process(const char *ifname, const char *ofname)
|
|||||||
fprintf(stderr, "cannot open %s for reading\n", ifname);
|
fprintf(stderr, "cannot open %s for reading\n", ifname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( createC ) {
|
||||||
ocfile = fopen(ocname, "wb");
|
ocfile = fopen(ocname, "wb");
|
||||||
if (ocfile == NULL) {
|
if (ocfile == NULL) {
|
||||||
fprintf(stderr, "cannot open %s for writing\n", ocname);
|
fprintf(stderr, "cannot open %s for writing\n", ocname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( createH ) {
|
||||||
ohfile = fopen(ohname, "wb");
|
ohfile = fopen(ohname, "wb");
|
||||||
if (ohfile == NULL) {
|
if (ohfile == NULL) {
|
||||||
fprintf(stderr, "cannot open %s for writing\n", ohname);
|
fprintf(stderr, "cannot open %s for writing\n", ohname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* find basename */
|
/* find basename */
|
||||||
if ((cp = strrchr(ifname, '/')) != NULL)
|
if ((cp = strrchr(ifname, '/')) != NULL)
|
||||||
++cp;
|
++cp;
|
||||||
@@ -117,6 +124,7 @@ void process(const char *ifname, const char *ofname)
|
|||||||
if (!isalnum(*p))
|
if (!isalnum(*p))
|
||||||
*p = '_';
|
*p = '_';
|
||||||
|
|
||||||
|
if ( createC ) {
|
||||||
/* print C file header */
|
/* print C file header */
|
||||||
fprintf(
|
fprintf(
|
||||||
ocfile,
|
ocfile,
|
||||||
@@ -161,11 +169,13 @@ void process(const char *ifname, const char *ofname)
|
|||||||
buf,
|
buf,
|
||||||
buf
|
buf
|
||||||
);
|
);
|
||||||
|
} /* createC */
|
||||||
|
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
/****** END OF C FILE *****/
|
/****** END OF C FILE *****/
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
|
|
||||||
|
if ( createH ) {
|
||||||
/* print H file header */
|
/* print H file header */
|
||||||
fprintf(
|
fprintf(
|
||||||
ohfile,
|
ohfile,
|
||||||
@@ -208,21 +218,22 @@ void process(const char *ifname, const char *ofname)
|
|||||||
"\n"
|
"\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
);
|
);
|
||||||
|
} /* createH */
|
||||||
|
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
/****** END OF H FILE *****/
|
/****** END OF H FILE *****/
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
|
|
||||||
fclose(ifile);
|
fclose(ifile);
|
||||||
fclose(ocfile);
|
if ( createC ) { fclose(ocfile); }
|
||||||
fclose(ohfile);
|
if ( createH ) { fclose(ohfile); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(
|
fprintf(
|
||||||
stderr,
|
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"
|
" <input_file> is the binary file to convert\n"
|
||||||
" <output_file> should not have a .c or .h extension\n"
|
" <output_file> should not have a .c or .h extension\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -230,6 +241,8 @@ void usage(void)
|
|||||||
" -s - do use static in declaration\n"
|
" -s - do use static in declaration\n"
|
||||||
" -v - verbose\n"
|
" -v - verbose\n"
|
||||||
" -z - add zero terminator\n"
|
" -z - add zero terminator\n"
|
||||||
|
" -H - create c-header only\n"
|
||||||
|
" -C - create c-source file only\n"
|
||||||
);
|
);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -253,6 +266,16 @@ int main(int argc, char **argv)
|
|||||||
zeroterminated = 1;
|
zeroterminated = 1;
|
||||||
--argc;
|
--argc;
|
||||||
++argv;
|
++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 {
|
} else {
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user