aboutsummaryrefslogtreecommitdiffstats
path: root/com32/cmenu
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-09-04 16:54:24 -0700
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-09-04 16:54:24 -0700
commit4873366ee31786f10381427c5522543a82a9e2ab (patch)
tree5b06032be46ab178a1f4a81b78302d1ba2d254d0 /com32/cmenu
parent9c111b3eb8f35bae1f6268eaa1b5f1808acd7d66 (diff)
parentfde17fb11b78a31d97653569acf8255a621e791a (diff)
downloadsyslinux-4873366ee31786f10381427c5522543a82a9e2ab.tar.gz
syslinux-4873366ee31786f10381427c5522543a82a9e2ab.tar.xz
syslinux-4873366ee31786f10381427c5522543a82a9e2ab.zip
Merge branch 'cmenu-video' of git://git.zytor.com/users/pam/hdt-pierre into cmenu-video
Diffstat (limited to 'com32/cmenu')
-rw-r--r--com32/cmenu/adv_menu.tpl41
-rw-r--r--com32/cmenu/complex.c71
-rw-r--r--com32/cmenu/libmenu/com32io.c131
-rw-r--r--com32/cmenu/libmenu/com32io.h64
-rw-r--r--com32/cmenu/libmenu/help.c88
-rw-r--r--com32/cmenu/libmenu/menu.c1325
-rw-r--r--com32/cmenu/libmenu/menu.h7
-rw-r--r--com32/cmenu/libmenu/tui.c149
-rw-r--r--com32/cmenu/libmenu/tui.h29
9 files changed, 951 insertions, 954 deletions
diff --git a/com32/cmenu/adv_menu.tpl b/com32/cmenu/adv_menu.tpl
index 6ce4acf8..22932fcb 100644
--- a/com32/cmenu/adv_menu.tpl
+++ b/com32/cmenu/adv_menu.tpl
@@ -40,6 +40,7 @@ modify this template to suit your needs
#include "com32io.h"
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
#define MAX_CMD_LINE_LENGTH 514
@@ -192,9 +193,15 @@ TIMEOUTCODE ontotaltimeout()
return timeout(totaltimeoutcmd);
}
-void keys_handler(t_menusystem *ms, t_menuitem *mi,unsigned int scancode)
+void keys_handler(t_menuitem *mi,unsigned int scancode)
{
- char nc;
+ int nc, nr;
+
+ if (getscreensize(1, &nr, &nc)) {
+ /* Unknown screen size? */
+ nc = 80;
+ nr = 24;
+ }
if ( ((scancode >> 8) == F1) && (mi->helpid != 0xFFFF) ) { // If scancode of F1 and non-trivial helpid
runhelpsystem(mi->helpid);
@@ -203,40 +210,44 @@ void keys_handler(t_menusystem *ms, t_menuitem *mi,unsigned int scancode)
// 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) &&
- (EDIT_ROW < getnumrows()) && (EDIT_ROW > 0) &&
+ (EDIT_ROW < nr) && (EDIT_ROW > 0) &&
(isallowed(username,"editcmd") || isallowed(username,"root"))) {
- nc = getnumcols();
// User typed TAB and has permissions to edit command line
- gotoxy(EDIT_ROW,1,ms->menupage);
+ gotoxy(EDIT_ROW,1);
csprint("Command line:",0x07);
editstring(mi->data,ACTIONLEN);
- gotoxy(EDIT_ROW,1,ms->menupage);
- cprint(' ',0x07,nc-1,ms->menupage);
+ gotoxy(EDIT_ROW,1);
+ cprint(' ',0x07,nc-1);
}
}
-t_handler_return login_handler(t_menusystem *ms, t_menuitem *mi)
+t_handler_return login_handler(t_menuitem *mi)
{
(void)mi; // Unused
char pwd[40];
char login[40];
- char nc;
+ int nc, nr;
t_handler_return rv;
rv = ACTION_INVALID;
if (PWD_ROW < 0) return rv; // No need to authenticate
if (mi->item == loginstr) { /* User wants to login */
- nc = getnumcols();
- gotoxy(PWD_ROW,1,ms->menupage);
+ if (getscreensize(1, &nr, &nc)) {
+ /* Unknown screen size? */
+ nc = 80;
+ nr = 24;
+ }
+
+ gotoxy(PWD_ROW,1);
csprint("Enter Username: ",0x07);
getstring(login, sizeof username);
- gotoxy(PWD_ROW,1,ms->menupage);
- cprint(' ',0x07,nc,ms->menupage);
+ gotoxy(PWD_ROW,1);
+ cprint(' ',0x07,nc);
csprint("Enter Password: ",0x07);
getpwd(pwd, sizeof pwd);
- gotoxy(PWD_ROW,1,ms->menupage);
- cprint(' ',0x07,nc,ms->menupage);
+ gotoxy(PWD_ROW,1);
+ cprint(' ',0x07,nc);
if (authenticate_user(login,pwd))
{
diff --git a/com32/cmenu/complex.c b/com32/cmenu/complex.c
index 063125d6..4bd74d54 100644
--- a/com32/cmenu/complex.c
+++ b/com32/cmenu/complex.c
@@ -21,6 +21,7 @@
#include "des.h"
#include <stdlib.h>
#include <stdio.h>
+#include <unistd.h>
/* Global variables */
char infoline[160];
@@ -65,9 +66,9 @@ TIMEOUTCODE ontimeout()
#define PWDATTR 0x74
#define EDITPROMPT 21
-void keys_handler(t_menusystem * ms, t_menuitem * mi, unsigned int scancode)
+void keys_handler(t_menuitem * mi, unsigned int scancode)
{
- char nc;
+ int nc, nr;
if ((scancode >> 8) == F1) { // If scancode of F1
runhelpsystem(mi->helpid);
@@ -76,35 +77,43 @@ void keys_handler(t_menusystem * ms, t_menuitem * mi, unsigned int scancode)
// and user has privileges to edit it, edit it in place.
if (((scancode & 0xFF) == 0x09) && (mi->action == OPT_RUN) &&
(isallowed(username, "editcmd") || isallowed(username, "root"))) {
- nc = getnumcols();
+ if (getscreensize(1, &nr, &nc)) {
+ /* Unknown screen size? */
+ nc = 80;
+ nr = 24;
+ }
// User typed TAB and has permissions to edit command line
- gotoxy(EDITPROMPT, 1, ms->menupage);
+ gotoxy(EDITPROMPT, 1);
csprint("Command line:", 0x07);
editstring(mi->data, ACTIONLEN);
- gotoxy(EDITPROMPT, 1, ms->menupage);
- cprint(' ', 0x07, nc - 1, ms->menupage);
+ gotoxy(EDITPROMPT, 1);
+ cprint(' ', 0x07, nc - 1);
}
}
-t_handler_return login_handler(t_menusystem * ms, t_menuitem * mi)
+t_handler_return login_handler(t_menuitem * mi)
{
(void)mi; // Unused
char pwd[40];
char login[40];
- char nc;
+ int nc, nr;
t_handler_return rv;
if (mi->item == loginstr) { /* User wants to login */
- nc = getnumcols();
- gotoxy(PWDPROMPT, 1, ms->menupage);
+ if (getscreensize(1, &nr, &nc)) {
+ /* Unknown screen size? */
+ nc = 80;
+ nr = 24;
+ }
+ gotoxy(PWDPROMPT, 1);
csprint("Enter Username: ", 0x07);
getstring(login, sizeof username);
- gotoxy(PWDPROMPT, 1, ms->menupage);
- cprint(' ', 0x07, nc, ms->menupage);
+ gotoxy(PWDPROMPT, 1);
+ cprint(' ', 0x07, nc);
csprint("Enter Password: ", 0x07);
getpwd(pwd, sizeof pwd);
- gotoxy(PWDPROMPT, 1, ms->menupage);
- cprint(' ', 0x07, nc, ms->menupage);
+ gotoxy(PWDPROMPT, 1);
+ cprint(' ', 0x07, nc);
if (authenticate_user(login, pwd)) {
strcpy(username, login);
@@ -133,22 +142,26 @@ t_handler_return login_handler(t_menusystem * ms, t_menuitem * mi)
void msys_handler(t_menusystem * ms, t_menuitem * mi)
{
- char nc;
+ int nc, nr;
void *v;
- nc = getnumcols(); // Get number of columns
- gotoxy(PWDLINE, PWDCOLUMN, ms->menupage);
+ if (getscreensize(1, &nr, &nc)) {
+ /* Unknown screen size? */
+ nc = 80;
+ nr = 24;
+ }
+ gotoxy(PWDLINE, PWDCOLUMN);
csprint("User: ", PWDATTR);
- cprint(ms->fillchar, ms->fillattr, sizeof username, ms->menupage);
- gotoxy(PWDLINE, PWDCOLUMN + 6, ms->menupage);
+ cprint(ms->fillchar, ms->fillattr, sizeof username);
+ gotoxy(PWDLINE, PWDCOLUMN + 6);
csprint(username, PWDATTR);
if (mi->parindex != PREPMENU) // If we are not in the PREP MENU
{
- gotoxy(INFLINE, 0, ms->menupage);
- cprint(' ', 0x07, nc, ms->menupage);
- gotoxy(INFLINE + 1, 0, ms->menupage);
- cprint(' ', 0x07, nc, ms->menupage);
+ gotoxy(INFLINE, 0);
+ cprint(' ', 0x07, nc);
+ gotoxy(INFLINE + 1, 0);
+ cprint(' ', 0x07, nc);
return;
}
strcpy(infoline, " ");
@@ -167,13 +180,13 @@ void msys_handler(t_menusystem * ms, t_menuitem * mi)
if (flags.linrep)
strcat(infoline, "repair=lin ");
- gotoxy(INFLINE, 0, ms->menupage);
- cprint(' ', 0x07, nc, ms->menupage);
- gotoxy(INFLINE + 1, 0, ms->menupage);
- cprint(' ', 0x07, nc, ms->menupage);
- gotoxy(INFLINE, 0, ms->menupage);
+ gotoxy(INFLINE, 0);
+ cprint(' ', 0x07, nc);
+ gotoxy(INFLINE + 1, 0);
+ cprint(' ', 0x07, nc);
+ gotoxy(INFLINE, 0);
csprint("Kernel Arguments:", 0x07);
- gotoxy(INFLINE, 17, ms->menupage);
+ gotoxy(INFLINE, 17);
csprint(infoline, 0x07);
}
diff --git a/com32/cmenu/libmenu/com32io.c b/com32/cmenu/libmenu/com32io.c
index d99eb87f..3c4f9219 100644
--- a/com32/cmenu/libmenu/com32io.c
+++ b/com32/cmenu/libmenu/com32io.c
@@ -13,33 +13,107 @@
#include <string.h>
#include <com32.h>
#include "com32io.h"
+#include "tui.h"
#include "syslnx.h"
com32sys_t inreg, outreg; // Global register sets for use
-/* Print character and attribute at cursor */
-void cprint(char chr, char attr, unsigned int times, char disppage)
+/**
+ * cprint_vga2ansi - given a VGA attribute, print a character
+ * @chr: character to print
+ * @attr: vga attribute
+ *
+ * Convert the VGA attribute @attr to an ANSI escape sequence and
+ * print it.
+ **/
+static void cprint_vga2ansi(const char chr, const char attr)
{
- REG_AH(inreg) = 0x09;
- REG_AL(inreg) = chr;
- REG_BH(inreg) = disppage;
- REG_BL(inreg) = attr;
- REG_CX(inreg) = times;
- __intcall(0x10, &inreg, &outreg);
+ static const char ansi_char[8] = "04261537";
+ static uint8_t last_attr = 0x300;
+ char buf[16], *p;
+
+ if (attr != last_attr) {
+ p = buf;
+ *p++ = '\033';
+ *p++ = '[';
+
+ if (last_attr & ~attr & 0x88) {
+ *p++ = '0';
+ *p++ = ';';
+ /* Reset last_attr to unknown to handle
+ * background/foreground attributes correctly */
+ last_attr = 0x300;
+ }
+ if (attr & 0x08) {
+ *p++ = '1';
+ *p++ = ';';
+ }
+ if (attr & 0x80) {
+ *p++ = '4';
+ *p++ = ';';
+ }
+ if ((attr ^ last_attr) & 0x07) {
+ *p++ = '3';
+ *p++ = ansi_char[attr & 7];
+ *p++ = ';';
+ }
+ if ((attr ^ last_attr) & 0x70) {
+ *p++ = '4';
+ *p++ = ansi_char[(attr >> 4) & 7];
+ *p++ = ';';
+ }
+ p[-1] = 'm'; /* We'll have generated at least one semicolon */
+ p[0] = '\0';
+
+ last_attr = attr;
+
+ fputs(buf, stdout);
+ }
+
+ putchar(chr);
}
-void setdisppage(char num) // Set the display page to specified number
+/**
+ * cprint - given a VGA attribute, print a single character at cursor
+ * @chr: character to print
+ * @attr: VGA attribute
+ * @times: number of times to print @chr
+ *
+ * Note: @attr is a VGA attribute.
+ **/
+void cprint(const char chr, const char attr, unsigned int times)
{
- REG_AH(inreg) = 0x05;
- REG_AL(inreg) = num;
- __intcall(0x10, &inreg, &outreg);
+ while (times--)
+ cprint_vga2ansi(chr, attr);
}
-char getdisppage() // Get current display page
+/**
+ * csprint - given a VGA attribute, print a NULL-terminated string
+ * @str: string to print
+ * @attr: VGA attribute
+ **/
+void csprint(const char *str, const char attr)
{
- REG_AH(inreg) = 0x0f;
- __intcall(0x10, &inreg, &outreg);
- return REG_BH(outreg);
+ while (*str) {
+ cprint(*str, attr, 1);
+ str++;
+ }
+}
+
+/**
+ * clearwindow - fill a given a region on the screen
+ * @top, @left, @bot, @right: coordinates to fill
+ * @fillchar: character to use to fill the region
+ * @fillattr: character attribute (VGA)
+ **/
+void clearwindow(const char top, const char left, const char bot,
+ const char right, const char fillchar, const char fillattr)
+{
+ char x;
+ for (x = top; x < bot + 1; x++) {
+ gotoxy(x, left);
+ cprint(fillchar, fillattr, right - left + 1);
+ }
}
void getpos(char *row, char *col, char page)
@@ -51,14 +125,6 @@ void getpos(char *row, char *col, char page)
*col = REG_DL(outreg);
}
-void gotoxy(char row, char col, char page)
-{
- REG_AH(inreg) = 0x02;
- REG_BH(inreg) = page;
- REG_DX(inreg) = (row << 8) + col;
- __intcall(0x10, &inreg, &outreg);
-}
-
unsigned char sleep(unsigned int msec)
{
unsigned long micro = 1000 * msec;
@@ -70,14 +136,6 @@ unsigned char sleep(unsigned int msec)
return REG_AH(outreg);
}
-void beep()
-{
- REG_AH(inreg) = 0x0E;
- REG_AL(inreg) = 0x07;
- REG_BH(inreg) = 0;
- __intcall(0x10, &inreg, &outreg);
-}
-
void scrollupwindow(char top, char left, char bot, char right, char attr,
char numlines)
{
@@ -101,7 +159,7 @@ char inputc(char *scancode)
void getcursorshape(char *start, char *end)
{
- char page = getdisppage();
+ char page = 0; // XXX TODO
REG_AH(inreg) = 0x03;
REG_BH(inreg) = page;
__intcall(0x10, &inreg, &outreg);
@@ -117,13 +175,6 @@ void setcursorshape(char start, char end)
__intcall(0x10, &inreg, &outreg);
}
-char getchar(void)
-{
- REG_AH(inreg) = 0x08;
- __intcall(0x21, &inreg, &outreg);
- return REG_AL(outreg);
-}
-
void setvideomode(char mode)
{
REG_AH(inreg) = 0x00;
diff --git a/com32/cmenu/libmenu/com32io.h b/com32/cmenu/libmenu/com32io.h
index ba955e99..91324d77 100644
--- a/com32/cmenu/libmenu/com32io.h
+++ b/com32/cmenu/libmenu/com32io.h
@@ -14,40 +14,64 @@
#define __COM32IO_H__
#include <com32.h>
+#include <stdio.h>
#ifndef NULL
#define NULL ((void *)0)
#endif
+#define CSI "\e["
+
+static inline void beep(void)
+{
+ fputs("\007", stdout);
+}
+
/* BIOS Assisted output routines */
-void cswprint(const char *str, char attr, char left);
// Print a C str (NUL-terminated) respecting the left edge of window
// i.e. \n in str will move cursor to column left
// Print a C str (NUL-terminated)
-static inline void csprint(const char *str, char attr)
+void csprint(const char *, const char);
+
+//static inline void cswprint(const char *str, const char attr)
+//{
+// csprint(str, attr);
+//}
+
+void cprint(const char, const char, unsigned int);
+
+static inline void putch(const char x, char attr)
{
- cswprint(str, attr, 0);
+ cprint(x, attr, 1);
}
-void cprint(char chr, char attr, unsigned int times, char disppage); // Print a char
-
-void setdisppage(char num); // Set the display page to specified number
+void clearwindow(const char, const char, const char, const char,
+ const char, const char);
-char getdisppage(); // Get current display page
+/*
+ * cls - clear and initialize the entire screen
+ *
+ * Note: when initializing xterm, one has to specify that
+ * G1 points to the alternate character set (this is not true
+ * by default). Without the initial printf "\033)0", line drawing
+ * characters won't be displayed.
+ */
+static inline void cls(void)
+{
+ fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout);
+}
-void gotoxy(char row, char col, char page);
+static inline void gotoxy(const char row, const char col)
+{
+ printf(CSI "%d;%dH", row + 1, col + 1);
+}
void getpos(char *row, char *col, char page);
char inputc(char *scancode); // Return ASCII char by val, and scancode by reference
-static inline void putch(char x, char attr, char page)
-{
- cprint(x, attr, 1, page);
-}
-
void setcursorshape(char start, char end); // Set cursor shape
void getcursorshape(char *start, char *end); // Get shape for current page
@@ -69,16 +93,6 @@ static inline unsigned char readbiosb(unsigned int ofs)
return *((unsigned char *)MK_PTR(0, ofs));
}
-static inline char getnumrows()
-{
- return readbiosb(0x484); // Actually numrows - 1
-}
-
-static inline char getnumcols(void)
-{
- return readbiosb(0x44a); // Actually numcols
-}
-
static inline char getshiftflags(void)
{
return readbiosb(0x417);
@@ -88,7 +102,7 @@ void scrollupwindow(char top, char left, char bot, char right, char attr, char n
static inline void scrollup(void) //Scroll up display screen by one line
{
- scrollupwindow(0, 0, getnumrows(), getnumcols(), 0x07, 1);
+ printf(CSI "S");
}
void setvideomode(char mode); // Set the video mode.
@@ -100,8 +114,6 @@ static inline char getvideomode(void) // Get the current video mode
unsigned char sleep(unsigned int msec); // Sleep for specified time
-void beep(); // A Bell
-
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?)
diff --git a/com32/cmenu/libmenu/help.c b/com32/cmenu/libmenu/help.c
index a635bd21..3b36c3d8 100644
--- a/com32/cmenu/libmenu/help.c
+++ b/com32/cmenu/libmenu/help.c
@@ -16,10 +16,11 @@
#include "com32io.h"
#include <syslinux/loadfile.h> // to read entire file into memory
+int nc, nr; // Number of columns/rows of the screen
char helpbasedir[HELPDIRLEN]; // name of help directory limited to HELPDIRLEN
// Find the occurence of the count'th \n in buffer (or NULL) if not found
-char *findline(char *buffer, int count)
+static char *findline(char *buffer, int count)
{
int ctr;
char *p = buffer - 1;
@@ -35,7 +36,7 @@ char *findline(char *buffer, int count)
}
// return the number of lines in buffer
-int countlines(char *buffer)
+static int countlines(char *buffer)
{
int ans;
const char *p;
@@ -50,14 +51,14 @@ int countlines(char *buffer)
}
// Print numlines of text starting from buf
-void printtext(char *buf, int from)
+static void printtext(char *buf, int from)
{
char *p, *f;
- char right, bot, nlines;
+ int right, bot, nlines;
// clear window to print
- right = getnumcols() - HELP_RIGHT_MARGIN;
- bot = getnumrows() - HELP_BOTTOM_MARGIN;
+ right = nc - HELP_RIGHT_MARGIN;
+ bot = nr - HELP_BOTTOM_MARGIN;
nlines = bot - HELP_BODY_ROW + 1;
scrollupwindow(HELP_BODY_ROW, HELP_LEFT_MARGIN, bot, right, 0x07, nlines);
@@ -69,15 +70,15 @@ void printtext(char *buf, int from)
p = findline(f, nlines);
if (p && (*p == '\n'))
*p = '\0'; // change to NUL
- gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE);
- cswprint(f, 0x07, HELP_LEFT_MARGIN);
+ gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN);
+ printf(f);
if (p)
*p = '\n'; // set it back
}
void showhelp(const char *filename)
{
- char nc, nr, ph;
+ char ph;
char *title, *text;
union {
char *buffer;
@@ -89,38 +90,25 @@ void showhelp(const char *filename)
char scan;
int rv, numlines, curr_line;
- nc = getnumcols();
- nr = getnumrows();
+ if (getscreensize(1, &nr, &nc)) {
+ /* Unknown screen size? */
+ nc = 80;
+ nr = 24;
+ }
ph = nr - HELP_BOTTOM_MARGIN - HELP_BODY_ROW - 1;
cls();
- drawbox(0, 0, nr, nc - 1, HELPPAGE, 0x07, HELPBOX);
+ drawbox(0, 0, nr, nc - 1, 0x07);
- drawhorizline(2, 0, nc - 1, HELPPAGE, 0x07, HELPBOX, 0); // dumb==0
+ drawhorizline(2, 0, nc - 1, 0x07, 0); // dumb==0
if (filename == NULL) { // print file contents
- gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE);
- cswprint("Filename not given", 0x07, HELP_LEFT_MARGIN);
- while (1) {
- inputc(&scan);
- if (scan == ESCAPE)
- break;
- }
- cls();
- return;
+ strcpy(line, "Filename not given");
+ goto puke;
}
rv = loadfile(filename, (void **)&buf.vbuf, &size); // load entire file into memory
if (rv < 0) { // Error reading file or no such file
- sprintf(line, "Error reading file or file not found\n file=%s",
- filename);
- gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE);
- cswprint(line, 0x07, HELP_LEFT_MARGIN);
- while (1) {
- inputc(&scan);
- if (scan == ESCAPE)
- break;
- }
- cls();
- return;
+ sprintf(line, "Error reading file or file not found\n file=%s", filename);
+ goto puke;
}
title = buf.buffer;
@@ -128,24 +116,24 @@ void showhelp(const char *filename)
*text++ = '\0'; // end the title string and increment text
// Now we have a file just print it.
- gotoxy(1, (nc - strlen(title)) / 2, HELPPAGE);
- csprint(title, 0x07);
+ gotoxy(1, (nc - strlen(title)) / 2);
+ printf(title);
numlines = countlines(text);
curr_line = 0;
scan = ESCAPE + 1; // anything except ESCAPE
while (scan != ESCAPE) {
printtext(text, curr_line);
- gotoxy(HELP_BODY_ROW - 1, nc - HELP_RIGHT_MARGIN, HELPPAGE);
+ gotoxy(HELP_BODY_ROW - 1, nc - HELP_RIGHT_MARGIN);
if (curr_line > 0)
- putch(HELP_MORE_ABOVE, 0x07, HELPPAGE);
+ putchar(HELP_MORE_ABOVE);
else
- putch(' ', 0x07, HELPPAGE);
- gotoxy(nr - HELP_BOTTOM_MARGIN + 1, nc - HELP_RIGHT_MARGIN, HELPPAGE);
+ putchar(' ');
+ gotoxy(nr - HELP_BOTTOM_MARGIN + 1, nc - HELP_RIGHT_MARGIN);
if (curr_line < numlines - ph)
- putch(HELP_MORE_BELOW, 0x07, HELPPAGE);
+ putchar(HELP_MORE_BELOW);
else
- putch(' ', 0x07, HELPPAGE);
+ putchar(' ');
inputc(&scan); // wait for user keypress
@@ -176,18 +164,26 @@ void showhelp(const char *filename)
if (curr_line < 0)
curr_line = 0;
}
+out:
cls();
return;
+
+puke:
+ gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN);
+ printf(line);
+ while (1) {
+ inputc(&scan);
+ if (scan == ESCAPE)
+ break;
+ }
+ goto out;
}
void runhelp(const char *filename)
{
- char dp;
char fullname[HELPDIRLEN + 16];
- dp = getdisppage();
- if (dp != HELPPAGE)
- setdisppage(HELPPAGE);
+ cls();
cursoroff();
if (helpbasedir[0] != 0) {
strcpy(fullname, helpbasedir);
@@ -196,8 +192,6 @@ void runhelp(const char *filename)
showhelp(fullname);
} else
showhelp(filename); // Assume filename is absolute
- if (dp != HELPPAGE)
- setdisppage(dp);
}
void runhelpsystem(unsigned int helpid)
diff --git a/com32/cmenu/libmenu/menu.c b/com32/cmenu/libmenu/menu.c
index cfe8f39f..f437520e 100644
--- a/com32/cmenu/libmenu/menu.c
+++ b/com32/cmenu/libmenu/menu.c
@@ -13,9 +13,10 @@
#include "menu.h"
#include "com32io.h"
#include <stdlib.h>
+#include <console.h>
// Local Variables
-static pt_menusystem ms; // Pointer to the menusystem
+static pt_menusystem ms; // Pointer to the menusystem
char TITLESTR[] =
"COMBOOT Menu System for SYSLINUX developed by Murali Krishnan Ganapathy";
char TITLELONG[] = " TITLE too long ";
@@ -47,83 +48,64 @@ char getch(char *scan)
// Wait until keypress if no handler specified
if ((ms->ontimeout == NULL) && (ms->ontotaltimeout == NULL))
- return inputc(scan);
+ return inputc(scan);
th = ms->ontimeout;
- while (1) // Forever do
+ 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
- }
- }
- 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;
- }
+ 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
+ }
+ }
+ 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;
}
-/* Print a menu item */
-/* attr[0] is non-hilite attr, attr[1] is highlight attr */
+/*
+ * Print a menu item
+ *
+ * attr[0] is non-hilite attr, attr[1] is highlight attr
+ */
void printmenuitem(const char *str, uchar * attr)
{
- uchar page = getdisppage();
- uchar row, col;
- int hlite = NOHLITE; // Initially no highlighting
+ int hlite = NOHLITE; // Initially no highlighting
- getpos(&row, &col, page);
while (*str) {
- switch (*str) {
- case '\b':
- --col;
- break;
- case '\n':
- ++row;
- break;
- case '\r':
- col = 0;
- break;
- case BELL: // No Bell Char
- break;
- case ENABLEHLITE: // Switch on highlighting
- hlite = HLITE;
- break;
- case DISABLEHLITE: // Turn off highlighting
- hlite = NOHLITE;
- break;
- default:
- putch(*str, attr[hlite], page);
- ++col;
- }
- if (col > getnumcols()) {
- ++row;
- col = 0;
- }
- if (row > getnumrows()) {
- scrollup();
- row = getnumrows();
- }
- gotoxy(row, col, page);
- str++;
+ switch (*str) {
+ case BELL: // No Bell Char
+ break;
+ case ENABLEHLITE: // Switch on highlighting
+ hlite = HLITE;
+ break;
+ case DISABLEHLITE: // Turn off highlighting
+ hlite = NOHLITE;
+ break;
+ default:
+ putch(*str, attr[hlite]);
+ }
+ str++;
}
}
@@ -135,244 +117,246 @@ int find_shortcut(pt_menu menu, uchar shortcut, int index)
// Garbage in garbage out
if ((index < 0) || (index >= menu->numitems))
- return index;
+ return index;
ans = index + 1;
// Go till end of menu
while (ans < menu->numitems) {
- mi = menu->items[ans];
- if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP)
- || (mi->shortcut != shortcut))
- ans++;
- else
- return ans;
+ mi = menu->items[ans];
+ if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP)
+ || (mi->shortcut != shortcut))
+ ans++;
+ else
+ return ans;
}
// Start at the beginning and try again
ans = 0;
while (ans < index) {
- mi = menu->items[ans];
- if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP)
- || (mi->shortcut != shortcut))
- ans++;
- else
- return ans;
+ mi = menu->items[ans];
+ if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP)
+ || (mi->shortcut != shortcut))
+ ans++;
+ else
+ return ans;
}
- return index; // Sorry not found
+ return index; // Sorry not found
}
// print the menu starting from FIRST
// will print a maximum of menu->menuheight items
void printmenu(pt_menu menu, int curr, uchar top, uchar left, uchar first)
{
- int x, row; // x = index, row = position from top
+ int x, row; // x = index, row = position from top
int numitems, menuwidth;
- char fchar[5], lchar[5]; // The first and last char in for each entry
- const char *str; // and inbetween the item or a seperator is printed
- uchar *attr; // attribute attr
- char sep[MENULEN]; // and inbetween the item or a seperator is printed
+ char fchar[6], lchar[6]; // The first and last char in for each entry
+ const char *str; // and inbetween the item or a seperator is printed
+ char sep[MENULEN]; // Separator (OPT_SEP)
+ uchar *attr; // attribute attr
pt_menuitem ci;
numitems = calc_visible(menu, first);
if (numitems > menu->menuheight)
- numitems = menu->menuheight;
+ numitems = menu->menuheight;
menuwidth = menu->menuwidth + 3;
clearwindow(top, left - 2, top + numitems + 1, left + menuwidth + 1,
- ms->menupage, ms->fillchar, ms->shadowattr);
+ ms->fillchar, ms->shadowattr);
drawbox(top - 1, left - 3, top + numitems, left + menuwidth,
- ms->menupage, ms->normalattr[NOHLITE], ms->menubt);
- memset(sep, ms->box_horiz, menuwidth); // String containing the seperator string
- sep[menuwidth - 1] = 0;
+ ms->normalattr[NOHLITE]);
// Menu title
x = (menuwidth - strlen(menu->title) - 1) >> 1;
- gotoxy(top - 1, left + x, ms->menupage);
+ gotoxy(top - 1, left + x);
printmenuitem(menu->title, ms->normalattr);
- row = -1; // 1 less than inital value of x
+ row = -1; // 1 less than inital value of x
for (x = first; x < menu->numitems; x++) {
- ci = menu->items[x];
- if (ci->action == OPT_INVISIBLE)
- continue;
- row++;
- if (row >= numitems)
- break; // Already have enough number of items
- // Setup the defaults now
- lchar[0] = fchar[0] = ' ';
- lchar[1] = fchar[1] = '\0'; // fchar and lchar are just spaces
- str = ci->item; // Pointer to item string
- attr = (x == curr ? ms->reverseattr : ms->normalattr); // Normal attributes
- switch (ci->action) // set up attr,str,fchar,lchar for everything
- {
- case OPT_INACTIVE:
- attr = (x == curr ? ms->revinactattr : ms->inactattr);
- break;
- case OPT_SUBMENU:
- lchar[0] = SUBMENUCHAR;
- lchar[1] = 0;
- break;
- case OPT_RADIOMENU:
- lchar[0] = RADIOMENUCHAR;
- lchar[1] = 0;
- break;
- case OPT_CHECKBOX:
- lchar[0] = (ci->itemdata.checked ? CHECKED : UNCHECKED);
- lchar[1] = 0;
- break;
- case OPT_SEP:
- fchar[0] = '\b';
- fchar[1] = ms->box_ltrt;
- fchar[2] = ms->box_horiz;
- fchar[3] = ms->box_horiz;
- fchar[4] = 0;
- lchar[0] = ms->box_horiz;
- lchar[1] = ms->box_rtlt;
- lchar[2] = 0;
- str = sep;
- break;
- case OPT_EXITMENU:
- fchar[0] = EXITMENUCHAR;
- fchar[1] = 0;
- break;
- default: // Just to keep the compiler happy
- break;
- }
- gotoxy(top + row, left - 2, ms->menupage);
- cprint(ms->spacechar, attr[NOHLITE], menuwidth + 2, ms->menupage); // Wipe area with spaces
- gotoxy(top + row, left - 2, ms->menupage);
- csprint(fchar, attr[NOHLITE]); // Print first part
- gotoxy(top + row, left, ms->menupage);
- printmenuitem(str, attr); // Print main part
- gotoxy(top + row, left + menuwidth - 1, ms->menupage); // Last char if any
- csprint(lchar, attr[NOHLITE]); // Print last part
+ ci = menu->items[x];
+ if (ci->action == OPT_INVISIBLE)
+ continue;
+ row++;
+ if (row >= numitems)
+ break; // Already have enough number of items
+ // Setup the defaults now
+ lchar[0] = fchar[0] = ' ';
+ lchar[1] = fchar[1] = '\0'; // fchar and lchar are just spaces
+ str = ci->item; // Pointer to item string
+ attr = (x == curr ? ms->reverseattr : ms->normalattr); // Normal attributes
+ switch (ci->action) // set up attr,str,fchar,lchar for everything
+ {
+ case OPT_INACTIVE:
+ attr = (x == curr ? ms->revinactattr : ms->inactattr);
+ break;
+ case OPT_SUBMENU:
+ lchar[0] = '>';
+ lchar[1] = 0;
+ break;
+ case OPT_RADIOMENU:
+ lchar[0] = RADIOMENUCHAR;
+ lchar[1] = 0;
+ break;
+ case OPT_CHECKBOX:
+ lchar[0] = (ci->itemdata.checked ? CHECKED : UNCHECKED);
+ lchar[1] = 0;
+ break;
+ case OPT_SEP:
+ fchar[0] = '\b';
+ fchar[1] = SO;
+ fchar[2] = LEFT_MIDDLE_BORDER;
+ fchar[3] = MIDDLE_BORDER;
+ fchar[4] = MIDDLE_BORDER;
+ fchar[5] = 0;
+ memset(sep, MIDDLE_BORDER, menuwidth);
+ sep[menuwidth - 1] = 0;
+ str = sep;
+ lchar[0] = MIDDLE_BORDER;
+ lchar[1] = RIGHT_MIDDLE_BORDER;
+ lchar[2] = SI;
+ lchar[3] = 0;
+ break;
+ case OPT_EXITMENU:
+ fchar[0] = '<';
+ fchar[1] = 0;
+ break;
+ default: // Just to keep the compiler happy
+ break;
+ }
+ gotoxy(top + row, left - 2);
+ cprint(ms->spacechar, attr[NOHLITE], menuwidth + 2); // Wipe area with spaces
+ gotoxy(top + row, left - 2);
+ csprint(fchar, attr[NOHLITE]); // Print first part
+ gotoxy(top + row, left);
+ printmenuitem(str, attr); // Print main part
+ gotoxy(top + row, left + menuwidth - 1); // Last char if any
+ csprint(lchar, attr[NOHLITE]); // Print last part
}
// Check if we need to MOREABOVE and MOREBELOW to be added
// reuse x
row = 0;
- x = next_visible_sep(menu, 0); // First item
- if (!isvisible(menu, first, x)) // There is more above
+ x = next_visible_sep(menu, 0); // First item
+ if (!isvisible(menu, first, x)) // There is more above
{
- row = 1;
- gotoxy(top, left + menuwidth, ms->menupage);
- cprint(MOREABOVE, ms->normalattr[NOHLITE], 1, ms->menupage);
+ row = 1;
+ gotoxy(top, left + menuwidth);
+ cprint(MOREABOVE, ms->normalattr[NOHLITE], 1);
}
- x = prev_visible_sep(menu, menu->numitems); // last item
- if (!isvisible(menu, first, x)) // There is more above
+ x = prev_visible_sep(menu, menu->numitems); // last item
+ if (!isvisible(menu, first, x)) // There is more above
{
- row = 1;
- gotoxy(top + numitems - 1, left + menuwidth, ms->menupage);
- cprint(MOREBELOW, ms->normalattr[NOHLITE], 1, ms->menupage);
+ row = 1;
+ gotoxy(top + numitems - 1, left + menuwidth);
+ cprint(MOREBELOW, ms->normalattr[NOHLITE], 1);
}
// Add a scroll box
x = ((numitems - 1) * curr) / (menu->numitems);
if ((x > 0) && (row == 1)) {
- gotoxy(top + x, left + menuwidth, ms->menupage);
- cprint(SCROLLBOX, ms->normalattr[NOHLITE], 1, ms->menupage);
+ gotoxy(top + x, left + menuwidth);
+ cprint(SCROLLBOX, ms->normalattr[NOHLITE], 1);
}
if (ms->handler)
- ms->handler(ms, menu->items[curr]);
+ ms->handler(ms, menu->items[curr]);
}
// Difference between this and regular menu, is that only
// OPT_INVISIBLE, OPT_SEP are honoured
void printradiomenu(pt_menu menu, int curr, uchar top, uchar left, int first)
{
- int x, row; // x = index, row = position from top
+ int x, row; // x = index, row = position from top
int numitems, menuwidth;
- char fchar[5], lchar[5]; // The first and last char in for each entry
- const char *str; // and inbetween the item or a seperator is printed
- uchar *attr; // all in the attribute attr
- char sep[MENULEN]; // and inbetween the item or a seperator is printed
+ char fchar[5], lchar[5]; // The first and last char in for each entry
+ const char *str; // and inbetween the item or a seperator is printed
+ uchar *attr; // all in the attribute attr
+ char sep[MENULEN]; // and inbetween the item or a seperator is printed
pt_menuitem ci;
numitems = calc_visible(menu, first);
if (numitems > menu->menuheight)
- numitems = menu->menuheight;
+ numitems = menu->menuheight;
menuwidth = menu->menuwidth + 3;
clearwindow(top, left - 2, top + numitems + 1, left + menuwidth + 1,
- ms->menupage, ms->fillchar, ms->shadowattr);
+ ms->fillchar, ms->shadowattr);
drawbox(top - 1, left - 3, top + numitems, left + menuwidth,
- ms->menupage, ms->normalattr[NOHLITE], ms->menubt);
- memset(sep, ms->box_horiz, menuwidth); // String containing the seperator string
+ ms->normalattr[NOHLITE]);
+ memset(sep, ms->box_horiz, menuwidth); // String containing the seperator string
sep[menuwidth - 1] = 0;
// Menu title
x = (menuwidth - strlen(menu->title) - 1) >> 1;
- gotoxy(top - 1, left + x, ms->menupage);
+ gotoxy(top - 1, left + x);
printmenuitem(menu->title, ms->normalattr);
- row = -1; // 1 less than inital value of x
+ row = -1; // 1 less than inital value of x
for (x = first; x < menu->numitems; x++) {
- ci = menu->items[x];
- if (ci->action == OPT_INVISIBLE)
- continue;
- row++;
- if (row > numitems)
- break;
- // Setup the defaults now
- fchar[0] = RADIOUNSEL;
- fchar[1] = '\0'; // Unselected ( )
- lchar[0] = '\0'; // Nothing special after
- str = ci->item; // Pointer to item string
- attr = ms->normalattr; // Always same attribute
- fchar[0] = (x == curr ? RADIOSEL : RADIOUNSEL);
- switch (ci->action) // set up attr,str,fchar,lchar for everything
- {
- case OPT_INACTIVE:
- attr = ms->inactattr;
- break;
- case OPT_SEP:
- fchar[0] = '\b';
- fchar[1] = ms->box_ltrt;
- fchar[2] = ms->box_horiz;
- fchar[3] = ms->box_horiz;
- fchar[4] = 0;
- lchar[0] = ms->box_horiz;
- lchar[1] = ms->box_rtlt;
- lchar[3] = 0;
- str = sep;
- break;
- default: // To keep the compiler happy
- break;
- }
- gotoxy(top + row, left - 2, ms->menupage);
- cprint(ms->spacechar, attr[NOHLITE], menuwidth + 2, ms->menupage); // Wipe area with spaces
- gotoxy(top + row, left - 2, ms->menupage);
- csprint(fchar, attr[NOHLITE]); // Print first part
- gotoxy(top + row, left, ms->menupage);
- printmenuitem(str, attr); // Print main part
- gotoxy(top + row, left + menuwidth - 1, ms->menupage); // Last char if any
- csprint(lchar, attr[NOHLITE]); // Print last part
+ ci = menu->items[x];
+ if (ci->action == OPT_INVISIBLE)
+ continue;
+ row++;
+ if (row > numitems)
+ break;
+ // Setup the defaults now
+ fchar[0] = RADIOUNSEL;
+ fchar[1] = '\0'; // Unselected ( )
+ lchar[0] = '\0'; // Nothing special after
+ str = ci->item; // Pointer to item string
+ attr = ms->normalattr; // Always same attribute
+ fchar[0] = (x == curr ? RADIOSEL : RADIOUNSEL);
+ switch (ci->action) // set up attr,str,fchar,lchar for everything
+ {
+ case OPT_INACTIVE:
+ attr = ms->inactattr;
+ break;
+ case OPT_SEP:
+ fchar[0] = '\b';
+ fchar[1] = ms->box_ltrt;
+ fchar[2] = ms->box_horiz;
+ fchar[3] = ms->box_horiz;
+ fchar[4] = 0;
+ lchar[0] = ms->box_horiz;
+ lchar[1] = ms->box_rtlt;
+ lchar[3] = 0;
+ str = sep;
+ break;
+ default: // To keep the compiler happy
+ break;
+ }
+ gotoxy(top + row, left - 2);
+ cprint(ms->spacechar, attr[NOHLITE], menuwidth + 2); // Wipe area with spaces
+ gotoxy(top + row, left - 2);
+ csprint(fchar, attr[NOHLITE]); // Print first part
+ gotoxy(top + row, left);
+ printmenuitem(str, attr); // Print main part
+ gotoxy(top + row, left + menuwidth - 1); // Last char if any
+ csprint(lchar, attr[NOHLITE]); // Print last part
}
// Check if we need to MOREABOVE and MOREBELOW to be added
// reuse x
row = 0;
- x = next_visible_sep(menu, 0); // First item
- if (!isvisible(menu, first, x)) // There is more above
+ x = next_visible_sep(menu, 0); // First item
+ if (!isvisible(menu, first, x)) // There is more above
{
- row = 1;
- gotoxy(top, left + menuwidth, ms->menupage);
- cprint(MOREABOVE, ms->normalattr[NOHLITE], 1, ms->menupage);
+ row = 1;
+ gotoxy(top, left + menuwidth);
+ cprint(MOREABOVE, ms->normalattr[NOHLITE], 1);
}
- x = prev_visible_sep(menu, menu->numitems); // last item
- if (!isvisible(menu, first, x)) // There is more above
+ x = prev_visible_sep(menu, menu->numitems); // last item
+ if (!isvisible(menu, first, x)) // There is more above
{
- row = 1;
- gotoxy(top + numitems - 1, left + menuwidth, ms->menupage);
- cprint(MOREBELOW, ms->normalattr[NOHLITE], 1, ms->menupage);
+ row = 1;
+ gotoxy(top + numitems - 1, left + menuwidth);
+ cprint(MOREBELOW, ms->normalattr[NOHLITE], 1);
}
// Add a scroll box
x = ((numitems - 1) * curr) / (menu->numitems);
if ((x > 0) && (row == 1)) {
- gotoxy(top + x, left + menuwidth, ms->menupage);
- cprint(SCROLLBOX, ms->normalattr[NOHLITE], 1, ms->menupage);
+ gotoxy(top + x, left + menuwidth);
+ cprint(SCROLLBOX, ms->normalattr[NOHLITE], 1);
}
if (ms->handler)
- ms->handler(ms, menu->items[curr]);
+ ms->handler(ms, menu->items[curr]);
}
void cleanupmenu(pt_menu menu, uchar top, uchar left, int numitems)
{
if (numitems > menu->menuheight)
- numitems = menu->menuheight;
- clearwindow(top, left - 2, top + numitems + 1, left + menu->menuwidth + 4, ms->menupage, ms->fillchar, ms->fillattr); // Clear the shadow
- clearwindow(top - 1, left - 3, top + numitems, left + menu->menuwidth + 3, ms->menupage, ms->fillchar, ms->fillattr); // main window
+ numitems = menu->menuheight;
+ clearwindow(top, left - 2, top + numitems + 1, left + menu->menuwidth + 4, ms->fillchar, ms->fillattr); // Clear the shadow
+ clearwindow(top - 1, left - 3, top + numitems, left + menu->menuwidth + 3, ms->fillchar, ms->fillattr); // main window
}
/* Handle a radio menu */
@@ -382,93 +366,92 @@ pt_menuitem getradiooption(pt_menu menu, uchar top, uchar left, uchar startopt)
int curr, i, first, tmp;
uchar asc, scan;
uchar numitems;
- pt_menuitem ci; // Current item
+ pt_menuitem ci; // Current item
numitems = calc_visible(menu, 0);
// Setup status line
- gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
- cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, ms->menupage);
+ gotoxy(ms->minrow + ms->statline, ms->mincol);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols);
// Initialise current menu item
curr = next_visible(menu, startopt);
- gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
- cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, 1);
- gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
+ gotoxy(ms->minrow + ms->statline, ms->mincol);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols);
+ gotoxy(ms->minrow + ms->statline, ms->mincol);
printmenuitem(menu->items[curr]->status, ms->statusattr);
first = calc_first_early(menu, curr);
- while (1) // Forever
+ while (1) // Forever
{
- printradiomenu(menu, curr, top, left, first);
- ci = menu->items[curr];
-
- asc = getch(&scan);
- switch (scan) {
- case HOMEKEY:
- curr = next_visible(menu, 0);
- first = calc_first_early(menu, curr);
- break;
- case ENDKEY:
- curr = prev_visible(menu, numitems - 1);
- first = calc_first_late(menu, curr);
- break;
- case PAGEDN:
- for (i = 0; i < 5; i++)
- curr = next_visible(menu, curr + 1);
- first = calc_first_late(menu, curr);
- break;
- case PAGEUP:
- for (i = 0; i < 5; i++)
- curr = prev_visible(menu, curr - 1);
- first = calc_first_early(menu, curr);
- break;
- case UPARROW:
- curr = prev_visible(menu, curr - 1);
- if (curr < first)
- first = calc_first_early(menu, curr);
- break;
- case DNARROW:
- curr = next_visible(menu, curr + 1);
- if (!isvisible(menu, first, curr))
- first = calc_first_late(menu, curr);
- break;
- case LTARROW:
- case ESCAPE:
- return NULL;
- break;
- case RTARROW:
- case ENTERA:
- case ENTERB:
- if (ci->action == OPT_INACTIVE)
- break;
- if (ci->action == OPT_SEP)
- break;
- return ci;
- break;
- default:
- // Check if this is a shortcut key
- if (((asc >= 'A') && (asc <= 'Z')) ||
- ((asc >= 'a') && (asc <= 'z')) ||
- ((asc >= '0') && (asc <= '9'))) {
- tmp = find_shortcut(menu, asc, curr);
- if ((tmp > curr) && (!isvisible(menu, first, tmp)))
- first = calc_first_late(menu, tmp);
- if (tmp < curr)
- first = calc_first_early(menu, tmp);
- curr = tmp;
- } else {
- if (ms->keys_handler) // Call extra keys handler
- ms->keys_handler(ms, menu->items[curr], (scan << 8) | asc);
- }
- break;
- }
- // Update status line
- gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
- cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols,
- ms->menupage);
- printmenuitem(menu->items[curr]->status, ms->statusattr);
+ printradiomenu(menu, curr, top, left, first);
+ ci = menu->items[curr];
+
+ asc = getch(&scan);
+ switch (scan) {
+ case HOMEKEY:
+ curr = next_visible(menu, 0);
+ first = calc_first_early(menu, curr);
+ break;
+ case ENDKEY:
+ curr = prev_visible(menu, numitems - 1);
+ first = calc_first_late(menu, curr);
+ break;
+ case PAGEDN:
+ for (i = 0; i < 5; i++)
+ curr = next_visible(menu, curr + 1);
+ first = calc_first_late(menu, curr);
+ break;
+ case PAGEUP:
+ for (i = 0; i < 5; i++)
+ curr = prev_visible(menu, curr - 1);
+ first = calc_first_early(menu, curr);
+ break;
+ case UPARROW:
+ curr = prev_visible(menu, curr - 1);
+ if (curr < first)
+ first = calc_first_early(menu, curr);
+ break;
+ case DNARROW:
+ curr = next_visible(menu, curr + 1);
+ if (!isvisible(menu, first, curr))
+ first = calc_first_late(menu, curr);
+ break;
+ case LTARROW:
+ case ESCAPE:
+ return NULL;
+ break;
+ case RTARROW:
+ case ENTERA:
+ case ENTERB:
+ if (ci->action == OPT_INACTIVE)
+ break;
+ if (ci->action == OPT_SEP)
+ break;
+ return ci;
+ break;
+ default:
+ // Check if this is a shortcut key
+ if (((asc >= 'A') && (asc <= 'Z')) ||
+ ((asc >= 'a') && (asc <= 'z')) ||
+ ((asc >= '0') && (asc <= '9'))) {
+ tmp = find_shortcut(menu, asc, curr);
+ if ((tmp > curr) && (!isvisible(menu, first, tmp)))
+ first = calc_first_late(menu, tmp);
+ if (tmp < curr)
+ first = calc_first_early(menu, tmp);
+ curr = tmp;
+ } else {
+ if (ms->keys_handler) // Call extra keys handler
+ ms->keys_handler(ms, menu->items[curr], (scan << 8) | asc);
+ }
+ break;
+ }
+ // Update status line
+ gotoxy(ms->minrow + ms->statline, ms->mincol);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols);
+ printmenuitem(menu->items[curr]->status, ms->statusattr);
}
- return NULL; // Should never come here
+ return NULL; // Should never come here
}
/* Handle one menu */
@@ -478,138 +461,140 @@ pt_menuitem getmenuoption(pt_menu menu, uchar top, uchar left, uchar startopt)
int curr, i, first, tmp;
uchar asc, scan;
uchar numitems;
- pt_menuitem ci; // Current item
- t_handler_return hr; // Return value of handler
+ pt_menuitem ci; // Current item
+ t_handler_return hr; // Return value of handler
numitems = calc_visible(menu, 0);
// Setup status line
- gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
- cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, ms->menupage);
+ gotoxy(ms->minrow + ms->statline, ms->mincol);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols);
// Initialise current menu item
curr = next_visible(menu, startopt);
- gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
- cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, 1);
- gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
+ gotoxy(ms->minrow + ms->statline, ms->mincol);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols);
+ gotoxy(ms->minrow + ms->statline, ms->mincol);
printmenuitem(menu->items[curr]->status, ms->statusattr);
first = calc_first_early(menu, curr);
- while (1) // Forever
+ while (1) // Forever
{
- printmenu(menu, curr, top, left, first);
- ci = menu->items[curr];
- asc = getch(&scan);
- switch (scan) {
- case HOMEKEY:
- curr = next_visible(menu, 0);
- first = calc_first_early(menu, curr);
- break;
- case ENDKEY:
- curr = prev_visible(menu, numitems - 1);
- first = calc_first_late(menu, curr);
- break;
- case PAGEDN:
- for (i = 0; i < 5; i++)
- curr = next_visible(menu, curr + 1);
- first = calc_first_late(menu, curr);
- break;
- case PAGEUP:
- for (i = 0; i < 5; i++)
- curr = prev_visible(menu, curr - 1);
- first = calc_first_early(menu, curr);
- break;
- case UPARROW:
- curr = prev_visible(menu, curr - 1);
- if (curr < first)
- first = calc_first_early(menu, curr);
- break;
- case DNARROW:
- curr = next_visible(menu, curr + 1);
- if (!isvisible(menu, first, curr))
- first = calc_first_late(menu, curr);
- break;
- case LTARROW:
- case ESCAPE:
- return NULL;
- break;
- case RTARROW:
- case ENTERA:
- case ENTERB:
- if (ci->action == OPT_INACTIVE)
- break;
- if (ci->action == OPT_CHECKBOX)
- break;
- if (ci->action == OPT_SEP)
- break;
- if (ci->action == OPT_EXITMENU)
- return NULL; // As if we hit Esc
- // If we are going into a radio menu, dont call handler, return ci
- if (ci->action == OPT_RADIOMENU)
- return ci;
- if (ci->handler != NULL) // Do we have a handler
- {
- hr = ci->handler(ms, ci);
- if (hr.refresh) // Do we need to refresh
- {
- // Cleanup menu using old number of items
- cleanupmenu(menu, top, left, numitems);
- // Recalculate the number of items
- numitems = calc_visible(menu, 0);
- // Reprint the menu
- printmenu(menu, curr, top, left, first);
- }
- if (hr.valid)
- return ci;
- } else
- return ci;
- break;
- case SPACEKEY:
- if (ci->action != OPT_CHECKBOX)
- break;
- ci->itemdata.checked = !ci->itemdata.checked;
- if (ci->handler != NULL) // Do we have a handler
- {
- hr = ci->handler(ms, ci);
- if (hr.refresh) // Do we need to refresh
- {
- // Cleanup menu using old number of items
- cleanupmenu(menu, top, left, numitems);
- // Recalculate the number of items
- numitems = calc_visible(menu, 0);
- // Reprint the menu
- printmenu(menu, curr, top, left, first);
- }
- }
- break;
- default:
- // Check if this is a shortcut key
- if (((asc >= 'A') && (asc <= 'Z')) ||
- ((asc >= 'a') && (asc <= 'z')) ||
- ((asc >= '0') && (asc <= '9'))) {
- tmp = find_shortcut(menu, asc, curr);
- if ((tmp > curr) && (!isvisible(menu, first, tmp)))
- first = calc_first_late(menu, tmp);
- if (tmp < curr)
- first = calc_first_early(menu, tmp);
- curr = tmp;
- } else {
- if (ms->keys_handler) // Call extra keys handler
- ms->keys_handler(ms, menu->items[curr], (scan << 8) | asc);
- }
- break;
- }
- // Update status line
- gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
- cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols,
- ms->menupage);
- printmenuitem(menu->items[curr]->status, ms->statusattr);
+ printmenu(menu, curr, top, left, first);
+ ci = menu->items[curr];
+ asc = getch(&scan);
+ switch (scan) {
+ case HOMEKEY:
+ curr = next_visible(menu, 0);
+ first = calc_first_early(menu, curr);
+ break;
+ case ENDKEY:
+ curr = prev_visible(menu, numitems - 1);
+ first = calc_first_late(menu, curr);
+ break;
+ case PAGEDN:
+ for (i = 0; i < 5; i++)
+ curr = next_visible(menu, curr + 1);
+ first = calc_first_late(menu, curr);
+ break;
+ case PAGEUP:
+ for (i = 0; i < 5; i++)
+ curr = prev_visible(menu, curr - 1);
+ first = calc_first_early(menu, curr);
+ break;
+ case UPARROW:
+ curr = prev_visible(menu, curr - 1);
+ if (curr < first)
+ first = calc_first_early(menu, curr);
+ break;
+ case DNARROW:
+ curr = next_visible(menu, curr + 1);
+ if (!isvisible(menu, first, curr))
+ first = calc_first_late(menu, curr);
+ break;
+ case LTARROW:
+ case ESCAPE:
+ return NULL;
+ break;
+ case RTARROW:
+ case ENTERA:
+ case ENTERB:
+ if (ci->action == OPT_INACTIVE)
+ break;
+ if (ci->action == OPT_CHECKBOX)
+ break;
+ if (ci->action == OPT_SEP)
+ break;
+ if (ci->action == OPT_EXITMENU)
+ return NULL; // As if we hit Esc
+ // If we are going into a radio menu, dont call handler, return ci
+ if (ci->action == OPT_RADIOMENU)
+ return ci;
+ if (ci->handler != NULL) // Do we have a handler
+ {
+ hr = ci->handler(ms, ci);
+ if (hr.refresh) // Do we need to refresh
+ {
+ // Cleanup menu using old number of items
+ cleanupmenu(menu, top, left, numitems);
+ // Recalculate the number of items
+ numitems = calc_visible(menu, 0);
+ // Reprint the menu
+ printmenu(menu, curr, top, left, first);
+ }
+ if (hr.valid)
+ return ci;
+ } else
+ return ci;
+ break;
+ case SPACEKEY:
+ if (ci->action != OPT_CHECKBOX)
+ break;
+ ci->itemdata.checked = !ci->itemdata.checked;
+ if (ci->handler != NULL) // Do we have a handler
+ {
+ hr = ci->handler(ms, ci);
+ if (hr.refresh) // Do we need to refresh
+ {
+ // Cleanup menu using old number of items
+ cleanupmenu(menu, top, left, numitems);
+ // Recalculate the number of items
+ numitems = calc_visible(menu, 0);
+ // Reprint the menu
+ printmenu(menu, curr, top, left, first);
+ }
+ }
+ break;
+ default:
+ // Check if this is a shortcut key
+ if (((asc >= 'A') && (asc <= 'Z')) ||
+ ((asc >= 'a') && (asc <= 'z')) ||
+ ((asc >= '0') && (asc <= '9'))) {
+ tmp = find_shortcut(menu, asc, curr);
+ if ((tmp > curr) && (!isvisible(menu, first, tmp)))
+ first = calc_first_late(menu, tmp);
+ if (tmp < curr)
+ first = calc_first_early(menu, tmp);
+ curr = tmp;
+ } else {
+ if (ms->keys_handler) // Call extra keys handler
+ ms->keys_handler(ms, menu->items[curr], (scan << 8) | asc);
+ }
+ break;
}
- return NULL; // Should never come here
+ // Update status line
+ /* Erase the previous status */
+ gotoxy(ms->minrow + ms->statline, ms->mincol);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols);
+ /* Print the new status */
+ gotoxy(ms->minrow + ms->statline, ms->mincol);
+ printmenuitem(menu->items[curr]->status, ms->statusattr);
+ }
+ return NULL; // Should never come here
}
/* Handle the entire system of menu's. */
pt_menuitem runmenusystem(uchar top, uchar left, pt_menu cmenu, uchar startopt,
- uchar menutype)
+ uchar menutype)
/*
* cmenu
* Which menu should be currently displayed
@@ -629,36 +614,37 @@ pt_menuitem runmenusystem(uchar top, uchar left, pt_menu cmenu, uchar startopt,
uchar row, col;
if (cmenu == NULL)
- return NULL;
+ return NULL;
+
startover:
// Set the menu height
cmenu->menuheight = ms->maxrow - top - 3;
if (cmenu->menuheight > ms->maxmenuheight)
- cmenu->menuheight = ms->maxmenuheight;
+ cmenu->menuheight = ms->maxmenuheight;
if (menutype == NORMALMENU)
- opt = getmenuoption(cmenu, top, left, startopt);
- else // menutype == RADIOMENU
- opt = getradiooption(cmenu, top, left, startopt);
+ opt = getmenuoption(cmenu, top, left, startopt);
+ else // menutype == RADIOMENU
+ opt = getradiooption(cmenu, top, left, startopt);
if (opt == NULL) {
- // User hit Esc
- cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
- return NULL;
+ // User hit Esc
+ cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
+ return NULL;
}
// Are we done with the menu system?
if ((opt->action != OPT_SUBMENU) && (opt->action != OPT_RADIOMENU)) {
- cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
- return opt; // parent cleanup other menus
+ cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
+ return opt; // parent cleanup other menus
}
// Either radiomenu or submenu
// Do we have a valid menu number? The next hack uses the fact that
// itemdata.submenunum = itemdata.radiomenunum (since enum data type)
- if (opt->itemdata.submenunum >= ms->nummenus) // This is Bad....
+ if (opt->itemdata.submenunum >= ms->nummenus) // This is Bad....
{
- gotoxy(12, 12, ms->menupage); // Middle of screen
- csprint("ERROR: Invalid submenu requested.", 0x07);
- cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
- return NULL; // Pretend user hit esc
+ gotoxy(12, 12); // Middle of screen
+ csprint("ERROR: Invalid submenu requested.", 0x07);
+ cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
+ return NULL; // Pretend user hit esc
}
// Call recursively for submenu
// Position the submenu below the current item,
@@ -666,32 +652,32 @@ startover:
row = ms->menus[(unsigned int)opt->itemdata.submenunum]->row;
col = ms->menus[(unsigned int)opt->itemdata.submenunum]->col;
if (row == 0xFF)
- row = top + opt->index + 2;
+ row = top + opt->index + 2;
if (col == 0xFF)
- col = left + 3 + (cmenu->menuwidth >> 1);
+ col = left + 3 + (cmenu->menuwidth >> 1);
mt = (opt->action == OPT_SUBMENU ? NORMALMENU : RADIOMENU);
startat = 0;
if ((opt->action == OPT_RADIOMENU) && (opt->data != NULL))
- startat = ((t_menuitem *) opt->data)->index;
+ startat = ((t_menuitem *) opt->data)->index;
choice = runmenusystem(row, col,
- ms->menus[(unsigned int)opt->itemdata.submenunum],
- startat, mt);
+ ms->menus[(unsigned int)opt->itemdata.submenunum],
+ startat, mt);
if (opt->action == OPT_RADIOMENU) {
- if (choice != NULL)
- opt->data = (void *)choice; // store choice in data field
- if (opt->handler != NULL)
- opt->handler(ms, opt);
- choice = NULL; // Pretend user hit esc
+ if (choice != NULL)
+ opt->data = (void *)choice; // store choice in data field
+ if (opt->handler != NULL)
+ opt->handler(ms, opt);
+ choice = NULL; // Pretend user hit esc
}
- if (choice == NULL) // User hit Esc in submenu
+ if (choice == NULL) // User hit Esc in submenu
{
- // Startover
- startopt = opt->index;
- goto startover;
+ // Startover
+ startopt = opt->index;
+ goto startover;
} else {
- cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
- return choice;
+ cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
+ return choice;
}
}
@@ -702,11 +688,11 @@ uchar find_menu_num(const char *name)
pt_menu m;
if (name == NULL)
- return (uchar) (-1);
+ return (uchar) (-1);
for (i = 0; i < ms->nummenus; i++) {
- m = ms->menus[i];
- if ((m->name) && (strcmp(m->name, name) == 0))
- return i;
+ m = ms->menus[i];
+ if ((m->name) && (strcmp(m->name, name) == 0))
+ return i;
}
return (uchar) (-1);
}
@@ -722,16 +708,16 @@ void fix_submenus()
i = 0;
for (i = 0; i < ms->nummenus; i++) {
- m = ms->menus[i];
- for (j = 0; j < m->numitems; j++) {
- mi = m->items[j];
- // if item is a submenu and has non-empty non-trivial data string
- if (mi->data && strlen(mi->data) > 0 &&
- ((mi->action == OPT_SUBMENU)
- || (mi->action == OPT_RADIOMENU))) {
- mi->itemdata.submenunum = find_menu_num(mi->data);
- }
- }
+ m = ms->menus[i];
+ for (j = 0; j < m->numitems; j++) {
+ mi = m->items[j];
+ // if item is a submenu and has non-empty non-trivial data string
+ if (mi->data && strlen(mi->data) > 0 &&
+ ((mi->action == OPT_SUBMENU)
+ || (mi->action == OPT_RADIOMENU))) {
+ mi->itemdata.submenunum = find_menu_num(mi->data);
+ }
+ }
}
}
@@ -740,34 +726,29 @@ void fix_submenus()
pt_menuitem showmenus(uchar startmenu)
{
pt_menuitem rv;
- uchar oldpage, tpos;
+ uchar tpos;
- fix_submenus(); // Fix submenu numbers incase nick names were used
+ fix_submenus(); // Fix submenu numbers incase nick names were used
// Setup screen for menusystem
- oldpage = getdisppage();
- setdisppage(ms->menupage);
cls();
clearwindow(ms->minrow, ms->mincol, ms->maxrow, ms->maxcol,
- ms->menupage, ms->fillchar, ms->fillattr);
- tpos = (ms->numcols - strlen(ms->title) - 1) >> 1; // center it on line
- gotoxy(ms->minrow, ms->mincol, ms->menupage);
- cprint(ms->tfillchar, ms->titleattr, ms->numcols, ms->menupage);
- gotoxy(ms->minrow, ms->mincol + tpos, ms->menupage);
+ ms->fillchar, ms->fillattr);
+ tpos = (ms->numcols - strlen(ms->title) - 1) >> 1; // center it on line
+ gotoxy(ms->minrow, ms->mincol);
+ cprint(ms->tfillchar, ms->titleattr, ms->numcols);
+ gotoxy(ms->minrow, ms->mincol + tpos);
csprint(ms->title, ms->titleattr);
- cursoroff(); // Doesn't seem to work?
+ cursoroff(); // Doesn't seem to work?
// Go, main menu cannot be a radio menu
rv = runmenusystem(ms->minrow + MENUROW, ms->mincol + MENUCOL,
- ms->menus[(unsigned int)startmenu], 0, NORMALMENU);
+ ms->menus[(unsigned int)startmenu], 0, NORMALMENU);
// Hide the garbage we left on the screen
cursoron();
- if (oldpage == ms->menupage)
- cls();
- else
- setdisppage(oldpage);
+ cls();
// Return user choice
return rv;
@@ -780,17 +761,17 @@ pt_menusystem init_menusystem(const char *title)
ms = NULL;
ms = (pt_menusystem) malloc(sizeof(t_menusystem));
if (ms == NULL)
- return NULL;
+ return NULL;
ms->nummenus = 0;
// Initialise all menu pointers
for (i = 0; i < MAXMENUS; i++)
- ms->menus[i] = NULL;
+ ms->menus[i] = NULL;
ms->title = (char *)malloc(TITLELEN + 1);
if (title == NULL)
- strcpy(ms->title, TITLESTR); // Copy string
+ strcpy(ms->title, TITLESTR); // Copy string
else
- strcpy(ms->title, title);
+ strcpy(ms->title, title);
// Timeout settings
ms->tm_stepsize = TIMEOUTSTEPSIZE;
@@ -820,12 +801,12 @@ pt_menusystem init_menusystem(const char *title)
ms->spacechar = SPACECHAR;
ms->shadowattr = SHADOWATTR;
- ms->menupage = MENUPAGE; // Usually no need to change this at all
+ ms->menupage = MENUPAGE; // Usually no need to change this at all
// Initialise all handlers
ms->handler = NULL;
ms->keys_handler = NULL;
- ms->ontimeout = NULL; // No timeout handler
+ ms->ontimeout = NULL; // No timeout handler
ms->tm_total_timeout = 0;
ms->tm_sofar_timeout = 0;
ms->ontotaltimeout = NULL;
@@ -838,79 +819,85 @@ pt_menusystem init_menusystem(const char *title)
// Figure out the size of the screen we are in now.
// By default we use the whole screen for our menu
+ if (getscreensize(1, &ms->numrows, &ms->numcols)) {
+ /* Unknown screen size? */
+ ms->numcols = 80;
+ ms->numrows = 24;
+ }
ms->minrow = ms->mincol = 0;
- ms->numcols = getnumcols();
- ms->numrows = getnumrows();
ms->maxcol = ms->numcols - 1;
ms->maxrow = ms->numrows - 1;
// How many entries per menu can we display at a time
ms->maxmenuheight = ms->maxrow - ms->minrow - 3;
if (ms->maxmenuheight > MAXMENUHEIGHT)
- ms->maxmenuheight = MAXMENUHEIGHT;
+ ms->maxmenuheight = MAXMENUHEIGHT;
// Set up the look of the box
set_box_type(MENUBOXTYPE);
+
+ openconsole(&dev_stdcon_r, &dev_ansiserial_w);
+
return ms;
}
void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal,
- uchar inactiveselected)
+ uchar inactiveselected)
{
if (normal != 0xFF)
- ms->normalattr[0] = normal;
+ ms->normalattr[0] = normal;
if (selected != 0xFF)
- ms->reverseattr[0] = selected;
+ ms->reverseattr[0] = selected;
if (inactivenormal != 0xFF)
- ms->inactattr[0] = inactivenormal;
+ ms->inactattr[0] = inactivenormal;
if (inactiveselected != 0xFF)
- ms->revinactattr[0] = inactiveselected;
+ ms->revinactattr[0] = inactiveselected;
}
void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal,
- uchar inactiveselected)
+ uchar inactiveselected)
{
if (normal != 0xFF)
- ms->normalattr[1] = normal;
+ ms->normalattr[1] = normal;
if (selected != 0xFF)
- ms->reverseattr[1] = selected;
+ ms->reverseattr[1] = selected;
if (inactivenormal != 0xFF)
- ms->inactattr[1] = inactivenormal;
+ ms->inactattr[1] = inactivenormal;
if (inactiveselected != 0xFF)
- ms->revinactattr[1] = inactiveselected;
+ ms->revinactattr[1] = inactiveselected;
}
void set_status_info(uchar statusattr, uchar statushlite, uchar statline)
{
if (statusattr != 0xFF)
- ms->statusattr[NOHLITE] = statusattr;
+ ms->statusattr[NOHLITE] = statusattr;
if (statushlite != 0xFF)
- ms->statusattr[HLITE] = statushlite;
+ ms->statusattr[HLITE] = statushlite;
// statline is relative to minrow
if (statline >= ms->numrows)
- statline = ms->numrows - 1;
- ms->statline = statline; // relative to ms->minrow, 0 based
+ statline = ms->numrows - 1;
+ ms->statline = statline; // relative to ms->minrow, 0 based
}
void set_title_info(uchar tfillchar, uchar titleattr)
{
if (tfillchar != 0xFF)
- ms->tfillchar = tfillchar;
+ ms->tfillchar = tfillchar;
if (titleattr != 0xFF)
- ms->titleattr = titleattr;
+ ms->titleattr = titleattr;
}
void set_misc_info(uchar fillchar, uchar fillattr, uchar spacechar,
- uchar shadowattr)
+ uchar shadowattr)
{
if (fillchar != 0xFF)
- ms->fillchar = fillchar;
+ ms->fillchar = fillchar;
if (fillattr != 0xFF)
- ms->fillattr = fillattr;
+ ms->fillattr = fillattr;
if (spacechar != 0xFF)
- ms->spacechar = spacechar;
+ ms->spacechar = spacechar;
if (shadowattr != 0xFF)
- ms->shadowattr = shadowattr;
+ ms->shadowattr = shadowattr;
}
void set_box_type(boxtype bt)
@@ -918,7 +905,7 @@ void set_box_type(boxtype bt)
uchar *bxc;
ms->menubt = bt;
bxc = getboxchars(bt);
- ms->box_horiz = bxc[BOX_HORIZ]; // The char used to draw top line
+ ms->box_horiz = bxc[BOX_HORIZ]; // The char used to draw top line
ms->box_ltrt = bxc[BOX_LTRT];
ms->box_rtlt = bxc[BOX_RTLT];
}
@@ -926,22 +913,26 @@ void set_box_type(boxtype bt)
void set_menu_options(uchar maxmenuheight)
{
if (maxmenuheight != 0xFF)
- ms->maxmenuheight = maxmenuheight;
+ ms->maxmenuheight = maxmenuheight;
}
// Set the window which menusystem should use
void set_window_size(uchar top, uchar left, uchar bot, uchar right)
{
+ int nr, nc;
- uchar nr, nc;
if ((top > bot) || (left > right))
- return; // Sorry no change will happen here
- nr = getnumrows();
- nc = getnumcols();
+ return; // Sorry no change will happen here
+
+ if (getscreensize(1, &nr, &nc)) {
+ /* Unknown screen size? */
+ nr = 80;
+ nc = 24;
+ }
if (bot >= nr)
- bot = nr - 1;
+ bot = nr - 1;
if (right >= nc)
- right = nc - 1;
+ right = nc - 1;
ms->minrow = top;
ms->mincol = left;
ms->maxrow = bot;
@@ -949,7 +940,7 @@ void set_window_size(uchar top, uchar left, uchar bot, uchar right)
ms->numcols = right - left + 1;
ms->numrows = bot - top + 1;
if (ms->statline >= ms->numrows)
- ms->statline = ms->numrows - 1; // Clip statline if need be
+ ms->statline = ms->numrows - 1; // Clip statline if need be
}
void reg_handler(t_handler htype, void *handler)
@@ -957,11 +948,11 @@ void reg_handler(t_handler htype, void *handler)
// If bad value set to default screen handler
switch (htype) {
case HDLR_KEYS:
- ms->keys_handler = (t_keys_handler) handler;
- break;
+ ms->keys_handler = (t_keys_handler) handler;
+ break;
default:
- ms->handler = (t_menusystem_handler) handler;
- break;
+ ms->handler = (t_menusystem_handler) handler;
+ break;
}
}
@@ -969,22 +960,22 @@ void unreg_handler(t_handler htype)
{
switch (htype) {
case HDLR_KEYS:
- ms->keys_handler = NULL;
- break;
+ ms->keys_handler = NULL;
+ break;
default:
- ms->handler = NULL;
- break;
+ ms->handler = NULL;
+ break;
}
}
void reg_ontimeout(t_timeout_handler handler, unsigned int numsteps,
- unsigned int stepsize)
+ unsigned int stepsize)
{
ms->ontimeout = handler;
if (numsteps != 0)
- ms->tm_numsteps = numsteps;
+ ms->tm_numsteps = numsteps;
if (stepsize != 0)
- ms->tm_stepsize = stepsize;
+ ms->tm_stepsize = stepsize;
}
void unreg_ontimeout()
@@ -993,12 +984,12 @@ void unreg_ontimeout()
}
void reg_ontotaltimeout(t_timeout_handler handler,
- unsigned long numcentiseconds)
+ unsigned long numcentiseconds)
{
if (numcentiseconds != 0) {
- ms->ontotaltimeout = handler;
- ms->tm_total_timeout = numcentiseconds * 10; // to convert to milliseconds
- ms->tm_sofar_timeout = 0;
+ ms->ontotaltimeout = handler;
+ ms->tm_total_timeout = numcentiseconds * 10; // to convert to milliseconds
+ ms->tm_sofar_timeout = 0;
}
}
@@ -1011,31 +1002,31 @@ int next_visible(pt_menu menu, int index)
{
int ans;
if (index < 0)
- ans = 0;
+ ans = 0;
else if (index >= menu->numitems)
- ans = menu->numitems - 1;
+ ans = menu->numitems - 1;
else
- ans = index;
+ ans = index;
while ((ans < menu->numitems - 1) &&
- ((menu->items[ans]->action == OPT_INVISIBLE) ||
- (menu->items[ans]->action == OPT_SEP)))
- ans++;
+ ((menu->items[ans]->action == OPT_INVISIBLE) ||
+ (menu->items[ans]->action == OPT_SEP)))
+ ans++;
return ans;
}
-int prev_visible(pt_menu menu, int index) // Return index of prev visible
+int prev_visible(pt_menu menu, int index) // Return index of prev visible
{
int ans;
if (index < 0)
- ans = 0;
+ ans = 0;
else if (index >= menu->numitems)
- ans = menu->numitems - 1;
+ ans = menu->numitems - 1;
else
- ans = index;
+ ans = index;
while ((ans > 0) &&
- ((menu->items[ans]->action == OPT_INVISIBLE) ||
- (menu->items[ans]->action == OPT_SEP)))
- ans--;
+ ((menu->items[ans]->action == OPT_INVISIBLE) ||
+ (menu->items[ans]->action == OPT_SEP)))
+ ans--;
return ans;
}
@@ -1043,28 +1034,28 @@ int next_visible_sep(pt_menu menu, int index)
{
int ans;
if (index < 0)
- ans = 0;
+ ans = 0;
else if (index >= menu->numitems)
- ans = menu->numitems - 1;
+ ans = menu->numitems - 1;
else
- ans = index;
+ ans = index;
while ((ans < menu->numitems - 1) &&
- (menu->items[ans]->action == OPT_INVISIBLE))
- ans++;
+ (menu->items[ans]->action == OPT_INVISIBLE))
+ ans++;
return ans;
}
-int prev_visible_sep(pt_menu menu, int index) // Return index of prev visible
+int prev_visible_sep(pt_menu menu, int index) // Return index of prev visible
{
int ans;
if (index < 0)
- ans = 0;
+ ans = 0;
else if (index >= menu->numitems)
- ans = menu->numitems - 1;
+ ans = menu->numitems - 1;
else
- ans = index;
+ ans = index;
while ((ans > 0) && (menu->items[ans]->action == OPT_INVISIBLE))
- ans--;
+ ans--;
return ans;
}
@@ -1073,11 +1064,11 @@ int calc_visible(pt_menu menu, int first)
int ans, i;
if (menu == NULL)
- return 0;
+ return 0;
ans = 0;
for (i = first; i < menu->numitems; i++)
- if (menu->items[i]->action != OPT_INVISIBLE)
- ans++;
+ if (menu->items[i]->action != OPT_INVISIBLE)
+ ans++;
return ans;
}
@@ -1085,9 +1076,9 @@ int calc_visible(pt_menu menu, int first)
int isvisible(pt_menu menu, int first, int curr)
{
if (curr < first)
- return 0;
+ return 0;
return (calc_visible(menu, first) - calc_visible(menu, curr) <
- menu->menuheight);
+ menu->menuheight);
}
// Calculate the first entry to be displayed
@@ -1098,11 +1089,11 @@ int calc_first_late(pt_menu menu, int curr)
nv = calc_visible(menu, 0);
if (nv <= menu->menuheight)
- return 0;
+ return 0;
// Start with curr and go back menu->menuheight times
ans = curr + 1;
for (i = 0; i < menu->menuheight; i++)
- ans = prev_visible_sep(menu, ans - 1);
+ ans = prev_visible_sep(menu, ans - 1);
return ans;
}
@@ -1114,13 +1105,13 @@ int calc_first_early(pt_menu menu, int curr)
nv = calc_visible(menu, 0);
if (nv <= menu->menuheight)
- return 0;
+ return 0;
// Start with curr and go back till >= menu->menuheight
// items are visible
- nv = calc_visible(menu, curr); // Already nv of them are visible
+ nv = calc_visible(menu, curr); // Already nv of them are visible
ans = curr;
for (i = 0; i < menu->menuheight - nv; i++)
- ans = prev_visible_sep(menu, ans - 1);
+ ans = prev_visible_sep(menu, ans - 1);
return ans;
}
@@ -1132,51 +1123,51 @@ uchar add_menu(const char *title, int maxmenusize)
num = ms->nummenus;
if (num >= MAXMENUS)
- return -1;
+ return -1;
m = NULL;
m = (pt_menu) malloc(sizeof(t_menu));
if (m == NULL)
- return -1;
+ return -1;
ms->menus[num] = m;
m->numitems = 0;
m->name = NULL;
m->row = 0xFF;
m->col = 0xFF;
if (maxmenusize < 1)
- m->maxmenusize = MAXMENUSIZE;
+ m->maxmenusize = MAXMENUSIZE;
else
- m->maxmenusize = maxmenusize;
+ m->maxmenusize = maxmenusize;
m->items = (pt_menuitem *) malloc(sizeof(pt_menuitem) * (m->maxmenusize));
for (i = 0; i < m->maxmenusize; i++)
- m->items[i] = NULL;
+ m->items[i] = NULL;
m->title = (char *)malloc(MENULEN + 1);
if (title) {
- if (strlen(title) > MENULEN - 2)
- strcpy(m->title, TITLELONG);
- else
- strcpy(m->title, title);
+ if (strlen(title) > MENULEN - 2)
+ strcpy(m->title, TITLELONG);
+ else
+ strcpy(m->title, title);
} else
- strcpy(m->title, EMPTYSTR);
+ strcpy(m->title, EMPTYSTR);
m->menuwidth = strlen(m->title);
ms->nummenus++;
return ms->nummenus - 1;
}
-void set_menu_name(const char *name) // Set the "name" of this menu
+void set_menu_name(const char *name) // Set the "name" of this menu
{
pt_menu m;
m = ms->menus[ms->nummenus - 1];
- if (m->name) // Free up previous name
+ if (m->name) // Free up previous name
{
- free(m->name);
- m->name = NULL;
+ free(m->name);
+ m->name = NULL;
}
if (name) {
- m->name = (char *)malloc(strlen(name) + 1);
- strcpy(m->name, name);
+ m->name = (char *)malloc(strlen(name) + 1);
+ strcpy(m->name, name);
}
}
@@ -1188,7 +1179,7 @@ uchar add_named_menu(const char *name, const char *title, int maxmenusize)
return ms->nummenus - 1;
}
-void set_menu_pos(uchar row, uchar col) // Set the position of this menu.
+void set_menu_pos(uchar row, uchar col) // Set the position of this menu.
{
pt_menu m;
@@ -1197,7 +1188,7 @@ void set_menu_pos(uchar row, uchar col) // Set the position of this menu.
m->col = col;
}
-pt_menuitem add_sep() // Add a separator to current menu
+pt_menuitem add_sep() // Add a separator to current menu
{
pt_menuitem mi;
pt_menu m;
@@ -1206,9 +1197,9 @@ pt_menuitem add_sep() // Add a separator to current menu
mi = NULL;
mi = (pt_menuitem) malloc(sizeof(t_menuitem));
if (mi == NULL)
- return NULL;
+ return NULL;
m->items[(unsigned int)m->numitems] = mi;
- mi->handler = NULL; // No handler
+ mi->handler = NULL; // No handler
mi->item = mi->status = mi->data = NULL;
mi->action = OPT_SEP;
mi->index = m->numitems++;
@@ -1220,20 +1211,20 @@ pt_menuitem add_sep() // Add a separator to current menu
// Add item to the "current" menu
pt_menuitem add_item(const char *item, const char *status, t_action action,
- const char *data, uchar itemdata)
+ const char *data, uchar itemdata)
{
pt_menuitem mi;
pt_menu m;
const char *str;
- uchar inhlite = 0; // Are we inside hlite area
+ uchar inhlite = 0; // Are we inside hlite area
m = (ms->menus[ms->nummenus - 1]);
mi = NULL;
mi = (pt_menuitem) malloc(sizeof(t_menuitem));
if (mi == NULL)
- return NULL;
+ return NULL;
m->items[(unsigned int)m->numitems] = mi;
- mi->handler = NULL; // No handler
+ mi->handler = NULL; // No handler
// Allocate space to store stuff
mi->item = (char *)malloc(MENULEN + 1);
@@ -1241,74 +1232,74 @@ pt_menuitem add_item(const char *item, const char *status, t_action action,
mi->data = (char *)malloc(ACTIONLEN + 1);
if (item) {
- if (strlen(item) > MENULEN) {
- strcpy(mi->item, ITEMLONG);
- } else {
- strcpy(mi->item, item);
- }
- if (strlen(mi->item) > m->menuwidth)
- m->menuwidth = strlen(mi->item);
+ if (strlen(item) > MENULEN) {
+ strcpy(mi->item, ITEMLONG);
+ } else {
+ strcpy(mi->item, item);
+ }
+ if (strlen(mi->item) > m->menuwidth)
+ m->menuwidth = strlen(mi->item);
} else
- strcpy(mi->item, EMPTYSTR);
+ strcpy(mi->item, EMPTYSTR);
if (status) {
- if (strlen(status) > STATLEN) {
- strcpy(mi->status, STATUSLONG);
- } else {
- strcpy(mi->status, status);
- }
+ if (strlen(status) > STATLEN) {
+ strcpy(mi->status, STATUSLONG);
+ } else {
+ strcpy(mi->status, status);
+ }
} else
- strcpy(mi->status, EMPTYSTR);
+ strcpy(mi->status, EMPTYSTR);
mi->action = action;
str = mi->item;
mi->shortcut = 0;
mi->helpid = 0xFFFF;
- inhlite = 0; // We have not yet seen an ENABLEHLITE char
+ inhlite = 0; // We have not yet seen an ENABLEHLITE char
// Find the first char in [A-Za-z0-9] after ENABLEHLITE and not arg to control char
while (*str) {
- if (*str == ENABLEHLITE) {
- inhlite = 1;
- }
- if (*str == DISABLEHLITE) {
- inhlite = 0;
- }
- if ((inhlite == 1) &&
- (((*str >= 'A') && (*str <= 'Z')) ||
- ((*str >= 'a') && (*str <= 'z')) ||
- ((*str >= '0') && (*str <= '9')))) {
- mi->shortcut = *str;
- break;
- }
- ++str;
+ if (*str == ENABLEHLITE) {
+ inhlite = 1;
+ }
+ if (*str == DISABLEHLITE) {
+ inhlite = 0;
}
- if ((mi->shortcut >= 'A') && (mi->shortcut <= 'Z')) // Make lower case
- mi->shortcut = mi->shortcut - 'A' + 'a';
+ if ((inhlite == 1) &&
+ (((*str >= 'A') && (*str <= 'Z')) ||
+ ((*str >= 'a') && (*str <= 'z')) ||
+ ((*str >= '0') && (*str <= '9')))) {
+ mi->shortcut = *str;
+ break;
+ }
+ ++str;
+ }
+ if ((mi->shortcut >= 'A') && (mi->shortcut <= 'Z')) // Make lower case
+ mi->shortcut = mi->shortcut - 'A' + 'a';
if (data) {
- if (strlen(data) > ACTIONLEN) {
- strcpy(mi->data, ACTIONLONG);
- } else {
- strcpy(mi->data, data);
- }
+ if (strlen(data) > ACTIONLEN) {
+ strcpy(mi->data, ACTIONLONG);
+ } else {
+ strcpy(mi->data, data);
+ }
} else
- strcpy(mi->data, EMPTYSTR);
+ strcpy(mi->data, EMPTYSTR);
switch (action) {
case OPT_SUBMENU:
- mi->itemdata.submenunum = itemdata;
- break;
+ mi->itemdata.submenunum = itemdata;
+ break;
case OPT_CHECKBOX:
- mi->itemdata.checked = itemdata;
- break;
+ mi->itemdata.checked = itemdata;
+ break;
case OPT_RADIOMENU:
- mi->itemdata.radiomenunum = itemdata;
- if (mi->data)
- free(mi->data);
- mi->data = NULL; // No selection made
- break;
- default: // to keep the compiler happy
- break;
+ mi->itemdata.radiomenunum = itemdata;
+ if (mi->data)
+ free(mi->data);
+ mi->data = NULL; // No selection made
+ break;
+ default: // to keep the compiler happy
+ break;
}
mi->index = m->numitems++;
mi->parindex = ms->nummenus - 1;
@@ -1323,13 +1314,13 @@ void set_item_options(uchar shortcut, int helpid)
m = (ms->menus[ms->nummenus - 1]);
if (m->numitems <= 0)
- return;
+ return;
mi = m->items[(unsigned int)m->numitems - 1];
if (shortcut != 0xFF)
- mi->shortcut = shortcut;
+ mi->shortcut = shortcut;
if (helpid != 0xFFFF)
- mi->helpid = helpid;
+ mi->helpid = helpid;
}
// Free internal datasutructures
@@ -1344,34 +1335,32 @@ void append_line_helper(int menunum, char *line)
pt_menuitem mi, ri;
char *app;
int ctr;
- char dp;
- dp = getdisppage();
menu = ms->menus[menunum];
for (ctr = 0; ctr < (int)menu->numitems; ctr++) {
- mi = menu->items[ctr];
- app = NULL; //What to append
- switch (mi->action) {
- case OPT_CHECKBOX:
- if (mi->itemdata.checked)
- app = mi->data;
- break;
- case OPT_RADIOMENU:
- if (mi->data) { // Some selection has been made
- ri = (pt_menuitem) (mi->data);
- app = ri->data;
- }
- break;
- case OPT_SUBMENU:
- append_line_helper(mi->itemdata.submenunum, line);
- break;
- default:
- break;
- }
- if (app) {
- strcat(line, " ");
- strcat(line, app);
- }
+ mi = menu->items[ctr];
+ app = NULL; //What to append
+ switch (mi->action) {
+ case OPT_CHECKBOX:
+ if (mi->itemdata.checked)
+ app = mi->data;
+ break;
+ case OPT_RADIOMENU:
+ if (mi->data) { // Some selection has been made
+ ri = (pt_menuitem) (mi->data);
+ app = ri->data;
+ }
+ break;
+ case OPT_SUBMENU:
+ append_line_helper(mi->itemdata.submenunum, line);
+ break;
+ default:
+ break;
+ }
+ if (app) {
+ strcat(line, " ");
+ strcat(line, app);
+ }
}
}
@@ -1383,6 +1372,6 @@ void gen_append_line(const char *menu_name, char *line)
menunum = find_menu_num(menu_name);
if (menunum < 0)
- return; // No such menu
+ return; // No such menu
append_line_helper(menunum, line);
}
diff --git a/com32/cmenu/libmenu/menu.h b/com32/cmenu/libmenu/menu.h
index 68adf278..98c48594 100644
--- a/com32/cmenu/libmenu/menu.h
+++ b/com32/cmenu/libmenu/menu.h
@@ -24,6 +24,7 @@
#include "syslnx.h"
#include "scancodes.h"
#include <string.h>
+#include <unistd.h>
// TIMEOUT PARAMETERS
/* If no key is pressed within TIMEOUTNUMSTEPS * TIMEOUTSTEPSIZE milliseconds
@@ -99,7 +100,7 @@
#define DEBUGLINE 23 // debugging info goes here
// Other Chars
-#define SUBMENUCHAR 175 // This is >> symbol
+#define SUBMENUCHAR '\172' // This is >> symbol
#define RADIOMENUCHAR '>' // > symbol for radio menu?
#define EXITMENUCHAR 174 // This is << symbol
#define CHECKED 251 // Check mark
@@ -214,8 +215,8 @@ typedef struct s_menusystem {
uchar shadowattr;
uchar statline;
uchar menupage;
- uchar maxrow, minrow, numrows; // Number of rows in the window
- uchar maxcol, mincol, numcols; // Number of columns in the window
+ int maxrow, minrow, numrows; // Number of rows in the window
+ int maxcol, mincol, numcols; // Number of columns in the window
// Menu box look
boxtype menubt; // What type of boxes should be drawn
diff --git a/com32/cmenu/libmenu/tui.c b/com32/cmenu/libmenu/tui.c
index 81e40793..e256502a 100644
--- a/com32/cmenu/libmenu/tui.c
+++ b/com32/cmenu/libmenu/tui.c
@@ -14,12 +14,12 @@
#include <string.h>
#include <com32.h>
#include <stdlib.h>
+#include "com32io.h"
com32sys_t inreg, outreg; // Global register sets for use
char bkspstr[] = " \b$";
char eolstr[] = "\n$";
-#define GETSTRATTR 0x07
// Reads a line of input from stdin. Replace CR with NUL byte
// password <> 0 implies not echoed on screen
@@ -33,14 +33,12 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
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
- char page;
char row, col;
char start, end; // Cursor shape
char fudge; // How many chars should be removed from output
char insmode; // Are we in insert or overwrite
- page = getdisppage();
- getpos(&row, &col, page); // Get current position
+ getpos(&row, &col, 0); // Get current position
getcursorshape(&start, &end);
insmode = 1;
@@ -67,7 +65,7 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
// col is the corresponding column on the screen
if (password == 0) // Not a password, print initial value
{
- gotoxy(row, col, page);
+ gotoxy(row, col);
csprint(str, GETSTRATTR);
}
while (1) { // Do forever
@@ -194,11 +192,11 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
}
// Now the string has been modified, print it
if (password == 0) {
- gotoxy(row, col, page);
+ gotoxy(row, col);
csprint(str, GETSTRATTR);
if (fudge > 0)
- cprint(' ', GETSTRATTR, fudge, page);
- gotoxy(row, col + (p - str), page);
+ cprint(' ', GETSTRATTR, fudge);
+ gotoxy(row, col + (p - str));
}
}
*p = '\0';
@@ -211,85 +209,6 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
free(str);
}
-/* Print a C string (NUL-terminated) */
-void cswprint(const char *str, char attr, char left)
-{
- char page = getdisppage();
- char newattr = 0, cha, chb;
- char row, col;
- char nr, nc;
-
- nr = getnumrows();
- nc = getnumcols();
- getpos(&row, &col, page);
- while (*str) {
- switch (*str) {
- case '\b':
- --col;
- break;
- case '\n':
- ++row;
- col = left;
- break;
- case '\r':
- //col=left;
- break;
- case BELL: // Bell Char
- beep();
- break;
- case CHRELATTR: // change attribute (relatively)
- case CHABSATTR: // change attribute (absolute)
- cha = *(str + 1);
- chb = *(str + 2);
- if ((((cha >= '0') && (cha <= '9')) || ((cha >= 'A') && (cha <= 'F'))) && (((chb >= '0') && (chb <= '9')) || ((chb >= 'A') && (chb <= 'F')))) // Next two chars are legal
- {
- if ((cha >= 'A') && (cha <= 'F'))
- cha = cha - 'A' + 10;
- else
- cha = cha - '0';
- if ((chb >= 'A') && (chb <= 'F'))
- chb = chb - 'A' + 10;
- else
- chb = chb - '0';
- newattr = (cha << 4) + chb;
- attr = (*str == CHABSATTR ? newattr : attr ^ newattr);
- str += 2; // Will be incremented again later
- }
- break;
- default:
- putch(*str, attr, page);
- ++col;
- }
- if (col >= nc) {
- ++row;
- col = left;
- }
- if (row > nr) {
- scrollup();
- row = nr;
- }
- gotoxy(row, col, page);
- str++;
- }
-}
-
-void clearwindow(char top, char left, char bot, char right, char page,
- char fillchar, char fillattr)
-{
- char x;
- for (x = top; x < bot + 1; x++) {
- gotoxy(x, left, page);
- cprint(fillchar, fillattr, right - left + 1, page);
- }
-}
-
-void cls(void)
-{
- unsigned char dp = getdisppage();
- gotoxy(0, 0, dp);
- cprint(' ', GETSTRATTR, (1 + getnumrows()) * getnumcols(), dp);
-}
-
//////////////////////////////Box Stuff
// This order of numbers must match
@@ -338,41 +257,35 @@ unsigned char *getboxchars(boxtype bt)
}
// Draw box and lines
-void drawbox(char top, char left, char bot, char right,
- char page, char attr, boxtype bt)
+void drawbox(const char top, const char left, const char bot,
+ const char right, const char attr)
{
- unsigned char *box_chars; // pointer to array of box chars
unsigned char x;
-
- box_chars = getboxchars(bt);
+ putchar(SO);
// Top border
- gotoxy(top, left, page);
- cprint(box_chars[BOX_TOPLEFT], attr, 1, page);
- gotoxy(top, left + 1, page);
- cprint(box_chars[BOX_TOP], attr, right - left, page);
- gotoxy(top, right, page);
- cprint(box_chars[BOX_TOPRIGHT], attr, 1, page);
+ gotoxy(top, left);
+ putch(TOP_LEFT_CORNER_BORDER, attr);
+ cprint(TOP_BORDER, attr, right - left - 1);
+ putch(TOP_RIGHT_CORNER_BORDER, attr);
// Bottom border
- gotoxy(bot, left, page);
- cprint(box_chars[BOX_BOTLEFT], attr, 1, page);
- gotoxy(bot, left + 1, page);
- cprint(box_chars[BOX_BOT], attr, right - left, page);
- gotoxy(bot, right, page);
- cprint(box_chars[BOX_BOTRIGHT], attr, 1, page);
+ gotoxy(bot, left);
+ putch(BOTTOM_LEFT_CORNER_BORDER, attr);
+ cprint(BOTTOM_BORDER, attr, right - left - 1);
+ putch(BOTTOM_RIGHT_CORNER_BORDER, attr);
// Left & right borders
for (x = top + 1; x < bot; x++) {
- gotoxy(x, left, page);
- cprint(box_chars[BOX_LEFT], attr, 1, page);
- gotoxy(x, right, page);
- cprint(box_chars[BOX_RIGHT], attr, 1, page);
+ gotoxy(x, left);
+ putch(LEFT_BORDER, attr);
+ gotoxy(x, right);
+ putch(RIGHT_BORDER, attr);
}
+ putchar(SI);
}
-void drawhorizline(char top, char left, char right, char page, char attr,
- boxtype bt, char dumb)
+void drawhorizline(const char top, const char left, const char right,
+ const char attr, char dumb)
{
unsigned char start, end;
- unsigned char *box_chars = getboxchars(bt);
if (dumb == 0) {
start = left + 1;
end = right - 1;
@@ -380,12 +293,14 @@ void drawhorizline(char top, char left, char right, char page, char attr,
start = left;
end = right;
}
- gotoxy(top, start, page);
- cprint(box_chars[BOX_HORIZ], attr, end - start + 1, page);
+ gotoxy(top, start);
+ putchar(SO);
+ cprint(MIDDLE_BORDER, attr, end - start + 1);
if (dumb == 0) {
- gotoxy(top, left, page);
- cprint(box_chars[BOX_LTRT], attr, 1, page);
- gotoxy(top, right, page);
- cprint(box_chars[BOX_RTLT], attr, 1, page);
+ gotoxy(top, left);
+ putch(MIDDLE_BORDER, attr);
+ gotoxy(top, right);
+ putch(MIDDLE_BORDER, attr);
}
+ putchar(SI);
}
diff --git a/com32/cmenu/libmenu/tui.h b/com32/cmenu/libmenu/tui.h
index 4df15327..c72a41d2 100644
--- a/com32/cmenu/libmenu/tui.h
+++ b/com32/cmenu/libmenu/tui.h
@@ -22,15 +22,26 @@
#define NULL ((void *)0)
#endif
+#define SO '\016'
+#define SI '\017'
+
+#define TOP_LEFT_CORNER_BORDER '\154'
+#define TOP_BORDER '\161'
+#define TOP_RIGHT_CORNER_BORDER '\153'
+#define BOTTOM_LEFT_CORNER_BORDER '\155'
+#define BOTTOM_BORDER '\161'
+#define BOTTOM_RIGHT_CORNER_BORDER '\152'
+#define LEFT_BORDER '\170'
+#define RIGHT_BORDER '\170'
+#define LEFT_MIDDLE_BORDER '\164'
+#define MIDDLE_BORDER '\161'
+#define RIGHT_MIDDLE_BORDER '\165'
+
#define BELL 0x07
// CHRELATTR = ^N, CHABSATTR = ^O
#define CHABSATTR 15
#define CHRELATTR 14
-
-void clearwindow(char top, char left, char bot, char right,
- char page, char fillchar, char fillattr);
-
-void cls(void); /* Clears the entire current screen page */
+#define GETSTRATTR 0x07
// Generic user input,
// password = 0 iff chars echoed on screen
@@ -74,14 +85,14 @@ typedef enum { BOX_SINSIN, BOX_DBLDBL, BOX_SINDBL, BOX_DBLSIN } boxtype;
unsigned char *getboxchars(boxtype bt);
-void drawbox(char top, char left, char bot, char right,
- char page, char attr, boxtype bt);
+void drawbox(const char, const char, const char, const char,
+ const char);
// Draw a horizontal line
// dumb == 1, means just draw the line
// dumb == 0 means check the first and last positions and depending on what is
// currently on the screen make it a LTRT and/or RTLT appropriately.
-void drawhorizline(char top, char left, char right, char page, char attr,
- boxtype bt, char dumb);
+void drawhorizline(const char, const char, const char, const char,
+ const char dumb);
#endif