From 7d45aa4f8ac922a1f7515a35b05ec0639290b34d Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Mon, 4 Jul 2022 00:29:50 +0800 Subject: [PATCH] evdev: generate code defs from c header --- .gitignore | 2 ++ Makefile | 12 +++++++++--- aux/event-codes/main.ha | 38 ++++++++++++++++++++++++++++++++++++++ evdev/codes.ha | 29 ----------------------------- 4 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 aux/event-codes/main.ha delete mode 100644 evdev/codes.ha diff --git a/.gitignore b/.gitignore index 485f898..c158694 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ /pointerd /motion-control /buttonc +/evdev/codes.ha +/event-codes diff --git a/Makefile b/Makefile index 53904ca..7ca3324 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,23 @@ SENSORS ?= gy801 +HEADERS_PREFIX ?= /usr/include BINARIES = evdev-dump-events uinput-pointer sensors-dump pointerd pointerc motion-control buttonc -evdev-dump-events uinput-pointer: +event-codes: + hare build -o $@ aux/$@/ +evdev/codes.ha: event-codes + ./event-codes <$(HEADERS_PREFIX)/linux/input-event-codes.h >$@ + +evdev-dump-events uinput-pointer: evdev/codes.ha hare build -levdev -o $@ tools/$@/ sensors-dump pointerc: hare build -T +$(SENSORS) -o $@ tools/$@/ buttonc: hare build -o $@ tools/$@/ -pointerd: +pointerd: evdev/codes.ha hare build -levdev -o $@ cmd/$@/ motion-control: hare build -T +$(SENSORS) -o $@ cmd/$@/ .PHONY: $(BINARIES) all: $(BINARIES) clean: - rm -f $(BINARIES) + rm -f event-codes evdev/codes.ha $(BINARIES) diff --git a/aux/event-codes/main.ha b/aux/event-codes/main.ha new file mode 100644 index 0000000..3ef97a5 --- /dev/null +++ b/aux/event-codes/main.ha @@ -0,0 +1,38 @@ +use bufio; +use fmt; +use io; +use os; +use strings; + +export fn main() void = { + for (true) { + const line = match (bufio::scanline(os::stdin)!) { + case let s: []u8 => + yield strings::fromutf8(s); + case io::EOF => + return; + }; + + if (!strings::hasprefix(line, "#define")) { + free(line); + continue; + }; + const iend = match (strings::index(strings::sub(line, 8, strings::end), '\t')) { + case void => + free(line); + continue; + case let s: size => + yield s + 8; + }; + const val = strings::trim(strings::sub(line, iend, strings::end), '\t'); + const val = match (strings::index(val, "/*")) { + case void => + yield val; + case let s: size => + yield strings::sub(val, 0, s); + }; + fmt::printfln("export def {}: u16\t= {};", strings::sub(line, 8, iend), val)!; + + free(line); + }; +}; diff --git a/evdev/codes.ha b/evdev/codes.ha deleted file mode 100644 index 1b31c3b..0000000 --- a/evdev/codes.ha +++ /dev/null @@ -1,29 +0,0 @@ -export def EV_SYN: u16 = 0x00; -export def EV_KEY: u16 = 0x01; -export def EV_REL: u16 = 0x02; -export def EV_ABS: u16 = 0x03; -export def EV_MSC: u16 = 0x04; -export def EV_SW: u16 = 0x05; -export def EV_LED: u16 = 0x11; -export def EV_SND: u16 = 0x12; -export def EV_REP: u16 = 0x14; -export def EV_FF: u16 = 0x15; -export def EV_PWR: u16 = 0x16; -export def EV_FF_STATUS: u16 = 0x17; -export def EV_MAX: u16 = 0x1f; -export def EV_CNT: u16 = EV_MAX + 1; - -export def SYN_REPORT: u16 = 0; -export def SYN_CONFIG: u16 = 1; -export def SYN_MT_REPORT: u16 = 2; -export def SYN_DROPPED: u16 = 3; -export def SYN_MAX: u16 = 0xf; -export def SYN_CNT: u16 = SYN_MAX + 1; - -export def BTN_LEFT: u16 = 0x110; -export def BTN_RIGHT: u16 = 0x111; -export def BTN_MIDDLE: u16 = 0x112; - -export def REL_X: u16 = 0x00; -export def REL_Y: u16 = 0x01; -export def REL_Z: u16 = 0x02; -- 2.45.2