mirror of
https://github.com/ep00ch/lwip-contrib-mac.git
synced 2024-10-03 20:55:18 +00:00
Fixed bug #36374 makefsdata.exe can't handle files with non-C characters (allow only 'A-Z', 'a-z', '0-9' and '_' for C variable names)
This commit is contained in:
parent
00e04f9cdb
commit
ec429c725a
@ -85,6 +85,12 @@ static int payload_alingment_dummy_counter = 0;
|
||||
|
||||
#define COPY_BUFSIZE 10240
|
||||
|
||||
struct file_entry
|
||||
{
|
||||
struct file_entry* next;
|
||||
const char* filename_c;
|
||||
};
|
||||
|
||||
int process_sub(FILE *data_file, FILE *struct_file);
|
||||
int process_file(FILE *data_file, FILE *struct_file, const char *filename);
|
||||
int file_write_http_header(FILE *data_file, const char *filename, int file_size,
|
||||
@ -107,6 +113,9 @@ unsigned char useHttp11 = 0;
|
||||
unsigned char supportSsi = 1;
|
||||
unsigned char precalcChksum = 0;
|
||||
|
||||
struct file_entry* first_file = NULL;
|
||||
struct file_entry* last_file = NULL;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FIND_T fInfo;
|
||||
@ -223,6 +232,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf(NEWLINE "Processed %d files - done." NEWLINE NEWLINE, filesProcessed);
|
||||
|
||||
while (first_file != NULL) {
|
||||
struct file_entry* fe = first_file;
|
||||
first_file = fe->next;
|
||||
free(fe);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -387,9 +402,71 @@ int write_checksums(FILE *struct_file, const char *filename, const char *varname
|
||||
return i;
|
||||
}
|
||||
|
||||
static int is_valid_char_for_c_var(char x)
|
||||
{
|
||||
if (((x >= 'A') && (x <= 'Z')) ||
|
||||
((x >= 'a') && (x <= 'z')) ||
|
||||
((x >= '0') && (x <= '9')) ||
|
||||
(x == '_'))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fix_filename_for_c(char* qualifiedName, size_t max_len)
|
||||
{
|
||||
struct file_entry* f;
|
||||
size_t len = strlen(qualifiedName);
|
||||
char *new_name = malloc(len + 2);
|
||||
int filename_ok;
|
||||
int cnt = 0;
|
||||
size_t i;
|
||||
if (len + 3 == max_len) {
|
||||
printf("File name too long: \"%s\"\n", qualifiedName);
|
||||
exit(-1);
|
||||
}
|
||||
strcpy(new_name, qualifiedName);
|
||||
for (i = 0; i < len; i++) {
|
||||
if (!is_valid_char_for_c_var(new_name[i])) {
|
||||
new_name[i] = '_';
|
||||
}
|
||||
}
|
||||
do {
|
||||
filename_ok = 1;
|
||||
for (f = first_file; f != NULL; f = f->next) {
|
||||
if (!strcmp(f->filename_c, new_name)) {
|
||||
filename_ok = 0;
|
||||
cnt++;
|
||||
// try next unique file name
|
||||
sprintf(&new_name[len], "%d", cnt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (!filename_ok && (cnt < 999));
|
||||
if (!filename_ok) {
|
||||
printf("Failed to get unique file name: \"%s\"\n", qualifiedName);
|
||||
exit(-1);
|
||||
}
|
||||
strcpy(qualifiedName, new_name);
|
||||
free(new_name);
|
||||
}
|
||||
|
||||
static void register_filename(const char* qualifiedName)
|
||||
{
|
||||
struct file_entry* fe = malloc(sizeof(struct file_entry));
|
||||
fe->filename_c = strdup(qualifiedName);
|
||||
fe->next = NULL;
|
||||
if (first_file == NULL) {
|
||||
first_file = last_file = fe;
|
||||
} else {
|
||||
last_file->next = fe;
|
||||
last_file = fe;
|
||||
}
|
||||
}
|
||||
|
||||
int process_file(FILE *data_file, FILE *struct_file, const char *filename)
|
||||
{
|
||||
char *pch;
|
||||
char varname[MAX_PATH_LEN];
|
||||
int i = 0;
|
||||
char qualifiedName[MAX_PATH_LEN];
|
||||
@ -403,9 +480,8 @@ int process_file(FILE *data_file, FILE *struct_file, const char *filename)
|
||||
/* create C variable name */
|
||||
strcpy(varname, qualifiedName);
|
||||
/* convert slashes & dots to underscores */
|
||||
while ((pch = strpbrk(varname, "./\\")) != NULL) {
|
||||
*pch = '_';
|
||||
}
|
||||
fix_filename_for_c(varname, MAX_PATH_LEN);
|
||||
register_filename(varname);
|
||||
#if ALIGN_PAYLOAD
|
||||
/* to force even alignment of array */
|
||||
fprintf(data_file, "static const " PAYLOAD_ALIGN_TYPE " dummy_align_%s = %d;" NEWLINE, varname, payload_alingment_dummy_counter++);
|
||||
|
Loading…
Reference in New Issue
Block a user