#!/usr/bin/env tclsh ############################################################################### # 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-2021 by The BRLTTY Developers. # # BRLTTY comes with ABSOLUTELY NO WARRANTY. # # This is free software, placed under the terms of the # GNU Lesser General Public License, as published by the Free Software # Foundation; either version 2.1 of the License, or (at your option) any # later version. Please see the file LICENSE-LGPL for details. # # Web Page: http://brltty.app/ # # This software is maintained by Dave Mielke . ############################################################################### source [file join [file dirname [info script]] .. .. "prologue.tcl"] proc getProperties {file names} { set properties [dict create] set comment # set pattern {^} append pattern "${comment}([join $names |])" append pattern "\\s+(\[^\\s${comment}\]+)" append pattern "\\s*(?:${comment}\\s*(.*?))?" append pattern {\s*$} if {[catch [list open $file {RDONLY}] stream] == 0} { while {[gets $stream record] >= 0} { if {[regexp $pattern $record x name code label]} { if {[string length $label] == 0} { set label $code } dict set properties $name $code $label } } close $stream } else { semanticError $stream } return $properties } proc makeResources {properties} { set lines [list] lappend lines {} lappend lines "" lappend lines "" set first 1 foreach name [dict keys $properties] { set property [dict get $properties $name] set prefix "[string toupper [string map {- _} $name]]_" set values [list] set labels [list] if {$first} { set first 0 } else { lappend lines "" } foreach code [lsort -command [list compareKeys $property] [dict keys $property]] { set label "${prefix}LABEL_[string map {- _} $code]" lappend lines " [dict get $property $code]" lappend values $code lappend labels "@string/$label" } lappend lines "" eval [list lappend lines] [makeArray "${prefix}LABELS" $labels] lappend lines "" eval [list lappend lines] [makeArray "${prefix}VALUES" $values] } lappend lines "" return $lines } proc compareKeys {dictionary key1 key2} { set value1 [dict get $dictionary $key1] set value2 [dict get $dictionary $key2] set upper1 [string is upper -strict [string index $value1 0]] set upper2 [string is upper -strict [string index $value2 0]] if {!$upper1 && $upper2} { return -1 } if {$upper1 && !$upper2} { return 1 } return [string compare $key1 $key2] } proc makeArray {name items} { set lines [list] lappend lines " " foreach item $items { lappend lines " $item" } lappend lines " " return $lines } proc writeProperties {file lines} { if {[catch [list open $file {WRONLY CREAT TRUNC}] stream] == 0} { puts $stream [join $lines \n] close $stream } else { semanticError $stream } } set inputFile [file join $sourceDirectory "Documents" "brltty.conf.in"] set outputFile [file join $sourceDirectory "Android" "Application" "res" "values" "settings_lists.xml"] set optionDefinitions { } processProgramArguments optionValues $optionDefinitions positionalArguments "\[property ...\]" if {[llength $positionalArguments] == 0} { lappend positionalArguments "braille-driver" lappend positionalArguments "text-table" lappend positionalArguments "attributes-table" lappend positionalArguments "contraction-table" lappend positionalArguments "keyboard-table" } if {[llength $positionalArguments] == 0} { syntaxError "properties not specified" } writeProperties $outputFile [makeResources [getProperties [file join $sourceDirectory $inputFile] $positionalArguments]] exit 0