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
26 echo "$0: Generate a html table from pcb menu res files."
27 echo "Usage: $0 file1 [file2 [file3 ... [fileN]]]"
34 # split the file into one token per line using a state machine
36 # - quoted strings ("")
37 # - control characters: {, }, =
46 # echo a character and remember if it was a newline
52 # echo a newline if the previous character written was not a newline
58 # parse state machine: eats input character by character
94 # whitespace are non-redundant newlines
112 # each new line of the input is a set of characters
113 # reset comment first, as it spanned to the previous newline
117 for(n = 1; n <= l; n++)
118 parse(substr($0, n, 1))
123 # "grammar": read tokens and output "key src action" where
124 # key is in base-modified-modifier format, modifiers ordered
125 # src is the source res file we are working from, passed as $1
126 # action is the action given right after the key or before the key
129 tokenize |
$AWK -v "src=$1" '
155 split(tolower(k2), K, "<key>")
158 if (K[1] ~ "alt") mods = mods "-alt"
159 if (K[1] ~ "ctrl") mods = mods "-ctrl"
160 if (K[1] ~ "shift") mods = mods "-shift"
165 gsub("[ \t]", "", key)
166 gsub("[ \t]", "", src)
167 gsub("[ \t]", "", action)
168 print key, src, action
180 # convert a "key src action" to a html table with rowspans for base keys
185 HIDNAMES["gpcb-menu.res"] = "gtk"
186 HIDNAMES["pcb-menu.res"] = "lesstif"
191 function to_base_key(combo)
193 sub("-.*", "", combo)
197 function to_mods(combo)
201 sub("^[^-]*[-]", "", combo)
207 LIST[key_combos++] = $1
208 ROWSPAN[to_base_key($1)]++
217 print "<h1> Key to action bindings </h1>"
218 print "<table border=1 cellspacing=0>"
219 printf("<tr><th> key <th> modifiers")
222 printf(" <th>%s<br>%s", h, HIDNAMES[h])
226 for(n = 0; n < key_combos; n++) {
228 base = to_base_key(key)
230 if (base != last_base)
232 print "<tr bgcolor=" CLR[clr_cnt % 2] ">"
233 if (base != last_base)
234 print " <th rowspan=" ROWSPAN[base] ">" base
247 print "</body></html>"
254 extract_from_res
"$n" < $n
255 done |
sort | gen_html