summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAriadne Conill <ariadne@treehouse.systems>2022-01-13 14:13:53 +0000
committerTimo Teräs <timo.teras@iki.fi>2022-01-13 14:13:53 +0000
commite8650d4d44d32a3a605283d921e535fff3a17089 (patch)
treec857000e1f540b8e3f1d5b78c55a967e4d4c3569
parent3d41d1c90aff8e4fac684ef3190037984db38051 (diff)
downloadapk-tools-e8650d4d44d32a3a605283d921e535fff3a17089.tar.gz
apk-tools-e8650d4d44d32a3a605283d921e535fff3a17089.tar.bz2
apk-tools-e8650d4d44d32a3a605283d921e535fff3a17089.tar.xz
apk-tools-e8650d4d44d32a3a605283d921e535fff3a17089.zip
support building with uncompressed help databases
-rw-r--r--meson_options.txt3
-rw-r--r--src/applet.c15
-rw-r--r--src/genhelp.lua35
-rw-r--r--src/meson.build7
4 files changed, 41 insertions, 19 deletions
diff --git a/meson_options.txt b/meson_options.txt
index 9d803d9..0eaa4e5 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -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)
diff --git a/src/applet.c b/src/applet.c
index 3b274d7..70dbf47 100644
--- a/src/applet.c
+++ b/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);
diff --git a/src/genhelp.lua b/src/genhelp.lua
index 217ec1b..51f5b73 100644
--- a/src/genhelp.lua
+++ b/src/genhelp.lua
@@ -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)
diff --git a/src/meson.build b/src/meson.build
index 14a4749..f83ad62 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -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(