You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
55 lines
1.1 KiB
#!/usr/bin/env python3 |
|
|
|
import re |
|
import sys |
|
import subprocess |
|
|
|
keys = subprocess.check_output(['keyd', '-l']).decode('utf8').split('\n') |
|
keymap = {k: k for k in keys} |
|
keymap.update({ |
|
"quotedbl": "\"", |
|
"apostrophe": "'", |
|
"Multi_key": "compose", |
|
"exclam": "!", |
|
"question": "?", |
|
"asciicircum": "^", |
|
}) |
|
|
|
|
|
def create_macro(keys): |
|
return f"macro({' '.join(keymap[k] for k in keys)})" |
|
|
|
|
|
macros = {} |
|
for line in open('/usr/share/X11/locale/en_US.UTF-8/Compose').readlines(): |
|
try: |
|
keys, glyph = re.match('(\s*<.*?>+)\s*:\s*"(.*?)".*', line).groups() |
|
keys = re.findall('<(.*?)>', keys) |
|
|
|
macros[glyph] = create_macro(keys) |
|
except: |
|
pass |
|
|
|
print('''/* GENERATED BY "%s" DO NOT EDIT BY HAND */ |
|
|
|
#ifndef ALIASES_H |
|
#define ALIASES_H |
|
struct alias { |
|
const char *name; |
|
const char *def; |
|
}; |
|
|
|
static struct alias aliases[] = { |
|
''' % sys.argv[0]) |
|
|
|
for glyph, macro in macros.items(): |
|
macro = macro.replace('"', '\\"') |
|
print('\t{"%s", "%s"},' % (glyph, macro)) |
|
|
|
print(''' |
|
}; |
|
|
|
const size_t nr_aliases = sizeof(aliases)/sizeof(aliases[0]); |
|
|
|
#endif |
|
''')
|
|
|