Codebase list brltty / debian/4.2-8 mkdocktb
debian/4.2-8

Tree @debian/4.2-8 (Download .tar.gz)

mkdocktb @debian/4.2-8raw · history · blame

#!/bin/bash -p
###############################################################################
# BRLTTY - A background process providing access to the console screen (when in
#          text mode) for a blind person using a refreshable braille display.
#
# Copyright (C) 1995-2010 by The BRLTTY Developers.
#
# BRLTTY comes with ABSOLUTELY NO WARRANTY.
#
# This is free software, placed under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any
# later version. Please see the file LICENSE-GPL for details.
#
# Web Page: http://mielke.cc/brltty/
#
# This software is maintained by Dave Mielke <dave@mielke.cc>.
###############################################################################

. "`dirname "${0}"`/prologue.sh"

set -e
umask 022
shopt -s nullglob

setOutputFile() {
   local prefix="${1}"

   local layout="${inputFile##*/}"
   layout="${layout%.*}"
   layout="${layout##*-}"

   outputFile="${outputDirectory}/${prefix}-${layout}.${plainTextExtension}"
}

beginSection() {
   local title="${1}"

   headerLevel=$((headerLevel + 1))
   echo >&3 "<H${headerLevel}>${title}</H${headerLevel}>"
}

endSection() {
   headerLevel=$((headerLevel - 1))
}

beginLayoutList() {
   layoutListed=false
}

endLayoutList() {
   ! "${layoutListed}" || {
      echo >&3 "</UL>"
   }
}

listLayout() {
   local category="${1}"

   exec 4<"${outputFile}"
   local description
   read -r -u 4 description
   exec 4<&-

   description="${description} "
   description="${description#* for }"
   [ -z "${category}" ] || description="${description#${category} }"
   description="${description% }"

   local prefix="All Models"
   [ -z "${description}" ] || {
      if [ "${description}" = "${description#(}" ]
      then
         prefix=""
      else
         prefix="${prefix} "
      fi
   }
   description="${prefix}${description}"

   "${layoutListed}" || {
      layoutListed=true
      echo >&3 "<UL>"
   }

   echo >&3 "<LI><A HREF=\"${outputFile##*/}\">${description}</A>"
}

translateKeyTable() {
   local program="${inputDirectory}/Programs/ktbtest"
   [ -x "${program}" ] || make -C "${program%/*}" -s "${program##*/}"
   "${program}" -L"../lib" -T"../${tablesSubdirectory}" -l "${inputFile##*/}" >"${outputFile}"
}

inputDirectory="$(dirname "${0}")"
outputDirectory="doc-ktb"

while getopts ":i:o:" option
do
   case "${option}"
   in
      i) inputDirectory="${OPTARG}";;
      o) outputDirectory="${OPTARG}";;
      :) syntaxError "missing value: -${OPTARG}";;
     \?) syntaxError "unknown option: -${OPTARG}";;
      *) syntaxError "unimplemented option: -${option}";;
   esac
done

shift $((OPTIND - 1))
[ "${#}" -eq 0 ] || syntaxError "too many parameters"

verifyInputDirectory "${inputDirectory}"
verifyOutputDirectory "${outputDirectory}"

driversSubdirectory="Drivers/Braille"
driversDirectory="${inputDirectory}/${driversSubdirectory}"

tablesSubdirectory="Tables"
tablesDirectory="${inputDirectory}/${tablesSubdirectory}"

braillePrefix="brl"
keyboardPrefix="kbd"

plainTextExtension="txt"
hypertextExtension="html"
keyTableExtension="ktb"

headerLevel=0

exec 3>"${outputDirectory}/index.${hypertextExtension}"
documentTitle="Key Table Help"
echo >&3 "<HTML>"
echo >&3 "<HEAD>"
echo >&3 "<TITLE>${documentTitle}</TITLE>"
echo >&3 "</HEAD>"
echo >&3 "<BODY>"
beginSection "${documentTitle}"

beginSection "Keyboard Key Tables"
beginLayoutList
set -- "${tablesDirectory}/${keyboardPrefix}-"*".${keyTableExtension}"
for inputFile
do
   setOutputFile "${keyboardPrefix}"
   translateKeyTable
   listLayout
done
endLayoutList
echo >&3 "<HR>"
endSection

beginSection "Braille Drivers"
echo >&3 "<DL>"
for driverDirectory in "${driversDirectory}/"*
do
   [ -d "${driverDirectory}" ] || continue
   driverName="${driverDirectory##*/}"
   driverCode="$(sed -n '/^DRIVER_CODE *=/s/^.*= *\([^ ]*\).*$/\1/p' "${driverDirectory}/Makefile.in")"

   header="${driverName}"
   inputFile="${driverDirectory}/README"
   [ ! -f "${inputFile}" ] || {
      outputFile="${outputDirectory}/${braillePrefix}-${driverCode}.${plainTextExtension}"
      cp -a -- "${inputFile}" "${outputFile}"
      header="<A HREF=\"${outputFile##*/}\">${header}</A>"
   }
   echo >&3 "<DT>${header}<DD>"

   beginLayoutList
   set -- "${tablesDirectory}/${braillePrefix}-${driverCode}-"*".${keyTableExtension}"
   if [ "${#}" -gt 0 ]
   then
      for inputFile
      do
         setOutputFile "${braillePrefix}-${driverCode}"
         translateKeyTable
         listLayout "${driverName}"
      done
   else
      set -- "${driverDirectory}/"*".hlp"
      for inputFile
      do
         setOutputFile "${braillePrefix}-${driverCode}"
         cp -a -- "${inputFile}" "${outputFile}"
         listLayout "${driverName}"
      done
   fi

   endLayoutList
done
echo >&3 "</DL>"
echo >&3 "<HR>"
endSection

endSection
echo >&3 "</BODY>"
echo >&3 "</HTML>"
exec 3>&-

exit 0