]> git.ipfire.org Git - thirdparty/git.git/blame - generate-cmdlist.sh
generate-cmdlist.sh: replace for loop by printf's auto-repeat feature
[thirdparty/git.git] / generate-cmdlist.sh
CommitLineData
82aec45b
ES
1#!/bin/sh
2
f318d739
NTND
3die () {
4 echo "$@" >&2
5 exit 1
6}
7
8command_list () {
724d6356 9 eval "grep -ve '^#' $exclude_programs" <"$1"
f318d739
NTND
10}
11
0f05f225 12get_category_line () {
a5bd7829 13 tr ' ' '\012' |
191eb491 14 LC_ALL=C sort -u
f318d739
NTND
15}
16
17category_list () {
18 command_list "$1" |
19 cut -c 40- |
0f05f225 20 tr ' ' '\012' |
48bcd823
ÆAB
21 grep -v '^$' |
22 LC_ALL=C sort -u
f318d739
NTND
23}
24
75ba897e
NTND
25get_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
35define_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
48define_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
63print_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"
66d55b99 70 printf " | CAT_%s" $(echo "$rest" | get_category_line)
f318d739
NTND
71 echo " },"
72 done
73 echo "};"
74}
75
724d6356
JS
76exclude_programs=
77while test "--exclude-program" = "$1"
78do
79 shift
80 exclude_programs="$exclude_programs -e \"^$1 \""
81 shift
82done
83
7513595a 84echo "/* Automatically generated by generate-cmdlist.sh */
82aec45b 85struct cmdname_help {
f318d739
NTND
86 const char *name;
87 const char *help;
cfb22a02 88 uint32_t category;
82aec45b 89};
f318d739 90"
60f487ac
NTND
91define_categories "$1"
92echo
3c777767
NTND
93define_category_names "$1"
94echo
60f487ac 95print_command_list "$1"