}  ypos = p_dwn_menu(wtab, (menuitem*)menustr[xpos].arg, ystart + 2, items_xpos[xpos] + 1); touchwin(menuwin); wrefresh(menuwin); } while (ypos == KEY_RIGHT || ypos == KEY_LEFT); break;
}
int top_menu(wint* wtab,menuitem menustr[],int ystart) {	int str_max_length = 0;	int str_length=0;	int cnt, pos;	int xpos, oldxpos;	int ypos=0;	int items=0;	int c;	WINDOW *menuwin;	int items_xpos[12];	curs_set(0);	/*cursor visibility off*/	for (items = 0; *(menustr[items].st_ptr) != 0; items++) {		if (items == 0)			items_xpos[0] = 1;		else			items_xpos[items] = items_xpos[items - 1] + str_length;		if (strlen(menustr[items].st_ptr) > str_max_length)			str_max_length = strlen(menustr[items].st_ptr);		str_length = strlen(menustr[items].st_ptr) + 1;	}	menuwin = winopen(wtab, 3, 80, ystart, 0, TRUE);  	wrefresh(menuwin);	pos = 0;	menu_write_item(menuwin, 1, TRUE, menustr[0].st_ptr);	for (xpos = 1; xpos < items; xpos++)		menu_write_item(menuwin, items_xpos[xpos], FALSE, menustr[xpos].st_ptr);	wrefresh(menuwin);	xpos = 0;	do {		while ((c = getch()) == ERR);		oldxpos = xpos;		switch (c) {			case KEY_RIGHT:				if (++xpos >= items)					xpos = 0;				break;			case KEY_LEFT:				if (xpos == 0)					xpos = items - 1;				else					xpos--;				break;			case KEY_DOWN:			case KEY_ENTER:			case '\r':			case '\n':			        ypos = 0;				do {					switch (ypos) {						case KEY_RIGHT:							if (++xpos >= items)								xpos = 0;							menu_write_item(menuwin, items_xpos[xpos], TRUE, menustr[xpos].st_ptr);							menu_write_item(menuwin, items_xpos[oldxpos], FALSE, menustr[oldxpos].st_ptr);							wrefresh(menuwin);							oldxpos = xpos;							break;						case KEY_LEFT:							if (xpos == 0)								xpos = items - 1;							else								xpos--;							menu_write_item(menuwin, items_xpos[xpos], TRUE, menustr[xpos].st_ptr);							menu_write_item(menuwin, items_xpos[oldxpos], FALSE, menustr[oldxpos].st_ptr);							wrefresh(menuwin);							oldxpos = xpos;							break;					}						ypos = p_dwn_menu(wtab, (menuitem*)menustr[xpos].arg, ystart + 2, items_xpos[xpos] + 1);					touchwin(menuwin);					wrefresh(menuwin);				} while (ypos == KEY_RIGHT || ypos == KEY_LEFT);				break;			default:				if ((char)c >= 'a' && (char)c <= 'z')					c -= 'a' - 'A';				for (cnt = 0; menustr[cnt].key != (char)c && cnt <= items; cnt++);				if (menustr[cnt].key == (char)c)					xpos = cnt;		}		if (xpos != oldxpos) {			menu_write_item(menuwin, items_xpos[xpos], TRUE, menustr[xpos].st_ptr);			menu_write_item(menuwin, items_xpos[oldxpos], FALSE, menustr[oldxpos].st_ptr);			wrefresh(menuwin);		}	} while (ypos == 0 && c != 0x1b);	delwin(menuwin);	curs_set(1);	winclose(wtab);	if (c == 0x1b)		return 0;	return (ypos & 0x0F) | ((xpos & 0x07) << 4);}