Debian Codegraph @

mkdocktb

raw
1 #!/bin/bash -p
2 ###############################################################################
3 # BRLTTY - A background process providing access to the console screen (when in
4 # text mode) for a blind person using a refreshable braille display.
5 #
6 # Copyright (C) 1995-2026 by The BRLTTY Developers.
7 #
8 # BRLTTY comes with ABSOLUTELY NO WARRANTY.
9 #
10 # This is free software, placed under the terms of the
11 # GNU Lesser General Public License, as published by the Free Software
12 # Foundation; either version 2.1 of the License, or (at your option) any
13 # later version. Please see the file LICENSE-LGPL for details.
14 #
15 # Web Page: http://brltty.app/
16 #
17 # This software is maintained by Dave Mielke <[email protected]>.
18 ###############################################################################
19
20 defaultOutputRoot="doc-ktb"
21
22 . "`dirname "${0}"`/brltty-prologue.sh"
23 addProgramOption s string.directory sourceRoot "top-level directory of source tree" "the location of this script"
24 addProgramOption b string.directory buildRoot "top-level directory of build tree" "the source tree"
25 addProgramOption o string.directory outputRoot "top-level directory of output tree" "${defaultOutputRoot}"
26 addProgramOption k flag keepFiles "don't remove intermediate files"
27 parseProgramArguments "${@}"
28
29 set -e
30 umask 022
31 shopt -s nullglob
32
33 [ -n "${sourceRoot}" ] || sourceRoot="$(dirname "${0}")"
34 verifyInputDirectory "${sourceRoot}"
35 sourceRoot="$(cd "${sourceRoot}" && pwd)"
36
37 [ -n "${buildRoot}" ] || buildRoot="${sourceRoot}"
38 buildRoot="$(cd "${buildRoot}" && pwd)"
39
40 [ -n "${outputRoot}" ] || outputRoot="${defaultOutputRoot}"
41 verifyOutputDirectory "${outputRoot}"
42
43 unset HOME
44 export XDG_CONFIG_HOME=/
45 export XDG_CONFIG_DIRS=/
46
47 readonly newLine=$'\n'
48
49 lineGroups=()
50 newLineGroup() {
51 local variable="${1}"
52
53 local group="lineGroup${#lineGroups[*]}"
54 lineGroups+=("${group}")
55 setVariable "${variable}" "${group}"
56
57 declare -g -a "${group}"
58 eval "${group}=()"
59 }
60
61 addLineToGroup() {
62 local group="${1}"
63 local line="${2}"
64
65 eval "${group}+="'("${line}")'
66 }
67
68 newDocLines() {
69 newLineGroup docLines
70 }
71
72 beginTocEntries() {
73 local variable="${1}"
74
75 newLineGroup "${variable}"
76 newDocLines
77
78 addLineToGroup "${!variable}" "<ul>"
79 }
80
81 endTocEntries() {
82 local group="${1}"
83
84 addLineToGroup "${group}" "</ul>"
85 }
86
87 addTocEntry() {
88 local group="${1}"
89 local title="${2}"
90 local anchor="${3}"
91
92 addLineToGroup "${group}" "<li><a href=\"#${anchor}\">${title}</a></li>"
93 }
94
95 addDocLine() {
96 local line="${1}"
97
98 addLineToGroup "${docLines}" "${line}"
99 }
100
101 addSectionTerminator() {
102 addDocLine "<hr />"
103 }
104
105 addAnchor() {
106 local anchor="${1}"
107
108 addDocLine "<a name=\"${anchor}\"></a>"
109 }
110
111 beginDocument() {
112 local title="${1}"
113
114 newDocLines
115 headerLevel=0
116
117 addDocLine "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
118 addDocLine "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
119
120 addDocLine "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">"
121 addDocLine "<head>"
122 addDocLine "<title>${title}</title>"
123 addDocLine "</head>"
124 addDocLine "<body>"
125 }
126
127 endDocument() {
128 local file="${1}"
129
130 addDocLine "</body>"
131 addDocLine "</html>"
132
133 exec 3>"${file}"
134 local group
135
136 for group in "${lineGroups[@]}"
137 do
138 eval set -- '"${'"${group}"'[@]}"'
139 local line
140
141 for line
142 do
143 echo >&3 "${line}"
144 done
145 done
146 exec 3>&-
147 }
148
149 beginSection() {
150 local title="${1}"
151
152 local anchor="${title,,?}"
153 anchor="${anchor//[^a-zA-Z_0-9]/-}"
154 addAnchor "${anchor}"
155
156 headerLevel=$((headerLevel + 1))
157 addDocLine "<h${headerLevel}>${title}</h${headerLevel}>"
158
159 if ((headerLevel == 1))
160 then
161 beginTocEntries tocSections
162 addSectionTerminator
163 else
164 addTocEntry "${tocSections}" "${title}" "${anchor}"
165 fi
166 }
167
168 endSection() {
169 if ((headerLevel == 1))
170 then
171 endTocEntries "${tocSections}"
172 else
173 addSectionTerminator
174 fi
175
176 headerLevel=$((headerLevel - 1))
177 }
178
179 beginLayoutList() {
180 layoutListed=false
181 }
182
183 endLayoutList() {
184 ! "${layoutListed}" || {
185 addDocLine "</ul>"
186 }
187 }
188
189 beginLayoutEntry() {
190 local prefix="${1}"
191 local outputExtension="${2}"
192
193 local layout="${inputFile##*/}"
194 layout="${layout%.*}"
195
196 outputFile="${outputRoot}/${prefix}-${layout}.${outputExtension}"
197 }
198
199 endLayoutEntry() {
200 local category="${1}"
201
202 exec 4<"${outputFile%.*}.${plainTextExtension}"
203 local description
204 read -r -u 4 description
205 exec 4<&-
206
207 description="${description} "
208 description="${description#*: }"
209 [ -z "${category}" ] || description="${description#${category} }"
210 description="${description% }"
211
212 local prefix="All Models"
213 [ -z "${description}" ] || {
214 if [ "${description}" = "${description#(}" ]
215 then
216 prefix=""
217 else
218 prefix="${prefix} "
219 fi
220 }
221 description="${prefix}${description}"
222
223 "${layoutListed}" || {
224 layoutListed=true
225 addDocLine "<ul>"
226 }
227
228 addDocLine "<li><a href=\"${outputFile##*/}\">${description}</a></li>"
229 }
230
231 listKeyTable() {
232 local driver="${1}"
233
234 local input="${inputFile##*/}"
235 local output="${outputFile%.*}"
236 local name="${output##*/}"
237
238 local command=( "${keyTableLister}" -D"${buildRoot}/lib" -T"${sourceRoot}/${tablesSubdirectory}" )
239 [ -n "${driver}" ] && command+=( -b "${driver}" )
240 "${command[@]}" -l "${input}" >"${output}.${plainTextExtension}" || {
241 rm -f "${output}.${plainTextExtension}"
242 return 1
243 }
244
245 "${command[@]}" -r "${input}" >"${output}.${reStructuredTextExtension}"
246 sed -e "2a\\${newLine}* \`Help Screen Version <${name}.${plainTextExtension}>\`_" -i "${output}.${reStructuredTextExtension}"
247
248 rst2html --config "${sourceRoot}/docutils.conf" "${output}.${reStructuredTextExtension}" "${output}.${hypertextExtension}"
249 "${keepFiles}" || rm "${output}.${reStructuredTextExtension}"
250 }
251
252 listBrailleKeyTables() {
253 beginSection "Braille Device Key Bindings"
254 addDocLine "The driver automatically selects the appropriate key table for the device model being used."
255 addDocLine "Click on the driver's name for general information about it."
256 addDocLine "Click on the device model for its key bindings."
257
258 local tocDrivers
259 beginTocEntries tocDrivers
260
261 addDocLine "<dl>"
262 local driverDirectory
263
264 for driverDirectory in "${driversDirectory}/"*
265 do
266 [ -d "${driverDirectory}" ] || continue
267
268 local driverName="${driverDirectory##*/}"
269 local driverCode="$(sed -n '/^DRIVER_CODE *=/s/^.*= *\([^ ]*\).*$/\1/p' "${driverDirectory}/Makefile.in")"
270
271 local header="${driverName}"
272 local inputFile="${driverDirectory}/README"
273
274 [ ! -f "${inputFile}" ] || {
275 local outputFile="${outputRoot}/${braillePrefix}-${driverCode}.${plainTextExtension}"
276 cp -a -- "${inputFile}" "${outputFile}"
277 header="<a href=\"${outputFile##*/}\">${header}</a>"
278 }
279
280 local anchor="${braillePrefix}-${driverCode}"
281 addTocEntry "${tocDrivers}" "${driverName}" "${anchor}"
282
283 addDocLine "<dt>"
284 addAnchor "${anchor}"
285 addDocLine "${header}"
286 addDocLine "</dt><dd>"
287
288 beginLayoutList
289 set -- "${tablesDirectory}/${brailleSubdirectory}/${driverCode}/"*".${keyTableExtension}"
290
291 if [ "${#}" -gt 0 ]
292 then
293 for inputFile
294 do
295 beginLayoutEntry "${braillePrefix}-${driverCode}" "${hypertextExtension}"
296 listKeyTable "${driverCode}" || continue
297 endLayoutEntry "${driverName}"
298 done
299 else
300 set -- "${tablesDirectory}/${brailleSubdirectory}/${driverCode}/"*".${plainTextExtension}"
301
302 for inputFile
303 do
304 beginLayoutEntry "${braillePrefix}-${driverCode}" "${plainTextExtension}"
305 cp -a -- "${inputFile}" "${outputFile}"
306 endLayoutEntry "${driverName}"
307 done
308 fi
309
310 endLayoutList
311 addDocLine "</dd>"
312 done
313
314 addDocLine "</dl>"
315 endTocEntries "${tocDrivers}"
316 endSection
317 }
318
319 listKeyboardKeyTables() {
320 beginSection "Keyboard Key Tables"
321 addDocLine "In order to use one of these keyboard tables,"
322 addDocLine "you need to explicitly specify it in one of the following ways:"
323
324 addDocLine "<ul>"
325 addDocLine "<li>Use BRLTTY's <tt>-k</tt> (or <tt>--keyboard-table=</tt>) command line option.</li>"
326 addDocLine "<li>Use the <tt>keyboard-table</tt> configuration file (<tt>brltty.conf</tt>) directive.</li>"
327 addDocLine "</ul>"
328
329 beginLayoutList
330 set -- "${tablesDirectory}/${keyboardSubdirectory}/"*".${keyTableExtension}"
331
332 local inputFile
333 for inputFile
334 do
335 beginLayoutEntry "${keyboardPrefix}" "${hypertextExtension}"
336 listKeyTable || continue
337 endLayoutEntry
338 done
339
340 endLayoutList
341 endSection
342 }
343
344 driversSubdirectory="Drivers/Braille"
345 driversDirectory="${sourceRoot}/${driversSubdirectory}"
346
347 tablesSubdirectory="Tables"
348 tablesDirectory="${sourceRoot}/${tablesSubdirectory}"
349
350 brailleSubdirectory="Input"
351 keyboardSubdirectory="Keyboard"
352
353 braillePrefix="brl"
354 keyboardPrefix="kbd"
355
356 plainTextExtension="txt"
357 reStructuredTextExtension="rst"
358 hypertextExtension="html"
359 keyTableExtension="ktb"
360
361 keyTableLister="${buildRoot}/Programs/brltty-ktb"
362 make -C "${keyTableLister%/*}" -s "${keyTableLister##*/}"
363
364 documentTitle="Key Binding Lists"
365 beginDocument "${documentTitle}"
366
367 beginSection "${documentTitle}"
368 listBrailleKeyTables
369 listKeyboardKeyTables
370 endSection
371
372 endDocument "${outputRoot}/index.${hypertextExtension}"
373 exit 0