Evgeny Grin (Karlson2k) 1 год назад
Родитель
Сommit
68de046442
5 измененных файлов с 167 добавлено и 1 удалено
  1. 0 1
      .gitignore
  2. 37 0
      scripts/d_options.rec
  3. 114 0
      scripts/d_options.sh
  4. 5 0
      scripts/d_options1.template
  5. 11 0
      scripts/d_options2.template

+ 0 - 1
.gitignore

@@ -16,7 +16,6 @@ Makefile
 /build-aux/*
 /exclude
 /autom4te.cache
-/scripts
 /keys
 /doc.tmp
 /.project

+ 37 - 0
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

+ 114 - 0
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

+ 5 - 0
scripts/d_options1.template

@@ -0,0 +1,5 @@
+/**
+ * {{Comments}}
+ */
+#define MHD_daemon_set_{{Name}}({{MArguments}}) \
+ (struct MHD_Option){ {{MBody}} }

+ 11 - 0
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;
+}
+