summaryrefslogtreecommitdiff
path: root/generate-cmdlist.sh
diff options
context:
space:
mode:
Diffstat (limited to 'generate-cmdlist.sh')
-rwxr-xr-xgenerate-cmdlist.sh78
1 files changed, 45 insertions, 33 deletions
diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh
index 9dbbb08e70..205541e0f7 100755
--- a/generate-cmdlist.sh
+++ b/generate-cmdlist.sh
@@ -6,37 +6,38 @@ die () {
}
command_list () {
- eval "grep -ve '^#' $exclude_programs" <"$1"
-}
-
-get_categories () {
- tr ' ' '\012'|
- grep -v '^$' |
- sort |
- uniq
+ while read cmd rest
+ do
+ case "$cmd" in
+ "#"* | '')
+ # Ignore comments and allow empty lines
+ continue
+ ;;
+ *)
+ case "$exclude_programs" in
+ *":$cmd:"*)
+ ;;
+ *)
+ echo "$cmd $rest"
+ ;;
+ esac
+ esac
+ done <"$1"
}
category_list () {
- command_list "$1" |
- cut -c 40- |
- get_categories
-}
-
-get_synopsis () {
- sed -n '
- /^NAME/,/'"$1"'/H
- ${
- x
- s/.*'"$1"' - \(.*\)/N_("\1")/
- p
- }' "Documentation/$1.txt"
+ echo "$1" |
+ cut -d' ' -f2- |
+ tr ' ' '\012' |
+ grep -v '^$' |
+ LC_ALL=C sort -u
}
define_categories () {
echo
echo "/* Command categories */"
bit=0
- category_list "$1" |
+ echo "$1" |
while read cat
do
echo "#define CAT_$cat (1UL << $bit)"
@@ -50,7 +51,7 @@ define_category_names () {
echo "/* Category names */"
echo "static const char *category_names[] = {"
bit=0
- category_list "$1" |
+ echo "$1" |
while read cat
do
echo " \"$cat\", /* (1UL << $bit) */"
@@ -63,27 +64,38 @@ define_category_names () {
print_command_list () {
echo "static struct cmdname_help command_list[] = {"
- command_list "$1" |
+ echo "$1" |
while read cmd rest
do
- printf " { \"$cmd\", $(get_synopsis $cmd), 0"
- for cat in $(echo "$rest" | get_categories)
+ synopsis=
+ while read line
do
- printf " | CAT_$cat"
- done
+ case "$line" in
+ "$cmd - "*)
+ synopsis=${line#$cmd - }
+ break
+ ;;
+ esac
+ done <"Documentation/$cmd.txt"
+
+ printf '\t{ "%s", N_("%s"), 0' "$cmd" "$synopsis"
+ printf " | CAT_%s" $rest
echo " },"
done
echo "};"
}
-exclude_programs=
+exclude_programs=:
while test "--exclude-program" = "$1"
do
shift
- exclude_programs="$exclude_programs -e \"^$1 \""
+ exclude_programs="$exclude_programs$1:"
shift
done
+commands="$(command_list "$1")"
+categories="$(category_list "$commands")"
+
echo "/* Automatically generated by generate-cmdlist.sh */
struct cmdname_help {
const char *name;
@@ -91,8 +103,8 @@ struct cmdname_help {
uint32_t category;
};
"
-define_categories "$1"
+define_categories "$categories"
echo
-define_category_names "$1"
+define_category_names "$categories"
echo
-print_command_list "$1"
+print_command_list "$commands"