Mercurial > hg > toybox
annotate scripts/config2help.sh @ 481:e1b9a8579ddb
mkswap helpstring and argument string
author | Elie De Brauwer <eliedebrauwer@gmail.com> |
---|---|
date | Sat, 18 Feb 2012 14:13:55 +0100 |
parents | b59217241f71 |
children | 786841fdb1e0 |
rev | line source |
---|---|
253
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 #!/bin/bash -e |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 function firstmajor() { |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 declare -i n j=$1 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 test $j -gt 0 || return -1 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 for j in $@; do |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 if [ $j -gt $1 ]; then |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 echo $j |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 return 0 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 fi |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 done |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 return 1 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 }; export -f firstmajor |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 function print_h() { |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 declare -i i c=$2 s=$3 e=$4 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 local str="$(echo "$1" | head -n$c | tail -n1 | sed -e "s,config[\t ]*,,")" |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 echo -n "#define help_"$str" \"" | tr [A-Z] [a-z] |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 echo -n "$1\\n" | head -n$e | tail -n$[e-s+1] | sed -e "s,\$,\r," | tr \\n\\r n\\ |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 echo \" |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 }; export -f print_h |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 file="$1" |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 if test "$0" != "bash"; then |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 if test -r "$file"; then |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 # echo "$file..." >&2 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 filetxt="$(sed -e "s,^[\t ]*,," -e "s,\([\"\\\\]\),\\\\\\1,g" "$file")" |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 helps=$(echo "$filetxt" | egrep -ne "^help *" -e "^---help--- *" | cut -d\: -f1) |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 configs=$(echo "$filetxt" | egrep -ne "^config *" | cut -d\: -f1) |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 endmenus=$(echo "$filetxt" | egrep -ne "^endmenu *" | cut -d\: -f1) |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 let last=$(echo "$filetxt" | wc -l)+2 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 declare -i i c s e |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 for i in $configs; do |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 # echo -n "c:$i" >&2 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 s=$(firstmajor $i $helps) |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 test $s -gt 0 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 e=$(firstmajor $s $configs || firstmajor $s $endmenus $last) |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 let s++ e-=2 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 test $e -ge $s |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 # echo " s:$s e:$e" >&2 |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 print_h "$filetxt" $i $s $e |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 done |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
44 for fle in $(cat "$file" | egrep -e "^[ \t]*source " | sed -e "s,^[ \t]*source *\(.*\),\\1,"); do |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 $0 $fle |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 done |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
47 else |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 echo |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 echo "USAGE EXAMPLE: $(basename $0) Config.in > generated/help.h" |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
50 echo |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 false |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
52 fi | sed -e "s,\\\\n\\\\n\"$,\\\\n\"," |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 fi |
b59217241f71
Script from Roberto Foglietta to do config2help in bash instead of python.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 |