aboutsummaryrefslogtreecommitdiffstats
path: root/com32/libutil
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2011-04-11 14:59:45 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2011-04-11 15:06:38 -0700
commita8e74b2834664543166744cf0832e1d6db36347f (patch)
tree2c22b842d476d69cbeeb95dbfe9df433c8fa60b4 /com32/libutil
parent868c474546ba68e9e448734e1833f873fd50ec0a (diff)
downloadsyslinux-a8e74b2834664543166744cf0832e1d6db36347f.tar.gz
syslinux-a8e74b2834664543166744cf0832e1d6db36347f.tar.xz
syslinux-a8e74b2834664543166744cf0832e1d6db36347f.zip
menu: Add "menu hiddenkey" to make terminating menu hidden a command
Use "menu hiddenkey" together with "menu hidden" for a one-keystroke action. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'com32/libutil')
-rw-r--r--com32/libutil/Makefile3
-rw-r--r--com32/libutil/include/getkey.h4
-rw-r--r--com32/libutil/keyname.c133
3 files changed, 139 insertions, 1 deletions
diff --git a/com32/libutil/Makefile b/com32/libutil/Makefile
index 02789ca6..7a6b5272 100644
--- a/com32/libutil/Makefile
+++ b/com32/libutil/Makefile
@@ -32,7 +32,8 @@
topdir = ../..
include ../MCONFIG
-LIBOBJS = ansiline.o ansiraw.o get_key.o sha1hash.o unbase64.o \
+LIBOBJS = ansiline.o ansiraw.o get_key.o keyname.o \
+ sha1hash.o unbase64.o \
md5.o crypt-md5.o sha256crypt.o sha512crypt.o base64.o
LNXLIBOBJS = $(patsubst %.o,%.lo,$(LIBOBJS))
diff --git a/com32/libutil/include/getkey.h b/com32/libutil/include/getkey.h
index 52312a25..a46de812 100644
--- a/com32/libutil/include/getkey.h
+++ b/com32/libutil/include/getkey.h
@@ -75,6 +75,10 @@
#define KEY_INSERT 0x0128
#define KEY_DELETE 0x0129
+#define KEY_MAX 0x012a
+
int get_key(FILE *, clock_t);
+int key_name_to_code(const char *);
+const char *key_code_to_name(int);
#endif /* LIBUTIL_GETKEY_H */
diff --git a/com32/libutil/keyname.c b/com32/libutil/keyname.c
new file mode 100644
index 00000000..6aebbd59
--- /dev/null
+++ b/com32/libutil/keyname.c
@@ -0,0 +1,133 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2011 Intel Corporation; author: H. Peter Anvin
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * keyname.c
+ *
+ * Conversion between strings and get_key() key numbers.
+ */
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/times.h>
+#include <getkey.h>
+#include <libutil.h>
+
+struct keyname {
+ const char *string;
+ int key;
+};
+
+static const struct keyname key_names[] = {
+ { "Backspace", KEY_BACKSPACE },
+ { "Tab", KEY_TAB },
+ { "Enter", KEY_ENTER },
+ { "Esc", KEY_ESC },
+ { "Escape", KEY_ESC },
+ { "Space", ' ' },
+ { "^?", KEY_DEL },
+ { "F1", KEY_F1 },
+ { "F2", KEY_F2},
+ { "F3", KEY_F3 },
+ { "F4", KEY_F4 },
+ { "F5", KEY_F5 },
+ { "F6", KEY_F6 },
+ { "F7", KEY_F7 },
+ { "F8", KEY_F8 },
+ { "F9", KEY_F9 },
+ { "F10", KEY_F10 },
+ { "F11", KEY_F11 },
+ { "F12", KEY_F12 },
+ { "Up", KEY_UP },
+ { "Down", KEY_DOWN },
+ { "Left", KEY_LEFT },
+ { "Right", KEY_RIGHT },
+ { "PgUp", KEY_PGUP },
+ { "PgDn", KEY_PGDN },
+ { "Home", KEY_HOME },
+ { "End", KEY_END },
+ { "Insert", KEY_INSERT },
+ { "Delete", KEY_DELETE },
+ { NULL, KEY_NONE }
+};
+
+int key_name_to_code(const char *code)
+{
+ const struct keyname *name;
+
+ if (code[0] && !code[1]) {
+ /* Single character */
+ return (unsigned char)code[0];
+ } else if (code[0] == '^' && code[1] && !code[2]) {
+ /* Control character */
+ if (code[1] == '?')
+ return 0x7f;
+ else
+ return (unsigned char)code[1] & 0x9f;
+ }
+
+
+ for (name = key_names; name->string; name++) {
+ if (!strcasecmp(name->string, code))
+ break;
+ }
+ return name->key; /* KEY_NONE at end of array */
+}
+
+const char *key_code_to_name(int key)
+{
+ static char buf[4];
+ const struct keyname *name;
+
+ if (key < 0)
+ return NULL;
+
+ if (key < 0x100 && key != ' ') {
+ if (key == 0x7f) {
+ return "^?";
+ } else if (key & 0x60) {
+ buf[0] = key;
+ buf[1] = '\0';
+ } else {
+ buf[0] = '^';
+ buf[1] = key | 0x40;
+ buf[2] = '\0';
+ }
+ return buf;
+ }
+
+ for (name = key_names; name->string; name++) {
+ if (key == name->key)
+ return name->string;
+ }
+
+ return NULL;
+}