From 68de046442b760cf1cde600ded900db2ca18885e Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Tue, 2 Apr 2024 01:14:11 +0200 Subject: [PATCH] daemon options draft script --- .gitignore | 1 - scripts/d_options.rec | 37 ++++++++++++ scripts/d_options.sh | 114 ++++++++++++++++++++++++++++++++++++ scripts/d_options1.template | 5 ++ scripts/d_options2.template | 11 ++++ 5 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 scripts/d_options.rec create mode 100644 scripts/d_options.sh create mode 100644 scripts/d_options1.template create mode 100644 scripts/d_options2.template diff --git a/.gitignore b/.gitignore index 010e0091..b276e4f4 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,6 @@ Makefile /build-aux/* /exclude /autom4te.cache -/scripts /keys /doc.tmp /.project diff --git a/scripts/d_options.rec b/scripts/d_options.rec new file mode 100644 index 00000000..397f1ee5 --- /dev/null +++ b/scripts/d_options.rec @@ -0,0 +1,37 @@ +# *-* mode: rec -*- +# +# MHD option registry +# +%rec: MHD_Option +%key: Name +%singular: Value +%mandatory: Value +%mandatory: Comment +%mandatory: Argument +%mandatory: Description +%constraint: ( Value > 0 ) + +Name: suppress_date +Value: 1 +Argument1: bool suppressed +Description1: . +Comment: Suppresses the date header. ++ * This option should only be set when the system lacks an RTC. ++ * ++ * @param bool true to not generate the Data header + +Value: 2 +Name: cert_callback +Comment: Set TLS callback +Argument1: Callback cb +Description1: [in] callback +Member1: opt.cb +Argument2: void* cls +Description2: [out] closure +Member2: opt.cls + + +Name: bind_address +Value: 3 +Comment: Set IPv4 address to bind to +Argument1: const struct sockaddr* in diff --git a/scripts/d_options.sh b/scripts/d_options.sh new file mode 100644 index 00000000..5d9a1ffe --- /dev/null +++ b/scripts/d_options.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +if command -v recsel >/dev/null 2>&1 ; then : ; else + echo "Error: The command 'recsel' is missing. Please install recutils." >&2 + exit 1 +fi + +if command -v recset >/dev/null 2>&1 ; then : ; else + echo "Error: The command 'recset' is missing. Please install recutils." >&2 + exit 1 +fi + +if command -v recfmt >/dev/null 2>&1 ; then : ; else + echo "Error: The command 'recfmt' is missing. Please install recutils." >&2 + exit 1 +fi + +if (( 0 + 1 )) 2>/dev/null && test "$(( 2 + 2 ))" = "4" 2>/dev/null ; then : ; else + echo "Error: Built-in shell math is required" >&2 + exit 1 +fi + +if declare -a ARGS 2>/dev/null ; then : ; else + echo "Error: Indexed arrays support is required" >&2 + exit 1 +fi + +# parameters +max_width=79 + +# cut string to given length at word boundary if possible +cut_str_word () { + local str="$1" + local len=$2 + declare -g cut_str_word_res='' + [[ $len -eq 0 ]] && return 1 + if [[ ${#str} -le $len ]]; then + cut_str_word_res="${str}" + return 0 + fi + if [[ "${str:${len}:1}" = " " ]]; then + cut_str_word_res="${str:0:${len}}" + return 0 + fi + cut_str_word_res="${str:0:${len}}" + cut_str_word_res="${cut_str_word_res% *}" + return 0 +} + +format_param_descr() { + local prefix1="$1" # first line prefix + local desc="$2" + local prefix2="$3" # prefix on all other lines + local width="$4" + local tmp_str + declare -g format_param_descr_res='' + [[ -z $3 ]] && prefix2=' *' + [[ -z $width ]] && width=79 + prefix1="${prefix1#${prefix1%%[! ]*}}" + prefix1="${prefix1%${prefix1##*[! ]}} " # trim prefix1 + desc="${desc#${desc%%[! ]*}}" + desc="${desc%${desc##*[! ]}}" # trim desc + local width_r=$(( width - ${#prefix1} )) + local tmp_str="${prefix1//?/ }" + prefix2=" +${prefix2}${tmp_str:${#prefix2}}" + cut_str_word "$desc" $width_r || return 1 + format_param_descr_res="${prefix1}${cut_str_word_res}" + desc="${desc:${#cut_str_word_res}}" + desc="${desc#${desc%%[! ]*}}" # trim leading spaces + while [[ -n "$desc" ]]; do + cut_str_word "$desc" $width_r || return 1 + format_param_descr_res+="${prefix2}${cut_str_word_res}" + desc="${desc:${#cut_str_word_res}}" + done + return 0 +} + + +cp d_options.rec tmp.rec || exit 2 + +for N in $(recsel -t MHD_Option -R Value d_options.rec) +do + NAME=$(recsel -t MHD_Option -P Name -e "Value=$N" d_options.rec) + COMMENT=$(recsel -t MHD_Option -P Comment -e "Value=$N" d_options.rec) + ARGS=( ) + DESCRS=( ) + MEMBRS=( ) + [[ -n $NAME ]] || exit 2 + M=1 + while + ARGM=$(recsel -t MHD_Option -P Argument${M} -e "Value=$N" d_options.rec) + [[ -n $ARGM ]] + do + ARGS+=( "$ARGM" ) + DESCRM=$(recsel -t MHD_Option -P Description${M} -e "Value=$N" d_options.rec) + if [[ -z $DESCRM ]]; then + echo "Empty Description${M} for argument \"$ARGM\" for $NAME" >&2 + exit 2 + fi + DESCRS+=( "$DESCRM" ) + MEMBRM=$(recsel -t MHD_Option -P Member${M} -e "Value=$N" d_options.rec) + [[ -z $MEMBRM ]] && MEMBRM="$ARGM" + MEMBRS+=( "$MEMBRM" ) + (( M++ )) + done + CBODY="" + MBODY="" + SBODY="" + echo $N - $NAME +done + +# recfmt -f d_option1.template tmp.rec +# recfmt -f d_option2.template tmp.rec diff --git a/scripts/d_options1.template b/scripts/d_options1.template new file mode 100644 index 00000000..83a09e05 --- /dev/null +++ b/scripts/d_options1.template @@ -0,0 +1,5 @@ +/** + * {{Comments}} + */ +#define MHD_daemon_set_{{Name}}({{MArguments}}) \ + (struct MHD_Option){ {{MBody}} } diff --git a/scripts/d_options2.template b/scripts/d_options2.template new file mode 100644 index 00000000..9d811aff --- /dev/null +++ b/scripts/d_options2.template @@ -0,0 +1,11 @@ +/** + * {{Comments}} + */ +inline static enum MHD_Option +MHD_daemon_set_{{Name}} ({{Arguments}}) { + struct MHD_Option opt; + + {{CBody}} + return opt; +} +