/* * STFL - The Structured Terminal Forms Language/Library * Copyright (C) 2007 Clifford Wolf * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * * binding.c: Helper functions for key bindings and stuff */ #include "stfl_internals.h" #include "stfl_compat.h" #include #include #include wchar_t *stfl_keyname(wchar_t ch, int isfunckey) { if (!isfunckey) { if (ch == L'\r' || ch == L'\n') return compat_wcsdup(L"ENTER"); if (ch == L' ') return compat_wcsdup(L"SPACE"); if (ch == L'\t') return compat_wcsdup(L"TAB"); if (ch == 27) return compat_wcsdup(L"ESC"); if (ch == 127) return compat_wcsdup(L"BACKSPACE"); wchar_t *ret; if (ch < 32) { const char * key = keyname(ch); unsigned int keylen = strlen(key) + 1, i; ret = malloc(keylen * sizeof(wchar_t)); for (i=0; i 0 && len == event_len && !wcsncmp(desc, event, len)) { free(event); return 1; } desc += len; } if (retry_auto_desc > 0) { retry_auto_desc = -1; desc = auto_desc; goto retry_auto_desc; } free(event); return 0; }