diff options
author | marha <marha@users.sourceforge.net> | 2012-11-19 10:16:38 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-11-19 10:16:38 +0100 |
commit | 3744281b9ae8aa0ab86ceaee1afe8a603e3aeb2c (patch) | |
tree | f59b9749730728729691a8a1efd54dce95f0177c /xorg-server/xkeyboard-config/tests/ruby | |
parent | 8d57b7fcb22cf1a52203ee57c745b64bba649249 (diff) | |
download | vcxsrv-3744281b9ae8aa0ab86ceaee1afe8a603e3aeb2c.tar.gz vcxsrv-3744281b9ae8aa0ab86ceaee1afe8a603e3aeb2c.tar.bz2 vcxsrv-3744281b9ae8aa0ab86ceaee1afe8a603e3aeb2c.zip |
dos -> unix
Diffstat (limited to 'xorg-server/xkeyboard-config/tests/ruby')
-rw-r--r-- | xorg-server/xkeyboard-config/tests/ruby/README | 6 | ||||
-rw-r--r-- | xorg-server/xkeyboard-config/tests/ruby/find_fragments.rb | 104 | ||||
-rw-r--r-- | xorg-server/xkeyboard-config/tests/ruby/find_match.rb | 84 | ||||
-rw-r--r-- | xorg-server/xkeyboard-config/tests/ruby/utils.rb | 128 | ||||
-rw-r--r-- | xorg-server/xkeyboard-config/tests/ruby/xkbparser.rb | 370 |
5 files changed, 346 insertions, 346 deletions
diff --git a/xorg-server/xkeyboard-config/tests/ruby/README b/xorg-server/xkeyboard-config/tests/ruby/README index 2ddf58a82..b1198b2c5 100644 --- a/xorg-server/xkeyboard-config/tests/ruby/README +++ b/xorg-server/xkeyboard-config/tests/ruby/README @@ -1,3 +1,3 @@ -This is just some stuff to play with symbols/inet file, trying to analize it.
-Only maintainers might be interested. It is written in Ruby - but it will
-never be actually used in xkeyboard-config distribution.
+This is just some stuff to play with symbols/inet file, trying to analize it. +Only maintainers might be interested. It is written in Ruby - but it will +never be actually used in xkeyboard-config distribution. diff --git a/xorg-server/xkeyboard-config/tests/ruby/find_fragments.rb b/xorg-server/xkeyboard-config/tests/ruby/find_fragments.rb index f991ad0ab..118de03be 100644 --- a/xorg-server/xkeyboard-config/tests/ruby/find_fragments.rb +++ b/xorg-server/xkeyboard-config/tests/ruby/find_fragments.rb @@ -1,52 +1,52 @@ -#!/usr/bin/ruby
-#
-# $Id$
-# The script finds the fragments
-#
-
-require "xkbparser.rb"
-
-baseDir = "../.."
-
-symbolsDir = "#{baseDir}/symbols"
-#symbolsDir = "."
-
-parser = Parser.new
-
-allSyms = parser.parse("#{symbolsDir}/inet")
-
-everything = allSyms.merge
-
-everything.filter(1)
-
-#numCombinations = 1
-
-#puts "everything:"
-
-#everything.find_all do | symName, keycodes |
-#puts "#{symName}, #{keycodes.length} mappings -> "
-# keycodes.find_all do | keycode, counter |
-# puts " #{keycode} -> #{counter} occurences"
-# end
-# numCombinations *= (keycodes.length + 1)
-#end
-
-#puts "Total mappings: #{everything.length}/#{everything.full_length()}, #{numCombinations} combinations"
-#
-
-numCombinations = 0
-allSyms.find_all do | symsName, symbols |
- puts "n: #{symsName}"
-
- # Counting only symbols which used more than once
- numDupSymbols = symbols.keys.inject(0) do | rv, keycode |
- c = everything.cardinality(keycode, symbols[keycode])
- puts "#{keycode} -> #{symbols[keycode]}, #{c}"
- (c > 0) ? rv : rv + 1
- end
-
- numCombinations += (1 << numDupSymbols)
- puts "l: #{symbols.length} d: #{numDupSymbols} c: #{numCombinations}"
-end
-
-puts "numCombinations: #{numCombinations}"
+#!/usr/bin/ruby +# +# $Id$ +# The script finds the fragments +# + +require "xkbparser.rb" + +baseDir = "../.." + +symbolsDir = "#{baseDir}/symbols" +#symbolsDir = "." + +parser = Parser.new + +allSyms = parser.parse("#{symbolsDir}/inet") + +everything = allSyms.merge + +everything.filter(1) + +#numCombinations = 1 + +#puts "everything:" + +#everything.find_all do | symName, keycodes | +#puts "#{symName}, #{keycodes.length} mappings -> " +# keycodes.find_all do | keycode, counter | +# puts " #{keycode} -> #{counter} occurences" +# end +# numCombinations *= (keycodes.length + 1) +#end + +#puts "Total mappings: #{everything.length}/#{everything.full_length()}, #{numCombinations} combinations" +# + +numCombinations = 0 +allSyms.find_all do | symsName, symbols | + puts "n: #{symsName}" + + # Counting only symbols which used more than once + numDupSymbols = symbols.keys.inject(0) do | rv, keycode | + c = everything.cardinality(keycode, symbols[keycode]) + puts "#{keycode} -> #{symbols[keycode]}, #{c}" + (c > 0) ? rv : rv + 1 + end + + numCombinations += (1 << numDupSymbols) + puts "l: #{symbols.length} d: #{numDupSymbols} c: #{numCombinations}" +end + +puts "numCombinations: #{numCombinations}" diff --git a/xorg-server/xkeyboard-config/tests/ruby/find_match.rb b/xorg-server/xkeyboard-config/tests/ruby/find_match.rb index 43af93482..10738fafd 100644 --- a/xorg-server/xkeyboard-config/tests/ruby/find_match.rb +++ b/xorg-server/xkeyboard-config/tests/ruby/find_match.rb @@ -1,42 +1,42 @@ -#!/usr/bin/ruby
-#
-# $Id$
-# The script finds best matching xkb_symbols in symbols/in
-#
-# Parameters: $0 - the name of the file with new xkb_symbols
-# $1 - max number of non-matching mappings (0 by default)
-#
-
-require "xkbparser.rb"
-
-baseDir = "../.."
-
-symbolsDir = "#{baseDir}/symbols"
-#symbolsDir = "."
-
-parser = Parser.new
-
-allSyms = parser.parse("#{symbolsDir}/inet")
-
-newSyms = parser.parse(ARGV[0])
-limit = ARGV[1].to_i
-
-newSyms.find_all do | key, value |
-
- if value.hidden?
- next
- end
-
- puts "Existing xkb_symbols matching #{key}: "
-
- sorted = allSyms.match_symbols(value,limit).sort_by do | symsName, diff |
- sprintf "%03d_%s", diff.size, symsName
- end
-
- sorted.find_all do | symsName, diff |
- puts " #{symsName}, up to #{allSyms[symsName].size} keys (difference #{diff.size})-> #{diff}"
- end
-
-end
-
-
+#!/usr/bin/ruby +# +# $Id$ +# The script finds best matching xkb_symbols in symbols/in +# +# Parameters: $0 - the name of the file with new xkb_symbols +# $1 - max number of non-matching mappings (0 by default) +# + +require "xkbparser.rb" + +baseDir = "../.." + +symbolsDir = "#{baseDir}/symbols" +#symbolsDir = "." + +parser = Parser.new + +allSyms = parser.parse("#{symbolsDir}/inet") + +newSyms = parser.parse(ARGV[0]) +limit = ARGV[1].to_i + +newSyms.find_all do | key, value | + + if value.hidden? + next + end + + puts "Existing xkb_symbols matching #{key}: " + + sorted = allSyms.match_symbols(value,limit).sort_by do | symsName, diff | + sprintf "%03d_%s", diff.size, symsName + end + + sorted.find_all do | symsName, diff | + puts " #{symsName}, up to #{allSyms[symsName].size} keys (difference #{diff.size})-> #{diff}" + end + +end + + diff --git a/xorg-server/xkeyboard-config/tests/ruby/utils.rb b/xorg-server/xkeyboard-config/tests/ruby/utils.rb index 93ff0ee5e..3c699a7a8 100644 --- a/xorg-server/xkeyboard-config/tests/ruby/utils.rb +++ b/xorg-server/xkeyboard-config/tests/ruby/utils.rb @@ -1,64 +1,64 @@ -#
-# $Id$
-#
-# Commont classes
-#
-
-#
-# The hash containing non-unique mappings
-# It can have a->b and a->c together
-# Also, for every mapping it counts the number of times this mapping was set
-#
-class NonuniqueCountingHash < Hash
-
- alias get_original []
- alias put_original []=
-
- def []=(key, value)
- own = self.get_original(key)
- hash = get_original(key)
- if hash.nil?
- put_original(key, hash = Hash.new)
- end
- if hash.has_key?(value)
- hash[value] += 1
- else
- hash[value] = 1
- end
- end
-
- #
- # Number of all mappings (a->b and a->c counted as 2 mappings)
- #
- def full_length()
- values.inject(0) do | rv, hash |
- rv + hash.length
- end
- end
-
- def cardinality(key1, key2)
- if has_key?(key1)
- hash = get_original(key1)
- if hash.has_key?(key2)
- hash[key2]
- else
- 0
- end
- else
- 0
- end
- end
-
- def filter(limit)
- find_all do | key, hash |
- hash.find_all do | key1, counter |
- if (counter <= limit)
- hash.delete(key1)
- end
- end
- if hash.empty?
- delete(key)
- end
- end
- end
-end
+# +# $Id$ +# +# Commont classes +# + +# +# The hash containing non-unique mappings +# It can have a->b and a->c together +# Also, for every mapping it counts the number of times this mapping was set +# +class NonuniqueCountingHash < Hash + + alias get_original [] + alias put_original []= + + def []=(key, value) + own = self.get_original(key) + hash = get_original(key) + if hash.nil? + put_original(key, hash = Hash.new) + end + if hash.has_key?(value) + hash[value] += 1 + else + hash[value] = 1 + end + end + + # + # Number of all mappings (a->b and a->c counted as 2 mappings) + # + def full_length() + values.inject(0) do | rv, hash | + rv + hash.length + end + end + + def cardinality(key1, key2) + if has_key?(key1) + hash = get_original(key1) + if hash.has_key?(key2) + hash[key2] + else + 0 + end + else + 0 + end + end + + def filter(limit) + find_all do | key, hash | + hash.find_all do | key1, counter | + if (counter <= limit) + hash.delete(key1) + end + end + if hash.empty? + delete(key) + end + end + end +end diff --git a/xorg-server/xkeyboard-config/tests/ruby/xkbparser.rb b/xorg-server/xkeyboard-config/tests/ruby/xkbparser.rb index ecf246b6c..4b15df3d2 100644 --- a/xorg-server/xkeyboard-config/tests/ruby/xkbparser.rb +++ b/xorg-server/xkeyboard-config/tests/ruby/xkbparser.rb @@ -1,185 +1,185 @@ -#
-# $Id$
-#
-# Commont parsing classes for symbols/inet
-# The parsing is simplified, based on regex - it is NOT a real parser for very
-# complex XKB format
-#
-
-require "utils.rb"
-
-class Symbols < Hash
-
- #
- # Constructor
- #
- def initialize
- @includedSyms = Array.new
- end
-
- # Write-only property, parent list of symbols definitions
- def symbols_list=(symbolsList)
- @symbolsList = symbolsList
- end
-
- # Whether this set of symbols is hidden or not
- def hidden?
- @hidden
- end
-
- def hidden=(h)
- @hidden = h
- end
-
- #
- # Add "dependency" - the symbols referenced using the "include" statement.
- #
- def add_included(other)
- @includedSyms.push(other)
- end
-
- alias get_original []
- alias keys_original keys
-
- #
- # Get the symbol, trying first own definitions, then walking through all
- # dependenies
- #
- def [](symName)
- own = self.get_original(symName)
- if own.nil?
- @includedSyms.find_all do | symsName |
- syms = @symbolsList[symsName]
- his = syms[symName]
- if !his.nil?
- own = his
- break
- end
- end
- end
- own
- end
-
- #
- # All keys - including the ones specified in the included sections
- #
- def keys()
- @includedSyms.inject(keys_original) do | rv, symsName |
- syms = @symbolsList[symsName]
- rv | syms.keys
- end
- end
-
- # Size of all keys
- def length()
- keys().length()
- end
-
- #
- # Size - takes into account overlapping key definitions
- #
- def size()
- keys.size()
- end
-
- #
- # Create a hash including all elements of this hash which are not in the
- # other hash, use symbols + and * for marking the elements which existed in
- # the original hash (+ if not existed)
- #
- def -(other)
- diff = self.class.new
- self.find_all do | key, value |
- existing = other[key]
- if existing != value
- diff[key] = [ value, existing.nil? ? '+' : '' ]
- end
- end
- diff
- end
-
-
- def to_s
- s = "{\n"
- # First output included syms
- @includedSyms.find_all do | symsName |
- s += " include \"inet(#{symsName})\"\n"
- end
- # Then - own definitions
- self.find_all do | key, value |
- s += " key #{key} { [ #{value} ] };\n"
- end
- s + "}";
- end
-
-end
-
-class SymbolsList < Hash
-
- #
- # Add new xkb_symbols
- #
- def add_symbols (symbolsName, hidden)
- newSyms = Symbols.new
- newSyms.symbols_list = self
- newSyms.hidden = hidden
- self[symbolsName] = newSyms
- end
-
- def to_s
- s = "// Autogenerated\n\n"
- self.find_all do | symbols, mapping |
- s += "partial alphanumeric_keys\nxkb_symbols \"#{symbols}\" #{mapping};\n\n"
- end
- s
- end
-
- def match_symbols(new_symbols,limit)
- matching = Hash.new
- find_all do | symbols, mapping |
- diff = new_symbols - mapping
- if diff.size <= limit
- matching[symbols] = diff
- end
- end
- matching
- end
-
- def merge()
- everything = NonuniqueCountingHash.new
- find_all do | symsName, syms |
- syms.find_all do | symName, keycode |
- everything[symName] = keycode
- end
- end
- everything
- end
-
-end
-
-class Parser
-
- def parse (fileName)
- allSyms = SymbolsList.new;
- currentSyms = nil
- hidden = false
- File.open(fileName) do | file |
- file.each_line do | line |
- line.scan(/xkb_symbols\s+"(\w+)"/) do | symsName |
- currentSyms = allSyms.add_symbols(symsName[0], hidden)
- end
- line.scan(/^\s*key\s*<(\w+)>\s*\{\s*\[\s*(\w+)/) do | keycode, keysym |
- currentSyms[keycode] = keysym
- end
- line.scan(/^partial\s+(hidden\s+)?alphanumeric_keys/) do | h |
- hidden = !h[0].nil?
- end
- line.scan(/^\s*include\s+"inet\((\w+)\)"/) do | otherPart |
- currentSyms.add_included(otherPart[0])
- end
- end
- end
- allSyms
- end
-
-end
+# +# $Id$ +# +# Commont parsing classes for symbols/inet +# The parsing is simplified, based on regex - it is NOT a real parser for very +# complex XKB format +# + +require "utils.rb" + +class Symbols < Hash + + # + # Constructor + # + def initialize + @includedSyms = Array.new + end + + # Write-only property, parent list of symbols definitions + def symbols_list=(symbolsList) + @symbolsList = symbolsList + end + + # Whether this set of symbols is hidden or not + def hidden? + @hidden + end + + def hidden=(h) + @hidden = h + end + + # + # Add "dependency" - the symbols referenced using the "include" statement. + # + def add_included(other) + @includedSyms.push(other) + end + + alias get_original [] + alias keys_original keys + + # + # Get the symbol, trying first own definitions, then walking through all + # dependenies + # + def [](symName) + own = self.get_original(symName) + if own.nil? + @includedSyms.find_all do | symsName | + syms = @symbolsList[symsName] + his = syms[symName] + if !his.nil? + own = his + break + end + end + end + own + end + + # + # All keys - including the ones specified in the included sections + # + def keys() + @includedSyms.inject(keys_original) do | rv, symsName | + syms = @symbolsList[symsName] + rv | syms.keys + end + end + + # Size of all keys + def length() + keys().length() + end + + # + # Size - takes into account overlapping key definitions + # + def size() + keys.size() + end + + # + # Create a hash including all elements of this hash which are not in the + # other hash, use symbols + and * for marking the elements which existed in + # the original hash (+ if not existed) + # + def -(other) + diff = self.class.new + self.find_all do | key, value | + existing = other[key] + if existing != value + diff[key] = [ value, existing.nil? ? '+' : '' ] + end + end + diff + end + + + def to_s + s = "{\n" + # First output included syms + @includedSyms.find_all do | symsName | + s += " include \"inet(#{symsName})\"\n" + end + # Then - own definitions + self.find_all do | key, value | + s += " key #{key} { [ #{value} ] };\n" + end + s + "}"; + end + +end + +class SymbolsList < Hash + + # + # Add new xkb_symbols + # + def add_symbols (symbolsName, hidden) + newSyms = Symbols.new + newSyms.symbols_list = self + newSyms.hidden = hidden + self[symbolsName] = newSyms + end + + def to_s + s = "// Autogenerated\n\n" + self.find_all do | symbols, mapping | + s += "partial alphanumeric_keys\nxkb_symbols \"#{symbols}\" #{mapping};\n\n" + end + s + end + + def match_symbols(new_symbols,limit) + matching = Hash.new + find_all do | symbols, mapping | + diff = new_symbols - mapping + if diff.size <= limit + matching[symbols] = diff + end + end + matching + end + + def merge() + everything = NonuniqueCountingHash.new + find_all do | symsName, syms | + syms.find_all do | symName, keycode | + everything[symName] = keycode + end + end + everything + end + +end + +class Parser + + def parse (fileName) + allSyms = SymbolsList.new; + currentSyms = nil + hidden = false + File.open(fileName) do | file | + file.each_line do | line | + line.scan(/xkb_symbols\s+"(\w+)"/) do | symsName | + currentSyms = allSyms.add_symbols(symsName[0], hidden) + end + line.scan(/^\s*key\s*<(\w+)>\s*\{\s*\[\s*(\w+)/) do | keycode, keysym | + currentSyms[keycode] = keysym + end + line.scan(/^partial\s+(hidden\s+)?alphanumeric_keys/) do | h | + hidden = !h[0].nil? + end + line.scan(/^\s*include\s+"inet\((\w+)\)"/) do | otherPart | + currentSyms.add_included(otherPart[0]) + end + end + end + allSyms + end + +end |