Merge branch 'jt/fetch-nego-tip' into ab/fetch-nego
[alt-git.git] / generate-cmdlist.sh
blob8d6d8b45ceb0138797eb7e54b15f7546925598ed
1 #!/bin/sh
3 die () {
4 echo "$@" >&2
5 exit 1
8 command_list () {
9 grep -v '^#' "$1"
12 get_categories () {
13 tr ' ' '\n'|
14 grep -v '^$' |
15 sort |
16 uniq
19 category_list () {
20 command_list "$1" |
21 cut -c 40- |
22 get_categories
25 get_synopsis () {
26 sed -n '
27 /^NAME/,/'"$1"'/H
30 s/.*'"$1"' - \(.*\)/N_("\1")/
32 }' "Documentation/$1.txt"
35 define_categories () {
36 echo
37 echo "/* Command categories */"
38 bit=0
39 category_list "$1" |
40 while read cat
42 echo "#define CAT_$cat (1UL << $bit)"
43 bit=$(($bit+1))
44 done
45 test "$bit" -gt 32 && die "Urgh.. too many categories?"
48 define_category_names () {
49 echo
50 echo "/* Category names */"
51 echo "static const char *category_names[] = {"
52 bit=0
53 category_list "$1" |
54 while read cat
56 echo " \"$cat\", /* (1UL << $bit) */"
57 bit=$(($bit+1))
58 done
59 echo " NULL"
60 echo "};"
63 print_command_list () {
64 echo "static struct cmdname_help command_list[] = {"
66 command_list "$1" |
67 while read cmd rest
69 printf " { \"$cmd\", $(get_synopsis $cmd), 0"
70 for cat in $(echo "$rest" | get_categories)
72 printf " | CAT_$cat"
73 done
74 echo " },"
75 done
76 echo "};"
79 echo "/* Automatically generated by generate-cmdlist.sh */
80 struct cmdname_help {
81 const char *name;
82 const char *help;
83 uint32_t category;
86 define_categories "$1"
87 echo
88 define_category_names "$1"
89 echo
90 print_command_list "$1"