aboutsummaryrefslogtreecommitdiffstats
path: root/menu/libmenu/menu.c
diff options
context:
space:
mode:
authorMurali Krishnan Ganapathy <gmurali@cs.uchicago.edu>2005-12-16 16:25:49 -0600
committerH. Peter Anvin <hpa@zytor.com>2005-12-16 14:29:04 -0800
commita22c4aff0e5649fa22bbb4b7fda9433d7a8c44de (patch)
tree9f1c365dfc9b7174b31fbc7c769faf9bf8a57d0c /menu/libmenu/menu.c
parent1afe52436215236ac88a7c523d779fb2cf4cbd2a (diff)
downloadsyslinux-elf-a22c4aff0e5649fa22bbb4b7fda9433d7a8c44de.tar.gz
syslinux-elf-a22c4aff0e5649fa22bbb4b7fda9433d7a8c44de.tar.xz
syslinux-elf-a22c4aff0e5649fa22bbb4b7fda9433d7a8c44de.zip
advanced menu patch
Python code to generate C code from ini-like file format and changes to libmenu to accomodate a one pass parser. Diff is against 3.20-pre3 - Murali
Diffstat (limited to 'menu/libmenu/menu.c')
-rw-r--r--menu/libmenu/menu.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/menu/libmenu/menu.c b/menu/libmenu/menu.c
index 7d7e76d2..75a8d724 100644
--- a/menu/libmenu/menu.c
+++ b/menu/libmenu/menu.c
@@ -652,6 +652,44 @@ pt_menuitem runmenusystem(uchar top, uchar left, pt_menu cmenu, uchar startopt,
}
}
+// Finds the indexof the menu with given name
+uchar find_menu_num(const char *name)
+{
+ int i;
+ pt_menu m;
+
+ if (name == NULL) return (uchar)(-1);
+ for (i=0; i < ms->nummenus; i++)
+ {
+ m = ms->menus[i];
+ if ((m->name) && (strcmp(m->name,name)==0)) return i;
+ }
+ return (uchar)(-1);
+}
+
+// Run through all items and if they are submenus
+// with a non-trivial "action" and trivial submenunum
+// replace submenunum with the menu with name "action"
+void fix_submenus()
+{
+ int i,j;
+ pt_menu m;
+ pt_menuitem mi;
+
+ 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 submenu with non-trivial data string
+ if ( (mi->action == OPT_SUBMENU) && (mi->data) )
+ mi->itemdata.submenunum = find_menu_num (mi->data);
+ }
+ }
+}
+
/* User Callable functions */
pt_menuitem showmenus(uchar startmenu)
@@ -659,6 +697,8 @@ pt_menuitem showmenus(uchar startmenu)
pt_menuitem rv;
uchar oldpage,tpos;
+ fix_submenus(); // Fix submenu numbers incase nick names were used
+
// Setup screen for menusystem
oldpage = getdisppage();
setdisppage(ms->menupage);
@@ -673,6 +713,7 @@ pt_menuitem showmenus(uchar startmenu)
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);
@@ -983,6 +1024,7 @@ uchar add_menu(const char *title, int maxmenusize)
if (m == NULL) return -1;
ms->menus[num] = m;
m->numitems = 0;
+ m->name = NULL;
m->row = 0xFF;
m->col = 0xFF;
if (maxmenusize < 1)
@@ -1004,6 +1046,32 @@ uchar add_menu(const char *title, int maxmenusize)
return ms->nummenus - 1;
}
+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
+ {
+ free(m->name);
+ m -> name = NULL;
+ }
+
+ if (name)
+ {
+ m->name = (char *)malloc(strlen(name)+1);
+ strcpy(m->name,name);
+ }
+}
+
+// Create a new named menu and return its position
+uchar add_named_menu(const char * name, const char *title, int maxmenusize)
+{
+ add_menu(title,maxmenusize);
+ set_menu_name(name);
+ return ms->nummenus - 1;
+}
+
void set_menu_pos(uchar row,uchar col) // Set the position of this menu.
{
pt_menu m;
@@ -1118,6 +1186,7 @@ pt_menuitem add_item(const char *item, const char *status, t_action action,
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
@@ -1146,3 +1215,4 @@ void set_item_options(uchar shortcut,int helpid)
void close_menusystem(void)
{
}
+