summaryrefslogtreecommitdiffstats
path: root/src/gen-macros.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/gen-macros.sh')
-rwxr-xr-xsrc/gen-macros.sh13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/gen-macros.sh b/src/gen-macros.sh
index 190d74a..a7d74c2 100755
--- a/src/gen-macros.sh
+++ b/src/gen-macros.sh
@@ -1,11 +1,24 @@
#!/bin/sh -e
echo "/* autogenerated, don't edit */"
+echo "#include <string.h>"
+echo "#include <stdlib.h>"
while read prefix base name type typedef; do
echo "// $base.$name ($type)"
case "$type" in
string )
+ echo "#define ${prefix}_has_${name}(d) ((d).${base}.${name} != 0)
+#define ${prefix}_${name}(d) (const char*)((d).${base}.${name})
+#define ${prefix}_${name}_length(d) strlen((d).${base}.${name})
+#define ${prefix}_set_${name}(d, v) \
+ if ((d)._${base}_${name}_alloced) { \
+ free((d).${base}.${name}); \
+ } \
+ (d).${base}.${name} = strdup(v); \
+ (d)._${base}_${name}_alloced = true;"
+ ;;
+ bytestring )
echo "#define ${prefix}_has_${name}(d) (bool)((d).${base}.has_${name})
#define ${prefix}_${name}(d) (const uint8_t*)((d).${base}.${name}.data)
#define ${prefix}_${name}_length(d) (size_t)((d).${base}.${name}.len)