omap: nand remove unnecessary condition
[barebox-mini2440.git] / lib / readkey.c
bloba42d1cb8ff55ad4d8f39dd5f5fddfccf4a889f9f
1 /*
2 * readkey.c - read keystrokes and decode standard escape sequences
4 * Partly based on busybox vi
6 * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
8 * See file CREDITS for list of people who contributed to this
9 * project.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <common.h>
26 #include <linux/ctype.h>
27 #include <readkey.h>
29 struct esc_cmds {
30 const char *seq;
31 char val;
34 static const struct esc_cmds esccmds[] = {
35 {"OA", KEY_UP}, // cursor key Up
36 {"OB", KEY_DOWN}, // cursor key Down
37 {"OC", KEY_RIGHT}, // Cursor Key Right
38 {"OD", KEY_LEFT}, // cursor key Left
39 {"OH", KEY_HOME}, // Cursor Key Home
40 {"OF", KEY_END}, // Cursor Key End
41 {"[A", KEY_UP}, // cursor key Up
42 {"[B", KEY_DOWN}, // cursor key Down
43 {"[C", KEY_RIGHT}, // Cursor Key Right
44 {"[D", KEY_LEFT}, // cursor key Left
45 {"[H", KEY_HOME}, // Cursor Key Home
46 {"[F", KEY_END}, // Cursor Key End
47 {"[1~", KEY_HOME}, // Cursor Key Home
48 {"[2~", KEY_INSERT}, // Cursor Key Insert
49 {"[3~", KEY_DEL}, // Cursor Key Delete
50 {"[4~", KEY_END}, // Cursor Key End
51 {"[5~", KEY_PAGEUP}, // Cursor Key Page Up
52 {"[6~", KEY_PAGEDOWN},// Cursor Key Page Down
55 int read_key(void)
57 char c;
58 char esc[5];
59 c = getc();
61 if (c == 27) {
62 int i = 0;
63 esc[i++] = getc();
64 esc[i++] = getc();
65 if (isdigit(esc[1])) {
66 while(1) {
67 esc[i] = getc();
68 if (esc[i++] == '~')
69 break;
72 esc[i] = 0;
73 for (i = 0; i < ARRAY_SIZE(esccmds); i++){
74 if (!strcmp(esc, esccmds[i].seq))
75 return esccmds[i].val;
77 return -1;
79 return c;
81 EXPORT_SYMBOL(read_key);