2 # keylist - list hotkey->actions found in .res files in a html table, per HID
3 # Copyright (C) 2015 Tibor 'Igor2' Palinkas
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 # http://repo.hu/projects/pcb-rnd
28 echo "$0: Generate a html table from pcb menu res files."
29 echo "Usage: $0 file1 [file2 [file3 ... [fileN]]]"
36 # split the file into one token per line using a state machine
38 # - quoted strings ("")
39 # - control characters: {, }, =
48 # echo a character and remember if it was a newline
54 # echo a newline if the previous character written was not a newline
60 # parse state machine: eats input character by character
96 # whitespace are non-redundant newlines
114 # each new line of the input is a set of characters
115 # reset comment first, as it spanned to the previous newline
119 for(n = 1; n <= l; n++)
120 parse(substr($0, n, 1))
125 # "grammar": read tokens and output "key src action" where
126 # key is in base-modified-modifier format, modifiers ordered
127 # src is the source res file we are working from, passed as $1
128 # action is the action given right after the key or before the key
131 tokenize |
$AWK -v "src=$1" '
157 split(tolower(k2), K, "<key>")
160 if (K[1] ~ "alt") mods = mods "-alt"
161 if (K[1] ~ "ctrl") mods = mods "-ctrl"
162 if (K[1] ~ "shift") mods = mods "-shift"
167 gsub("[ \t]", "", key)
168 gsub("[ \t]", "", src)
169 gsub("[ \t]", "", action)
170 print key, src, action
182 # convert a "key src action" to a html table with rowspans for base keys
187 HIDNAMES["gpcb-menu.res"] = "gtk"
188 HIDNAMES["pcb-menu.res"] = "lesstif"
193 function to_base_key(combo)
195 sub("-.*", "", combo)
199 function to_mods(combo)
203 sub("^[^-]*[-]", "", combo)
209 LIST[key_combos++] = $1
210 ROWSPAN[to_base_key($1)]++
219 print "<h1> Key to action bindings </h1>"
220 print "<table border=1 cellspacing=0>"
221 printf("<tr><th> key <th> modifiers")
224 printf(" <th>%s<br>%s", h, HIDNAMES[h])
228 for(n = 0; n < key_combos; n++) {
230 base = to_base_key(key)
232 if (base != last_base)
234 print "<tr bgcolor=" CLR[clr_cnt % 2] ">"
235 if (base != last_base)
236 print " <th rowspan=" ROWSPAN[base] ">" base
249 print "</body></html>"
256 extract_from_res
"$n" < $n
257 done |
sort | gen_html