Hello,
I need some help to understand what I'm doing :)
I'm writing code for an embedded system and I need to create a navigable
menu system. I'm going to use these structures:
typedef struct {
char *name[2];
int type;
int num_param;
void *ptr;
} menuitem_t;
typedef struct {
char *name[2];
int num_items;
menuitem_t *items;
} menu_t;
The latter defines each menu or submenu with a name, a number of items
and a pointer to the items structure.
The former defines each menu item with a name, a type (see below) the
number of parameters - if any - and finally a generic pointer (see below
again).
In this way I can generate menus of any complexity and very flexible.
The void pointer should point to another menu_t struct if the item leads
to a submenu, to an array if it leads to a parameter list. But it could
also leads to a function if the selection of this item needs an action
to be executed.
Actually I have two questions:
1) I can't cast correctly the void *ptr. Let's say I want to access to:
char *par[] = {"First", "Second"};
ot invoke:
void myfunc();
Please, may you help me to understand how to cast and then to use that
pointer in these cases?
2) It would be nice if I can know the path the user is following. For
example:
mainmenu -seconditem -firstitem
where each of these entities are menu_t structs.
How would you implement such a dynamic path?
Thank you and I apologize for my poor English
Marco / iw2nzm
Comment