Fix shell scripts to work better with FreeBSD's sed
[elinks.git] / doc / tools / help2doc
blob1f8e4937994f80a8f668e89c0b4d3f87ac7703a9
1 #!/bin/sh
4 # Script used to generate doc/book/config/cmdoptions.xml
5 # and hopefully other in the future.
7 # Updated by option handlind via --elinks=path/to/elinks option
8 elinks="$1"
9 option="$2"
11 # Option handling {{{1
13 command=
15 case "$option" in
16 *command*)
17 filter="sed 0,/^Options:/d"
18 option=--long-help
20 *config*)
21 filter="sed 0,/^Configuration/d"
22 option=--config-help
24 esac
26 print_description_line()
28 line="$1"
29 number="$2"
31 case "$line" in
32 -eval*)
33 echo
36 line="$(echo $line | sed 's,\(-touch-files\|-no-connect\|-session-ring\|-dump\|-default-mime-type\|text/html\|~/\.elinks\),\`\1\`,g')"
37 line=$(echo $line | sed "s,'\([^']*\)',\\\'\1\\\',")
38 line=$(echo $line | sed "s,ELinks,'ELinks',g")
39 line=$(echo $line | sed "s,HOME,'HOME',g")
40 line="$(echo $line | sed 's/^\([a-zA-Z]*([^)]*)\).*:/- \`\1\`:/')"
42 if test -n "$number";
43 then
44 echo -n " - $number:"
46 esac
47 echo " $line"
50 print_option_tree()
52 title="$1"
53 path="$2"
54 echo "$path::"
57 print_option_type()
59 path="$1"
60 typeid="$2"
61 default="$3"
62 typestring="$path"
63 if test -n "$typeid" && test "$typeid" != "$path";
64 then
65 if test "$typeid" = "(alias";
66 then
67 typestring="$typestring ($default)"
68 default=
69 else
70 typestring="$typestring $typeid"
73 if test -n "$default" && test "$default" != "$path";
74 then
75 typestring="$typestring ($default)"
77 if test "$default" = "-?, -h, -help";
78 then
79 typestring="$default"
82 echo "$typestring::"
86 # The main loop {{{1
88 # State variables
89 parse_description=
90 parse_int_option=
91 use_log=
93 "$elinks" $option | $filter | while read line
95 if test -n "$parse_description"
96 then
97 # If the line is empty it is our clue that
98 # the desciption is over.
99 if test -z "$line"
100 then
101 echo
102 parse_description=
103 parse_int_option=
104 continue
107 line=`echo "$line" | sed -e "s/[ ]*(DISABLED)//"`
108 line=`echo "$line" | sed 's/\([{}]\)/\\\\\1/g'`
109 number=
110 if test -n "$parse_int_option";
111 then
112 case "$line" in
113 -[0-9]*)
114 number="`echo $line | sed -e 's/\(-[0-9-]*\).*/\1/'`"
115 line=`echo "$line" | sed -e "s/$number[ ]*//"`
118 [0-9]*)
119 number="`echo $line | sed -e 's/\([0-9-]*\).*/\1/'`"
120 line=`echo "$line" | sed -e "s/$number[ ]*//"`
122 esac
125 print_description_line "$line" "$number"
126 continue
129 case "$line" in
130 Features:*)
132 [A-Z]*:" ("*[a-z]*)
133 parse_description=1
134 title="`echo $line | sed -e 's/\([A-Z]*\):.*/\1/'`"
135 path="`echo $line | sed -e 's/.*: (\([a-z_].*\))/\1/'`"
136 print_option_tree "$title" "$path"
139 [a-z_-]*[.a-z_-]*)
140 parse_description=1
141 path="$(echo "$line" | sed -e 's/\([a-z-][^ ]*\).*/\1/')"
142 typeid="$(echo "$line" | sed -n 's/[ ]*[a-z-][^ ]* \([^ ]*\).*/\1/p')"
143 default="$(echo "$line" | sed -n 's/.*[^(]*(\(.*\))/\1/p')"
144 print_option_type "$path" "$typeid" "$default"
145 if test "$typeid" = "<num>";
146 then
147 parse_int_option=1
153 esac
154 done
156 version="`$elinks -version | head -n 1 | sed -e 's/ELinks \([0-9][^ ]*\).*/\1/'`"
157 echo "Generated using output from ELinks version $version."
160 # vim: tabstop=4 shiftwidth=4