(2006-08-06) rescue-bootcd
This commit is contained in:
147
extra/syslinux-3.09/menu/libmenu/com32io.c
Normal file
147
extra/syslinux-3.09/menu/libmenu/com32io.c
Normal file
@@ -0,0 +1,147 @@
|
||||
/* -*- 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.
|
||||
*
|
||||
* ----------------------------------------------------------------------- */
|
||||
|
||||
#include <string.h>
|
||||
#include <com32.h>
|
||||
#include "com32io.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)
|
||||
{
|
||||
REG_AH(inreg) = 0x09;
|
||||
REG_AL(inreg) = chr;
|
||||
REG_BH(inreg) = disppage;
|
||||
REG_BL(inreg) = attr;
|
||||
REG_CX(inreg) = times;
|
||||
__intcall(0x10,&inreg,&outreg);
|
||||
}
|
||||
|
||||
void setdisppage(char num) // Set the display page to specified number
|
||||
{
|
||||
REG_AH(inreg) = 0x05;
|
||||
REG_AL(inreg) = num;
|
||||
__intcall(0x10,&inreg,&outreg);
|
||||
}
|
||||
|
||||
char getdisppage() // Get current display page
|
||||
{
|
||||
REG_AH(inreg) = 0x0f;
|
||||
__intcall(0x10,&inreg,&outreg);
|
||||
return REG_BH(outreg);
|
||||
}
|
||||
|
||||
void getpos(char * row, char * col, char page)
|
||||
{
|
||||
REG_AH(inreg) = 0x03;
|
||||
REG_BH(inreg) = page;
|
||||
__intcall(0x10,&inreg,&outreg);
|
||||
*row = REG_DH(outreg);
|
||||
*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;
|
||||
|
||||
REG_AH(inreg) = 0x86;
|
||||
REG_CX(inreg) = (micro >> 16);
|
||||
REG_DX(inreg) = (micro % 0x10000);
|
||||
__intcall(0x15,&inreg,&outreg);
|
||||
return REG_AH(outreg);
|
||||
}
|
||||
|
||||
void beep()
|
||||
{
|
||||
REG_AH(inreg) = 0x0E;
|
||||
REG_AL(inreg) = 0x07;
|
||||
REG_BH(inreg) = 0;
|
||||
__intcall(0x10,&inreg,&outreg);
|
||||
}
|
||||
|
||||
void scrollup()
|
||||
{
|
||||
unsigned int dx = (getnumrows()<< 8) + getnumcols();
|
||||
REG_AH(inreg) = 0x06;
|
||||
REG_AL(inreg) = 0x01;
|
||||
REG_BH(inreg) = 0x07; // Attribute to write blanks lines
|
||||
REG_DX(inreg) = dx; // BOT RIGHT corner to window
|
||||
REG_CX(inreg) = 0; // TOP LEFT of window
|
||||
}
|
||||
|
||||
char inputc(char * scancode)
|
||||
{
|
||||
REG_AH(inreg) = 0x10;
|
||||
__intcall(0x16,&inreg,&outreg);
|
||||
if (scancode)
|
||||
*scancode = REG_AH(outreg);
|
||||
return REG_AL(outreg);
|
||||
}
|
||||
|
||||
void getcursorshape(char *start, char *end)
|
||||
{
|
||||
char page = getdisppage();
|
||||
REG_AH(inreg) = 0x03;
|
||||
REG_BH(inreg) = page;
|
||||
__intcall(0x10,&inreg,&outreg);
|
||||
*start = REG_CH(outreg);
|
||||
*end = REG_CL(outreg);
|
||||
}
|
||||
|
||||
void setcursorshape(char start, char end)
|
||||
{
|
||||
REG_AH(inreg) = 0x01;
|
||||
REG_CH(inreg) = start;
|
||||
REG_CL(inreg) = 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;
|
||||
REG_AL(inreg) = 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)
|
||||
{
|
||||
REG_AH(inreg) = 0x08;
|
||||
REG_BH(inreg) = page;
|
||||
__intcall(0x16,&inreg,&outreg);
|
||||
return REG_AL(outreg);
|
||||
}
|
||||
|
||||
97
extra/syslinux-3.09/menu/libmenu/com32io.h
Normal file
97
extra/syslinux-3.09/menu/libmenu/com32io.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/* -*- 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 __COM32IO_H__
|
||||
#define __COM32IO_H__
|
||||
|
||||
#include <com32.h>
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
/* 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)
|
||||
{
|
||||
cswprint(str,attr,0);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
char getdisppage(); // Get current display page
|
||||
|
||||
void gotoxy(char row,char col, char page);
|
||||
|
||||
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
|
||||
|
||||
// Get char displayed at current position in specified page
|
||||
unsigned char getcharat(char page);
|
||||
|
||||
static inline void cursoroff(void) /* Turns off cursor */
|
||||
{
|
||||
setcursorshape(32,33);
|
||||
}
|
||||
|
||||
static inline void cursoron(void) /* Turns on cursor */
|
||||
{
|
||||
setcursorshape(6,7);
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
void scrollup(); //Scroll up display screen by one line
|
||||
|
||||
void setvideomode(char mode); // Set the 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?)
|
||||
{
|
||||
while (checkkbdbuf()) inputc(NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
1102
extra/syslinux-3.09/menu/libmenu/des.c
Normal file
1102
extra/syslinux-3.09/menu/libmenu/des.c
Normal file
File diff suppressed because it is too large
Load Diff
9
extra/syslinux-3.09/menu/libmenu/des.h
Normal file
9
extra/syslinux-3.09/menu/libmenu/des.h
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
#ifndef _DES_H_
|
||||
#define _DES_H_
|
||||
|
||||
// des crypt
|
||||
extern char *crypt (const char *key, const char *salt);
|
||||
|
||||
#endif
|
||||
|
||||
84
extra/syslinux-3.09/menu/libmenu/help.c
Normal file
84
extra/syslinux-3.09/menu/libmenu/help.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/* -*- 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.
|
||||
*
|
||||
* ----------------------------------------------------------------------- */
|
||||
|
||||
#include "help.h"
|
||||
#include <stdio.h>
|
||||
#include "string.h"
|
||||
|
||||
char helpbasedir[HELPDIRLEN]; // name of help directory limited to HELPDIRLEN
|
||||
|
||||
void showhelp(const char *filename)
|
||||
{
|
||||
char nc,nr;
|
||||
FILE *f;
|
||||
char line[512]; // Max length of a line
|
||||
|
||||
nc = getnumcols();
|
||||
nr = getnumrows();
|
||||
cls();
|
||||
drawbox(0,0,nr,nc-1,HELPPAGE,0x07,HELPBOX);
|
||||
|
||||
drawhorizline(2,0,nc-1,HELPPAGE,0x07,HELPBOX,0); // dumb==0
|
||||
if (filename == NULL) { // print file contents
|
||||
gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
|
||||
cswprint("Help system not initialized",0x07,HELP_LEFT_MARGIN);
|
||||
return;
|
||||
}
|
||||
|
||||
f = fopen(filename,"r");
|
||||
if (!f) { // No such file
|
||||
sprintf(line, "File %s not found",filename);
|
||||
gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
|
||||
cswprint(line,0x07,HELP_LEFT_MARGIN);
|
||||
return;
|
||||
}
|
||||
|
||||
// Now we have a file just print it.
|
||||
fgets(line,sizeof line,f); // Get first line (TITLE)
|
||||
gotoxy(1,(nc-strlen(line))/2,HELPPAGE);
|
||||
csprint(line,0x07);
|
||||
|
||||
gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
|
||||
while ( fgets(line, sizeof line, f) ) cswprint(line,0x07,HELP_LEFT_MARGIN);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void runhelpsystem(unsigned int helpid)
|
||||
{
|
||||
char dp;
|
||||
char scan;
|
||||
char filename[HELPDIRLEN+16];
|
||||
|
||||
dp = getdisppage();
|
||||
if (dp != HELPPAGE) setdisppage(HELPPAGE);
|
||||
if (helpbasedir[0] != 0) {
|
||||
sprintf(filename,"%s/hlp%05d.txt",helpbasedir,helpid);
|
||||
showhelp(filename);
|
||||
}
|
||||
else showhelp (NULL);
|
||||
while (1) {
|
||||
inputc(&scan);
|
||||
if (scan == ESCAPE) break;
|
||||
}
|
||||
if (dp != HELPPAGE) setdisppage(dp);
|
||||
}
|
||||
|
||||
void init_help(const char *helpdir)
|
||||
{
|
||||
if (helpdir != NULL)
|
||||
strcpy(helpbasedir,helpdir);
|
||||
else helpbasedir[0] = 0;
|
||||
}
|
||||
|
||||
void close_help(void)
|
||||
{
|
||||
}
|
||||
39
extra/syslinux-3.09/menu/libmenu/help.h
Normal file
39
extra/syslinux-3.09/menu/libmenu/help.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* -*- 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 __HELP_H_
|
||||
#define __HELP_H_
|
||||
|
||||
#include "menu.h"
|
||||
#include "com32io.h"
|
||||
#include "tui.h"
|
||||
#include <string.h>
|
||||
|
||||
// How many rows for the title
|
||||
#define HELP_TITLE_HEIGHT 1
|
||||
#define HELP_BODY_ROW (HELP_TITLE_HEIGHT+3)
|
||||
#define HELP_LEFT_MARGIN 2
|
||||
#define HELPBOX BOX_SINSIN
|
||||
#define HELPDIRLEN 64
|
||||
|
||||
// Display one screen of help information
|
||||
void showhelp(const char *filename);
|
||||
|
||||
// Start the help system using id helpid
|
||||
void runhelpsystem(unsigned int helpid);
|
||||
|
||||
// Directory where help files are located
|
||||
void init_help(const char *helpdir);
|
||||
// Free internal datastructures
|
||||
void close_help(void);
|
||||
|
||||
#endif
|
||||
1148
extra/syslinux-3.09/menu/libmenu/menu.c
Normal file
1148
extra/syslinux-3.09/menu/libmenu/menu.c
Normal file
File diff suppressed because it is too large
Load Diff
287
extra/syslinux-3.09/menu/libmenu/menu.h
Normal file
287
extra/syslinux-3.09/menu/libmenu/menu.h
Normal file
@@ -0,0 +1,287 @@
|
||||
/* -*- 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.
|
||||
*
|
||||
* ----------------------------------------------------------------------- */
|
||||
|
||||
/* This program can be compiled for DOS with the OpenWatcom compiler
|
||||
* (http://www.openwatcom.org/):
|
||||
*
|
||||
* wcl -3 -osx -mt <filename>.c
|
||||
*/
|
||||
|
||||
#ifndef __MENU_H__
|
||||
#define __MENU_H__
|
||||
|
||||
#include "com32io.h"
|
||||
#include "tui.h"
|
||||
#include "syslnx.h"
|
||||
#include "scancodes.h"
|
||||
#include <string.h>
|
||||
|
||||
// TIMEOUT PARAMETERS
|
||||
/* If no key is pressed within TIMEOUTNUMSTEPS * TIMEOUTSTEPSIZE milliseconds
|
||||
and if a timeout handler is registered, then that will be called.
|
||||
The handler should either either take control from there on, or return without
|
||||
producing any change in the current video settings.
|
||||
|
||||
For e.g. the handler could
|
||||
* Could just quit the menu program
|
||||
* beep and return.
|
||||
|
||||
TIMEOUTSTEPSIZE is the interval for which the program sleeps without checking for
|
||||
any keystroke. So increasing this will make the response of the system slow.
|
||||
Decreasing this will make a lot of interrupt calls using up your CPU. Default
|
||||
value of TIMEOUTSTEPSIZE of 0.1 seconds should be right in most cases.
|
||||
|
||||
TIMEOUTNUMSTEPS of 3000 corresponds to a wait time of 300 seconds or 5 minutes
|
||||
*/
|
||||
|
||||
#define TIMEOUTSTEPSIZE 10
|
||||
#define TIMEOUTNUMSTEPS 30000L
|
||||
|
||||
// Attributes
|
||||
#define NORMALATTR 0x17
|
||||
#define NORMALHLITE 0x1F // Normal Highlight attribute
|
||||
#define REVERSEATTR 0x70
|
||||
#define REVERSEHLITE 0x78 // Reverse Hightlight attribute
|
||||
#define INACTATTR 0x18
|
||||
#define INACTHLITE 0x10 // Inactive Highlight attribute
|
||||
#define REVINACTATTR 0x78
|
||||
#define REVINACTHLITE 0x70 // Reverse Inactive Highlight attr
|
||||
|
||||
#define STATUSATTR 0x74
|
||||
#define STATUSHLITE 0x7B // Status highlight
|
||||
|
||||
#define FILLCHAR 177
|
||||
#define FILLATTR 0x01
|
||||
#define SHADOWATTR 0x00
|
||||
#define SPACECHAR ' '
|
||||
|
||||
#define TFILLCHAR ' '
|
||||
#define TITLEATTR 0x70
|
||||
|
||||
#define ENABLEHLITE '<' // Char which turns on highlight
|
||||
#define DISABLEHLITE '>' // Char which turns off highlight
|
||||
#define NOHLITE 0 // The offset into attrib array for non-hilite
|
||||
#define HLITE 1 // The offset for Hlite attrib
|
||||
|
||||
#define MOREABOVE 24 // char to print when more menu items available above
|
||||
#define MOREBELOW 25 // more items available below
|
||||
#define SCROLLBOX 176 // Filled char to display
|
||||
|
||||
// Attributes of the menu system
|
||||
#define MAXMENUS 10 // Maximum number of menu's allowed
|
||||
#define MAXMENUSIZE 30 // Default value for max num of entries in each menu
|
||||
#define MAXMENUHEIGHT 14 // Maximum number of entries displayed
|
||||
#define MENUBOXTYPE BOX_SINSIN // Default box type Look at tui.h for other values
|
||||
|
||||
// Upper bounds on lengths
|
||||
// We copy the given string, so user can reuse the space used to store incoming arguments.
|
||||
#define MENULEN 40 // Each menu entry is atmost MENULEN chars
|
||||
#define STATLEN 80 // Maximum length of status string
|
||||
#define TITLELEN 80 // Maximum length of title string
|
||||
#define ACTIONLEN 255 // Maximum length of an action string
|
||||
|
||||
// Layout of menu
|
||||
#define MENUROW 3 // Row where menu is displayed (relative to window)
|
||||
#define MENUCOL 4 // Col where menu is displayed (relative to window)
|
||||
#define MENUPAGE 1 // show in display page 1
|
||||
#define HELPPAGE 2 // Use this page for any additional information
|
||||
#define STATLINE 24 // Line number where status line starts (relative to window)
|
||||
|
||||
// Used for printing debugging messages
|
||||
#define DEBUGLINE 23 // debugging info goes here
|
||||
|
||||
// Other Chars
|
||||
#define SUBMENUCHAR 175 // This is >> symbol
|
||||
#define RADIOMENUCHAR '>' // > symbol for radio menu?
|
||||
#define EXITMENUCHAR 174 // This is << symbol
|
||||
#define CHECKED 251 // Check mark
|
||||
#define UNCHECKED 250 // Light bullet
|
||||
#define RADIOSEL '.' // Current Radio Selection
|
||||
#define RADIOUNSEL ' ' // Radio option not selected
|
||||
|
||||
typedef unsigned char uchar;
|
||||
|
||||
// Types of menu's
|
||||
#define NORMALMENU 1
|
||||
#define RADIOMENU 2
|
||||
|
||||
typedef enum {OPT_INACTIVE, OPT_SUBMENU, OPT_RUN, OPT_EXITMENU, OPT_CHECKBOX,
|
||||
OPT_RADIOMENU, OPT_SEP, OPT_INVISIBLE,
|
||||
OPT_RADIOITEM} t_action;
|
||||
|
||||
typedef union {
|
||||
uchar submenunum; // For submenu's
|
||||
uchar checked; // For check boxes
|
||||
uchar radiomenunum; // Item mapping to a radio menu
|
||||
} t_itemdata;
|
||||
|
||||
struct s_menuitem;
|
||||
struct s_menu;
|
||||
struct s_menusystem;
|
||||
|
||||
typedef struct {
|
||||
unsigned int valid :1; // Is action valid?
|
||||
unsigned int refresh:1; // Should we recompute menu stuff?
|
||||
unsigned int reserved:6; // For future expansion
|
||||
} t_handler_return;
|
||||
|
||||
t_handler_return ACTION_VALID,ACTION_INVALID; // Specific values
|
||||
|
||||
typedef t_handler_return (*t_item_handler)(struct s_menusystem *, struct s_menuitem *);
|
||||
typedef void (*t_menusystem_handler)(struct s_menusystem *, struct s_menuitem *);
|
||||
typedef void (*t_keys_handler)(struct s_menusystem *, struct s_menuitem *,
|
||||
unsigned int scancode);
|
||||
// Last parameter = HIGH BYTE = scan code , LOW BYTE = ASCII CODE
|
||||
|
||||
typedef enum {HDLR_SCREEN, HDLR_KEYS } t_handler;
|
||||
// Types of handlers for menu system
|
||||
|
||||
// TIMEOUT is the list of possible values which can be returned by the handler
|
||||
// instructing the menusystem what to do. The default is CODE_WAIT
|
||||
typedef enum {CODE_WAIT, CODE_ENTER, CODE_ESCAPE } TIMEOUTCODE;
|
||||
typedef TIMEOUTCODE (*t_timeout_handler)(void);
|
||||
|
||||
typedef struct s_menuitem {
|
||||
char *item;
|
||||
char *status;
|
||||
char *data; // string containing kernel to run.. but...
|
||||
// for radio menu's this is a pointer to the item selected or NULL (initially)
|
||||
void * extra_data; // Any other data user can point to
|
||||
t_item_handler handler; // Pointer to function of type menufn
|
||||
t_action action;
|
||||
t_itemdata itemdata; // Data depends on action value
|
||||
unsigned int helpid; // context sensitive help system ID
|
||||
uchar shortcut; // one of [A-Za-z0-9] shortcut for this menu item
|
||||
uchar index; // Index within the menu array
|
||||
uchar parindex; // Index of the menu in which this item appears.
|
||||
} t_menuitem;
|
||||
|
||||
typedef t_menuitem *pt_menuitem; // Pointer to type menuitem
|
||||
|
||||
typedef struct s_menu {
|
||||
pt_menuitem *items; // pointer to array of pointer to menuitems
|
||||
char *title;
|
||||
int maxmenusize; // the size of array allocated
|
||||
uchar numitems; // how many items do we actually have
|
||||
uchar menuwidth;
|
||||
uchar row,col; // Position where this menu should be displayed
|
||||
uchar menuheight; // Maximum number of items to be displayed
|
||||
} t_menu;
|
||||
|
||||
typedef t_menu *pt_menu; // Pointer to type menu
|
||||
|
||||
typedef struct s_menusystem {
|
||||
pt_menu menus[MAXMENUS];
|
||||
char *title;
|
||||
t_menusystem_handler handler; // Menu system handler
|
||||
t_keys_handler keys_handler; // Handler for unknown keys
|
||||
t_timeout_handler ontimeout; // Timeout handler
|
||||
unsigned long tm_numsteps;
|
||||
// Time to wait for key press=numsteps * stepsize milliseconds
|
||||
unsigned int tm_stepsize; // Timeout step size (in milliseconds)
|
||||
|
||||
int maxmenuheight;
|
||||
uchar nummenus;
|
||||
uchar normalattr[2]; // [0] is non-hlite attr, [1] is hlite attr
|
||||
uchar reverseattr[2];
|
||||
uchar inactattr[2];
|
||||
uchar revinactattr[2];
|
||||
uchar statusattr[2];
|
||||
uchar fillchar;
|
||||
uchar fillattr;
|
||||
uchar spacechar;
|
||||
uchar tfillchar;
|
||||
uchar titleattr;
|
||||
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
|
||||
|
||||
// Menu box look
|
||||
boxtype menubt; // What type of boxes should be drawn
|
||||
char box_horiz,box_ltrt,box_rtlt; // Some chars of the box, for redrawing portions of the box
|
||||
|
||||
} t_menusystem;
|
||||
|
||||
typedef t_menusystem *pt_menusystem; // Pointer to type menusystem
|
||||
|
||||
/************************************************************************
|
||||
* IMPORTANT INFORMATION
|
||||
*
|
||||
* All functions which take a string as argument store the pointer
|
||||
* for later use. So if you have alloc'ed a space for the string
|
||||
* and are passing it to any of these functions, DO NOT deallocate it.
|
||||
*
|
||||
* If they are constant strings, you may receive warning from the compiler
|
||||
* about "converting from char const * to char *". Ignore these errors.
|
||||
*
|
||||
* This hack/trick of storing these pointers will help in reducing the size
|
||||
* of the internal structures by a lot.
|
||||
*
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
pt_menuitem showmenus(uchar startmenu);
|
||||
|
||||
pt_menusystem init_menusystem(const char *title);
|
||||
void close_menusystem(); // Deallocate memory used
|
||||
|
||||
void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected);
|
||||
|
||||
void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected);
|
||||
|
||||
void set_status_info(uchar statusattr, uchar statushlite, uchar statline);
|
||||
|
||||
void set_title_info(uchar tfillchar, uchar titleattr);
|
||||
|
||||
void set_misc_info(uchar fillchar, uchar fillattr,uchar spacechar, uchar shadowattr);
|
||||
void set_box_type(boxtype bt);
|
||||
|
||||
void set_window_size(uchar top, uchar left, uchar bot, uchar right); // Set the window which menusystem should use
|
||||
|
||||
void set_menu_options(uchar maxmenuheight);
|
||||
// maximum height of a menu
|
||||
|
||||
void reg_handler(t_handler htype, void * handler); // Register handler
|
||||
|
||||
void unreg_handler( t_handler htype);
|
||||
|
||||
void reg_ontimeout(t_timeout_handler, unsigned int numsteps, unsigned int stepsize);
|
||||
// Set timeout handler, set 0 for default values.
|
||||
// So stepsize=0 means numsteps is measured in centiseconds.
|
||||
void unreg_ontimeout();
|
||||
|
||||
// Create a new menu and return its position
|
||||
uchar add_menu(const char *title, int maxmenusize);
|
||||
|
||||
void set_menu_pos(uchar row,uchar col); // Set the position of this 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);
|
||||
|
||||
// Set shortcut key and help id
|
||||
void set_item_options(uchar shortcut,int helpid);
|
||||
|
||||
// Set the shortcut key for the current item
|
||||
static inline void set_shortcut(uchar shortcut)
|
||||
{
|
||||
set_item_options(shortcut,0xFFFF);
|
||||
}
|
||||
|
||||
// Add a separator to the "current" menu
|
||||
pt_menuitem add_sep();
|
||||
|
||||
// Main function for the user's config file
|
||||
int menumain(char *cmdline);
|
||||
|
||||
#endif
|
||||
140
extra/syslinux-3.09/menu/libmenu/passwords.c
Normal file
140
extra/syslinux-3.09/menu/libmenu/passwords.c
Normal file
@@ -0,0 +1,140 @@
|
||||
/* -*- 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,
|
||||
* Bostom MA 02111-1307, USA; either version 2 of the License, or
|
||||
* (at your option) any later version; incorporated herein by reference.
|
||||
*
|
||||
* ----------------------------------------------------------------------- */
|
||||
|
||||
#include "passwords.h"
|
||||
#include "des.h"
|
||||
#include "string.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "tui.h"
|
||||
|
||||
#define MAX_LINE 512
|
||||
// Max line length in a pwdfile
|
||||
p_pwdentry userdb[MAX_USERS]; // Array of pointers
|
||||
int numusers; // Actual number of users
|
||||
|
||||
// returns true or false, i.e. 1 or 0
|
||||
char authenticate_user(const char * username, const char* pwd)
|
||||
{
|
||||
char salt[12];
|
||||
int i, password_ok;
|
||||
|
||||
password_ok=0;
|
||||
|
||||
for (i=0; i< numusers; i++) {
|
||||
if (userdb[i] == NULL) continue;
|
||||
if (strcmp(username,userdb[i]->username)==0) {
|
||||
strcpy(salt, userdb[i]->pwdhash);
|
||||
salt[2] = '\0';
|
||||
if (strcmp(userdb[i]->pwdhash,crypt(pwd,salt))==0) return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Does user USERNAME have permission PERM
|
||||
char isallowed(const char *username, const char *perm)
|
||||
{
|
||||
int i;
|
||||
char *dperm;
|
||||
char *tmp;
|
||||
|
||||
if (strcmp(username,GUEST_USER) == 0) return 0;
|
||||
dperm = (char *) malloc(strlen(perm)+3);
|
||||
strcpy(dperm+1,perm);
|
||||
dperm[0] = ':';
|
||||
dperm[strlen(perm)+1]=':';
|
||||
dperm[strlen(perm)+2]=0;
|
||||
// Now dperm = ":perm:"
|
||||
for (i=0; i < numusers; i++) {
|
||||
if (strcmp(userdb[i]->username,username)==0) // Found the user
|
||||
{
|
||||
if (userdb[i]->perms == NULL) return 0; // No permission
|
||||
tmp = strstr(userdb[i]->perms,dperm); // Search for permission
|
||||
free (dperm); // Release memory
|
||||
if (tmp == NULL) return 0; else return 1;
|
||||
}
|
||||
}
|
||||
// User not found return 0
|
||||
free (dperm);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Initialise the list of of user passwords permissions from file
|
||||
void init_passwords(const char *filename)
|
||||
{
|
||||
int i;
|
||||
char line[MAX_LINE], *p,*user,*pwdhash,*perms;
|
||||
FILE *f;
|
||||
|
||||
for (i=0; i < MAX_USERS; i++) userdb[i] = NULL;
|
||||
numusers = 0;
|
||||
|
||||
if ( !filename ) return; // No filename specified
|
||||
|
||||
f = fopen(filename,"r");
|
||||
if ( !f ) return; // File does not exist
|
||||
|
||||
// Process each line
|
||||
while ( fgets(line, sizeof line, f) ) {
|
||||
// Replace EOLN with \0
|
||||
p = strchr(line, '\r');
|
||||
if ( p ) *p = '\0';
|
||||
p = strchr(line, '\n');
|
||||
if ( p ) *p = '\0';
|
||||
|
||||
// If comment line or empty ignore line
|
||||
p = line;
|
||||
while (*p==' ') p++; // skip initial spaces
|
||||
if ( (*p == '#') || (*p == '\0')) continue; // Skip comment lines
|
||||
|
||||
user = p; // This is where username starts
|
||||
p = strchr(user,':');
|
||||
if (p == NULL) continue; // Malformed line skip
|
||||
*p = '\0';
|
||||
pwdhash = p+1;
|
||||
if (*pwdhash == 0) continue; // Malformed line (no password specified)
|
||||
p = strchr(pwdhash,':');
|
||||
if (p == NULL) { // No perms specified
|
||||
perms = NULL;
|
||||
} else {
|
||||
*p = '\0';
|
||||
perms = p+1;
|
||||
if (*perms == 0) perms = NULL;
|
||||
}
|
||||
// At this point we have user,pwdhash and perms setup
|
||||
userdb[numusers] = (p_pwdentry)malloc(sizeof(pwdentry));
|
||||
strcpy(userdb[numusers]->username,user);
|
||||
strcpy(userdb[numusers]->pwdhash,pwdhash);
|
||||
if (perms == NULL)
|
||||
userdb[numusers]->perms = NULL;
|
||||
else {
|
||||
userdb[numusers]->perms = (char *)malloc(strlen(perms)+3);
|
||||
(userdb[numusers]->perms)[0] = ':';
|
||||
strcpy(userdb[numusers]->perms + 1,perms);
|
||||
(userdb[numusers]->perms)[strlen(perms)+1] = ':';
|
||||
(userdb[numusers]->perms)[strlen(perms)+2] = 0;
|
||||
// Now perms field points to ":perms:"
|
||||
}
|
||||
numusers++;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void close_passwords()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < numusers; i++)
|
||||
if (userdb[i] != NULL) free(userdb[i]);
|
||||
numusers = 0;
|
||||
}
|
||||
27
extra/syslinux-3.09/menu/libmenu/passwords.h
Normal file
27
extra/syslinux-3.09/menu/libmenu/passwords.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef _PASSWORDS_H_
|
||||
#define _PASSWORDS_H_
|
||||
|
||||
char authenticate_user(const char * username, const char* pwd);
|
||||
|
||||
char isallowed(const char *username, const char * perm);
|
||||
|
||||
// Initialise the list of of user passwords permissions from file
|
||||
void init_passwords(const char *filename);
|
||||
// Free all space used for internal data structures
|
||||
void close_passwords();
|
||||
|
||||
#define MAX_USERS 128 // Maximum number of users
|
||||
#define USERNAME_LENGTH 12 // Max length of user name
|
||||
#define PWDHASH_LENGTH 40 // Max lenght of pwd hash
|
||||
|
||||
typedef struct {
|
||||
char username[USERNAME_LENGTH+1];
|
||||
char pwdhash[PWDHASH_LENGTH+1];
|
||||
char *perms; // pointer to string containing ":" delimited permissions
|
||||
} pwdentry;
|
||||
|
||||
typedef pwdentry *p_pwdentry;
|
||||
|
||||
#define GUEST_USER "guest"
|
||||
|
||||
#endif
|
||||
75
extra/syslinux-3.09/menu/libmenu/scancodes.h
Normal file
75
extra/syslinux-3.09/menu/libmenu/scancodes.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/* -*- 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
|
||||
|
||||
#endif
|
||||
44
extra/syslinux-3.09/menu/libmenu/syslnx.c
Normal file
44
extra/syslinux-3.09/menu/libmenu/syslnx.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* -*- 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.
|
||||
*
|
||||
* ----------------------------------------------------------------------- */
|
||||
|
||||
#include <string.h>
|
||||
#include <com32.h>
|
||||
#include "syslnx.h"
|
||||
|
||||
com32sys_t inreg,outreg; // Global registers for this module
|
||||
|
||||
char issyslinux(void)
|
||||
{
|
||||
REG_EAX(inreg) = 0x00003000;
|
||||
REG_EBX(inreg) = REG_ECX(inreg) = REG_EDX(inreg) = 0xFFFFFFFF;
|
||||
__intcall(0x21,&inreg,&outreg);
|
||||
return (REG_EAX(outreg) == 0x59530000) &&
|
||||
(REG_EBX(outreg) == 0x4c530000) &&
|
||||
(REG_ECX(outreg) == 0x4e490000) &&
|
||||
(REG_EDX(outreg) == 0x58550000);
|
||||
}
|
||||
|
||||
void runsyslinuxcmd(const char *cmd)
|
||||
{
|
||||
strcpy(__com32.cs_bounce, cmd);
|
||||
REG_AX(inreg) = 0x0003; // Run command
|
||||
REG_BX(inreg) = OFFS(__com32.cs_bounce);
|
||||
inreg.es = SEG(__com32.cs_bounce);
|
||||
__intcall(0x22, &inreg, &outreg);
|
||||
}
|
||||
|
||||
void gototxtmode(void)
|
||||
{
|
||||
REG_AX(inreg) = 0x0005;
|
||||
__intcall(0x22,&inreg,&outreg);
|
||||
}
|
||||
|
||||
47
extra/syslinux-3.09/menu/libmenu/syslnx.h
Normal file
47
extra/syslinux-3.09/menu/libmenu/syslnx.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/* -*- 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 __SYSLNX_H__
|
||||
#define __SYSLNX_H__
|
||||
|
||||
#include <com32.h>
|
||||
|
||||
//Macros which help user not have to remember the structure of register
|
||||
// Data structure
|
||||
|
||||
#define REG_AH(x) ((x).eax.b[1])
|
||||
#define REG_AL(x) ((x).eax.b[0])
|
||||
#define REG_AX(x) ((x).eax.w[0])
|
||||
#define REG_EAX(x) ((x).eax.l)
|
||||
|
||||
#define REG_BH(x) ((x).ebx.b[1])
|
||||
#define REG_BL(x) ((x).ebx.b[0])
|
||||
#define REG_BX(x) ((x).ebx.w[0])
|
||||
#define REG_EBX(x) ((x).ebx.l)
|
||||
|
||||
#define REG_CH(x) ((x).ecx.b[1])
|
||||
#define REG_CL(x) ((x).ecx.b[0])
|
||||
#define REG_CX(x) ((x).ecx.w[0])
|
||||
#define REG_ECX(x) ((x).ecx.l)
|
||||
|
||||
#define REG_DH(x) ((x).edx.b[1])
|
||||
#define REG_DL(x) ((x).edx.b[0])
|
||||
#define REG_DX(x) ((x).edx.w[0])
|
||||
#define REG_EDX(x) ((x).edx.l)
|
||||
|
||||
char issyslinux(void); /* Check if syslinux is running */
|
||||
|
||||
void runsyslinuxcmd(const char *cmd); /* Run specified command */
|
||||
|
||||
void gototxtmode(void); /* Change mode to text mode */
|
||||
|
||||
#endif
|
||||
360
extra/syslinux-3.09/menu/libmenu/tui.c
Normal file
360
extra/syslinux-3.09/menu/libmenu/tui.c
Normal file
@@ -0,0 +1,360 @@
|
||||
/* -*- 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.
|
||||
*
|
||||
* ----------------------------------------------------------------------- */
|
||||
|
||||
#include <string.h>
|
||||
#include <com32.h>
|
||||
#include "tui.h"
|
||||
#include "syslnx.h"
|
||||
#include "com32io.h"
|
||||
#include "scancodes.h"
|
||||
#include <stdlib.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
|
||||
// showoldvalue <> 0 implies currentvalue displayed first
|
||||
// If showoldvalue <> 0 then caller responsibility to ensure that
|
||||
// str is NULL terminated.
|
||||
void getuserinput(char *stra, unsigned int size, unsigned int password,
|
||||
unsigned int showoldvalue)
|
||||
{
|
||||
unsigned char c,scan;
|
||||
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
|
||||
getcursorshape(&start,&end);
|
||||
insmode = 1;
|
||||
|
||||
str = (char *)malloc(size+1); // Allocate memory to store user input
|
||||
memset(str,0,size+1); // Zero it out
|
||||
if (password != 0) showoldvalue = 0; // Password's never displayed
|
||||
|
||||
if (showoldvalue != 0) strcpy(str,stra); // If show old value copy current value
|
||||
|
||||
last = str;
|
||||
while (*last) {last++;} // Find the terminating null byte
|
||||
p = str+ strlen(str);
|
||||
|
||||
if (insmode == 0)
|
||||
setcursorshape(1,7); // Block cursor
|
||||
else setcursorshape(6,7); // Normal cursor
|
||||
|
||||
// Invariants: p is the current char
|
||||
// col is the corresponding column on the screen
|
||||
if (password == 0) // Not a password, print initial value
|
||||
{
|
||||
gotoxy(row,col,page);
|
||||
csprint(str,GETSTRATTR);
|
||||
}
|
||||
while (1) { // Do forever
|
||||
c = inputc(&scan);
|
||||
if (c == '\r') break; // User hit Enter getout of loop
|
||||
if (scan == ESCAPE) // User hit escape getout and nullify string
|
||||
{ *str = 0;
|
||||
break;
|
||||
}
|
||||
fudge = 0;
|
||||
// if scan code is regognized do something
|
||||
// else if char code is recognized do something
|
||||
// else ignore
|
||||
switch(scan) {
|
||||
case HOMEKEY:
|
||||
p = str;
|
||||
break;
|
||||
case ENDKEY:
|
||||
p = last;
|
||||
break;
|
||||
case LTARROW:
|
||||
if (p > str) p--;
|
||||
break;
|
||||
case CTRLLT:
|
||||
if (p==str) break;
|
||||
if (*p == ' ')
|
||||
while ((p > str) && (*p == ' ')) p--;
|
||||
else {
|
||||
if (*(p-1) == ' ') {
|
||||
p--;
|
||||
while ((p > str) && (*p == ' ')) p--;
|
||||
}
|
||||
}
|
||||
while ((p > str) && ((*p == ' ') || (*(p-1) != ' '))) p--;
|
||||
break;
|
||||
case RTARROW:
|
||||
if (p < last) p++;
|
||||
break;
|
||||
case CTRLRT:
|
||||
if (*p==0) break; // At end of string
|
||||
if (*p != ' ')
|
||||
while ((*p!=0) && (*p != ' ')) p++;
|
||||
while ((*p!=0) && ((*p == ' ') && (*(p+1) != ' '))) p++;
|
||||
if (*p==' ') p++;
|
||||
break;
|
||||
case DELETE:
|
||||
q = p;
|
||||
while (*(q+1)) {*q = *(q+1); q++; }
|
||||
if (last > str) last--;
|
||||
fudge = 1;
|
||||
break;
|
||||
case 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
|
||||
q=p;
|
||||
while ( q <= last ) { *(q-1)=*q; q++;}
|
||||
if (last > str) last--;
|
||||
if (p > str) p--;
|
||||
fudge = 1;
|
||||
break;
|
||||
case '\x15': /* Ctrl-U: kill input */
|
||||
fudge = last-str;
|
||||
while ( p > str ) *p--=0;
|
||||
p = str; *p=0; last = str;
|
||||
break;
|
||||
default: // Handle insert and overwrite mode
|
||||
if ((c >= ' ') && (c < 128) &&
|
||||
((unsigned int)(p-str) < size-1) ) {
|
||||
if (insmode == 0) { // Overwrite mode
|
||||
if (p==last) last++;
|
||||
*last = 0;
|
||||
*p++ = c;
|
||||
} else { // Insert mode
|
||||
if (p==last) { // last char
|
||||
last++;
|
||||
*last=0;
|
||||
*p++=c;
|
||||
} else { // Non-last char
|
||||
q=last++;
|
||||
while (q >= p) { *q=*(q-1); q--;}
|
||||
*p++=c;
|
||||
}
|
||||
}
|
||||
}
|
||||
else beep();
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Now the string has been modified, print it
|
||||
if (password == 0) {
|
||||
gotoxy(row,col,page);
|
||||
csprint(str,GETSTRATTR);
|
||||
if (fudge > 0) cprint(' ',GETSTRATTR,fudge,page);
|
||||
gotoxy(row,col+(p-str),page);
|
||||
}
|
||||
}
|
||||
*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) strcpy(stra,str);
|
||||
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
|
||||
// the values of BOX_TOPLEFT,... in the header file
|
||||
|
||||
unsigned char SINSIN_CHARS[] = {218,192,191,217, //Corners
|
||||
196,179, // Horiz and Vertical
|
||||
195,180,194,193,197}; // Connectors & Middle
|
||||
|
||||
unsigned char DBLDBL_CHARS[] = {201,200,187,188, // Corners
|
||||
205,186, // Horiz and Vertical
|
||||
199,182,203,202,206}; // Connectors & Middle
|
||||
|
||||
unsigned char SINDBL_CHARS[] = {214,211,183,189, // Corners
|
||||
196,186, // Horiz & Vert
|
||||
199,182,210,208,215}; // Connectors & Middle
|
||||
|
||||
unsigned char DBLSIN_CHARS[] = {213,212,184,190, // Corners
|
||||
205,179, // Horiz & Vert
|
||||
198,181,209,207,216}; // Connectors & Middle
|
||||
|
||||
unsigned char * getboxchars(boxtype bt)
|
||||
{
|
||||
switch (bt)
|
||||
{
|
||||
case BOX_SINSIN:
|
||||
return SINSIN_CHARS;
|
||||
break;
|
||||
case BOX_DBLDBL:
|
||||
return DBLDBL_CHARS;
|
||||
break;
|
||||
case BOX_SINDBL:
|
||||
return SINDBL_CHARS;
|
||||
break;
|
||||
case BOX_DBLSIN:
|
||||
return DBLSIN_CHARS;
|
||||
break;
|
||||
default:
|
||||
return SINSIN_CHARS;
|
||||
break;
|
||||
}
|
||||
return SINSIN_CHARS;
|
||||
}
|
||||
|
||||
// Draw box and lines
|
||||
void drawbox(char top,char left,char bot, char right,
|
||||
char page, char attr,boxtype bt)
|
||||
{
|
||||
unsigned char *box_chars; // pointer to array of box chars
|
||||
unsigned char x;
|
||||
|
||||
box_chars = getboxchars(bt);
|
||||
// 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);
|
||||
// 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);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
void drawhorizline(char top, char left, char right, char page, char attr,
|
||||
boxtype bt, char dumb)
|
||||
{
|
||||
unsigned char start,end;
|
||||
unsigned char *box_chars = getboxchars(bt);
|
||||
if (dumb==0) {
|
||||
start = left+1;
|
||||
end = right-1;
|
||||
} else {
|
||||
start = left;
|
||||
end = right;
|
||||
}
|
||||
gotoxy(top,start,page);
|
||||
cprint(box_chars[BOX_HORIZ],attr,end-start+1,page);
|
||||
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);
|
||||
}
|
||||
}
|
||||
85
extra/syslinux-3.09/menu/libmenu/tui.h
Normal file
85
extra/syslinux-3.09/menu/libmenu/tui.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/* -*- 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 __TUI_H__
|
||||
#define __TUI_H__
|
||||
|
||||
#include <com32.h>
|
||||
#include "com32io.h"
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
#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 */
|
||||
|
||||
// Generic user input,
|
||||
// password = 0 iff chars echoed on screen
|
||||
// showoldvalue <> 0 iff current displayed for editing
|
||||
void getuserinput(char *str, unsigned int size,
|
||||
unsigned int password, unsigned int showoldvalue);
|
||||
|
||||
static inline void getstring(char *str, unsigned int size)
|
||||
{
|
||||
getuserinput(str,size,0,0);
|
||||
}
|
||||
|
||||
static inline void editstring(char *str, unsigned int size)
|
||||
{
|
||||
getuserinput(str,size,0,1);
|
||||
}
|
||||
|
||||
static inline void getpwd(char * str, unsigned int size)
|
||||
{
|
||||
getuserinput(str,size,1,0);
|
||||
}
|
||||
|
||||
// Box drawing Chars offsets into array
|
||||
#define BOX_TOPLEFT 0x0
|
||||
#define BOX_BOTLEFT 0x1
|
||||
#define BOX_TOPRIGHT 0x2
|
||||
#define BOX_BOTRIGHT 0x3
|
||||
#define BOX_TOP 0x4 // TOP = BOT = HORIZ
|
||||
#define BOX_BOT 0x4
|
||||
#define BOX_HORIZ 0x4
|
||||
#define BOX_LEFT 0x5
|
||||
#define BOX_RIGHT 0x5
|
||||
#define BOX_VERT 0x5 // LEFT=RIGHT=VERT
|
||||
#define BOX_LTRT 0x6
|
||||
#define BOX_RTLT 0x7
|
||||
#define BOX_TOPBOT 0x8
|
||||
#define BOX_BOTTOP 0x9
|
||||
#define BOX_MIDDLE 0xA
|
||||
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user