| Rob Landley | 8dd5134 | 2008-01-30 17:05:37 -0600 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | |
| 3 | function firstmajor() { |
| 4 | declare -i n j=$1 |
| 5 | test $j -gt 0 || return -1 |
| 6 | for j in $@; do |
| 7 | if [ $j -gt $1 ]; then |
| 8 | echo $j |
| 9 | return 0 |
| 10 | fi |
| 11 | done |
| 12 | return 1 |
| 13 | }; export -f firstmajor |
| 14 | |
| 15 | function print_h() { |
| 16 | declare -i i c=$2 s=$3 e=$4 |
| 17 | local str="$(echo "$1" | head -n$c | tail -n1 | sed -e "s,config[\t ]*,,")" |
| 18 | echo -n "#define help_"$str" \"" | tr [A-Z] [a-z] |
| 19 | echo -n "$1\\n" | head -n$e | tail -n$[e-s+1] | sed -e "s,\$,\r," | tr \\n\\r n\\ |
| 20 | echo \" |
| 21 | }; export -f print_h |
| 22 | |
| 23 | file="$1" |
| 24 | if test "$0" != "bash"; then |
| 25 | if test -r "$file"; then |
| 26 | # echo "$file..." >&2 |
| 27 | filetxt="$(sed -e "s,^[\t ]*,," -e "s,\([\"\\\\]\),\\\\\\1,g" "$file")" |
| 28 | helps=$(echo "$filetxt" | egrep -ne "^help *" -e "^---help--- *" | cut -d\: -f1) |
| 29 | configs=$(echo "$filetxt" | egrep -ne "^config *" | cut -d\: -f1) |
| 30 | endmenus=$(echo "$filetxt" | egrep -ne "^endmenu *" | cut -d\: -f1) |
| 31 | let last=$(echo "$filetxt" | wc -l)+2 |
| 32 | |
| 33 | declare -i i c s e |
| 34 | for i in $configs; do |
| 35 | # echo -n "c:$i" >&2 |
| 36 | s=$(firstmajor $i $helps) |
| 37 | test $s -gt 0 |
| 38 | e=$(firstmajor $s $configs || firstmajor $s $endmenus $last) |
| 39 | let s++ e-=2 |
| 40 | test $e -ge $s |
| 41 | # echo " s:$s e:$e" >&2 |
| 42 | print_h "$filetxt" $i $s $e |
| 43 | done |
| 44 | for fle in $(cat "$file" | egrep -e "^[ \t]*source " | sed -e "s,^[ \t]*source *\(.*\),\\1,"); do |
| 45 | $0 $fle |
| 46 | done |
| 47 | else |
| 48 | echo |
| 49 | echo "USAGE EXAMPLE: $(basename $0) Config.in > generated/help.h" |
| 50 | echo |
| 51 | false |
| 52 | fi | sed -e "s,\\\\n\\\\n\"$,\\\\n\"," |
| 53 | fi |
| 54 | |