makefsdata: don't use FindFirstFile to see if a directory exist but CHDIR() to it directly
This commit is contained in:
parent
9f6dc6ad94
commit
dc27bc8c07
|
@ -38,9 +38,7 @@
|
||||||
|
|
||||||
#define GETCWD(path, len) GetCurrentDirectoryA(len, path)
|
#define GETCWD(path, len) GetCurrentDirectoryA(len, path)
|
||||||
#define CHDIR(path) SetCurrentDirectoryA(path)
|
#define CHDIR(path) SetCurrentDirectoryA(path)
|
||||||
|
#define CHDIR_SUCCEEDED(ret) (ret == TRUE)
|
||||||
#define NEWLINE "\r\n"
|
|
||||||
#define NEWLINE_LEN 2
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -57,9 +55,13 @@
|
||||||
|
|
||||||
#define GETCWD(path, len) getcwd(path, len)
|
#define GETCWD(path, len) getcwd(path, len)
|
||||||
#define CHDIR(path) chdir(path)
|
#define CHDIR(path) chdir(path)
|
||||||
|
#define CHDIR_SUCCEEDED(ret) (ret == 0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define NEWLINE "\r\n"
|
||||||
|
#define NEWLINE_LEN 2
|
||||||
|
|
||||||
/* define this to get the header variables we use to build HTTP headers */
|
/* define this to get the header variables we use to build HTTP headers */
|
||||||
#define LWIP_HTTPD_DYNAMIC_HEADERS 1
|
#define LWIP_HTTPD_DYNAMIC_HEADERS 1
|
||||||
#define LWIP_HTTPD_SSI 1
|
#define LWIP_HTTPD_SSI 1
|
||||||
|
@ -98,7 +100,6 @@ int file_write_http_header(FILE *data_file, const char *filename, int file_size,
|
||||||
int file_put_ascii(FILE *file, const char *ascii_string, int len, int *i);
|
int file_put_ascii(FILE *file, const char *ascii_string, int len, int *i);
|
||||||
int s_put_ascii(char *buf, const char *ascii_string, int len, int *i);
|
int s_put_ascii(char *buf, const char *ascii_string, int len, int *i);
|
||||||
void concat_files(const char *file1, const char *file2, const char *targetfile);
|
void concat_files(const char *file1, const char *file2, const char *targetfile);
|
||||||
static int check_path(char* path, size_t size);
|
|
||||||
|
|
||||||
static unsigned char file_buffer_raw[COPY_BUFSIZE];
|
static unsigned char file_buffer_raw[COPY_BUFSIZE];
|
||||||
/* 5 bytes per char + 3 bytes per line */
|
/* 5 bytes per char + 3 bytes per line */
|
||||||
|
@ -119,8 +120,6 @@ struct file_entry* last_file = NULL;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FIND_T fInfo;
|
|
||||||
FIND_RET_T fret;
|
|
||||||
char path[MAX_PATH_LEN];
|
char path[MAX_PATH_LEN];
|
||||||
char appPath[MAX_PATH_LEN];
|
char appPath[MAX_PATH_LEN];
|
||||||
FILE *data_file;
|
FILE *data_file;
|
||||||
|
@ -161,14 +160,9 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!check_path(path, sizeof(path))) {
|
GETCWD(appPath, MAX_PATH_LEN);
|
||||||
printf("Invalid path: \"%s\"." NEWLINE);
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if command line param or subdir named 'fs' not found spout usage verbiage */
|
/* if command line param or subdir named 'fs' not found spout usage verbiage */
|
||||||
fret = FINDFIRST_DIR(path, &fInfo);
|
if (!CHDIR_SUCCEEDED(CHDIR(path))) {
|
||||||
if (!FINDFIRST_SUCCEEDED(fret)) {
|
|
||||||
/* if no subdir named 'fs' (or the one which was given) exists, spout usage verbiage */
|
/* if no subdir named 'fs' (or the one which was given) exists, spout usage verbiage */
|
||||||
printf(" Failed to open directory \"%s\"." NEWLINE NEWLINE, path);
|
printf(" Failed to open directory \"%s\"." NEWLINE NEWLINE, path);
|
||||||
printf(" Usage: htmlgen [targetdir] [-s] [-i] [-f:<filename>]" NEWLINE NEWLINE);
|
printf(" Usage: htmlgen [targetdir] [-s] [-i] [-f:<filename>]" NEWLINE NEWLINE);
|
||||||
|
@ -183,6 +177,7 @@ int main(int argc, char *argv[])
|
||||||
printf(" process files in subdirectory 'fs'" NEWLINE);
|
printf(" process files in subdirectory 'fs'" NEWLINE);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
CHDIR(appPath);
|
||||||
|
|
||||||
printf("HTTP %sheader will %s statically included." NEWLINE,
|
printf("HTTP %sheader will %s statically included." NEWLINE,
|
||||||
(includeHttpHeader ? (useHttp11 ? "1.1 " : "1.0 ") : ""),
|
(includeHttpHeader ? (useHttp11 ? "1.1 " : "1.0 ") : ""),
|
||||||
|
@ -196,7 +191,6 @@ int main(int argc, char *argv[])
|
||||||
printf("..." NEWLINE NEWLINE);
|
printf("..." NEWLINE NEWLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
GETCWD(appPath, MAX_PATH_LEN);
|
|
||||||
data_file = fopen("fsdata.tmp", "wb");
|
data_file = fopen("fsdata.tmp", "wb");
|
||||||
if (data_file == NULL) {
|
if (data_file == NULL) {
|
||||||
printf("Failed to create file \"fsdata.tmp\"\n");
|
printf("Failed to create file \"fsdata.tmp\"\n");
|
||||||
|
@ -205,6 +199,7 @@ int main(int argc, char *argv[])
|
||||||
struct_file = fopen("fshdr.tmp", "wb");
|
struct_file = fopen("fshdr.tmp", "wb");
|
||||||
if (struct_file == NULL) {
|
if (struct_file == NULL) {
|
||||||
printf("Failed to create file \"fshdr.tmp\"\n");
|
printf("Failed to create file \"fshdr.tmp\"\n");
|
||||||
|
fclose(data_file);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,29 +248,6 @@ int main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_path(char* path, size_t size)
|
|
||||||
{
|
|
||||||
size_t slen;
|
|
||||||
if (path[0] == 0) {
|
|
||||||
/* empty */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
slen = strlen(path);
|
|
||||||
if (slen >= size) {
|
|
||||||
/* not NULL-terminated */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
while ((slen > 0) && ((path[slen] == '\\') || (path[slen] == '/'))) {
|
|
||||||
/* path should not end with trailing backslash */
|
|
||||||
path[slen] = 0;
|
|
||||||
slen--;
|
|
||||||
}
|
|
||||||
if (slen == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void copy_file(const char *filename_in, FILE *fout)
|
static void copy_file(const char *filename_in, FILE *fout)
|
||||||
{
|
{
|
||||||
FILE *fin;
|
FILE *fin;
|
||||||
|
|
Loading…
Reference in New Issue