]>
Commit | Line | Data |
---|---|---|
82aec45b ES |
1 | #!/bin/sh |
2 | ||
f318d739 NTND |
3 | die () { |
4 | echo "$@" >&2 | |
5 | exit 1 | |
6 | } | |
7 | ||
8 | command_list () { | |
cfb22a02 | 9 | grep -v '^#' "$1" |
f318d739 NTND |
10 | } |
11 | ||
12 | get_categories () { | |
13 | tr ' ' '\n'| | |
14 | grep -v '^$' | | |
15 | sort | | |
16 | uniq | |
17 | } | |
18 | ||
19 | category_list () { | |
20 | command_list "$1" | | |
21 | cut -c 40- | | |
22 | get_categories | |
23 | } | |
24 | ||
75ba897e NTND |
25 | get_synopsis () { |
26 | sed -n ' | |
27 | /^NAME/,/'"$1"'/H | |
28 | ${ | |
29 | x | |
30 | s/.*'"$1"' - \(.*\)/N_("\1")/ | |
31 | p | |
32 | }' "Documentation/$1.txt" | |
33 | } | |
34 | ||
f318d739 NTND |
35 | define_categories () { |
36 | echo | |
37 | echo "/* Command categories */" | |
38 | bit=0 | |
39 | category_list "$1" | | |
40 | while read cat | |
41 | do | |
42 | echo "#define CAT_$cat (1UL << $bit)" | |
43 | bit=$(($bit+1)) | |
44 | done | |
45 | test "$bit" -gt 32 && die "Urgh.. too many categories?" | |
46 | } | |
47 | ||
3c777767 NTND |
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 | |
55 | do | |
56 | echo " \"$cat\", /* (1UL << $bit) */" | |
57 | bit=$(($bit+1)) | |
58 | done | |
59 | echo " NULL" | |
60 | echo "};" | |
61 | } | |
62 | ||
f318d739 NTND |
63 | print_command_list () { |
64 | echo "static struct cmdname_help command_list[] = {" | |
65 | ||
66 | command_list "$1" | | |
67 | while read cmd rest | |
68 | do | |
69 | printf " { \"$cmd\", $(get_synopsis $cmd), 0" | |
70 | for cat in $(echo "$rest" | get_categories) | |
71 | do | |
72 | printf " | CAT_$cat" | |
73 | done | |
74 | echo " }," | |
75 | done | |
76 | echo "};" | |
77 | } | |
78 | ||
3ac68a93 NTND |
79 | print_config_list () { |
80 | cat <<EOF | |
81 | static const char *config_name_list[] = { | |
82 | EOF | |
83 | grep '^[a-zA-Z].*\..*::$' Documentation/config.txt | | |
84 | sed '/deprecated/d; s/::$//; s/, */\n/g' | | |
85 | sort | | |
86 | while read line | |
87 | do | |
88 | echo " \"$line\"," | |
89 | done | |
90 | cat <<EOF | |
91 | NULL, | |
92 | }; | |
93 | EOF | |
94 | } | |
95 | ||
7513595a | 96 | echo "/* Automatically generated by generate-cmdlist.sh */ |
82aec45b | 97 | struct cmdname_help { |
f318d739 NTND |
98 | const char *name; |
99 | const char *help; | |
cfb22a02 | 100 | uint32_t category; |
82aec45b | 101 | }; |
f318d739 | 102 | " |
60f487ac NTND |
103 | define_categories "$1" |
104 | echo | |
3c777767 NTND |
105 | define_category_names "$1" |
106 | echo | |
60f487ac | 107 | print_command_list "$1" |
3ac68a93 NTND |
108 | echo |
109 | print_config_list |