i18n: factorize "no directory given for --foo"
[git/debian.git] / generate-cmdlist.sh
blob205541e0f7f81b1df4061215ae34a2742a45475d
1 #!/bin/sh
3 die () {
4 echo "$@" >&2
5 exit 1
8 command_list () {
9 while read cmd rest
11 case "$cmd" in
12 "#"* | '')
13 # Ignore comments and allow empty lines
14 continue
17 case "$exclude_programs" in
18 *":$cmd:"*)
21 echo "$cmd $rest"
23 esac
24 esac
25 done <"$1"
28 category_list () {
29 echo "$1" |
30 cut -d' ' -f2- |
31 tr ' ' '\012' |
32 grep -v '^$' |
33 LC_ALL=C sort -u
36 define_categories () {
37 echo
38 echo "/* Command categories */"
39 bit=0
40 echo "$1" |
41 while read cat
43 echo "#define CAT_$cat (1UL << $bit)"
44 bit=$(($bit+1))
45 done
46 test "$bit" -gt 32 && die "Urgh.. too many categories?"
49 define_category_names () {
50 echo
51 echo "/* Category names */"
52 echo "static const char *category_names[] = {"
53 bit=0
54 echo "$1" |
55 while read cat
57 echo " \"$cat\", /* (1UL << $bit) */"
58 bit=$(($bit+1))
59 done
60 echo " NULL"
61 echo "};"
64 print_command_list () {
65 echo "static struct cmdname_help command_list[] = {"
67 echo "$1" |
68 while read cmd rest
70 synopsis=
71 while read line
73 case "$line" in
74 "$cmd - "*)
75 synopsis=${line#$cmd - }
76 break
78 esac
79 done <"Documentation/$cmd.txt"
81 printf '\t{ "%s", N_("%s"), 0' "$cmd" "$synopsis"
82 printf " | CAT_%s" $rest
83 echo " },"
84 done
85 echo "};"
88 exclude_programs=:
89 while test "--exclude-program" = "$1"
91 shift
92 exclude_programs="$exclude_programs$1:"
93 shift
94 done
96 commands="$(command_list "$1")"
97 categories="$(category_list "$commands")"
99 echo "/* Automatically generated by generate-cmdlist.sh */
100 struct cmdname_help {
101 const char *name;
102 const char *help;
103 uint32_t category;
106 define_categories "$categories"
107 echo
108 define_category_names "$categories"
109 echo
110 print_command_list "$commands"