1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-09-27 06:22:20 +02:00
zsh/Src/Modules/curses_keys.awk
Daniel Shahaf c6a8516361 github #64: Fix a build-time error when building against ncurses that hadn't been built with --enable-wgetch-events.
The --enable-wgetch-events codepath is experimental (according to
ncurses-6.2/INSTALL) and off by default (according to
ncurses-6.2/configure.in).  With that codepath disabled, the macro
KEY_EVENT is not provided, which (before this commit) manifested as a
build-time error:

    [  245s] gcc -c -I. -I../../Src -I../../Src -I../../Src/Zle -I.  -DHAVE_CONFIG_H -DMODULE -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g -fPIE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/usr/include/ncursesw -fPIC -o curses..o curses.c
    [  246s] In file included from curses.c:210:
    [  246s] curses_keys.h:93:15: error: 'KEY_EVENT' undeclared here (not in a function); did you mean 'KEY_RESET'?
    [  246s]    93 |     {"EVENT", KEY_EVENT},
    [  246s]       |               ^~~~~~~~~
    [  246s]       |               KEY_RESET

curses_keys.h is only used for setting the "kevent" output parameter of
'zcurses input' (and the associated $zcurses_keycodes special variable),
so there's no harm in just leaving KEY_EVENT out of it.  (That codepath
deals gracefully with numeric values that don't correspond to any of the
known compile-time values, as that can happen whenever the build- and
run-time versions of ncurses don't provide the same set of KEY_* macros,
with or without relation to that configure flag.)

Reported by Martin Liska.
2020-08-28 02:54:51 +00:00

25 lines
688 B
Awk

BEGIN {nkeydefs = 0}
/^[\t ]*#[\t ]*define[\t _]*KEY_[A-Z0-9_]*[\t ]/ {
keyindex = index($0, "KEY_")
keytail = substr($0, keyindex, 80)
split(keytail, tmp)
keynam = substr(tmp[1], 5, 30)
if (keynam != "MIN" && keynam != "MAX" && keynam != "CODE_YES") {
name[nkeydefs++] = keynam
}
}
END {
printf("static const struct zcurses_namenumberpair keypad_names[] = {\n")
for (i = 0; i < 0 + nkeydefs; i++) {
if (name[i] == "EVENT")
printf("#ifdef KEY_EVENT\n")
printf(" {\"%s\", KEY_%s},\n", name[i], name[i])
if (name[i] == "EVENT")
printf("#endif\n")
}
printf(" {NULL, 0}\n")
printf("};\n")
}