aboutsummaryrefslogtreecommitdiff
path: root/keyboards/system76/layouts.sh
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/system76/layouts.sh')
-rwxr-xr-xkeyboards/system76/layouts.sh75
1 files changed, 75 insertions, 0 deletions
diff --git a/keyboards/system76/layouts.sh b/keyboards/system76/layouts.sh
new file mode 100755
index 000000000..1c9118562
--- /dev/null
+++ b/keyboards/system76/layouts.sh
@@ -0,0 +1,75 @@
1#!/usr/bin/env bash
2#
3# This script produces layout data for the System76 Keyboard Configurator.
4#
5# Copyright (C) 2021 System76
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, version 3.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19set -eEuo pipefail
20
21R=$(git rev-parse --show-toplevel)
22cd "${R}"
23rm -rf .build/layouts
24mkdir -p .build/layouts
25D="$(realpath .build/layouts)"
26
27binary="${D}/keymap"
28source="${binary}.c"
29header="quantum/keycode.h"
30printf "#include <stdio.h>\n" >"$source"
31printf "#include \"%s\"\n\n" "${header}" >>"$source"
32echo "int main(int argc, char **argv) {" >>"$source"
33grep '^ KC_' "$header" |
34 cut -d ' ' -f5 |
35 cut -d ',' -f1 |
36 while read -r keycode; do
37 name=$(echo "${keycode}" | cut -d '_' -f2-)
38 printf " printf(\"%s,0x%%04X\\\n\", $keycode);\n" "${name}" >>"$source"
39 done
40printf "\n return 0;\n}\n" >>"$source"
41gcc -I. "$source" -o "$binary"
42"${binary}" | tee "${D}/keymap.csv"
43
44cd keyboards
45for board in system76/launch_*; do
46 file="$board/$(basename "$board").h"
47 if [ ! -e "$file" ]; then
48 continue
49 fi
50 echo "# ${board}"
51 mkdir -p "${D}/${board}"
52 cp "${D}/keymap.csv" "${D}/${board}"
53 row=0
54 rg \
55 --multiline \
56 --multiline-dotall \
57 --regexp '#define LAYOUT\(.*\) \{.*\}' \
58 "$file" |
59 grep --only-matching '\{.*\}' |
60 sed 's/^{ //' |
61 sed 's/ }$//' |
62 sed 's/, / /g' |
63 while read -r line; do
64 col=0
65 for word in $line; do
66 if [[ "${word}" != "___" ]]; then
67 echo "${word},${row},${col}"
68 fi
69 col=$((col + 1))
70 done
71 row=$((row + 1))
72 done |
73 sort -n |
74 tee "${D}/${board}/layout.csv"
75done