support building with uncompressed help databases
parent
3d41d1c90a
commit
e8650d4d44
|
@ -1,5 +1,6 @@
|
|||
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_version', description: 'Lua version to build against', type: 'string', value: '5.3')
|
||||
option('static_apk', description: 'Also build apk.static', type: 'boolean', value: false)
|
||||
|
|
15
src/applet.c
15
src/applet.c
|
@ -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)
|
||||
{
|
||||
#ifndef NO_HELP
|
||||
char buf[uncompressed_help_size], *ptr, *msg;
|
||||
unsigned long len = sizeof buf;
|
||||
#ifdef COMPRESSED_HELP
|
||||
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;
|
||||
|
||||
uncompress((unsigned char*) buf, &len, compressed_help, sizeof compressed_help);
|
||||
for (ptr = buf; *ptr && ptr < &buf[len]; ptr = msg + strlen(msg) + 1) {
|
||||
#ifdef COMPRESSED_HELP
|
||||
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;
|
||||
if (is_group(applet, ptr)) {
|
||||
fputc('\n', stdout);
|
||||
|
|
|
@ -242,7 +242,11 @@ function scdoc:render(out)
|
|||
table.insert(out, "\0")
|
||||
end
|
||||
|
||||
local do_compress = true
|
||||
local function compress(data)
|
||||
if not do_compress then
|
||||
return data
|
||||
end
|
||||
local zlib = require 'zlib'
|
||||
local level = 9
|
||||
if type(zlib.version()) == "string" then
|
||||
|
@ -258,8 +262,9 @@ local function dump_compressed_vars(name, data, header)
|
|||
local width = 16
|
||||
local cout = compress(data)
|
||||
if header then print(header) end
|
||||
print(("static const unsigned int uncompressed_%s_size = %d;"):format(name, #data))
|
||||
print(("static const unsigned char compressed_%s[] = { /* %d bytes */"):format(name, #cout))
|
||||
if do_compress then print("#define COMPRESSED_HELP") end
|
||||
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
|
||||
if i % width == 1 then
|
||||
io.write("\t")
|
||||
|
@ -275,17 +280,21 @@ end
|
|||
|
||||
local f = {}
|
||||
for _, fn in ipairs(arg) do
|
||||
doc = setmetatable({
|
||||
width = 78,
|
||||
section = "HEADER",
|
||||
usage = {},
|
||||
description = {},
|
||||
commands = {},
|
||||
notes = {},
|
||||
optgroup = {},
|
||||
}, scdoc)
|
||||
doc:parse(fn)
|
||||
table.insert(f, doc)
|
||||
if fn == '--no-zlib' then
|
||||
do_compress = false
|
||||
else
|
||||
doc = setmetatable({
|
||||
width = 78,
|
||||
section = "HEADER",
|
||||
usage = {},
|
||||
description = {},
|
||||
commands = {},
|
||||
notes = {},
|
||||
optgroup = {},
|
||||
}, scdoc)
|
||||
doc:parse(fn)
|
||||
table.insert(f, doc)
|
||||
end
|
||||
end
|
||||
table.sort(f, function(a, b) return a.applet < b.applet end)
|
||||
|
||||
|
|
|
@ -86,13 +86,18 @@ apk_src = [
|
|||
|
||||
if lua_bin.found()
|
||||
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(
|
||||
'help.h',
|
||||
capture: true,
|
||||
output: 'help.h',
|
||||
input: man_files,
|
||||
command: [lua_bin, genhelp_script, '@INPUT@'],
|
||||
command: genhelp_args,
|
||||
)
|
||||
else
|
||||
generated_help = custom_target(
|
||||
|
|
Loading…
Reference in New Issue