mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-01 13:10:43 +00:00
Revert "Make packed fs always available, and manually settable"
This commit is contained in:
1 parent
b852e0f8c3
commit
bb37f72a63
83 files changed
+8051
-288
No files matched your search
+33
-3
@@ -2,7 +2,7 @@
|
||||
// All rights reserved.
|
||||
|
||||
// This program is used to pack arbitrary data into a C binary. It takes
|
||||
// a list of files as an input, and produc es a .c data file that contains
|
||||
// a list of files as an input, and produces a .c data file that contains
|
||||
// contents of all these files as a collection of byte arrays.
|
||||
//
|
||||
// Usage:
|
||||
@@ -24,12 +24,35 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
static const char *code =
|
||||
"static int scmp(const char *a, const char *b) {\n"
|
||||
" while (*a && (*a == *b)) a++, b++;\n"
|
||||
" return *(const unsigned char *) a - *(const unsigned char *) b;\n"
|
||||
"}\n"
|
||||
"const char *mg_unlist(size_t no) {\n"
|
||||
" return packed_files[no].name;\n"
|
||||
"}\n"
|
||||
"const char *mg_unpack(const char *name, size_t *size, time_t *mtime) {\n"
|
||||
" const struct packed_file *p;\n"
|
||||
" for (p = packed_files; p->name != NULL; p++) {\n"
|
||||
" if (scmp(p->name, name) != 0) continue;\n"
|
||||
" if (size != NULL) *size = p->size - 1;\n"
|
||||
" if (mtime != NULL) *mtime = p->mtime;\n"
|
||||
" return (const char *) p->data;\n"
|
||||
" }\n"
|
||||
" return NULL;\n"
|
||||
"}\n";
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i, j, ch;
|
||||
const char *strip_prefix = "";
|
||||
|
||||
printf("%s", "#include \"mongoose.h\"\n");
|
||||
printf("%s", "\n");
|
||||
printf("%s", "#if defined(__cplusplus)\nextern \"C\" {\n#endif\n");
|
||||
printf("%s", "const char *mg_unlist(size_t no);\n");
|
||||
printf("%s", "const char *mg_unpack(const char *, size_t *, time_t *);\n");
|
||||
printf("%s", "#if defined(__cplusplus)\n}\n#endif\n\n");
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-s") == 0) {
|
||||
@@ -56,12 +79,18 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
// Append zero byte at the end, to make text files appear in memory
|
||||
// as nul-terminated strings.
|
||||
// printf(" 0 // %.*s\n", (int) sizeof(ascii), ascii);
|
||||
printf(" 0 // %.*s\n};\n", j, ascii);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s", "\nconst struct mg_mem_file mg_packed_files[] = {\n");
|
||||
printf("%s", "\nstatic const struct packed_file {\n");
|
||||
printf("%s", " const char *name;\n");
|
||||
printf("%s", " const unsigned char *data;\n");
|
||||
printf("%s", " size_t size;\n");
|
||||
printf("%s", " time_t mtime;\n");
|
||||
printf("%s", "} packed_files[] = {\n");
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
struct stat st;
|
||||
@@ -73,11 +102,12 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
stat(argv[i], &st);
|
||||
if (strncmp(name, strip_prefix, n) == 0) name += n;
|
||||
printf(" {\"/%s\", v%d, sizeof(v%d) - 1, %lu},\n", name, i, i,
|
||||
printf(" {\"/%s\", v%d, sizeof(v%d), %lu},\n", name, i, i,
|
||||
(unsigned long) st.st_mtime);
|
||||
}
|
||||
printf("%s", " {NULL, NULL, 0, 0}\n");
|
||||
printf("%s", "};\n\n");
|
||||
printf("%s", code);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in new issue
Block a user