From: lufia <lufia@xxxxxxxxx> Signed-off-by: lufia <lufia@xxxxxxxxx> --- generate-cmdlist.rc | 102 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 generate-cmdlist.rc diff --git a/generate-cmdlist.rc b/generate-cmdlist.rc new file mode 100755 index 0000000000..18699ea9c4 --- /dev/null +++ b/generate-cmdlist.rc @@ -0,0 +1,102 @@ +#!/bin/rc + +rfork e + +fn die { + echo $* >[1=2] + exit die +} + +fn command_list { + grep -v '^#' $1 +} + +fn get_categories { + tr ' ' '\x0a'| + grep -v '^$' | + sort | + uniq +} + +fn category_list { + command_list $1 | + awk '{ print substr($0, 40) }' | + get_categories +} + +fn get_synopsis { + sed -n ' + /^NAME/,/'$1'/h + ${ + x + s/.*'$1' - (.*)/N_\("\1"\)/ + p + }' Documentation/$1.txt +} + +fn define_categories { + echo + echo '/* Command categories */' + bit=0 + category_list $1 | + while(cat=`{read}){ + echo '#define CAT_'$"cat' (1UL << '$bit')' + bit=`{hoc -e $bit' + 1'} + } + test $bit -gt 32 && die 'Urgh.. too many categories?' +} + +fn define_category_names { + echo + echo '/* Category names */' + echo 'static const char *category_names[] = {' + bit=0 + category_list $1 | + while(cat=`{read}){ + echo ' "'$"cat'", /* (1UL << '$bit') */' + bit=`{hoc -e $bit' + 1'} + } + echo ' NULL,' + echo '};' +} + +fn print_command_list { + echo 'static struct cmdname_help command_list[] = {' + + command_list $1 | + while(a=`{read}){ + s=`{get_synopsis $a(1)} + q=`{seq 2 $#a} + echo -n ' { "'^$a(1)^'", '$"s', 0' + for(cat in `{echo $a($q) | get_categories}) + echo -n ' | CAT_'^$cat + echo ' },' + } + echo '};' +} + +fn print_config_list { + echo 'static const char *config_name_list[] = {' + grep -h '^[a-zA-Z].*\..*::$' Documentation/*config.txt Documentation/config/*.txt | + sed '/deprecated/d; s/::$//; s/, */\n/g' | + sort | + while(line=`{read}) + echo ' "'$"line'",' + echo ' NULL' + echo '};' +} + +echo '/* Automatically generated by generate-cmdlist.sh */ +struct cmdname_help { + const char *name; + const char *help; + uint32_t category; +}; +' +define_categories $1 +echo +define_category_names $1 +echo +print_command_list $1 +echo +print_config_list -- gitgitgadget