/* * STFL - The Structured Terminal Forms Language/Library * Copyright (C) 2006 Clifford Wolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 && (ch == L'\r' || ch == L'\n')) return compat_wcsdup(L"ENTER"); if (!isfunckey && ch == L' ') return compat_wcsdup(L"SPACE"); if (!isfunckey && ch == L'\t') return compat_wcsdup(L"TAB"); if (!isfunckey && ch == 27) return compat_wcsdup(L"ESC"); if (isfunckey && KEY_F(0) <= ch && ch <= KEY_F(63)) { wchar_t *name = malloc(4 * sizeof(wchar_t)); swprintf(name, 4, L"F%d", ch - KEY_F0); return name; } char *event_c = isfunckey ? keyname(ch) : key_name(ch); if (!event_c) return compat_wcsdup(L"UNKNOWN"); if (!strncmp(event_c, "KEY_", 4)) event_c += 4; int event_len = strlen(event_c) + 1, i; wchar_t *event = malloc(event_len * 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; }