summaryrefslogtreecommitdiff
path: root/src/apk_applet.h
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2020-08-24 13:35:36 +0300
committerTimo Teräs <timo.teras@iki.fi>2020-08-24 13:35:36 +0300
commitedb45ae46449ddabcac3dea6b3f42c6cec01510a (patch)
treea27a046df30e4ead8f36c559dabdecb2fa1d7ea5 /src/apk_applet.h
parent82de29cf7bad3d9cbb0aeb4dbe756ad2bde73eb3 (diff)
downloadapk-tools-edb45ae46449ddabcac3dea6b3f42c6cec01510a.tar.gz
apk-tools-edb45ae46449ddabcac3dea6b3f42c6cec01510a.tar.bz2
apk-tools-edb45ae46449ddabcac3dea6b3f42c6cec01510a.tar.xz
apk-tools-edb45ae46449ddabcac3dea6b3f42c6cec01510a.zip
enforce options definitions to bind the enum and the descriptor
This uses some macro trickery to make sure that there's one-to-one mapping with the option index enum and the descriptor. The down side is that enum's are generated via #define's and editors might not pick them up for auto completion, but the benefits are more: it's no longer possible have mismatching enum value and descriptor index, and the amount of source code lines is less.
Diffstat (limited to 'src/apk_applet.h')
-rw-r--r--src/apk_applet.h25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/apk_applet.h b/src/apk_applet.h
index e682314..3bc2eb9 100644
--- a/src/apk_applet.h
+++ b/src/apk_applet.h
@@ -15,12 +15,33 @@
#include "apk_defines.h"
#include "apk_database.h"
-#define APK_OPTAPPLET "\x00"
-#define APK_OPTGROUP(_name) _name "\x00"
+#if 0
#define APK_OPT1n(_opt) "\xf0" _opt "\x00"
#define APK_OPT1R(_opt) "\xaf" "\xf0" _opt "\x00"
#define APK_OPT2n(_opt, _short) _short _opt "\x00"
#define APK_OPT2R(_opt, _short) "\xaf" _short _opt "\x00"
+#endif
+
+#define __APK_OPTAPPLET "\x00"
+#define __APK_OPTGROUP(_name) _name "\x00"
+#define __APK_OPT_ENUM(_enum,__desc) _enum,
+#define __APK_OPT_DESC(_enum,__desc) __desc "\x00"
+
+#define APK_OPT_ARG "\xaf"
+#define APK_OPT_SH(x) "\xf1" x
+#define APK_OPT_S2(x) "\xf2" x
+
+#define APK_OPT_APPLET(var_name, init_macro) \
+ enum { init_macro(__APK_OPT_ENUM) }; \
+ static const char var_name[] = __APK_OPTAPPLET init_macro(__APK_OPT_DESC);
+
+#define APK_OPT_GROUP(var_name, group_name, init_macro) \
+ enum { init_macro(__APK_OPT_ENUM) }; \
+ static const char var_name[] = __APK_OPTGROUP(group_name) init_macro(__APK_OPT_DESC);
+
+#define APK_OPT_GROUP2(var_name, group_name, init_macro, init_macro2) \
+ enum { init_macro(__APK_OPT_ENUM) init_macro2(__APK_OPT_ENUM) }; \
+ static const char var_name[] = __APK_OPTGROUP(group_name) init_macro(__APK_OPT_DESC) init_macro2(__APK_OPT_DESC);
struct apk_option_group {
const char *desc;