for (i = 0; i < max_choice; i++) if (i != choice && toupper (key) == toupper (groups[scroll + i].textstr[0]))
unsigned int j;  for (i = 1; i < max_choice; i++) { j = (choice + i) % max_choice; if (toupper (key) == toupper (groups[scroll + j].textstr[0])) { i = j;
int yast_menu (const char *title, const char *prompt, int height, int width){  int keep_going = 1;  int mod_height;  int mod_menu_on = 0;  int i, x, y, cur_x, cur_y;  int key = 0;  static int button = BUTTON_OK, choice = 0, scroll = 0;  int max_choice = MIN (MAX_GRP_DSP, groups.size ());  int menu_height = max_choice;  WINDOW *dialog, *menu, *mod_menu = NULL;  int item_no = groups.size ();  int button_x = 0, button_y = 0;  char hostname[BUFSIZ];  string titlestr;  hostname[0] = 0;  gethostname (hostname, BUFSIZ);  titlestr = string (YAST_TITLE) + string (hostname);  titlestr.resize (COLS - 2, ' ');  x = 0;  y = 0;  dialog = yast_newwin (LINES, COLS, y, x, 1);/*    wattrset (dialog, dialog_attr);    wmove (dialog, LINES - 3, 0);    waddch (dialog, ACS_LTEE); *//*    for (i = 0; i < (COLS-1) - 2; i++)	waddch (dialog, ACS_HLINE);  wattrset (dialog, dialog_attr);  waddch (dialog, ACS_RTEE);*/  /* top line 3 */  wattrset (dialog, dialog_attr);  wmove (dialog, y + 3, 0);  waddch (dialog, ACS_LTEE);  for (i = 0; i < COLS - 2; i++)    waddch (dialog, ACS_HLINE);  wattrset (dialog, dialog_attr);  waddch (dialog, ACS_RTEE);  wmove (dialog, (LINES - 1) - 2, 1);  for (i = 0; i < (COLS - 1) - 2; i++)    waddch (dialog, ' ');  yast_title (dialog, width, titlestr);  yast_print_autowrap (dialog, prompt, (COLS - 1) - 2, 2, 3, check_attr);  menu_width = width - 6;  for (i = 0; i < item_no; i++)   {     tag_x = MAX (tag_x, groups[i].textstr.size () + 2);     item_x = MAX (item_x, groups[i].textstr.size ());   }  menu_width = tag_x + 3;/* set mod_height, mod_width */  mod_height =    MIN (INFO_Y - (box_y + choice) - 2, modules[scroll + choice].size ());;  mod_width = COLS - (menu_width + box_x + x + 10);  getyx (dialog, cur_y, cur_x);  box_y = y + GROUP_Y;/*    box_x = (width - menu_width) / 2 - 1  + GROUP_X; */  box_x = GROUP_X;  /* create new window for the menu */  menu = subwin (dialog, menu_height, menu_width, y + box_y + 1,		 x + box_x + 1);  wrefresh (dialog);  keypad (menu, TRUE);  /* draw a box around the menu items */  yast_draw_box (dialog, box_y, box_x, menu_height + 2, menu_width + 2,		 menubox_border_attr, menubox_attr);  yast_grp_menu (dialog, menu, choice, menu_width, menu_height);  button_x = COLS / 2 - 11;  button_y = (LINES - 1) - 2;  yast_print_button (dialog, button_help, button_y, 3,		     (button == BUTTON_HELP) ? TRUE : FALSE);  yast_print_button (dialog, button_cancel, button_y,		     (COLS - 5) - strlen (button_cancel),		     (button == BUTTON_CANCEL) ? TRUE : FALSE);  wrefresh (dialog);  max_mod_width = (COLS - 5) - (box_x + menu_width + 2);  /* auto-open module frame */  if (yast_mod_auto && modules[scroll + choice].size () > 0)   {     int max_items =       MIN (INFO_Y - (box_y + choice) - 2, modules[scroll + choice].size ());     int i, max_len = 0, tmplen = 0;     max_mod_dsp = max_items;     mod_height = max_mod_dsp;     for (i = 0; i < modules[scroll + choice].size (); i++)       if ((tmplen = modules[scroll + choice][i].textstr.size ()) > max_len)	 mod_width = max_len =	   yast_dyn_mod ? MIN (max_mod_width, tmplen + 2) : max_mod_width;     print_sec_item (menu, groups[scroll + choice].textstr,		     "->", choice, TRUE);     wnoutrefresh (menu);     mod_menu =       subwin (dialog, mod_height, mod_width, box_y + choice + y + 1,	       3 + x + box_x + menu_width);     yast_draw_box (dialog, box_y + choice, 2 + box_x + menu_width,		    max_items + 2, mod_width + 2, menubox_border_attr,		    inputbox_attr);     yast_mod_menu (dialog, mod_menu, scroll + choice, mod_width, mod_height);   }				/* auto-open module frame */  while (keep_going)   {     wmove (dialog, 0, COLS - 1);     wrefresh (dialog);     key = mouse_wgetch (dialog);     if (mod_menu_on)      {	if (button == BUTTON_OK)	  switch (mod_nav		  (dialog, mod_menu, scroll + choice,		   (mod_width / 2) + box_x + x, box_y + y + choice + 1, key))	   {	   case 1:	     continue;	   case 2:	     return 0;	   }      }     if (button == BUTTON_OK)      {	/* Check if key pressed matches first character of any	   item tag in menu */	for (i = 0; i < max_choice; i++)	  if (i != choice	      && toupper (key) == toupper (groups[scroll + i].textstr[0]))	    break;	if (i < max_choice ||	    (key >= '1' && key <= MIN ('9', '0' + max_choice)) ||	    key == KEY_UP || key == KEY_DOWN || key == '-' ||	    key == '+' || (key >= M_EVENT && key - M_EVENT < ' '))	 {	   if (key >= '1' && key <= MIN ('9', '0' + max_choice))	     i = key - '1';	   else if (key >= M_EVENT)	     i = key - M_EVENT;	   else if (key == KEY_UP || key == '-')	    {	      if (!choice)	       {		 if (scroll)		  {		    /* Scroll menu down */		    getyx (dialog, cur_y, cur_x);		    if (menu_height > 1)		     {		       /* De-highlight current first item */		       print_sec_item (menu, groups[scroll].textstr,				       " ", 0, FALSE);		       scrollok (menu, TRUE);		       wscrl (menu, -1);		       scrollok (menu, FALSE);		       /* auto-close module frame */		       if (yast_mod_auto			   && modules[scroll + choice].size () > 0)			{			  int max_items = MIN (max_mod_dsp,					       modules[scroll +						      choice].size ());			  mod_menu_on = 0;			  yast_del_box (dialog, box_y + choice,					2 + box_x + menu_width,					max_items + 2, mod_width + 2,					dialog_attr, dialog_attr);			  wnoutrefresh (menu);			  wrefresh (dialog);			}	/* auto-close module frame */		     }		    scroll--;		    print_sec_item (menu, groups[scroll].textstr,				    " ", 0, TRUE);		    /* auto-open module frame */		    if (yast_mod_auto)		     {		       int max_items = MIN (INFO_Y - (box_y + choice) - 2,					    modules[scroll + choice].size ());		       int i, max_len = 0, tmplen;		       mod_height = max_mod_dsp = max_items;		       for (i = 0; i < modules[scroll + choice].size (); i++)			 if ((tmplen =			      modules[scroll + choice][i].textstr.size ()) >			     max_len)			   mod_width = max_len =			     yast_dyn_mod ? MIN (max_mod_width,						 tmplen + 2) : max_mod_width;		       print_sec_item (menu, groups[scroll + choice].textstr,				       "->", choice, TRUE);		       wnoutrefresh (menu);		       mod_menu =			 subwin (dialog, mod_height, mod_width,				 box_y + choice + y + 1,				 3 + x + box_x + menu_width);		       yast_draw_box (dialog, box_y + choice,				      2 + box_x + menu_width,				      max_items + 2, mod_width + 2,				      menubox_border_attr, inputbox_attr);		       yast_mod_menu (dialog, mod_menu, scroll + choice,				      mod_width, mod_height);		     }		/* auto-open module frame */		    wnoutrefresh (menu);		    wrefresh (dialog);		    /* print the up/down arrows */		    wmove (dialog, box_y, box_x + tag_x + 1);		    wattrset (dialog, scroll ? uarrow_attr : menubox_attr);		    waddch (dialog, scroll ? ACS_UARROW : ACS_HLINE);		    wmove (dialog, box_y, box_x + tag_x + 2);		    waddch (dialog, scroll ? '(' : ACS_HLINE);		    wmove (dialog, box_y, box_x + tag_x + 3);		    waddch (dialog, scroll ? '-' : ACS_HLINE);		    wmove (dialog, box_y, box_x + tag_x + 4);		    waddch (dialog, scroll ? ')' : ACS_HLINE);		    wattrset (dialog, darrow_attr);		    wmove (dialog, box_y + menu_height + 1,			   box_x + tag_x + 1);		    waddch (dialog, ACS_DARROW);		    wmove (dialog, box_y + menu_height + 1,			   box_x + tag_x + 2);		    waddstr (dialog, "(+)");		    wmove (dialog, cur_y, cur_x);		    wrefresh (dialog);		  }		 continue;	/* wait for another key press */	       }	      else		i = choice - 1;	    }	   else	    {	      if (key == KEY_DOWN || key == '+')	       {		 if (choice == max_choice - 1)		  {		    if (scroll + choice < item_no - 1)		     {		       /* Scroll menu up */		       getyx (dialog, cur_y, cur_x);		       if (menu_height > 1)			{			  /* De-highlight current last item */			  print_sec_item (menu,					  groups[scroll + max_choice -						 1].textstr, " ",					  max_choice - 1, FALSE);			  scrollok (menu, TRUE);			  scroll (menu);			  scrollok (menu, FALSE);			  /* auto-close module frame  */			  if (yast_mod_auto			      && modules[scroll + choice].size () > 0)			   {			     int max_items = MIN (max_mod_dsp,						  modules[scroll +							 choice].size ());			     mod_menu_on = 0;			     yast_del_box (dialog, box_y + choice,					   2 + box_x + menu_width,					   max_items + 2, mod_width + 2,					   dialog_attr, dialog_attr);			     wnoutrefresh (menu);			     wrefresh (dialog);			   }	/* auto-close module frame */			}		       scroll++;		       print_sec_item (menu,				       groups[scroll + max_choice -					      1].textstr, " ", max_choice - 1,				       TRUE);		       wnoutrefresh (menu);		       /* print the up/down arrows */		       wattrset (dialog, uarrow_attr);		       wmove (dialog, box_y, box_x + tag_x + 1);		       waddch (dialog, ACS_UARROW);		       wmove (dialog, box_y, box_x + tag_x + 2);		       waddstr (dialog, "(-)");		       wmove (dialog, box_y + menu_height + 1,			      box_x + tag_x + 1);		       wattrset (dialog,				 scroll + choice <				 item_no -				 1 ? darrow_attr : menubox_border_attr);		       waddch (dialog,			       scroll + choice <			       item_no - 1 ? ACS_DARROW : ACS_HLINE);		       wmove (dialog, box_y + menu_height + 1,			      box_x + tag_x + 2);		       waddch (dialog,			       scroll + choice <			       item_no - 1 ? '(' : ACS_HLINE);		       wmove (dialog, box_y + menu_height + 1,			      box_x + tag_x + 3);		       waddch (dialog,			       scroll + choice <			       item_no - 1 ? '+' : ACS_HLINE);		       wmove (dialog, box_y + menu_height + 1,			      box_x + tag_x + 4);		       waddch (dialog,			       scroll + choice <			       item_no - 1 ? ')' : ACS_HLINE);		       wmove (dialog, cur_y, cur_x);		       wrefresh (dialog);		     }		    continue;	/* wait for another key press */		  }		 else		   i = choice + 1;	       }		/* if */	    }			/* else */	   if (i != choice)	    {	      /* De-highlight current item */	      getyx (dialog, cur_y, cur_x);	/* Save cursor position */	      print_sec_item (menu, groups[scroll + choice].textstr,			      " ", choice, FALSE);	      /* auto-close  module frame */	      if (yast_mod_auto && modules[scroll + choice].size () > 0)	       {		 int max_items =		   MIN (max_mod_dsp, modules[scroll + choice].size ());		 mod_menu_on = 0;		 yast_del_box (dialog, box_y + choice,			       2 + box_x + menu_width, max_items + 2,			       mod_width + 2, dialog_attr, dialog_attr);		 wnoutrefresh (menu);		 wrefresh (dialog);	       }		/* auto-close module frame */	      /* Highlight new item */	      choice = i;	      print_sec_item (menu, groups[scroll + choice].textstr,			      " ", choice, TRUE);	      wnoutrefresh (menu);	      /* auto-open module frame */	      if (yast_mod_auto && modules[scroll + choice].size () > 0)	       {		 int max_items = MIN (INFO_Y - (box_y + choice) - 2,				      modules[scroll + choice].size ());		 int i, max_len = 0, tmplen;		 mod_height = max_mod_dsp = max_items;		 for (i = 0; i < modules[scroll + choice].size (); i++)		   if ((tmplen =			modules[scroll + choice][i].textstr.size ()) >		       max_len)		     mod_width = max_len =		       yast_dyn_mod ? MIN (max_mod_width,					   tmplen + 2) : max_mod_width;		 print_sec_item (menu, groups[scroll + choice].textstr,				 "->", choice, TRUE);		 wnoutrefresh (menu);		 mod_menu =		   subwin (dialog, mod_height, mod_width,			   box_y + choice + y + 1,			   3 + x + box_x + menu_width);		 yast_draw_box (dialog, box_y + choice,				2 + box_x + menu_width, max_items + 2,				mod_width + 2, menubox_border_attr,				inputbox_attr);		 yast_mod_menu (dialog, mod_menu, scroll + choice, mod_width,				mod_height);	       }		/* auto-open module frame */	      wmove (dialog, cur_y, cur_x);	      wrefresh (dialog);	    }	   continue;		/* wait for another key press */	 }      }				/* button==BUTTON_OK */     switch (key)      {      case CTRL_B:	if (button > 0)	  button--;	else	  button = BUTTONCNT;	yast_print_button (dialog, button_help, button_y,			   3, (button == BUTTON_HELP) ? TRUE : FALSE);	yast_print_button (dialog, button_cancel, button_y,			   (COLS - 5) - strlen (button_cancel),			   (button == BUTTON_CANCEL) ? TRUE : FALSE);	if (button != BUTTON_OK)	 {	   if (mod_menu_on)	     yast_draw_frame (dialog, box_y + choice,			      2 + box_x + menu_width, MIN (max_mod_dsp,							   modules[scroll +								  choice].size ()) + 2,			      mod_width + 2, menubox_border_attr,			      inputbox_attr);	   yast_draw_frame (dialog, box_y, box_x, menu_height + 2,			    menu_width + 2, menubox_border_attr,			    inputbox_attr);	 }	else	 {	   if (mod_menu_on)	     yast_draw_frame (dialog, box_y + choice,			      2 + box_x + menu_width, MIN (max_mod_dsp,							   modules[scroll +								  choice].size ()) + 2,			      mod_width + 2, menubox_border_attr,			      menubox_attr);	   yast_draw_frame (dialog, box_y, box_x, menu_height + 2,			    menu_width + 2, menubox_border_attr,			    menubox_attr);	 }	wrefresh (dialog);	wrefresh (dialog);	break;      case ESC:		/* check for alt+tab */       {	 int altkey = 0;	 nodelay (dialog, TRUE);	 altkey = mouse_wgetch (dialog);	 if (toupper (altkey) == toupper (button_cancel[0]))	   return 1;	 if (altkey == TAB)	  {	    nodelay (dialog, FALSE);	    if (button > 0)	      button--;	    else	      button = BUTTONCNT;	    yast_print_button (dialog, button_help, button_y,			       3, (button == BUTTON_HELP) ? TRUE : FALSE);	    yast_print_button (dialog, button_cancel, button_y,			       (COLS - 5) - strlen (button_cancel),			       (button == BUTTON_CANCEL) ? TRUE : FALSE);	    if (button != BUTTON_OK)	     {	       if (mod_menu_on)		 yast_draw_frame (dialog, box_y + choice,				  2 + box_x + menu_width, MIN (max_mod_dsp,							       modules[scroll +								      choice].size ()) + 2,				  mod_width + 2, menubox_border_attr,				  inputbox_attr);	       yast_draw_frame (dialog, box_y, box_x, menu_height + 2,				menu_width + 2, menubox_border_attr,				inputbox_attr);	     }	    else	     {	       if (mod_menu_on)		 yast_draw_frame (dialog, box_y + choice,				  2 + box_x + menu_width, MIN (max_mod_dsp,							       modules[scroll +								      choice].size ()) + 2,				  mod_width + 2, menubox_border_attr,				  menubox_attr);	       yast_draw_frame (dialog, box_y, box_x, menu_height + 2,				menu_width + 2, menubox_border_attr,				menubox_attr);	     }	    wrefresh (dialog);	    break;	  }			/* alt+tab */	 else	   nodelay (dialog, FALSE);       }      case KEY_LEFT:	if (button != BUTTON_OK)	  break;	if (mod_menu_on)	 {	   int max_items = MIN (INFO_Y - (box_y + choice) - 2,				modules[scroll + choice].size ());	   mod_height = max_mod_dsp = max_items;	   mod_menu_on = 0;	   if (!yast_mod_auto)	    {	      print_sec_item (menu, groups[scroll + choice].textstr,			      " ", choice, TRUE);	      yast_del_box (dialog, box_y + choice, 2 + box_x + menu_width,			    max_items + 2, mod_width + 2, dialog_attr,			    dialog_attr);	      print_mod_info (dialog, "");	      wnoutrefresh (menu);	      wrefresh (dialog);	    }	   else	    {	      mod_nav (dialog, mod_menu, scroll + choice,		       (mod_width / 2) + box_x + x, box_y + y + choice + 1,		       NAV_RESET);	      print_mod_info (dialog, "");	      yast_draw_frame (dialog, box_y + choice, 2 + box_x + menu_width,			       max_items + 2, mod_width + 2,			       menubox_border_attr, inputbox_attr);	      wrefresh (dialog);	    }	 }	break;/* buttoncancel */      case '\n':	if (button == BUTTON_CANCEL	    || (!groups[scroll + choice].textstr.compare (button_cancel)		&& button == BUTTON_OK))	 {	   keep_going = 0;	   break;	 }      case KEY_RIGHT:	if (button != BUTTON_OK)	  break;	if (!mod_menu_on && modules[scroll + choice].size () > 0)	 {	   int max_items = MIN (INFO_Y - (box_y + choice) - 2,				modules[scroll + choice].size ());	   int i, max_len = 0, tmplen;	   max_mod_dsp = max_items;	   mod_height = max_mod_dsp;	   mod_menu_on = 1;	   for (i = 0; i < modules[scroll + choice].size (); i++)	     if ((tmplen =		  modules[scroll + choice][i].textstr.size ()) > max_len)	       mod_width = max_len =		 yast_dyn_mod ? MIN (max_mod_width,				     tmplen + 2) : max_mod_width;	   print_sec_item (menu, groups[scroll + choice].textstr,			   "->", choice, TRUE);	   if (!yast_mod_auto)	    {	      mod_menu =		subwin (dialog, mod_height, mod_width, box_y + choice + y + 1,			3 + x + box_x + menu_width);	      yast_draw_box (dialog, box_y + choice,			     2 + box_x + menu_width, max_items + 2,			     mod_width + 2, menubox_border_attr,			     menubox_attr);	      yast_mod_menu (dialog, mod_menu, scroll + choice, mod_width,			     mod_height);	    }	   else	     yast_draw_frame (dialog, box_y + choice, 2 + box_x + menu_width,			      max_items + 2, mod_width + 2,			      menubox_border_attr, menubox_attr);	   /*  init the menu-navigation */	   mod_nav (dialog, mod_menu, scroll + choice,		    (mod_width / 2) + box_x + x, box_y + y + choice + 1,		    NAV_INIT);	 }	wnoutrefresh (menu);	wrefresh (dialog);	break;      case TAB:      case CTRL_F:	if (button < BUTTONCNT)	  button++;	else	  button = 0;	yast_print_button (dialog, button_help, button_y,			   3, (button == BUTTON_HELP) ? TRUE : FALSE);	yast_print_button (dialog, button_cancel, button_y,			   (COLS - 5) - strlen (button_cancel),			   (button == BUTTON_CANCEL) ? TRUE : FALSE);	if (button != BUTTON_OK)	 {	   if (mod_menu_on)	     yast_draw_frame (dialog, box_y + choice, 2 + box_x + menu_width,			      MIN (max_mod_dsp,				   modules[scroll + choice].size ()) + 2,			      mod_width + 2, menubox_border_attr,			      inputbox_attr);	   yast_draw_frame (dialog, box_y, box_x, menu_height + 2,			    menu_width + 2, menubox_border_attr,			    inputbox_attr);	 }	else	 {	   if (mod_menu_on)	     yast_draw_frame (dialog, box_y + choice, 2 + box_x + menu_width,			      MIN (max_mod_dsp,				   modules[scroll + choice].size ()) + 2,			      mod_width + 2, menubox_border_attr,			      menubox_attr);	   yast_draw_frame (dialog, box_y, box_x, menu_height + 2,			    menu_width + 2, menubox_border_attr,			    menubox_attr);	 }	wrefresh (dialog);	break;      }   }  delwin (dialog);  return -1;			/* ESC pressed */}