aboutsummaryrefslogtreecommitdiffstats
path: root/com32
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-09-05 22:51:04 -0700
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-09-05 22:51:04 -0700
commit843f0ef16067d920e9e181ef897abbaa4a432da9 (patch)
tree861c3a353967955cfe325ed489c4429d52a63f64 /com32
parent71fb86d8596fb12a6ddf1d182116044406b2b8ca (diff)
downloadsyslinux-843f0ef16067d920e9e181ef897abbaa4a432da9.tar.gz
syslinux-843f0ef16067d920e9e181ef897abbaa4a432da9.tar.xz
syslinux-843f0ef16067d920e9e181ef897abbaa4a432da9.zip
cmenu: use get_key library for keyboard functions
Syslinux already uses a get_key library to handle stdin. Let's leverage it. cmenu now works over serial completely. Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Diffstat (limited to 'com32')
-rw-r--r--com32/cmenu/adv_menu.tpl4
-rw-r--r--com32/cmenu/complex.c29
-rw-r--r--com32/cmenu/libmenu/com32io.c7
-rw-r--r--com32/cmenu/libmenu/com32io.h18
-rw-r--r--com32/cmenu/libmenu/help.c26
-rw-r--r--com32/cmenu/libmenu/menu.c95
-rw-r--r--com32/cmenu/libmenu/menu.h1
-rw-r--r--com32/cmenu/libmenu/scancodes.h86
-rw-r--r--com32/cmenu/libmenu/tui.c41
-rw-r--r--com32/cmenu/libmenu/tui.h3
10 files changed, 99 insertions, 211 deletions
diff --git a/com32/cmenu/adv_menu.tpl b/com32/cmenu/adv_menu.tpl
index 22932fcb..9c38407b 100644
--- a/com32/cmenu/adv_menu.tpl
+++ b/com32/cmenu/adv_menu.tpl
@@ -203,13 +203,13 @@ void keys_handler(t_menuitem *mi,unsigned int scancode)
nr = 24;
}
- if ( ((scancode >> 8) == F1) && (mi->helpid != 0xFFFF) ) { // If scancode of F1 and non-trivial helpid
+ if ( (scancode == KEY_F1) && (mi->helpid != 0xFFFF) ) { // If scancode of F1 and non-trivial helpid
runhelpsystem(mi->helpid);
}
// If user hit TAB, and item is an "executable" item
// and user has privileges to edit it, edit it in place.
- if (((scancode & 0xFF) == 0x09) && (mi->action == OPT_RUN) &&
+ if ((scancode == KEY_TAB) && (mi->action == OPT_RUN) &&
(EDIT_ROW < nr) && (EDIT_ROW > 0) &&
(isallowed(username,"editcmd") || isallowed(username,"root"))) {
// User typed TAB and has permissions to edit command line
diff --git a/com32/cmenu/complex.c b/com32/cmenu/complex.c
index 9dd43729..ce5e1f74 100644
--- a/com32/cmenu/complex.c
+++ b/com32/cmenu/complex.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#include <getkey.h>
/* Global variables */
char infoline[160];
@@ -70,12 +71,12 @@ void keys_handler(t_menuitem * mi, unsigned int scancode)
{
int nc, nr;
- if ((scancode >> 8) == F1) { // If scancode of F1
+ if ((scancode) == KEY_F1) { // If scancode of F1
runhelpsystem(mi->helpid);
}
// If user hit TAB, and item is an "executable" item
// and user has privileges to edit it, edit it in place.
- if (((scancode & 0xFF) == 0x09) && (mi->action == OPT_RUN) &&
+ if ((scancode == KEY_TAB) && (mi->action == OPT_RUN) &&
(isallowed(username, "editcmd") || isallowed(username, "root"))) {
if (getscreensize(1, &nr, &nc)) {
/* Unknown screen size? */
@@ -238,25 +239,6 @@ t_handler_return checkbox_handler(t_menusystem * ms, t_menuitem * mi)
return ACTION_VALID;
}
-/*
- Clears keyboard buffer and then
- wait for stepsize*numsteps milliseconds for user to press any key
- checks for keypress every stepsize milliseconds.
- Returns: 1 if user pressed a key (not read from the buffer),
- 0 if time elapsed
-*/
-int checkkeypress(int stepsize, int numsteps)
-{
- int i;
- clearkbdbuf();
- for (i = 0; i < numsteps; i++) {
- if (checkkbdbuf())
- return 1;
- sleep(stepsize);
- }
- return 0;
-}
-
int main()
{
t_menuitem *curr;
@@ -416,12 +398,11 @@ int main()
0);
set_item_options(-1, 30);
csprint("Press any key within 5 seconds to show menu...", 0x07);
- if (!checkkeypress(100, 50)) // Granularity of 100 milliseconds
+ if (get_key(stdin, 50) == KEY_NONE) // Granularity of 100 milliseconds
{
csprint("Sorry! Time's up.\r\n", 0x07);
return 1;
- } else
- clearkbdbuf(); // Just in case user pressed something important
+ }
curr = showmenus(MAIN);
if (curr) {
if (curr->action == OPT_RUN) {
diff --git a/com32/cmenu/libmenu/com32io.c b/com32/cmenu/libmenu/com32io.c
index b910959f..f03043fb 100644
--- a/com32/cmenu/libmenu/com32io.c
+++ b/com32/cmenu/libmenu/com32io.c
@@ -84,13 +84,6 @@ void setvideomode(char mode)
__intcall(0x10, &inreg, &outreg);
}
-unsigned char checkkbdbuf()
-{
- REG_AH(inreg) = 0x11;
- __intcall(0x16, &inreg, &outreg);
- return !(outreg.eflags.l & EFLAGS_ZF);
-}
-
// Get char displayed at current position
unsigned char getcharat(char page)
{
diff --git a/com32/cmenu/libmenu/com32io.h b/com32/cmenu/libmenu/com32io.h
index 6a1b670b..95135e64 100644
--- a/com32/cmenu/libmenu/com32io.h
+++ b/com32/cmenu/libmenu/com32io.h
@@ -21,6 +21,17 @@
#define NULL ((void *)0)
#endif
+/* Bits representing ShiftFlags, See Int16/Function 2 or Mem[0x417] to get this info */
+
+#define INSERT_ON (1<<7)
+#define CAPSLOCK_ON (1<<6)
+#define NUMLOCK_ON (1<<5)
+#define SCRLLOCK_ON (1<<4)
+#define ALT_PRESSED (1<<3)
+#define CTRL_PRESSED (1<<2)
+// actually 1<<1 is Left Shift, 1<<0 is right shift
+#define SHIFT_PRESSED (1<<1 | 1 <<0)
+
/* BIOS Assisted output routines */
void getpos(char *row, char *col, char page);
@@ -54,12 +65,7 @@ static inline char getvideomode(void) // Get the current video mode
unsigned char sleep(unsigned int msec); // Sleep for specified time
-unsigned char checkkbdbuf(); // Check to see if there is kbd buffer is non-empty?
+//unsigned char checkkbdbuf(); // Check to see if there is kbd buffer is non-empty?
-static inline void clearkbdbuf() // Clear the kbd buffer (how many chars removed?)
-{
- while (checkkbdbuf())
- inputc(NULL);
-}
#endif
diff --git a/com32/cmenu/libmenu/help.c b/com32/cmenu/libmenu/help.c
index 3b36c3d8..f0e149e5 100644
--- a/com32/cmenu/libmenu/help.c
+++ b/com32/cmenu/libmenu/help.c
@@ -87,7 +87,7 @@ void showhelp(const char *filename)
char line[512];
size_t size;
- char scan;
+ int scan;
int rv, numlines, curr_line;
if (getscreensize(1, &nr, &nc)) {
@@ -120,9 +120,9 @@ void showhelp(const char *filename)
printf(title);
numlines = countlines(text);
curr_line = 0;
- scan = ESCAPE + 1; // anything except ESCAPE
+ scan = KEY_ESC + 1; // anything except ESCAPE
- while (scan != ESCAPE) {
+ while (scan != KEY_ESC) {
printtext(text, curr_line);
gotoxy(HELP_BODY_ROW - 1, nc - HELP_RIGHT_MARGIN);
if (curr_line > 0)
@@ -135,25 +135,25 @@ void showhelp(const char *filename)
else
putchar(' ');
- inputc(&scan); // wait for user keypress
+ scan = get_key(stdout, 0); // wait for user keypress
switch (scan) {
- case HOMEKEY:
+ case KEY_HOME:
curr_line = 0;
break;
- case ENDKEY:
+ case KEY_END:
curr_line = numlines;
break;
- case UPARROW:
+ case KEY_UP:
curr_line--;
break;
- case DNARROW:
+ case KEY_DOWN:
curr_line++;
break;
- case PAGEUP:
+ case KEY_PGUP:
curr_line -= ph;
break;
- case PAGEDN:
+ case KEY_PGDN:
curr_line += ph;
break;
default:
@@ -170,10 +170,10 @@ out:
puke:
gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN);
- printf(line);
+ fputs(line, stdout);
while (1) {
- inputc(&scan);
- if (scan == ESCAPE)
+ scan = get_key(stdin, 0);
+ if (scan == KEY_ESC)
break;
}
goto out;
diff --git a/com32/cmenu/libmenu/menu.c b/com32/cmenu/libmenu/menu.c
index 6a1d7a37..25adef3c 100644
--- a/com32/cmenu/libmenu/menu.c
+++ b/com32/cmenu/libmenu/menu.c
@@ -40,47 +40,45 @@ int isvisible(pt_menu menu, int first, int curr);
// This is same as inputc except it honors the ontimeout handler
// and calls it when needed. For the callee, there is no difference
// as this will not return unless a key has been pressed.
-char getch(char *scan)
+static int getch()
{
- unsigned long i;
- TIMEOUTCODE c;
t_timeout_handler th;
+ int key;
+ unsigned long i;
// Wait until keypress if no handler specified
if ((ms->ontimeout == NULL) && (ms->ontotaltimeout == NULL))
- return inputc(scan);
+ return get_key(stdin, 0);
th = ms->ontimeout;
- while (1) // Forever do
- {
- for (i = 0; i < ms->tm_numsteps; i++) {
- if (checkkbdbuf())
- return inputc(scan);
- sleep(ms->tm_stepsize);
- if ((ms->tm_total_timeout == 0) || (ms->ontotaltimeout == NULL))
- continue; // Dont bother with calculations if no handler
- ms->tm_sofar_timeout += ms->tm_stepsize;
- if (ms->tm_sofar_timeout >= ms->tm_total_timeout) {
- th = ms->ontotaltimeout;
- ms->tm_sofar_timeout = 0;
- break; // Get out of the for loop
+ for (;;) {
+ for (i = 0; i < ms->tm_numsteps; i++) {
+ key = get_key(stdin, ms->tm_stepsize);
+ if (key != KEY_NONE)
+ return key;
+
+ if ((ms->tm_total_timeout == 0) || (ms->ontotaltimeout == NULL))
+ continue; // Dont bother with calculations if no handler
+ ms->tm_sofar_timeout += ms->tm_stepsize;
+ if (ms->tm_sofar_timeout >= ms->tm_total_timeout) {
+ th = ms->ontotaltimeout;
+ ms->tm_sofar_timeout = 0;
+ break; // Get out of the for loop
+ }
+ }
+ if (!th)
+ continue; // no handler
+ key = th();
+ switch (key) {
+ case CODE_ENTER: // Pretend user hit enter
+ return KEY_ENTER;
+ case CODE_ESCAPE: // Pretend user hit escape
+ return KEY_ESC;
+ default:
+ break;
}
}
- if (!th)
- continue; // no handler dont call
- c = th();
- switch (c) {
- case CODE_ENTER: // Pretend user hit enter
- *scan = ENTERA;
- return '\015'; // \015 octal = 13
- case CODE_ESCAPE: // Pretend user hit escape
- *scan = ESCAPE;
- return '\033'; // \033 octal = 27
- default:
- break;
- }
- }
- return 0;
+ return KEY_NONE;
}
/*
@@ -295,7 +293,7 @@ static pt_menuitem getmenuoption(pt_menu menu, uchar top, uchar left, uchar star
// Return item chosen or NULL if ESC was hit.
{
int curr, i, first, tmp;
- uchar asc, scan;
+ int asc = 0;
uchar numitems;
pt_menuitem ci; // Current item
t_handler_return hr; // Return value of handler
@@ -317,43 +315,42 @@ static pt_menuitem getmenuoption(pt_menu menu, uchar top, uchar left, uchar star
{
printmenu(menu, curr, top, left, first, radio);
ci = menu->items[curr];
- asc = getch(&scan);
- switch (scan) {
- case HOMEKEY:
+ asc = getch();
+ switch (asc) {
+ case KEY_HOME:
curr = next_visible(menu, 0);
first = calc_first_early(menu, curr);
break;
- case ENDKEY:
+ case KEY_END:
curr = prev_visible(menu, numitems - 1);
first = calc_first_late(menu, curr);
break;
- case PAGEDN:
+ case KEY_PGDN:
for (i = 0; i < 5; i++)
curr = next_visible(menu, curr + 1);
first = calc_first_late(menu, curr);
break;
- case PAGEUP:
+ case KEY_PGUP:
for (i = 0; i < 5; i++)
curr = prev_visible(menu, curr - 1);
first = calc_first_early(menu, curr);
break;
- case UPARROW:
+ case KEY_UP:
curr = prev_visible(menu, curr - 1);
if (curr < first)
first = calc_first_early(menu, curr);
break;
- case DNARROW:
+ case KEY_DOWN:
curr = next_visible(menu, curr + 1);
if (!isvisible(menu, first, curr))
first = calc_first_late(menu, curr);
break;
- case LTARROW:
- case ESCAPE:
+ case KEY_LEFT:
+ case KEY_ESC:
return NULL;
break;
- case RTARROW:
- case ENTERA:
- case ENTERB:
+ case KEY_RIGHT:
+ case KEY_ENTER:
if (ci->action == OPT_INACTIVE)
break;
if (ci->action == OPT_CHECKBOX)
@@ -382,7 +379,7 @@ static pt_menuitem getmenuoption(pt_menu menu, uchar top, uchar left, uchar star
} else
return ci;
break;
- case SPACEKEY:
+ case SPACECHAR:
if (ci->action != OPT_CHECKBOX)
break;
ci->itemdata.checked = !ci->itemdata.checked;
@@ -413,7 +410,7 @@ static pt_menuitem getmenuoption(pt_menu menu, uchar top, uchar left, uchar star
curr = tmp;
} else {
if (ms->keys_handler) // Call extra keys handler
- ms->keys_handler(ms, menu->items[curr], (scan << 8) | asc);
+ ms->keys_handler(ms, menu->items[curr], asc);
}
break;
}
@@ -673,7 +670,7 @@ pt_menusystem init_menusystem(const char *title)
if (ms->maxmenuheight > MAXMENUHEIGHT)
ms->maxmenuheight = MAXMENUHEIGHT;
- openconsole(&dev_stdcon_r, &dev_ansiserial_w);
+ console_ansi_raw();
return ms;
}
diff --git a/com32/cmenu/libmenu/menu.h b/com32/cmenu/libmenu/menu.h
index 6c14dab0..b373e760 100644
--- a/com32/cmenu/libmenu/menu.h
+++ b/com32/cmenu/libmenu/menu.h
@@ -22,7 +22,6 @@
#include "com32io.h"
#include "tui.h"
#include "syslnx.h"
-#include "scancodes.h"
#include <string.h>
#include <unistd.h>
diff --git a/com32/cmenu/libmenu/scancodes.h b/com32/cmenu/libmenu/scancodes.h
deleted file mode 100644
index b70f6c67..00000000
--- a/com32/cmenu/libmenu/scancodes.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/* -*- c -*- ------------------------------------------------------------- *
- *
- * Copyright 2004-2005 Murali Krishnan Ganapathy - All Rights Reserved
- *
- * 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, Inc., 53 Temple Place Ste 330,
- * Boston MA 02111-1307, USA; either version 2 of the License, or
- * (at your option) any later version; incorporated herein by reference.
- *
- * ----------------------------------------------------------------------- */
-
-#ifndef __SCANCODES_H__
-#define __SCANCODES_H__
-
-// Scancodes of some keys
-#define ESCAPE 1
-#define ENTERA 28
-#define ENTERB 224
-
-#define HOMEKEY 71
-#define UPARROW 72
-#define PAGEUP 73
-#define LTARROW 75
-#define RTARROW 77
-#define ENDKEY 79
-#define DNARROW 80
-#define PAGEDN 81
-#define INSERT 82
-#define DELETE 83
-#define SPACEKEY 57 // Scan code for SPACE
-
-#define CTRLLT 0x73
-#define CTRLRT 0x74
-
-#define F1 0x3B
-#define F2 0x3C
-#define F3 0x3D
-#define F4 0x3E
-#define F5 0x3F
-#define F6 0x40
-#define F7 0x41
-#define F8 0x42
-#define F9 0x43
-#define F10 0x44
-#define F11 0x85
-#define F12 0x86
-
-#define CTRLF1 0x5E
-#define CTRLF2 0x5F
-#define CTRLF3 0x60
-#define CTRLF4 0x61
-#define CTRLF5 0x62
-#define CTRLF6 0x63
-#define CTRLF7 0x64
-#define CTRLF8 0x65
-#define CTRLF9 0x66
-#define CTRLF10 0x67
-#define CTRLF11 0x89
-#define CTRLF12 0x8A
-
-#define ALTF1 0x68
-#define ALTF2 0x69
-#define ALTF3 0x6A
-#define ALTF4 0x6B
-#define ALTF5 0x6C
-#define ALTF6 0x6D
-#define ALTF7 0x6E
-#define ALTF8 0x6F
-#define ALTF9 0x70
-#define ALTF10 0x71
-#define ALTF11 0x8B
-#define ALTF12 0x8C
-
-/* Bits representing ShiftFlags, See Int16/Function 2 or Mem[0x417] to get this info */
-
-#define INSERT_ON (1<<7)
-#define CAPSLOCK_ON (1<<6)
-#define NUMLOCK_ON (1<<5)
-#define SCRLLOCK_ON (1<<4)
-#define ALT_PRESSED (1<<3)
-#define CTRL_PRESSED (1<<2)
-// actually 1<<1 is Left Shift, 1<<0 is right shift
-#define SHIFT_PRESSED (1<<1 | 1 <<0)
-
-#endif
diff --git a/com32/cmenu/libmenu/tui.c b/com32/cmenu/libmenu/tui.c
index ecc65bdf..dd69277a 100644
--- a/com32/cmenu/libmenu/tui.c
+++ b/com32/cmenu/libmenu/tui.c
@@ -29,7 +29,7 @@ char eolstr[] = "\n$";
void getuserinput(char *stra, unsigned int size, unsigned int password,
unsigned int showoldvalue)
{
- unsigned char c, scan;
+ unsigned int c;
char *p, *q; // p = current char of string, q = tmp
char *last; // The current last char of string
char *str; // pointer to string which is going to be allocated
@@ -69,10 +69,10 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
csprint(str, GETSTRATTR);
}
while (1) { // Do forever
- c = inputc(&scan);
- if (c == '\r')
+ c = get_key(stdin, 0);
+ if (c == KEY_ENTER)
break; // User hit Enter getout of loop
- if (scan == ESCAPE) // User hit escape getout and nullify string
+ if (c == KEY_ESC) // User hit escape getout and nullify string
{
*str = 0;
break;
@@ -81,18 +81,18 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
// if scan code is regognized do something
// else if char code is recognized do something
// else ignore
- switch (scan) {
- case HOMEKEY:
+ switch (c) {
+ case KEY_HOME:
p = str;
break;
- case ENDKEY:
+ case KEY_END:
p = last;
break;
- case LTARROW:
+ case KEY_LEFT:
if (p > str)
p--;
break;
- case CTRLLT:
+ case KEY_CTRL(KEY_LEFT):
if (p == str)
break;
if (*p == ' ')
@@ -108,11 +108,11 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
while ((p > str) && ((*p == ' ') || (*(p - 1) != ' ')))
p--;
break;
- case RTARROW:
+ case KEY_RIGHT:
if (p < last)
p++;
break;
- case CTRLRT:
+ case KEY_CTRL(KEY_RIGHT):
if (*p == 0)
break; // At end of string
if (*p != ' ')
@@ -123,7 +123,8 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
if (*p == ' ')
p++;
break;
- case DELETE:
+ case KEY_DEL:
+ case KEY_DELETE:
q = p;
while (*(q + 1)) {
*q = *(q + 1);
@@ -133,17 +134,14 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
last--;
fudge = 1;
break;
- case INSERT:
+ case KEY_INSERT:
insmode = 1 - insmode; // Switch mode
if (insmode == 0)
setcursorshape(1, 7); // Block cursor
else
setcursorshape(6, 7); // Normal cursor
break;
-
- default: // Unrecognized scan code, look at the ascii value
- switch (c) {
- case '\b': // Move over by one
+ case KEY_BACKSPACE: // Move over by one
q = p;
while (q <= last) {
*(q - 1) = *q;
@@ -155,7 +153,7 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
p--;
fudge = 1;
break;
- case '\x15': /* Ctrl-U: kill input */
+ case KEY_CTRL('U'): /* Ctrl-U: kill input */
fudge = last - str;
while (p > str)
*p-- = 0;
@@ -163,7 +161,7 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
*p = 0;
last = str;
break;
- default: // Handle insert and overwrite mode
+ default: // Handle insert and overwrite mode
if ((c >= ' ') && (c < 128) &&
((unsigned int)(p - str) < size - 1)) {
if (insmode == 0) { // Overwrite mode
@@ -187,7 +185,6 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
}
} else
beep();
- }
break;
}
// Now the string has been modified, print it
@@ -198,13 +195,13 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
cprint(' ', GETSTRATTR, fudge);
gotoxy(row, col + (p - str));
}
- }
+ } /* while */
*p = '\0';
if (password == 0)
csprint("\r\n", GETSTRATTR);
setcursorshape(start, end); // Block cursor
// If user hit ESCAPE so return without any changes
- if (scan != ESCAPE)
+ if (c != KEY_ESC)
strcpy(stra, str);
free(str);
}
diff --git a/com32/cmenu/libmenu/tui.h b/com32/cmenu/libmenu/tui.h
index ab3873df..ed554878 100644
--- a/com32/cmenu/libmenu/tui.h
+++ b/com32/cmenu/libmenu/tui.h
@@ -14,9 +14,10 @@
#define __TUI_H__
#include <com32.h>
+#include <getkey.h>
+#include <consoles.h>
#include "syslnx.h"
#include "com32io.h"
-#include "scancodes.h"
#ifndef NULL
#define NULL ((void *)0)