mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-30 12:50:58 +00:00
Better packed test
This commit is contained in:
1 parent
2af5d07467
commit
3a46055e52
14 files changed
+161
-80
No files matched your search
@@ -1,20 +1,20 @@
|
||||
PROG ?= example
|
||||
SOURCES ?= ../../mongoose.c main.c mjson.c packed_fs.c
|
||||
CFLAGS ?= -I../.. $(EXTRA)
|
||||
CFLAGS ?= -I../.. -DMG_ENABLE_PACKED_FS=1 $(EXTRA)
|
||||
FILES_TO_EMBED ?= $(wildcard web_root/*.js) $(wildcard web_root/*.css) $(wildcard web_root/*.html) $(wildcard web_root/images/*.png) $(wildcard images/*.jpg)
|
||||
|
||||
all: $(PROG)
|
||||
$(RUN) ./$(PROG)
|
||||
|
||||
$(PROG):
|
||||
$(CC) pack.c -o pack
|
||||
$(CC) ../../test/pack.c -o pack
|
||||
./pack $(FILES_TO_EMBED) > packed_fs.c
|
||||
$(CC) -W -Wall -Wextra -Os -g3 $(CFLAGS) -o $(PROG) $(SOURCES)
|
||||
|
||||
ROOT ?= $(realpath $(CURDIR)/../..)
|
||||
DOCKER ?= docker run -it --rm -e Tmp=. -e WINEDEBUG=-all -v $(ROOT):$(ROOT) -w $(CURDIR) mdashnet/vc98 wine
|
||||
windows:
|
||||
$(DOCKER) cl.exe /nologo $(CFLAGS) pack.c /Fepack.exe
|
||||
$(DOCKER) cl.exe /nologo $(CFLAGS) ../../test/pack.c /Fepack.exe
|
||||
$(DOCKER) cmd /c 'pack.exe $(FILES_TO_EMBED) > packed_fs.c'
|
||||
$(DOCKER) cl.exe /nologo /O2 $(CFLAGS) $(SOURCES) ws2_32.lib /Fe$(PROG).exe
|
||||
$(DOCKER) $(PROG).exe
|
||||
|
||||
@@ -119,7 +119,8 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
"Pragma: no-cache\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT\r\n"
|
||||
"Content-Type: multipart/x-mixed-replace; boundary=--foo\r\n\r\n");
|
||||
} else if (mg_http_match_uri(hm, "/api/log/static")) {
|
||||
struct mg_http_serve_opts opts = {.root_dir = NULL};
|
||||
struct mg_http_serve_opts opts;
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
mg_http_serve_file(c, hm, "log.txt", &opts);
|
||||
} else if (mg_http_match_uri(hm, "/api/log/live")) {
|
||||
c->label[0] = 'L'; // Mark that connection as live log listener
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
// Copyright (c) Cesanta Software Limited
|
||||
// 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 produces a .c data file that contains
|
||||
// contents of all these files as a collection of byte arrays.
|
||||
//
|
||||
// Usage:
|
||||
// 1. Compile this file:
|
||||
// cc -o pack pack.c
|
||||
//
|
||||
// 2. Convert list of files into single .c:
|
||||
// ./pack file1.data file2.data > fs.c
|
||||
//
|
||||
// 3. In your application code, you can access files using this function:
|
||||
// const char *mg_unpack(const char *file_name, size_t *size);
|
||||
//
|
||||
// 4. Build your app with fs.c:
|
||||
// cc -o my_app my_app.c fs.c
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static const char *code =
|
||||
"const char *mg_unpack(const char *name, size_t *size) {\n"
|
||||
" const struct packed_file *p;\n"
|
||||
" for (p = packed_files; p->name != NULL; p++) {\n"
|
||||
" if (strcmp(p->name, name) != 0) continue;\n"
|
||||
" if (size != NULL) *size = p->size - 1;\n"
|
||||
" return (const char *) p->data;\n"
|
||||
" }\n"
|
||||
" return NULL;\n"
|
||||
"}\n";
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i, j, ch;
|
||||
|
||||
printf("%s", "#include <stddef.h>\n");
|
||||
printf("%s", "#include <string.h>\n");
|
||||
printf("%s", "\n");
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
FILE *fp = fopen(argv[i], "rb");
|
||||
char ascii[12];
|
||||
if (fp == NULL) exit(EXIT_FAILURE);
|
||||
|
||||
printf("static const unsigned char v%d[] = {\n", i);
|
||||
for (j = 0; (ch = fgetc(fp)) != EOF; j++) {
|
||||
if (j == (int) sizeof(ascii)) {
|
||||
printf(" // %.*s\n", j, ascii);
|
||||
j = 0;
|
||||
}
|
||||
ascii[j] = (char) ((ch >= ' ' && ch <= '~' && ch != '\\') ? ch : '.');
|
||||
printf(" %3u,", ch);
|
||||
}
|
||||
// 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", "\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", "} packed_files[] = {\n");
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
printf(" {\"%s\", v%d, sizeof(v%d) },\n", argv[i], i, i);
|
||||
}
|
||||
printf("%s", " {NULL, NULL, 0}\n");
|
||||
printf("%s", "};\n\n");
|
||||
printf("%s", code);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -15,4 +15,4 @@ flash:
|
||||
cd build && $(ESPTOOL) --chip esp32 -p $(COMPORT) -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 2MB 0x8000 partition_table/partition-table.bin 0x1000 bootloader/bootloader.bin 0x100000 mongoose-esp32-example.bin
|
||||
|
||||
clean:
|
||||
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb mongoose mongoose_* mongoose.* build sdkconfig build
|
||||
rm -rf build
|
||||
Reference in new issue
Block a user