#!/bin/sh gofmt < $hex, ident => $ident, comment => $comment }; $nametokeysym{$name} = $ident; # All but the first name listed should be considered deprecated. $keysymtoname{$ident} = $name unless exists $seen{$hex}; $seen{$hex}++; # TODO: Try stringer, see # https://eli.thegreenplace.net/2021/a-comprehensive-guide-to-go-generate/ END { print "const ("; print "$_->{ident} = 0x$_->{hex} // $_->{comment}" for @a; print ")"; # Very large tables, should be an on-demand package :( # # KeysymToName/NameToKeysym can also be compress/lzw (small code), # that may reduce string data to about 1/3. It's still rather small # (27K -> 8K), I'm not sure where all those bytes come from. # # KeysymToName might be generated from NameToKeysym. # KeysymToName may just be an index into the ntk constant. # # Actually we may just include a $name => $hex table and screw # all else. But the text still begs for compression and the numbers # for filtering and compression. # # Or actually []{$hex, $name}, stable sorted by $hex, and having # the $name be an index into a constant. On construction we keep # a map so that only the first $hex occurrence receives a name. # # My biggest gripe is probably source code size that won't go down # because the constants are just so large (158K). my (@ktnK, @ktnV); for (sort keys %keysymtoname) { push @ktnK, $_; push @ktnV, $keysymtoname{$_}; } print "var ktnKeys = []xproto.Keysym{${\join \", \", @ktnK}}"; print "var ktnValues = \"${\join \" \", @ktnV}\""; my (@ntkK, @ntkV); for (sort keys %nametokeysym) { push @ntkK, $_; push @ntkV, $nametokeysym{$_}; } print "var ntkKeys = \"${\join \" \", @ntkK}\""; print "var ntkValues = []xproto.Keysym{${\join \", \", @ntkV}}"; } ') // KeysymToName maps X11 keysym constants to their names. var KeysymToName = map[xproto.Keysym]string{} // NameToKeysym maps X11 keysym names to their constants. var NameToKeysym = map[string]xproto.Keysym{} func init() { x := strings.Split(ktnValues, " ") for i, keysym := range ktnKeys { KeysymToName[keysym] = x[i] } for i, name := range strings.Split(ntkKeys, " ") { NameToKeysym[name] = ntkValues[i] } } EOF