diff options
author | hpa <hpa> | 2004-02-03 05:42:25 +0000 |
---|---|---|
committer | hpa <hpa> | 2004-02-03 05:42:25 +0000 |
commit | dfd8bb83c7fd3f0d8c3b0caf6335d376c55732d1 (patch) | |
tree | d0021ca8fe28a76d3e680033997127426953151e /menu | |
parent | 5e4b11cb257f5137062690473ec3fe79a928141b (diff) | |
download | syslinux-dfd8bb83c7fd3f0d8c3b0caf6335d376c55732d1.tar.gz |
Make it all work better... remove use of DOS routines while expecting
attributes to be unchanged; create a wrapper routine for start.
Diffstat (limited to 'menu')
-rw-r--r-- | menu/Makefile | 2 | ||||
-rw-r--r-- | menu/biosio.c | 79 | ||||
-rw-r--r-- | menu/biosio.h | 6 | ||||
-rw-r--r-- | menu/complex.c | 11 | ||||
-rw-r--r-- | menu/main.c | 37 | ||||
-rw-r--r-- | menu/menu.c | 551 | ||||
-rw-r--r-- | menu/menu.h | 13 | ||||
-rw-r--r-- | menu/simple.c | 8 | ||||
-rw-r--r-- | menu/string.c | 9 | ||||
-rw-r--r-- | menu/string.h | 2 | ||||
-rw-r--r-- | menu/syslinux.c | 8 | ||||
-rw-r--r-- | menu/syslinux.h | 8 |
12 files changed, 377 insertions, 357 deletions
diff --git a/menu/Makefile b/menu/Makefile index 7e938112..7b1654d3 100644 --- a/menu/Makefile +++ b/menu/Makefile @@ -12,7 +12,7 @@ LD = ld -m elf_i386 OBJCOPY = objcopy RANLIB = ranlib -LIBMENU = biosio.o16 string.o16 menu.o16 syslinux.o16 +LIBMENU = main.o16 biosio.o16 string.o16 menu.o16 syslinux.o16 MENUS = simple.com complex.com diff --git a/menu/biosio.c b/menu/biosio.c index faa63c96..95cb0387 100644 --- a/menu/biosio.c +++ b/menu/biosio.c @@ -13,34 +13,9 @@ #include "string.h" #include "biosio.h" -static inline void asm_putchar(char x) -{ - asm volatile("int $0x21" : : "a" (x + 0x0200)); -} - -static inline void asm_sprint(const char *str) -{ - asm volatile("movb $0x09,%%ah ; int $0x21" : : "d" (str) : "eax"); -} - /* BIOS Assisted output routines */ -void csprint(char *str) // Print a C str (NULL terminated) -{ - int o,l; - - o = (long)(str) & 0xffff; // Offset of location - l = strlen(str); - str[l] = '$'; // Replace \0 with $ - asm_sprint(str); - str[l] = '\0'; // Change it back. -} - -void sprint(const char *str) -{ - asm_sprint(str); -} - +/* Print character and attribute at cursor */ static inline void asm_cprint(char chr, char attr, int times, char disppage) { asm volatile("movb $0x09,%%ah ; int $0x10" @@ -66,9 +41,11 @@ void setdisppage(char num) // Set the display page to specified number static inline char asm_getdisppage(void) { - register char page asm("%bh"); + char page; - asm("movb $0x0f,%%ah ; int $0x10" : "=r" (page) : : "eax"); + asm("movb $0x0f,%%ah ; " + "int $0x10 ; " + "movb %%bh,%0" : "=rm" (page) : : "eax", "ebp"); return page; } @@ -77,7 +54,26 @@ char getdisppage() // Get current display page return asm_getdisppage(); } -void clearwindow(char top,char left,char bot,char right, char page,char fillchar, char fillattr) +static inline void asm_putchar(char x, char page) +{ + asm volatile("movb %1,%%bh ; movb $0x0e,%%ah ; int $0x10" + : "+a" (x) + : "g" (page) + : "ebx", "ebp"); +} + +/* Print a C string (NUL-terminated) */ +void csprint(const char *str) +{ + char page = asm_getdisppage(); + + while ( *str ) { + asm_putchar(*str, 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++) @@ -94,10 +90,11 @@ void cls(void) static inline void asm_gotoxy(char row,char col, char page) { - asm volatile("movb $0x02,%%ah ; " + asm volatile("movb %1,%%bh ; " + "movb $0x02,%%ah ; " "int $0x10" - : : "d" ((row << 8) + col), "b" (page << 8) - : "eax"); + : : "d" ((row << 8) + col), "g" (page) + : "eax", "ebx"); } void gotoxy(char row,char col, char page) @@ -107,13 +104,14 @@ void gotoxy(char row,char col, char page) static inline void asm_getpos(char *row, char *col, char page) { - asm("movb $0x03,%%ah ; " + asm("movb %2,%%bh ; " + "movb $0x03,%%ah ; " "int $0x10 ; " "movb %%dh,%0 ; " "movb %%dl,%1" : "=m" (*row), "=m" (*col) - : "b" (page << 8) - : "eax", "ecx", "edx"); + : "g" (page) + : "eax", "ebx", "ecx", "edx"); } void getpos(char * row, char * col, char page) @@ -140,7 +138,7 @@ char inputc(char * scancode) return asm_inputc(scancode); } -void asm_cursorshape(char start, char end) +static inline void asm_cursorshape(char start, char end) { asm volatile("movb $0x01,%%ah ; int $0x10" : : "c" ((start << 8) + end) : "eax"); @@ -148,7 +146,7 @@ void asm_cursorshape(char start, char end) void cursoroff(void) { - asm_cursorshape(31,31); + asm_cursorshape(32,32); } void cursoron(void) @@ -174,6 +172,7 @@ void getstring(char *str, unsigned int size) { char c; char *p = str; + char page = asm_getdisppage(); while ( (c = asm_getchar()) != '\r' ) { switch (c) { @@ -183,19 +182,19 @@ void getstring(char *str, unsigned int size) case '\b': if ( p > str ) { p--; - sprint("\b \b$"); + csprint("\b \b"); } break; case '\x15': /* Ctrl-U: kill input */ while ( p > str ) { p--; - sprint("\b \b$"); + csprint("\b \b"); } break; default: if ( c >= ' ' && (unsigned int)(p-str) < size-1 ) { *p++ = c; - asm_putchar(c); + asm_putchar(c, page); } break; } diff --git a/menu/biosio.h b/menu/biosio.h index b090266a..719a8e15 100644 --- a/menu/biosio.h +++ b/menu/biosio.h @@ -25,9 +25,7 @@ /* BIOS Assisted output routines */ -void csprint(char *str); // Print a C str (NULL terminated) - -void sprint(const char *str); // Print a $ terminated string +void csprint(const char *str); // Print a C str (NUL-terminated) void cprint(char chr,char attr,int times,char disppage); // Print a char @@ -37,7 +35,7 @@ char getdisppage(); // Get current display page void clearwindow(char top,char left,char bot,char right, char page,char fillchar, char fillattr); -void cls(); +void cls(void); void gotoxy(char row,char col, char page); diff --git a/menu/complex.c b/menu/complex.c index 04aefce2..c0bb30bd 100644 --- a/menu/complex.c +++ b/menu/complex.c @@ -21,7 +21,6 @@ /* Global variables */ char infoline[160]; -char syslinux; // Is syslinux running? struct { unsigned int baseurl : 1; // Do we need to specify by url @@ -59,7 +58,7 @@ void msys_handler(t_menusystem *ms, t_menuitem *mi) gotoxy(21,0,ms->menupage); cprint(ms->spacechar,ms->statusattr,80,ms->menupage); gotoxy(20,0,ms->menupage); - sprint("Kernel Arguments:$"); + csprint("Kernel Arguments:"); gotoxy(20,17,ms->menupage); csprint(infoline); } @@ -111,7 +110,7 @@ void checkbox_handler(t_menusystem *ms, t_menuitem *mi) if (strcmp(mi->data,"dhcp") == 0) flags.dhcp = (mi->itemdata.checked ? 1 : 0); } -int main(void) +int menumain(void) { t_menuitem * curr; char cmdline[160]; @@ -167,10 +166,6 @@ int main(void) add_item("Testing...","Options to test hardware",OPT_SUBMENU,NULL,TESTING); add_item("Exit to prompt", "Exit the menu system", OPT_EXITMENU, "exit", 0); - syslinux = issyslinux(); // Find if syslinux is running - //if (syslinux) sprint("Syslinux is running!\r\n$"); else sprint("Nope its not.\r\n$"); - - if (syslinux) gototxtmode(); // Else assume we are running in a DOS box curr = showmenus(MAIN); if (curr) { @@ -183,7 +178,7 @@ int main(void) strcat(cmdline,infoline); if (flags.network && !flags.dhcp) // We want static { - sprint("Enter IP address (last two octets only): $"); + csprint("Enter IP address (last two octets only): "); getstring(ip, sizeof ip); strcat(cmdline,"ipaddr=128.135."); strcat(cmdline,ip); diff --git a/menu/main.c b/menu/main.c new file mode 100644 index 00000000..63765c0c --- /dev/null +++ b/menu/main.c @@ -0,0 +1,37 @@ +/* -*- c -*- ------------------------------------------------------------- * + * + * Copyright 2004 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. + * + * ----------------------------------------------------------------------- */ + +#ifndef NULL +#define NULL ((void *) 0) +#endif + +#include "menu.h" +#include "biosio.h" +#include "string.h" +#include "syslinux.h" + +int syslinux; + +int main(void) +{ + int rv; + int origpage; + char r,c; + + syslinux = issyslinux(); /* Find if syslinux is running */ + if (syslinux) gototxtmode(); /* (else assume we are running in DOS) */ + + rv = menumain(); /* Run the actual menu system */ + + return rv; +} + diff --git a/menu/menu.c b/menu/menu.c index 74acad0e..26d6b17f 100644 --- a/menu/menu.c +++ b/menu/menu.c @@ -1,265 +1,272 @@ -/* -*- c -*- ------------------------------------------------------------- * - * - * Copyright 2004 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 "biosio.h" -#include "string.h" -#include "menu.h" - -// Structures - -// Declare a menusystem here -static t_menusystem menusystem; - -/* Basic Menu routines */ - -void drawbox(char top, char left, char bot, char right,char attr, char page) -{ - char x; - - // Top border - gotoxy(top,left,page); - cprint(TOPLEFT,attr,1,page); - gotoxy(top,left+1,page); - cprint(TOP,attr,right-left,page); - gotoxy(top,right,page); - cprint(TOPRIGHT,attr,1,page); - // Bottom border - gotoxy(bot,left,page); - cprint(BOTLEFT,attr,1,page); - gotoxy(bot,left+1,page); - cprint(BOT,attr,right-left,page); - gotoxy(bot,right,page); - cprint(BOTRIGHT,attr,1,page); - // Left & right borders - for (x=top+1; x < bot; x++) - { - gotoxy(x,left,page); - cprint(LEFT,attr,1,page); - gotoxy(x,right,page); - cprint(RIGHT,attr,1,page); - } -} - -void printmenu(t_menu * menu, int curr, char top, char left) -{ - int x; - int numitems,menuwidth; - t_menusystem *ms; - char attr; - - ms = & menusystem; - numitems = menu->numitems; - menuwidth = menu->menuwidth+2; - clearwindow(top,left-1,top+numitems+1,left+menuwidth+1,ms->menupage,ms->fillchar,ms->shadowattr); - drawbox(top-1,left-2,top+numitems,left+menuwidth,ms->normalattr,ms->menupage); - // Menu title - x = (menuwidth - strlen(menu->title) - 1) >> 1; - gotoxy(top-1,left+x,ms->menupage); - sprint(menu->title); - for (x=0; x < numitems; x++) - { - gotoxy(top+x,left-1,ms->menupage); - if (menu->items[x].action == OPT_INACTIVE) - { - attr = (x==curr? ms->revinactattr : ms->inactattr); - } else { - attr = (x==curr ? ms->reverseattr : ms->normalattr); - } - cprint(ms->spacechar,attr,menuwidth+1,ms->menupage); - gotoxy(top+x,left,ms->menupage); - sprint(menu->items[x].item); - gotoxy(top+x,left+menuwidth-1,ms->menupage); // Last char if any - switch (menu->items[x].action) - { - case OPT_SUBMENU: - cprint(SUBMENUCHAR,attr,1,ms->menupage); - break; - case OPT_CHECKBOX: - cprint( (menu->items[x].itemdata.checked ? CHECKED : UNCHECKED),attr,1,ms->menupage); - break; - } - } - if (menusystem.handler) menusystem.handler(&menusystem,menu->items+curr); -} - -void cleanupmenu(t_menu *menu, char top,char left) -{ - t_menusystem *ms = &menusystem; - clearwindow(top,left-1,top+menu->numitems+1,left+menu->menuwidth+3,ms->menupage,ms->fillchar,ms->fillattr); // Clear the shadow - clearwindow(top-1,left-2,top+menu->numitems,left+menu->menuwidth+2,ms->menupage,ms->fillchar,ms->fillattr); // clear the main window -} - -/* Handle one menu */ -t_menuitem * getmenuoption( t_menu *menu, char top, char left, char startopt) -// Return item chosen or NULL if ESC was hit. -{ - int curr; - char asc,scan; - char numitems; - t_menusystem *ms; - t_menuitem *ci; // Current item - - ms = & menusystem; - numitems = menu->numitems; - // Setup status line - gotoxy(ms->statline,0,ms->menupage); - cprint(ms->spacechar,ms->reverseattr,80,ms->menupage); - - // Initialise current menu item - curr = startopt; - gotoxy(ms->statline,0,ms->menupage); - cprint(ms->spacechar,ms->statusattr,80,1); - gotoxy(ms->statline,0,ms->menupage); - sprint(menu->items[curr].status); - while (1) // Forever - { - printmenu(menu,curr,top,left); - ci = &(menu->items[curr]); - asc = inputc(&scan); - switch (scan) - { - case HOMEKEY: - curr = 0; - break; - case ENDKEY: - curr = numitems -1; - break; - case PAGEDN: - curr += 5; - break; - case PAGEUP: - curr -= 5; - break; - case UPARROW: - curr --; - break; - case DNARROW: - curr++; - break; - case LTARROW: - case ESCAPE: - return NULL; - break; - case ENTERA: - case RTARROW: - case ENTERB: - if (ci->action == OPT_INACTIVE) break; - if (ci->action == OPT_CHECKBOX) break; - if (ci->action == OPT_EXITMENU) return NULL; // As if we hit Esc - return ci; - break; - case SPACEKEY: - if (ci->action != OPT_CHECKBOX) break; - ci->itemdata.checked = !ci->itemdata.checked; - // Call handler to see it anything needs to be done - if (ci->handler != NULL) ci->handler(&menusystem,ci); - break; - } - // Adjust within range - if (curr < 0) curr=0; - if (curr >= numitems) curr = numitems -1; - // Update status line - gotoxy(ms->statline,0,ms->menupage); - cprint(ms->spacechar,ms->statusattr,80,ms->menupage); - sprint(menu->items[curr].status); + /* -*- c -*- ------------------------------------------------------------- * + * + * Copyright 2004 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 "biosio.h" + #include "string.h" + #include "menu.h" + + // Structures + + // Declare a menusystem here + static t_menusystem menusystem; + + /* Basic Menu routines */ + + void drawbox(char top, char left, char bot, char right,char attr, char page) + { + char x; + + // Top border + gotoxy(top,left,page); + cprint(TOPLEFT,attr,1,page); + gotoxy(top,left+1,page); + cprint(TOP,attr,right-left,page); + gotoxy(top,right,page); + cprint(TOPRIGHT,attr,1,page); + // Bottom border + gotoxy(bot,left,page); + cprint(BOTLEFT,attr,1,page); + gotoxy(bot,left+1,page); + cprint(BOT,attr,right-left,page); + gotoxy(bot,right,page); + cprint(BOTRIGHT,attr,1,page); + // Left & right borders + for (x=top+1; x < bot; x++) + { + gotoxy(x,left,page); + cprint(LEFT,attr,1,page); + gotoxy(x,right,page); + cprint(RIGHT,attr,1,page); + } + } + + void printmenu(t_menu * menu, int curr, char top, char left) + { + int x; + int numitems,menuwidth; + t_menusystem *ms; + char attr; + + ms = & menusystem; + numitems = menu->numitems; + menuwidth = menu->menuwidth+2; + clearwindow(top,left-1,top+numitems+1,left+menuwidth+1,ms->menupage,ms->fillchar,ms->shadowattr); + drawbox(top-1,left-2,top+numitems,left+menuwidth,ms->normalattr,ms->menupage); + // Menu title + x = (menuwidth - strlen(menu->title) - 1) >> 1; + gotoxy(top-1,left+x,ms->menupage); + csprint(menu->title); + for (x=0; x < numitems; x++) + { + gotoxy(top+x,left-1,ms->menupage); + if (menu->items[x].action == OPT_INACTIVE) + { + attr = (x==curr? ms->revinactattr : ms->inactattr); + } else { + attr = (x==curr ? ms->reverseattr : ms->normalattr); + } + cprint(ms->spacechar,attr,menuwidth+1,ms->menupage); + gotoxy(top+x,left,ms->menupage); + csprint(menu->items[x].item); + gotoxy(top+x,left+menuwidth-1,ms->menupage); // Last char if any + switch (menu->items[x].action) + { + case OPT_SUBMENU: + cprint(SUBMENUCHAR,attr,1,ms->menupage); + break; + case OPT_CHECKBOX: + cprint( (menu->items[x].itemdata.checked ? CHECKED : UNCHECKED),attr,1,ms->menupage); + break; + } + } + if (menusystem.handler) menusystem.handler(&menusystem,menu->items+curr); + } + + void cleanupmenu(t_menu *menu, char top,char left) + { + t_menusystem *ms = &menusystem; + clearwindow(top,left-1,top+menu->numitems+1,left+menu->menuwidth+3,ms->menupage,ms->fillchar,ms->fillattr); // Clear the shadow + clearwindow(top-1,left-2,top+menu->numitems,left+menu->menuwidth+2,ms->menupage,ms->fillchar,ms->fillattr); // clear the main window + } + + /* Handle one menu */ + t_menuitem * getmenuoption( t_menu *menu, char top, char left, char startopt) + // Return item chosen or NULL if ESC was hit. + { + int curr; + char asc,scan; + char numitems; + t_menusystem *ms; + t_menuitem *ci; // Current item + + ms = & menusystem; + numitems = menu->numitems; + // Setup status line + gotoxy(ms->statline,0,ms->menupage); + cprint(ms->spacechar,ms->reverseattr,80,ms->menupage); + + // Initialise current menu item + curr = startopt; + gotoxy(ms->statline,0,ms->menupage); + cprint(ms->spacechar,ms->statusattr,80,1); + gotoxy(ms->statline,0,ms->menupage); + csprint(menu->items[curr].status); + while (1) // Forever + { + printmenu(menu,curr,top,left); + ci = &(menu->items[curr]); + asc = inputc(&scan); + switch (scan) + { + case HOMEKEY: + curr = 0; + break; + case ENDKEY: + curr = numitems -1; + break; + case PAGEDN: + curr += 5; + break; + case PAGEUP: + curr -= 5; + break; + case UPARROW: + curr --; + break; + case DNARROW: + curr++; + break; + case LTARROW: + case ESCAPE: + return NULL; + break; + case ENTERA: + case RTARROW: + case ENTERB: + if (ci->action == OPT_INACTIVE) break; + if (ci->action == OPT_CHECKBOX) break; + if (ci->action == OPT_EXITMENU) return NULL; // As if we hit Esc + return ci; + break; + case SPACEKEY: + if (ci->action != OPT_CHECKBOX) break; + ci->itemdata.checked = !ci->itemdata.checked; + // Call handler to see it anything needs to be done + if (ci->handler != NULL) ci->handler(&menusystem,ci); + break; + } + // Adjust within range + if (curr < 0) curr=0; + if (curr >= numitems) curr = numitems -1; + // Update status line + gotoxy(ms->statline,0,ms->menupage); + cprint(ms->spacechar,ms->statusattr,80,ms->menupage); + csprint(menu->items[curr].status); + } + return NULL; // Should never come here + } + + /* Handle the entire system of menu's. */ + t_menuitem * runmenusystem(char top, char left, int currmenu) + /* + * currmenu + * Which menu should be currently displayed + * top,left + * What is the position of the top,left corner of the menu + * + * Return Value: + * Returns a pointer to the final item chosen, or NULL if nothing chosen. + */ + { + t_menu *cmenu; + t_menusystem *ms = &menusystem; + t_menuitem *opt,*choice; + int numitems; + char startopt; + + startopt = 0; + startover: + cmenu = (menusystem.menus+currmenu); + numitems = menusystem.menus[currmenu].numitems; + opt = getmenuoption(cmenu,top,left,startopt); + if (opt == NULL) + { + // User hit Esc + cleanupmenu(cmenu,top,left); + return NULL; + } + if (opt->action != OPT_SUBMENU) // We are done with the menu system + { + cleanupmenu(cmenu,top,left); + return opt; // parent cleanup other menus + } + if (opt->itemdata.submenunum >= menusystem.nummenus) // This is Bad.... + { + gotoxy(12,12,ms->menupage); // Middle of screen + csprint("Invalid submenu requested. Ask administrator to correct this."); + cleanupmenu(cmenu,top,left); + return NULL; // Pretend user hit esc + } + // Call recursively for submenu + // Position the submenu below the current item, + // covering half the current window (horizontally) + choice = runmenusystem(top+opt->index+2, left+3+(cmenu->menuwidth >> 1), opt->itemdata.submenunum); + if (choice==NULL) // User hit Esc in submenu + { + // Startover + startopt = opt->index; + goto startover; + } + else + { + cleanupmenu(cmenu,top,left); + return choice; + } + } + + /* User Callable functions */ + + t_menuitem * showmenus(char startmenu) + { + t_menuitem *rv; + t_menusystem *ms; + char oldpage, tpos; + char oldrow, oldcol; + + ms = & menusystem; + // Setup screen for menusystem + oldpage = getdisppage(); + getpos(&oldrow, &oldcol, oldpage); + setdisppage(ms->menupage); + clearwindow(0,0,24,79,ms->menupage,ms->fillchar,ms->fillattr); + tpos = (80 - strlen(menusystem.title) - 1) >> 1; // To center it on line + gotoxy(0,0,ms->menupage); + cprint(ms->tfillchar,ms->titleattr,80,ms->menupage); + gotoxy(0,tpos,ms->menupage); + csprint(menusystem.title); + + cursoroff(); // Doesn't seem to work? + + // Go + rv = runmenusystem(MENUROW, MENUCOL, startmenu); + + // Hide the garbage we left on the screen + cursoron(); + if (oldpage == ms->menupage) { + cls(); + } else { + setdisppage(oldpage); + gotoxy(oldrow, oldcol, oldpage); } - return NULL; // Should never come here -} - -/* Handle the entire system of menu's. */ -t_menuitem * runmenusystem(char top, char left, int currmenu) -/* - * currmenu - * Which menu should be currently displayed - * top,left - * What is the position of the top,left corner of the menu - * - * Return Value: - * Returns a pointer to the final item chosen, or NULL if nothing chosen. - */ -{ - t_menu *cmenu; - t_menusystem *ms = &menusystem; - t_menuitem *opt,*choice; - int numitems; - char startopt; - - startopt = 0; -startover: - cmenu = (menusystem.menus+currmenu); - numitems = menusystem.menus[currmenu].numitems; - opt = getmenuoption(cmenu,top,left,startopt); - if (opt == NULL) - { - // User hit Esc - cleanupmenu(cmenu,top,left); - return NULL; - } - if (opt->action != OPT_SUBMENU) // We are done with the menu system - { - cleanupmenu(cmenu,top,left); - return opt; // parent cleanup other menus - } - if (opt->itemdata.submenunum >= menusystem.nummenus) // This is Bad.... - { - gotoxy(12,12,ms->menupage); // Middle of screen - sprint("Invalid submenu requested. Ask administrator to correct this.$"); - cleanupmenu(cmenu,top,left); - return NULL; // Pretend user hit esc - } - // Call recursively for submenu - // Position the submenu below the current item, - // covering half the current window (horizontally) - choice = runmenusystem(top+opt->index+2, left+3+(cmenu->menuwidth >> 1), opt->itemdata.submenunum); - if (choice==NULL) // User hit Esc in submenu - { - // Startover - startopt = opt->index; - goto startover; - } - else - { - cleanupmenu(cmenu,top,left); - return choice; - } -} - -/* User Callable functions */ - -t_menuitem * showmenus(char startmenu) -{ - t_menuitem *rv; - t_menusystem *ms; - char oldpage,tpos; - - ms = & menusystem; - // Setup screen for menusystem - oldpage = getdisppage(); - setdisppage(ms->menupage); - clearwindow(0,0,24,79,ms->menupage,ms->fillchar,ms->fillattr); - tpos = (80 - strlen(menusystem.title) - 1) >> 1; // To center it on line - gotoxy(0,0,ms->menupage); - cprint(ms->tfillchar,ms->titleattr,80,ms->menupage); - gotoxy(0,tpos,ms->menupage); - sprint(menusystem.title); - - cursoroff(); // Doesn't seem to work? - - // Go - rv = runmenusystem(MENUROW, MENUCOL, startmenu); - - // Hide the garbage we left on the screen - cursoron(); - if (oldpage == ms->menupage) cls(); else setdisppage(oldpage); // Return user choice return rv; @@ -269,8 +276,8 @@ void init_menusystem(const char *title) { menusystem.nummenus = 0; if (title == NULL) - dstrcpy(menusystem.title,TITLESTR); - else dstrcpy(menusystem.title,title); + strcpy(menusystem.title,TITLESTR); + else strcpy(menusystem.title,title); menusystem.normalattr = NORMALATTR; menusystem.reverseattr= REVERSEATTR; @@ -339,14 +346,14 @@ int add_menu(const char *title) // Create a new menu and return its position if (title) { if (strlen(title) > MENULEN - 2) { - dstrcpy(menusystem.menus[num].title," TITLE TOO LONG "); + strcpy(menusystem.menus[num].title," TITLE TOO LONG "); } else { - dstrcpy(menusystem.menus[num].title,title); + strcpy(menusystem.menus[num].title,title); } } else { - dstrcpy(menusystem.menus[num].title,""); + strcpy(menusystem.menus[num].title,""); } return menusystem.nummenus++; @@ -362,20 +369,20 @@ t_menuitem * add_item(const char *item, const char *status, t_action action, con mi->handler = NULL; // No handler if (item) { if (strlen(item) > MENULEN - 2) { - dstrcpy(mi->item,"ITEM TOO LONG"); + strcpy(mi->item,"ITEM TOO LONG"); } else { - dstrcpy(mi->item,item); + strcpy(mi->item,item); if (strlen(item) > m->menuwidth) m->menuwidth = strlen(item); } - } else dstrcpy(mi->item,""); + } else strcpy(mi->item,""); if (status) { if (strlen(status) > STATLEN - 2) { - dstrcpy(mi->status,"STATUS STRING TOO LONG"); + strcpy(mi->status,"STATUS STRING TOO LONG"); } else { - dstrcpy(mi->status,status); + strcpy(mi->status,status); } - } else dstrcpy(mi->status,""); + } else strcpy(mi->status,""); mi->action = action; diff --git a/menu/menu.h b/menu/menu.h index dc6a9de5..854f1f83 100644 --- a/menu/menu.h +++ b/menu/menu.h @@ -10,12 +10,6 @@ * * ----------------------------------------------------------------------- */ -/* 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__ @@ -41,7 +35,7 @@ #define NORMALATTR 0x70 #define REVERSEATTR 0x87 #define INACTATTR 0x74 -#define REVINACTATTR 0x87 +#define REVINACTATTR 0x1F #define STATUSATTR 0xF0 #define FILLCHAR 178 #define FILLATTR 0x07 @@ -50,7 +44,7 @@ #define TFILLCHAR ' ' #define TITLEATTR 0x70 -#define TITLESTR "COMBOOT Menu System for SYSLINUX developed by Murali Krishnan Ganapathy$" // Must be $ terminated +#define TITLESTR "COMBOOT Menu System for SYSLINUX developed by Murali Krishnan Ganapathy" // Single line Box drawing Chars @@ -173,4 +167,7 @@ int add_menu(const char *title); // Add item to the "current" menu t_menuitem * add_item(const char *item, const char *status, t_action action, const char *data, char itemdata); +// Main function for the user's config file +int menumain(void); + #endif diff --git a/menu/simple.c b/menu/simple.c index 13c14800..7870a94e 100644 --- a/menu/simple.c +++ b/menu/simple.c @@ -19,10 +19,9 @@ #include "string.h" #include "syslinux.h" -int syslinux; char TESTING,RESCUE,MAIN,PREP; -int main(void) +int menumain(void) { t_menuitem * curr; @@ -60,9 +59,6 @@ int main(void) add_item("Testing...","Options to test hardware",OPT_SUBMENU,NULL,TESTING); add_item("Exit to prompt", "Exit the menu system", OPT_EXITMENU, "exit", 0); - syslinux = issyslinux(); // Find if syslinux is running - - if (syslinux) gototxtmode(); // Else assume we are running in a DOS box curr = showmenus(MAIN); // Initial menu is the one with index MAIN if (curr) { @@ -73,7 +69,7 @@ int main(void) else csprint(curr->data); return 1; } - sprint("Error in programming!$"); // Must be $ terminated + csprint("Error in programming!"); } return 0; } diff --git a/menu/string.c b/menu/string.c index 9d90b5b9..936331de 100644 --- a/menu/string.c +++ b/menu/string.c @@ -44,15 +44,6 @@ char *strcat(char *dst, const char * src) return r; } -void dstrcpy(char *dst, const char *src) // DOS strcpy: Make it $ terminated and null terminated -{ - while ( *src ) - *dst++ = *src++; - - *dst++ = '$'; - *dst = '\0'; -} - int strcmp(const char *a, const char*b) { while (*a) diff --git a/menu/string.h b/menu/string.h index 8aa4628e..359e15b0 100644 --- a/menu/string.h +++ b/menu/string.h @@ -8,8 +8,6 @@ void *memset(void *buf, int chr, unsigned int len); char *strcpy(char *dst, const char *src); -void dstrcpy(char *dst, const char *src); // DOS strcpy: Make it $ terminated and null terminated - char *strcat(char *dst, const char * src); int strcmp(const char *a,const char*b); diff --git a/menu/syslinux.c b/menu/syslinux.c index 40b357f7..67a1585e 100644 --- a/menu/syslinux.c +++ b/menu/syslinux.c @@ -24,22 +24,22 @@ static inline int asm_issyslinux(void) (ecx == 0x494e0000) && (edx == 0x55580000); } -char issyslinux() +char issyslinux(void) { return asm_issyslinux(); } -static inline void asm_runcommand(char *cmd) +static inline void asm_runcommand(const char *cmd) { asm volatile("int $0x22" : : "a" (0x0003), "b" (cmd)); } -void runcommand(char *cmd) +void runcommand(const char *cmd) { asm_runcommand(cmd); } -static inline void asm_gototxtmode() +static inline void asm_gototxtmode(void) { asm volatile("int $0x22" : : "a" (0x0005)); } diff --git a/menu/syslinux.h b/menu/syslinux.h index 550c10a9..87b79798 100644 --- a/menu/syslinux.h +++ b/menu/syslinux.h @@ -2,10 +2,12 @@ #ifndef _SYSLINUX_H_ #define _SYSLINUX_H_ -char issyslinux(); // Check if syslinux is running +extern int syslinux; /* Syslinux flag */ -void runcommand(char *cmd); // Run specified command +char issyslinux(void); /* Check if syslinux is running */ -void gototxtmode(); // Change mode to text mode +void runcommand(const char *cmd); /* Run specified command */ + +void gototxtmode(void); /* Change mode to text mode */ #endif |