support building with uncompressed help databases

cute-signatures
Ariadne Conill 2022-01-13 14:13:53 +00:00 committed by Timo Teräs
parent 3d41d1c90a
commit e8650d4d44
4 changed files with 41 additions and 19 deletions

View File

@ -1,5 +1,6 @@
option('docs', description: 'Build manpages with scdoc', type: 'feature', value: 'auto') option('docs', description: 'Build manpages with scdoc', type: 'feature', value: 'auto')
option('help', description: 'Build help into apk binaries, needs lua and lua-zlib', type: 'feature', value: 'auto') option('help', description: 'Build help into apk binaries, needs lua', type: 'feature', value: 'auto')
option('compressed-help', description: 'Compress help database, needs lua-zlib', type: 'boolean', value: true)
option('lua', description: 'Build luaapk (lua bindings)', type: 'feature', value: 'auto') option('lua', description: 'Build luaapk (lua bindings)', type: 'feature', value: 'auto')
option('lua_version', description: 'Lua version to build against', type: 'string', value: '5.3') option('lua_version', description: 'Lua version to build against', type: 'string', value: '5.3')
option('static_apk', description: 'Also build apk.static', type: 'boolean', value: false) option('static_apk', description: 'Also build apk.static', type: 'boolean', value: false)

View File

@ -46,12 +46,19 @@ static inline int is_group(struct apk_applet *applet, const char *topic)
void apk_applet_help(struct apk_applet *applet, struct apk_out *out) void apk_applet_help(struct apk_applet *applet, struct apk_out *out)
{ {
#ifndef NO_HELP #ifndef NO_HELP
char buf[uncompressed_help_size], *ptr, *msg; #ifdef COMPRESSED_HELP
unsigned long len = sizeof buf; unsigned char buf[payload_help_size];
#endif
const char *ptr = (const char *) payload_help, *base = ptr, *msg;
unsigned long len = payload_help_size;
int num = 0; int num = 0;
uncompress((unsigned char*) buf, &len, compressed_help, sizeof compressed_help); #ifdef COMPRESSED_HELP
for (ptr = buf; *ptr && ptr < &buf[len]; ptr = msg + strlen(msg) + 1) { uncompress(buf, &len, payload_help, sizeof payload_help);
ptr = base = (const char *) buf;
len = sizeof buf;
#endif
for (; *ptr && ptr < &base[len]; ptr = msg + strlen(msg) + 1) {
msg = ptr + strlen(ptr) + 1; msg = ptr + strlen(ptr) + 1;
if (is_group(applet, ptr)) { if (is_group(applet, ptr)) {
fputc('\n', stdout); fputc('\n', stdout);

View File

@ -242,7 +242,11 @@ function scdoc:render(out)
table.insert(out, "\0") table.insert(out, "\0")
end end
local do_compress = true
local function compress(data) local function compress(data)
if not do_compress then
return data
end
local zlib = require 'zlib' local zlib = require 'zlib'
local level = 9 local level = 9
if type(zlib.version()) == "string" then if type(zlib.version()) == "string" then
@ -258,8 +262,9 @@ local function dump_compressed_vars(name, data, header)
local width = 16 local width = 16
local cout = compress(data) local cout = compress(data)
if header then print(header) end if header then print(header) end
print(("static const unsigned int uncompressed_%s_size = %d;"):format(name, #data)) if do_compress then print("#define COMPRESSED_HELP") end
print(("static const unsigned char compressed_%s[] = { /* %d bytes */"):format(name, #cout)) print(("static const unsigned int payload_%s_size = %d;"):format(name, #data))
print(("static const unsigned char payload_%s[] = { /* %d bytes */"):format(name, #cout))
for i = 1, #cout do for i = 1, #cout do
if i % width == 1 then if i % width == 1 then
io.write("\t") io.write("\t")
@ -275,17 +280,21 @@ end
local f = {} local f = {}
for _, fn in ipairs(arg) do for _, fn in ipairs(arg) do
doc = setmetatable({ if fn == '--no-zlib' then
width = 78, do_compress = false
section = "HEADER", else
usage = {}, doc = setmetatable({
description = {}, width = 78,
commands = {}, section = "HEADER",
notes = {}, usage = {},
optgroup = {}, description = {},
}, scdoc) commands = {},
doc:parse(fn) notes = {},
table.insert(f, doc) optgroup = {},
}, scdoc)
doc:parse(fn)
table.insert(f, doc)
end
end end
table.sort(f, function(a, b) return a.applet < b.applet end) table.sort(f, function(a, b) return a.applet < b.applet end)

View File

@ -86,13 +86,18 @@ apk_src = [
if lua_bin.found() if lua_bin.found()
genhelp_script = files('genhelp.lua') genhelp_script = files('genhelp.lua')
genhelp_args = [lua_bin, genhelp_script, '@INPUT@']
if not get_option('compressed-help')
genhelp_args += ['--no-zlib']
endif
generated_help = custom_target( generated_help = custom_target(
'help.h', 'help.h',
capture: true, capture: true,
output: 'help.h', output: 'help.h',
input: man_files, input: man_files,
command: [lua_bin, genhelp_script, '@INPUT@'], command: genhelp_args,
) )
else else
generated_help = custom_target( generated_help = custom_target(