]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - generate-cmdlist.sh
git-prompt: change == to = for zsh's sake
[thirdparty/git.git] / generate-cmdlist.sh
... / ...
CommitLineData
1#!/bin/sh
2
3die () {
4 echo "$@" >&2
5 exit 1
6}
7
8command_list () {
9 eval "grep -ve '^#' $exclude_programs" <"$1"
10}
11
12get_categories () {
13 tr ' ' '\n'|
14 grep -v '^$' |
15 sort |
16 uniq
17}
18
19category_list () {
20 command_list "$1" |
21 cut -c 40- |
22 get_categories
23}
24
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
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
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
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"
70 for cat in $(echo "$rest" | get_categories)
71 do
72 printf " | CAT_$cat"
73 done
74 echo " },"
75 done
76 echo "};"
77}
78
79exclude_programs=
80while test "--exclude-program" = "$1"
81do
82 shift
83 exclude_programs="$exclude_programs -e \"^$1 \""
84 shift
85done
86
87echo "/* Automatically generated by generate-cmdlist.sh */
88struct cmdname_help {
89 const char *name;
90 const char *help;
91 uint32_t category;
92};
93"
94define_categories "$1"
95echo
96define_category_names "$1"
97echo
98print_command_list "$1"