THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
1.8KB

  1. #!/bin/sh
  2. die () {
  3. echo "$@" >&2
  4. exit 1
  5. }
  6. command_list () {
  7. eval "grep -ve '^#' $exclude_programs" <"$1"
  8. }
  9. get_categories () {
  10. tr ' ' '\n'|
  11. grep -v '^$' |
  12. sort |
  13. uniq
  14. }
  15. category_list () {
  16. command_list "$1" |
  17. cut -c 40- |
  18. get_categories
  19. }
  20. get_synopsis () {
  21. sed -n '
  22. /^NAME/,/'"$1"'/H
  23. ${
  24. x
  25. s/.*'"$1"' - \(.*\)/N_("\1")/
  26. p
  27. }' "Documentation/$1.txt"
  28. }
  29. define_categories () {
  30. echo
  31. echo "/* Command categories */"
  32. bit=0
  33. category_list "$1" |
  34. while read cat
  35. do
  36. echo "#define CAT_$cat (1UL << $bit)"
  37. bit=$(($bit+1))
  38. done
  39. test "$bit" -gt 32 && die "Urgh.. too many categories?"
  40. }
  41. define_category_names () {
  42. echo
  43. echo "/* Category names */"
  44. echo "static const char *category_names[] = {"
  45. bit=0
  46. category_list "$1" |
  47. while read cat
  48. do
  49. echo " \"$cat\", /* (1UL << $bit) */"
  50. bit=$(($bit+1))
  51. done
  52. echo " NULL"
  53. echo "};"
  54. }
  55. print_command_list () {
  56. echo "static struct cmdname_help command_list[] = {"
  57. command_list "$1" |
  58. while read cmd rest
  59. do
  60. printf " { \"$cmd\", $(get_synopsis $cmd), 0"
  61. for cat in $(echo "$rest" | get_categories)
  62. do
  63. printf " | CAT_$cat"
  64. done
  65. echo " },"
  66. done
  67. echo "};"
  68. }
  69. print_config_list () {
  70. cat <<EOF
  71. static const char *config_name_list[] = {
  72. EOF
  73. grep -h '^[a-zA-Z].*\..*::$' Documentation/*config.txt Documentation/config/*.txt |
  74. sed '/deprecated/d; s/::$//; s/, */\n/g' |
  75. sort |
  76. while read line
  77. do
  78. echo " \"$line\","
  79. done
  80. cat <<EOF
  81. NULL,
  82. };
  83. EOF
  84. }
  85. exclude_programs=
  86. while test "--exclude-program" = "$1"
  87. do
  88. shift
  89. exclude_programs="$exclude_programs -e \"^$1 \""
  90. shift
  91. done
  92. echo "/* Automatically generated by generate-cmdlist.sh */
  93. struct cmdname_help {
  94. const char *name;
  95. const char *help;
  96. uint32_t category;
  97. };
  98. "
  99. define_categories "$1"
  100. echo
  101. define_category_names "$1"
  102. echo
  103. print_command_list "$1"
  104. echo
  105. print_config_list