]>
Commit | Line | Data |
---|---|---|
82aec45b ES |
1 | #!/bin/sh |
2 | ||
f318d739 NTND |
3 | die () { |
4 | echo "$@" >&2 | |
5 | exit 1 | |
6 | } | |
7 | ||
8 | command_list () { | |
e88842ee ÆAB |
9 | while read cmd rest |
10 | do | |
11 | case "$cmd" in | |
12 | "#"* | '') | |
13 | # Ignore comments and allow empty lines | |
14 | continue | |
15 | ;; | |
16 | *) | |
17 | case "$exclude_programs" in | |
18 | *":$cmd:"*) | |
19 | ;; | |
20 | *) | |
21 | echo "$cmd $rest" | |
22 | ;; | |
23 | esac | |
24 | esac | |
25 | done <"$1" | |
f318d739 NTND |
26 | } |
27 | ||
f318d739 | 28 | category_list () { |
1cecd06e | 29 | echo "$1" | |
e88842ee | 30 | cut -d' ' -f2- | |
0f05f225 | 31 | tr ' ' '\012' | |
48bcd823 ÆAB |
32 | grep -v '^$' | |
33 | LC_ALL=C sort -u | |
f318d739 NTND |
34 | } |
35 | ||
f318d739 NTND |
36 | define_categories () { |
37 | echo | |
38 | echo "/* Command categories */" | |
39 | bit=0 | |
1cecd06e | 40 | echo "$1" | |
f318d739 NTND |
41 | while read cat |
42 | do | |
43 | echo "#define CAT_$cat (1UL << $bit)" | |
44 | bit=$(($bit+1)) | |
45 | done | |
46 | test "$bit" -gt 32 && die "Urgh.. too many categories?" | |
47 | } | |
48 | ||
3c777767 NTND |
49 | define_category_names () { |
50 | echo | |
51 | echo "/* Category names */" | |
52 | echo "static const char *category_names[] = {" | |
53 | bit=0 | |
1cecd06e | 54 | echo "$1" | |
3c777767 NTND |
55 | while read cat |
56 | do | |
57 | echo " \"$cat\", /* (1UL << $bit) */" | |
58 | bit=$(($bit+1)) | |
59 | done | |
60 | echo " NULL" | |
61 | echo "};" | |
62 | } | |
63 | ||
f318d739 NTND |
64 | print_command_list () { |
65 | echo "static struct cmdname_help command_list[] = {" | |
66 | ||
1cecd06e | 67 | echo "$1" | |
f318d739 NTND |
68 | while read cmd rest |
69 | do | |
3ebeb1d6 JK |
70 | synopsis= |
71 | while read line | |
72 | do | |
73 | case "$line" in | |
74 | "$cmd - "*) | |
75 | synopsis=${line#$cmd - } | |
76 | break | |
77 | ;; | |
78 | esac | |
79 | done <"Documentation/$cmd.txt" | |
80 | ||
81 | printf '\t{ "%s", N_("%s"), 0' "$cmd" "$synopsis" | |
8d5be8b4 | 82 | printf " | CAT_%s" $rest |
f318d739 NTND |
83 | echo " }," |
84 | done | |
85 | echo "};" | |
86 | } | |
87 | ||
e88842ee | 88 | exclude_programs=: |
724d6356 JS |
89 | while test "--exclude-program" = "$1" |
90 | do | |
91 | shift | |
e88842ee | 92 | exclude_programs="$exclude_programs$1:" |
724d6356 JS |
93 | shift |
94 | done | |
95 | ||
1cecd06e ÆAB |
96 | commands="$(command_list "$1")" |
97 | categories="$(category_list "$commands")" | |
98 | ||
7513595a | 99 | echo "/* Automatically generated by generate-cmdlist.sh */ |
82aec45b | 100 | struct cmdname_help { |
f318d739 NTND |
101 | const char *name; |
102 | const char *help; | |
cfb22a02 | 103 | uint32_t category; |
82aec45b | 104 | }; |
f318d739 | 105 | " |
1cecd06e | 106 | define_categories "$categories" |
60f487ac | 107 | echo |
1cecd06e | 108 | define_category_names "$categories" |
3c777767 | 109 | echo |
1cecd06e | 110 | print_command_list "$commands" |