Skip to content

Commit

Permalink
Add a first pass at keylist generation scripts
Browse files Browse the repository at this point in the history
- Added `extract-keys.sh` to extract argument-taking and non-argument-taking macros from key definitions.
- Added `generate-macro-printer.sh` to generate a C++ program for printing macro values.
  • Loading branch information
obra committed Mar 21, 2024
1 parent 3d678b0 commit 7bcbdd6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions etc/generate-keylist/extract-keys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Find potential argument-taking macros
ggrep --no-filename -oP '^#define \K\w+\s*\([^)]*\)' src/kaleidoscope/key_defs/*.h > /tmp/arg_macros.txt

# Find non-argument-taking macros
ggrep --no-filename -oP '^#define \K\w+' src/kaleidoscope/key_defs/*.h | ggrep -vFf /tmp/arg_macros.txt > /tmp/non_arg_macros.txt

27 changes: 27 additions & 0 deletions etc/generate-keylist/generate-macro-printer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
PROGRAM=/tmp/list-macros.cpp
echo '#include <stdio.h>' > ${PROGRAM}
echo '#include "kaleidoscope/key_defs.h"' >> ${PROGRAM}
echo '#include "kaleidoscope/HIDTables.h"' >> ${PROGRAM}
echo 'int main() {' >> ${PROGRAM}
echo 'printf("{\\n");' >> ${PROGRAM}

# Handle non-argument-taking macros
while IFS= read -r macro; do
echo "printf(\"'$macro': %d,\", $macro.getRaw());" >> ${PROGRAM}
echo "printf(\"\\\n\");" >> ${PROGRAM}
done < /tmp/non_arg_macros.txt

# Handle argument-taking macros, generating 32 versions for each
while IFS= read -r macro; do
# Strip off parentheses for the argument-taking macro names
macro=$(echo $macro | sed 's/(.*)//')
for i in {0..31}; do
echo "printf(\"'$macro$i': %d,\", $macro($i).getRaw());" >> ${PROGRAM}
echo "printf(\"\\\n\");" >> ${PROGRAM}
done
done < /tmp/arg_macros.txt

echo 'printf("};\\n");' >> ${PROGRAM}
echo 'return 0;' >> ${PROGRAM}
echo '}' >> ${PROGRAM}

0 comments on commit 7bcbdd6

Please sign in to comment.