1#!/bin/sh23die () {4echo "$@" >&25exit 16}78command_list () {9grep -v '^#' "$1"10}1112get_categories () {13tr ' ' '\n'|14grep -v '^$' |15sort |16uniq17}1819category_list () {20command_list "$1" |21cut -c 40- |22get_categories23}2425get_synopsis () {26sed -n '27/^NAME/,/'"$1"'/H28${29x30s/.*'"$1"' - \(.*\)/N_("\1")/31p32}' "Documentation/$1.txt"33}3435define_categories () {36echo37echo "/* Command categories */"38bit=039category_list "$1" |40while read cat41do42echo "#define CAT_$cat (1UL << $bit)"43bit=$(($bit+1))44done45test "$bit" -gt 32 && die "Urgh.. too many categories?"46}4748print_command_list () {49echo "static struct cmdname_help command_list[] = {"5051command_list "$1" |52while read cmd rest53do54printf " { \"$cmd\", $(get_synopsis $cmd), 0"55for cat in $(echo "$rest" | get_categories)56do57printf " | CAT_$cat"58done59echo " },"60done61echo "};"62}6364echo "/* Automatically generated by generate-cmdlist.sh */65struct cmdname_help {66const char *name;67const char *help;68uint32_t category;69};70"71if test -z "$2"72then73define_categories "$1"74echo75print_command_list "$1"76exit 077fi7879echo "static const char *common_cmd_groups[] = {"8081grps=grps$$.tmp82match=match$$.tmp83trap "rm -f '$grps' '$match'" 0 1 2 3 158485sed -n '861,/^### common groups/b87/^### command list/q88/^#/b89/^[ ]*$/b90h;s/^[^ ][^ ]*[ ][ ]*\(.*\)/ N_("\1"),/p91g;s/^\([^ ][^ ]*\)[ ].*/\1/w '$grps'92' "$1"93printf '};\n\n'9495n=096substnum=97while read grp98do99echo "^git-..*[ ]$grp"100substnum="$substnum${substnum:+;}s/[ ]$grp/$n/"101n=$(($n+1))102done <"$grps" >"$match"103104printf 'static struct cmdname_help common_cmds[] = {\n'105grep -f "$match" "$1" |106sed 's/^git-//' |107sort |108while read cmd tags109do110tag=$(echo "$tags" | sed "$substnum; s/[^0-9]//g")111echo " {\"$cmd\", $(get_synopsis git-$cmd), $tag},"112done113echo "};"