mirror of
https://git.rtems.org/rtems-tools/
synced 2025-10-16 01:24:46 +08:00
bin2c: Improve file name sanitation
Only use alpha-numeric characters for header guards.
This commit is contained in:
@@ -42,6 +42,15 @@ int zeroterminated = 0;
|
|||||||
int createC = 1;
|
int createC = 1;
|
||||||
int createH = 1;
|
int createH = 1;
|
||||||
|
|
||||||
|
static void sanitize_file_name(char *p)
|
||||||
|
{
|
||||||
|
while (*p != '\0') {
|
||||||
|
if (!isalnum((unsigned char)*p)) /* cast to avoid negative indexing */
|
||||||
|
*p = '_';
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int myfgetc(FILE *f)
|
int myfgetc(FILE *f)
|
||||||
{
|
{
|
||||||
int c = fgetc(f);
|
int c = fgetc(f);
|
||||||
@@ -55,7 +64,7 @@ int myfgetc(FILE *f)
|
|||||||
void process(const char *ifname, const char *ofname, const char *forced_name)
|
void process(const char *ifname, const char *ofname, const char *forced_name)
|
||||||
{
|
{
|
||||||
FILE *ifile, *ocfile, *ohfile;
|
FILE *ifile, *ocfile, *ohfile;
|
||||||
char buf[PATH_MAX+1], *p;
|
char buf[PATH_MAX+1];
|
||||||
char obasename[PATH_MAX+1];
|
char obasename[PATH_MAX+1];
|
||||||
char ocname[PATH_MAX+5];
|
char ocname[PATH_MAX+5];
|
||||||
char ohname[PATH_MAX+5];
|
char ohname[PATH_MAX+5];
|
||||||
@@ -132,10 +141,7 @@ void process(const char *ifname, const char *ofname, const char *forced_name)
|
|||||||
ifbasename = basename(ifbasename_to_free);
|
ifbasename = basename(ifbasename_to_free);
|
||||||
|
|
||||||
strcpy(buf, ifbasename);
|
strcpy(buf, ifbasename);
|
||||||
for (p = buf; *p != '\0'; ++p) {
|
sanitize_file_name(buf);
|
||||||
if (!isalnum((unsigned char)*p)) /* cast to avoid negative indexing */
|
|
||||||
*p = '_';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( createC ) {
|
if ( createC ) {
|
||||||
/* print C file header */
|
/* print C file header */
|
||||||
@@ -191,18 +197,12 @@ void process(const char *ifname, const char *ofname, const char *forced_name)
|
|||||||
if ( createH ) {
|
if ( createH ) {
|
||||||
/* print H file header */
|
/* print H file header */
|
||||||
char hbasename[PATH_MAX];
|
char hbasename[PATH_MAX];
|
||||||
char* p;
|
|
||||||
/* Clean up the file name if it is an abs path */
|
/* Clean up the file name if it is an abs path */
|
||||||
strcpy(
|
strcpy(
|
||||||
hbasename,
|
hbasename,
|
||||||
obasename
|
obasename
|
||||||
);
|
);
|
||||||
p = hbasename;
|
sanitize_file_name(hbasename);
|
||||||
while (*p != '\0') {
|
|
||||||
if (*p < '0' || *p > 'z')
|
|
||||||
*p = '_';
|
|
||||||
++p;
|
|
||||||
}
|
|
||||||
fprintf(
|
fprintf(
|
||||||
ohfile,
|
ohfile,
|
||||||
"/*\n"
|
"/*\n"
|
||||||
|
Reference in New Issue
Block a user