Lorolem upravena verze - LittleFS, FSBrowser pro offline, pouziti PROGMEM.
This commit is contained in:
22
extras/README.md
Normal file
22
extras/README.md
Normal file
@ -0,0 +1,22 @@
|
||||
### Extras
|
||||
Additions to facilitate code modifications (for MS Win, similar can be done on Linux)
|
||||
|
||||
- **ehg.c (ehg.exe):** Tool to generate C-code array from file' bytes
|
||||
Based on [bin2array](https://github.com/TheLivingOne/bin2array/) PROGMEM keyword can optionally be added.
|
||||
|
||||
- **rehg.c (rehg.exe):** Tool to reverse C-code array generated by **ehg.exe** back to a file
|
||||
Based on [c2bin](https://github.com/birkett/cbintools/tree/master/c2bin)
|
||||
First 4 lines of source are ignored, then parses the 0xHH - formated bytes
|
||||
until a } is found on separate new line.
|
||||
|
||||
### Tools
|
||||
- [TCC : Tiny C Compiler](https://bellard.org/tcc/) for **ehg** and **rehg** compiling on MS Win
|
||||
- [7-Zip](https://www.7-zip.org) Install 7z and use the included gzip as command line tool
|
||||
- [Node.js](https://nodejs.org) Install Node with default settings, then run:
|
||||
|
||||
``` npm install html-minifier-terser -g, npm install -g github-files-fetcher ```
|
||||
|
||||
### Batch files provided
|
||||
- **do.bat:** Generates **edit.htm.gz.h** file
|
||||
- **undo.bat:** Reverts **edit.htm** from C array header to file (still minified!)
|
||||
- **update_ace.bat:** Updates **acefull.js.gz** file from latest GitHub Ace sources
|
7
extras/do.bat
Normal file
7
extras/do.bat
Normal file
@ -0,0 +1,7 @@
|
||||
copy ..\src\edit.htm edit_src.htm
|
||||
call html-minifier-terser --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --minify-css true --minify-js true -o edit.htm edit_src.htm
|
||||
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 edit.htm.gz edit.htm
|
||||
ehg edit.htm.gz PROGMEM
|
||||
copy edit.htm.gz.h ..\src\edit.htm.gz.h
|
||||
pause
|
||||
del edit.htm edit.htm.gz edit.htm.gz.h edit_src.htm
|
124
extras/ehg.c
Normal file
124
extras/ehg.c
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Simple, but very fast converter of file to C++ array; written in old school C.
|
||||
* ehg.c (ehg.exe)
|
||||
* Based on https://github.com/TheLivingOne/bin2array/
|
||||
* by (C) Sergey A. Galin, 2019, sergey.galin@gmail.com, sergey.galin@yandex.ru
|
||||
* and compiled with TynyCC https://bellard.org/tcc/
|
||||
* This file is a Public Domain.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char* replace_char(char* str, char find, char replace){
|
||||
char *current_pos = strchr(str,find);
|
||||
for (char* p = current_pos; (current_pos = strchr(str, find)) != NULL; *current_pos = replace);
|
||||
return str;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
if ((argc > 3)||(argc < 2)) {
|
||||
printf("USAGE: %s <input file> [PROGMEM]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char * in = argv[1];
|
||||
const char * pr = argv[2];
|
||||
char pr_o[8] = " ";
|
||||
|
||||
if (argv[2]) sprintf(pr_o, "%s", pr);
|
||||
|
||||
// Hello stack overflow :)
|
||||
char out_cpp[4096];
|
||||
char usname[4096];
|
||||
sprintf(usname, "%s", in);
|
||||
sprintf(out_cpp, "%s.h", in);
|
||||
|
||||
replace_char(usname,'.', '_');
|
||||
|
||||
printf("Input: %s, output: %s\n", in, out_cpp);
|
||||
|
||||
//
|
||||
// Working with the input file
|
||||
//
|
||||
FILE * fin = fopen(in, "rb");
|
||||
if (!fin) {
|
||||
printf("Error opening input file!\n");
|
||||
return 2;
|
||||
}
|
||||
fseek(fin, 0, SEEK_END);
|
||||
size_t size = (size_t)ftell(fin);
|
||||
fseek(fin, 0, SEEK_SET);
|
||||
printf("Input data size: %ld\n", (long)size);
|
||||
|
||||
unsigned char * data = malloc(size);
|
||||
if (fread(data, size, 1, fin) != 1) {
|
||||
printf("Failed to read input file!\n");
|
||||
free(data);
|
||||
fclose(fin);
|
||||
return 2;
|
||||
}
|
||||
fclose(fin);
|
||||
|
||||
unsigned char arr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
||||
unsigned char * text = malloc(size * 6);
|
||||
unsigned char * out_ptr = text;
|
||||
unsigned char * in_ptr = data;
|
||||
for (size_t i = 1, col = 1; i <= size; i++, in_ptr++) {
|
||||
unsigned char x = *in_ptr;
|
||||
unsigned char y = (x & 0xF0) >> 4;
|
||||
unsigned char z = (x & 0x0F);
|
||||
|
||||
*out_ptr++ = '0';
|
||||
*out_ptr++ = 'x';
|
||||
|
||||
*out_ptr++ = arr[y];
|
||||
*out_ptr++ = arr[z];
|
||||
|
||||
if (i != size) {
|
||||
*out_ptr++ = ',';
|
||||
}
|
||||
if (col == 20) {
|
||||
*out_ptr++ = '\n';
|
||||
col = 1;
|
||||
} else
|
||||
col++;
|
||||
}
|
||||
free(data);
|
||||
// *out_ptr = 0; not necessary as we're using fwrite()
|
||||
|
||||
//
|
||||
// Writing output file
|
||||
//
|
||||
|
||||
FILE * fout = fopen(out_cpp, "wb");
|
||||
if (!fout) {
|
||||
printf("Error opening output file!\n");
|
||||
free(text);
|
||||
return 2;
|
||||
}
|
||||
fprintf(
|
||||
fout,
|
||||
"\n//File: %s, Size: %ld\n"
|
||||
"#define %s_len %ld\n"
|
||||
"const uint8_t %s[] %s = {\n",
|
||||
in,
|
||||
(long)size,
|
||||
usname,
|
||||
(long)size,
|
||||
usname,
|
||||
pr_o);
|
||||
if (fwrite(text, out_ptr - text, 1, fout) != 1) {
|
||||
printf("Error writing output file!");
|
||||
free(text);
|
||||
fclose(fout);
|
||||
return 2;
|
||||
}
|
||||
fprintf(fout, "\n};\n");
|
||||
fclose(fout);
|
||||
free(text);
|
||||
return 0;
|
||||
}
|
||||
|
BIN
extras/ehg.exe
Normal file
BIN
extras/ehg.exe
Normal file
Binary file not shown.
101
extras/rehg.c
Normal file
101
extras/rehg.c
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2015 Anthony Birkett
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* rehg.c (rehg.exe): Tool to reverse C-code array to file converted by ehg.exe
|
||||
* Based on https://github.com/birkett/cbintools/tree/master/c2bin
|
||||
* and compiled with TynyCC https://bellard.org/tcc/
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BUFFER_SIZE 500
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *inputFile = NULL;
|
||||
FILE *outputFile = NULL;
|
||||
char sBuffer[BUFFER_SIZE];
|
||||
char *pch;
|
||||
char *newline, *endBracket;
|
||||
int i;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
printf("%s %s %s\n", "Usage:", argv[0], "<header> <output>");
|
||||
return 1;
|
||||
}
|
||||
|
||||
inputFile = fopen(argv[1], "r");
|
||||
|
||||
if (inputFile == NULL)
|
||||
{
|
||||
printf("%s %s\n", "Unable to open input header:", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
outputFile = fopen(argv[2], "wb");
|
||||
|
||||
if (outputFile == NULL)
|
||||
{
|
||||
printf("%s %s\n", "Unable to open output file:", argv[2]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Skip the first 4 lines.
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
fgets(sBuffer, BUFFER_SIZE, inputFile);
|
||||
}
|
||||
|
||||
// Get the contents of each line of the array.
|
||||
while (fgets(sBuffer, BUFFER_SIZE, inputFile))
|
||||
{
|
||||
// Get rid of the new line character.
|
||||
newline = strchr(sBuffer, '\n');
|
||||
if (newline)
|
||||
{
|
||||
*newline = 0;
|
||||
}
|
||||
|
||||
// Skip this line if its the closing "};".
|
||||
endBracket = strchr(sBuffer, '}');
|
||||
if (endBracket)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Write out each character.
|
||||
pch = strtok(sBuffer, ",");
|
||||
while (pch != NULL)
|
||||
{
|
||||
fprintf(outputFile, "%c", strtol(pch, NULL, 0)); // autodetect
|
||||
pch = strtok(NULL, ",");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
extras/rehg.exe
Normal file
BIN
extras/rehg.exe
Normal file
Binary file not shown.
0
extras/tmp1/placeholder
Normal file
0
extras/tmp1/placeholder
Normal file
4
extras/undo.bat
Normal file
4
extras/undo.bat
Normal file
@ -0,0 +1,4 @@
|
||||
copy ..\src\edit.htm.gz.h edit.htm.gz.h
|
||||
rehg edit.htm.gz.h edit.htm.gz
|
||||
"C:\Program Files\7-Zip\7z.exe" e -tgzip edit.htm.gz
|
||||
pause
|
39
extras/update_ace.bat
Normal file
39
extras/update_ace.bat
Normal file
@ -0,0 +1,39 @@
|
||||
REM https://www.npmjs.com/package/github-files-fetcher
|
||||
REM npm install -g github-files-fetcher
|
||||
REM fetcher --url=resource_url --out=output_directory
|
||||
|
||||
call fetcher --url="https://github.com/ajaxorg/ace-builds/blob/master/src-min-noconflict/ace.js" --out=tmp1
|
||||
call fetcher --url="https://github.com/ajaxorg/ace-builds/blob/master/src-min-noconflict/mode-html.js" --out=tmp1
|
||||
call fetcher --url="https://github.com/ajaxorg/ace-builds/blob/master/src-min-noconflict/theme-monokai.js" --out=tmp1
|
||||
call fetcher --url="https://github.com/ajaxorg/ace-builds/blob/master/src-min-noconflict/ext-searchbox.js" --out=tmp1
|
||||
|
||||
REM if you don't need worker(s), modify line#446 of edit.htm .setUseWorker(!0) to (!1) (true to false)
|
||||
REM and do not take and include them below
|
||||
call fetcher --url="https://github.com/ajaxorg/ace-builds/blob/master/src-min-noconflict/worker-html.js" --out=tmp1
|
||||
call fetcher --url="https://github.com/ajaxorg/ace-builds/blob/master/src-min-noconflict/worker-css.js" --out=tmp1
|
||||
call fetcher --url="https://github.com/ajaxorg/ace-builds/blob/master/src-min-noconflict/worker-javascript.js" --out=tmp1
|
||||
|
||||
cd tmp1
|
||||
type ace.js mode-html.js theme-monokai.js ext-searchbox.js > acefull.js
|
||||
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 acefull.js.gz acefull.js
|
||||
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 worker-html.js.gz worker-html.js
|
||||
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 worker-javascript.js.gz worker-javascript.js
|
||||
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 worker-css.js.gz worker-css.js
|
||||
|
||||
REM update SmartSwitch /data:
|
||||
pause
|
||||
copy acefull.js.gz ..\..\examples\SmartSwitch\data\acefull.js.gz
|
||||
copy worker-html.js.gz ..\..\examples\SmartSwitch\data\worker-html.js.gz
|
||||
copy worker-javascript.js.gz ..\..\examples\SmartSwitch\data\worker-javascript.js.gz
|
||||
copy worker-css.js.gz ..\..\examples\SmartSwitch\data\worker-css.js.gz
|
||||
|
||||
REM update ESP_AsyncFSBrowser /data:
|
||||
pause
|
||||
copy acefull.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\acefull.js.gz
|
||||
copy worker-html.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\worker-html.js.gz
|
||||
copy worker-javascript.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\worker-javascript.js.gz
|
||||
copy worker-css.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\worker-css.js.gz
|
||||
|
||||
REM delete temporary stuff
|
||||
pause
|
||||
del *.js *.gz
|
Reference in New Issue
Block a user