void do_menu(struct setupMenu *newmenu) { struct setupMenu *savedmenu = Menu; int saveditem = item; Menu = newmenu; if(!ItemName||!expline||!myline) __console_alloc(); item = menu[0].dnext; popwidth = Menu->width; popheight = Menu->height; if(!Menu->action||!Menu->action(MBEGIN)) default_action(MBEGIN); setup_flag = 0; __popup(menu[0].y,menu[0].x,popheight,popwidth); printmenu(); while(!setup_flag) { int msg = getch(); if(menu[item].action && menu[item].action(msg))continue; if(Menu->action && Menu->action(msg))continue; default_action(msg); } __popdown(menu[0].y,menu[0].x,popheight,popwidth); if(!Menu->action||!Menu->action(MEND)) default_action(MEND); setup_flag = 0; Menu = savedmenu; if(Menu){ popwidth = Menu->width; popheight = Menu->height; } item = saveditem; }
void deselectitem(void) { do{ if(menu[item].action && menu[item].action(UPDATE))continue; if(Menu->action && Menu->action(UPDATE))continue; default_action(UPDATE); }while(0); }
static void printmenu(void) { int olditem=item; for(item=0;menu[item].msg;item++) { if(item==olditem)continue; if(menu[item].action && menu[item].action(UPDATE))continue; if(Menu->action && Menu->action(UPDATE))continue; default_action(UPDATE); } item=olditem; selectitem(); }
int parser_option(int argc, char **argv) { if(argc < 2){ show_usage(); return -1; } int ret; /** * Here may be two suitations: * 1. tview command * 2. tview option * */ if(argc == 2) { if(compare_command(argv[1])) { ret = default_action(argv[1]); return ret; }else if((ret = compare_option(argv[1]))) { if(ret == 1) show_usage(); else if(ret == 2) show_command(); }else { /*error, just show the usage*/ show_usage(); } } /** * Here may be some suitations * 1. tview command directory * 2. tview command pattern * * * **/ if(argc == 3) { if(compare_command(argv[1])) /*command with parameter*/ { ret = default_action_third(argv[1]); return ret; } } if(argc == 4) { ret = IS_FIND; find_action_parse(argv[1]); return ret; } if(argc == 5) { ret = IS_FIND; find_type = FIND_FULL; return ret; } return -1; }