summaryrefslogtreecommitdiffstats
path: root/generate-cmdlist.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 14:47:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 14:47:53 +0000
commitc8bae7493d2f2910b57f13ded012e86bdcfb0532 (patch)
tree24e09d9f84dec336720cf393e156089ca2835791 /generate-cmdlist.sh
parentInitial commit. (diff)
downloadgit-c8bae7493d2f2910b57f13ded012e86bdcfb0532.tar.xz
git-c8bae7493d2f2910b57f13ded012e86bdcfb0532.zip
Adding upstream version 1:2.39.2.upstream/1%2.39.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'generate-cmdlist.sh')
-rwxr-xr-xgenerate-cmdlist.sh110
1 files changed, 110 insertions, 0 deletions
diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh
new file mode 100755
index 0000000..205541e
--- /dev/null
+++ b/generate-cmdlist.sh
@@ -0,0 +1,110 @@
+#!/bin/sh
+
+die () {
+ echo "$@" >&2
+ exit 1
+}
+
+command_list () {
+ while read cmd rest
+ do
+ case "$cmd" in
+ "#"* | '')
+ # Ignore comments and allow empty lines
+ continue
+ ;;
+ *)
+ case "$exclude_programs" in
+ *":$cmd:"*)
+ ;;
+ *)
+ echo "$cmd $rest"
+ ;;
+ esac
+ esac
+ done <"$1"
+}
+
+category_list () {
+ echo "$1" |
+ cut -d' ' -f2- |
+ tr ' ' '\012' |
+ grep -v '^$' |
+ LC_ALL=C sort -u
+}
+
+define_categories () {
+ echo
+ echo "/* Command categories */"
+ bit=0
+ echo "$1" |
+ while read cat
+ do
+ echo "#define CAT_$cat (1UL << $bit)"
+ bit=$(($bit+1))
+ done
+ test "$bit" -gt 32 && die "Urgh.. too many categories?"
+}
+
+define_category_names () {
+ echo
+ echo "/* Category names */"
+ echo "static const char *category_names[] = {"
+ bit=0
+ echo "$1" |
+ while read cat
+ do
+ echo " \"$cat\", /* (1UL << $bit) */"
+ bit=$(($bit+1))
+ done
+ echo " NULL"
+ echo "};"
+}
+
+print_command_list () {
+ echo "static struct cmdname_help command_list[] = {"
+
+ echo "$1" |
+ while read cmd rest
+ do
+ synopsis=
+ while read line
+ do
+ case "$line" in
+ "$cmd - "*)
+ synopsis=${line#$cmd - }
+ break
+ ;;
+ esac
+ done <"Documentation/$cmd.txt"
+
+ printf '\t{ "%s", N_("%s"), 0' "$cmd" "$synopsis"
+ printf " | CAT_%s" $rest
+ echo " },"
+ done
+ echo "};"
+}
+
+exclude_programs=:
+while test "--exclude-program" = "$1"
+do
+ shift
+ exclude_programs="$exclude_programs$1:"
+ shift
+done
+
+commands="$(command_list "$1")"
+categories="$(category_list "$commands")"
+
+echo "/* Automatically generated by generate-cmdlist.sh */
+struct cmdname_help {
+ const char *name;
+ const char *help;
+ uint32_t category;
+};
+"
+define_categories "$categories"
+echo
+define_category_names "$categories"
+echo
+print_command_list "$commands"