예제 #1
0
/*
 * sends command to the menu 
 */
static int wdg_file_driver(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse)
{
   WDG_WO_EXT(struct wdg_file_handle, ww);
   int c;
   struct stat buf;
   
   c = menu_driver(ww->m, wdg_file_virtualize(key) );
   
   /* skip non selectable items */
   if ( !(item_opts(current_item(ww->m)) & O_SELECTABLE) )
      c = menu_driver(ww->m, wdg_file_virtualize(key) );

   /* one item has been selected */
   if (c == E_UNKNOWN_COMMAND) {
      /* the item is not selectable (probably selected with mouse) */
      if ( !(item_opts(current_item(ww->m)) & O_SELECTABLE) )
         return WDG_ESUCCESS;
         
      stat(item_name(current_item(ww->m)), &buf);
      /* if it is a directory, change to it */
      if (S_ISDIR(buf.st_mode)) {
         chdir(item_name(current_item(ww->m)));
         return -WDG_ENOTHANDLED;
      } else {
         /* invoke the callback and return */
         wdg_file_callback(wo, ww->curpath, (char *)item_name(current_item(ww->m)));
         return WDG_ESUCCESS;
      }
   
   }

   wnoutrefresh(ww->mwin);
      
   return WDG_ESUCCESS;
}
예제 #2
0
void			MemberMod::sortItems(const int &length) {
	const static auto comp = [](const ITEM *lhs, const ITEM *rhs) -> bool {
		const char *lhsName = item_name(lhs);
		const char *rhsName = item_name(rhs);
		if(!strcmp(lhsName, "Return") || !strcmp(rhsName, "New member")) {
			return (false);
		} else if(!strcmp(lhsName, "New member") || !strcmp(rhsName, "Return")) {
			return (true);
		} else {
			return (strcmp(lhsName, rhsName) > 0);
		}
	};
	std::sort(_menuItems, _menuItems + length, comp);
}
예제 #3
0
int default_utt_break(cst_tokenstream *ts,
		      const char *token,
		      cst_relation *tokens)
{
    /* This is the default utt break functions, languages may override this */
    /* This will be ok for some latin based languages */
    const char *postpunct = item_feat_string(relation_tail(tokens), "punc");
    const char *ltoken = item_name(relation_tail(tokens));

    if (cst_strchr(ts->whitespace,'\n') != cst_strrchr(ts->whitespace,'\n'))
	 /* contains two new lines */
	 return TRUE;
    else if (strchr(postpunct,':') ||
	     strchr(postpunct,'?') ||
	     strchr(postpunct,'!'))
	return TRUE;
    else if (strchr(postpunct,'.') &&
	     (cst_strlen(ts->whitespace) > 1) &&
	     strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",token[0]))
	return TRUE;
    else if (strchr(postpunct,'.') &&
	     /* next word starts with a capital */
	     strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",token[0]) &&
	     /* last word isn't an abbreviation */
	     !(strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",ltoken[cst_strlen(ltoken)-1])||
	       ((cst_strlen(ltoken) < 4) &&
		strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",ltoken[0]))))
	return TRUE;
    else
	return FALSE;
}
예제 #4
0
void
column_select_update_columns(ui_t *ui)
{
    int column, attr_id;

    // Get panel information
    column_select_info_t *info = column_select_info(ui);

    // Set enabled fields
    ui_t *ui_list = ui_find_by_type(PANEL_CALL_LIST);
    call_list_info_t *list_info = call_list_info(ui_list);

    // Reset column count
    list_info->columncnt = 0;

    // Add all selected columns
    for (column = 0; column < item_count(info->menu); column++) {
        // If column is active
        if (!strncmp(item_name(info->items[column]), "[ ]", 3))
            continue;

        // Get column attribute
        attr_id = sip_attr_from_name(item_userptr(info->items[column]));
        // Add a new column to the list
        call_list_add_column(ui_list, attr_id, sip_attr_get_name(attr_id),
                             sip_attr_get_title(attr_id), sip_attr_get_width(attr_id));
    }
}
예제 #5
0
파일: choosewin.c 프로젝트: weezel/fcd
void
show_chooser_win(MENU *dirmenu, size_t items, char *buf)
{
	int	 c = 0;
	size_t	 buflen, offset = 0;
	char	*tmp;

	buflen = strlen(buf) - 1;

	set_menu_fore(dirmenu, A_REVERSE);
	returnval = set_menu_format(dirmenu, LINES, 1);
	post_menu(dirmenu);
	refresh();

	while ((c = getch()) != 'q') {
		switch(c) {
		case 'j':
		case KEY_DOWN:
			menu_driver(dirmenu, REQ_DOWN_ITEM);
			break;
		case 'k':
		case KEY_UP:
			menu_driver(dirmenu, REQ_UP_ITEM);
			break;
		case KEY_NPAGE:
			menu_driver(dirmenu, REQ_SCR_DPAGE);
			break;
		case KEY_PPAGE:
			menu_driver(dirmenu, REQ_SCR_UPAGE);
			break;
		case KEY_END:
			menu_driver(dirmenu, REQ_LAST_ITEM);
			break;
		case KEY_HOME:
			menu_driver(dirmenu, REQ_FIRST_ITEM);
			break;
		case 10: /* Enter */
			move(20, 0);
			clrtoeol();

			tmp = (char *)item_name(current_item(dirmenu));
			offset = strlcpy(buf, tmp, MAX_CHOICESIZE);
			if (offset >= MAX_CHOICESIZE)
				goto toolong;
			if (strlcpy(buf + offset,
				    item_description(current_item(dirmenu)),
				    MAX_CHOICESIZE - offset))
				goto toolong;

			pos_menu_cursor(dirmenu);
			break;
		}
	}
toolong:
	unpost_menu(dirmenu);
	fprintf(stdout, "shit happens\n");

	fprintf(stdout, "VALUE WAS: %d\n", returnval);
}
예제 #6
0
파일: main.c 프로젝트: JonathanFu/OpenAM-1
int mainmenu(int height, int width) {
    int ret;
    ITEM **menu_items;
    MENU *main_menu;
    int n_choices, i;

    clean_main_menu();
    build_main_menu(instance_path);

    n_choices = menu_size;
    menu_items = (ITEM **) calloc(n_choices + 1, sizeof (ITEM *));
    for (i = 0; i < n_choices; ++i) {
        menu_items[i] = new_item(menu_values[i], menu_values[i]);
        set_item_userptr(menu_items[i], (void *) menu_selected);
    }
    menu_items[n_choices] = (ITEM *) NULL;
    main_menu = new_menu((ITEM **) menu_items);
    menu_opts_off(main_menu, O_SHOWDESC);

    set_menu_sub(main_menu, derwin(stdscr, 10, 50, 6, 10));

    post_menu(main_menu);
    attron(A_BOLD);
    mvprintw(0, 0, name);
    mvprintw(0, width - strlen(vers), vers);
    attroff(A_BOLD);
    refresh();
    pos_menu_cursor(main_menu);
    while ((i = getch()) != KEY_F(4)) {
        switch (i) {
            case KEY_DOWN:
                menu_driver(main_menu, REQ_DOWN_ITEM);
                break;
            case KEY_UP:
                menu_driver(main_menu, REQ_UP_ITEM);
                break;
            case 10:
            {
                ITEM *cur;
                int (*p)(char *);
                cur = current_item(main_menu);
                p = (int (*)(char *))item_userptr(cur);
                ret = p((char *) item_name(cur));
                pos_menu_cursor(main_menu);
                goto menu_sel;
            }
        }
    }
    if (i == KEY_F(4)) {
        ret = menu_size - 1;
    }

menu_sel:
    unpost_menu(main_menu);
    free_menu(main_menu);
    for (i = 0; i < n_choices; ++i)
        free_item(menu_items[i]);
    return ret;
}
예제 #7
0
void
column_select_toggle_item(ui_t *ui, ITEM *item)
{
    // Change item name
    if (!strncmp(item_name(item), "[ ]", 3)) {
        item->name.str = "[*]";
    } else {
        item->name.str = "[ ]";
    }
}
예제 #8
0
cst_utterance *cart_duration(cst_utterance *u)
{
    cst_cart *dur_tree;
    cst_item *s;
    float zdur, dur_stretch, local_dur_stretch, dur;
    float end;
    dur_stats *ds;
    const dur_stat *dur_stat;

    end = 0;

    if (feat_present(u->features,"no_segment_duration_model"))
        return u;  /* not all methods need segment durations */

    dur_tree = val_cart(feat_val(u->features,"dur_cart"));
    dur_stretch = get_param_float(u->features,"duration_stretch", 1.0);
    ds = val_dur_stats(feat_val(u->features,"dur_stats"));
    
    for (s=relation_head(utt_relation(u,"Segment")); s; s=item_next(s))
    {
	zdur = val_float(cart_interpret(s,dur_tree));
	dur_stat = phone_dur_stat(ds,item_name(s));

	local_dur_stretch = ffeature_float(s, "R:SylStructure.parent.parent."
					   "R:Token.parent.local_duration_stretch");
	if (local_dur_stretch)
	    local_dur_stretch *= dur_stretch;
	else
	    local_dur_stretch = dur_stretch;

	dur = local_dur_stretch * ((zdur*dur_stat->stddev)+dur_stat->mean);
	DPRINTF(0,("phone %s accent %s stress %s pdur %f stretch %f mean %f std %f dur %f\n",
		   item_name(s),
		   ffeature_string(s,"R:SylStructure.parent.accented"),
		   ffeature_string(s,"R:SylStructure.parent.stress"),
		   zdur, local_dur_stretch, dur_stat->mean,
		   dur_stat->stddev, dur));
	end += dur;
	item_set_float(s,"end",end);
    }
    return u;
}
예제 #9
0
/*
 * The button have been pressed, the corresponding function is called.
 * @param item The button pressed
 */
static void driver_buttons(ITEM *item)
{
	const char *name = item_name(item);
	int i = 0;

	while (popup_btn_action[i] && strcmp(popup_btn_action[i]->key, name) != 0)
		i++;

	if (popup_btn_action[i])
		popup_btn_action[i]->func();
}
예제 #10
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
        int n_choices, i;
	ITEM *cur_item;
	
	
	initscr();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));

        for(i = 0; i < n_choices; ++i)
                my_items[i] = new_item(choices[i], choices[i]);
	my_items[n_choices] = (ITEM *)NULL;

	my_menu = new_menu((ITEM **)my_items);
	post_menu(my_menu);
	refresh();

	while((c = getch()) != KEY_F(1))
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
			case 10:	/* Enter */
				cur_item = current_item(my_menu);
				move(LINES - 2, 0);
				clrtoeol();
				mvprintw(LINES - 2, 0, "You have chosen %d item with name %s and description %s", 
				item_index(cur_item) + 1,  item_name(cur_item), 
				item_description(cur_item));
				
				refresh();
				pos_menu_cursor(my_menu);
				break;
		}
	}	

	free_item(my_items[0]);
        free_item(my_items[1]);
	free_menu(my_menu);
	endwin();
}
예제 #11
0
/* this function make sure that the user selection is valid--not a category
   or white space */
void vwm_menu_marshall(MENU *menu,gint32 key_vector)
{
   gchar  *item_text;

   if(key_vector!=REQ_UP_ITEM && key_vector!=REQ_DOWN_ITEM) return;

   do
   {
      item_text=(gchar*)item_name(current_item(menu));
      if(memcmp(item_text,"..",2)==0) break;
      menu_driver(menu,key_vector);
   }
   while(1);

   return;
}
예제 #12
0
static turn_command_t player_move(game_t * game, int input)
{
    int x_speed = 0, y_speed = 0;
    int mob_id;
    get_speed(input, &x_speed, &y_speed);
    mob_id = get_mob(game->level, game->player.mob->position.y + y_speed, game->player.mob->position.x + x_speed);

    if (mob_id != -1)
    {
        attack(game, game->player.mob, &(game->level->mobs[mob_id]));
        return turn_command_complete;
    }
    else if (try_move_mob(game, game->level, game->player.mob, y_speed, x_speed))
    {
        explore(game->level, game->player.mob);
        explore_map(game->level, game->player.mob->position);

        if (game->level->map[game->player.mob->position.y * game->level->width + game->player.mob->position.x].type == tile_stair &&
            prompt_yn("Go down the stairs?"))
        {
            return turn_command_descend;
        }

        item_t * item = game->level->map[game->player.mob->position.y * game->level->width + game->player.mob->position.x].item;

        if (item != NULL)
        {
            char item_n[100];
            char line[MSGLEN];

            item_name(item_n, item);

            snprintf(line, MSGLEN, "There is %s here.", item_n);

            print_msg(line);
            wait();

            clear_msg();
        }

        draw_map(game->input_type, game->level);
        return turn_command_complete;
    }

    print_msg("You cannot go there.");
    return turn_command_void;
}
예제 #13
0
파일: serial.cpp 프로젝트: swuecho/igblast
static void s_ResolveItems(CTypeInfo*& info, const char*& name,
                           ETypeFamily req_family)
{
    TTypeInfo info0 = info;
    const char* name0 = name;
    while ( const char* dot = strchr(name, '.') ) {
        CTempString item_name(name, dot-name);
        TTypeInfo new_info;
        switch ( info->GetTypeFamily() ) {
        case eTypeFamilyClass:
            new_info = dynamic_cast<CClassTypeInfo*>(info)
                ->GetMemberInfo(item_name)->GetTypeInfo();
            break;
        case eTypeFamilyChoice:
            new_info = dynamic_cast<CChoiceTypeInfo*>(info)
                ->GetVariantInfo(item_name)->GetTypeInfo();
            break;
        case eTypeFamilyContainer:
            if ( item_name != "E" ) {
                NCBI_THROW_FMT(CSerialException,eInvalidData,
                               info0->GetName()<<'.'<<
                               CTempString(name0, name-name0)<<
                               ": element name must be 'E'");
            }
            new_info = dynamic_cast<CContainerTypeInfo*>(info)
                ->GetElementType();
            break;
        default:
            new_info = info;
            break;
        }
        // skip all pointers (CRef<>)
        while ( new_info->GetTypeFamily() == eTypeFamilyPointer ) {
            new_info = dynamic_cast<const CPointerTypeInfo*>(new_info)
                ->GetPointedType();
        }
        info = const_cast<CTypeInfo*>(new_info);
        name = dot+1;
    }
    if ( info->GetTypeFamily() != req_family ) {
        NCBI_THROW_FMT(CSerialException,eInvalidData,
                       info0->GetName()<<'.'<<
                       CTempString(name0, name-name0)<<
                       ": not a "<<
                       (req_family == eTypeFamilyClass? "class": "choice"));
    }
}
예제 #14
0
int main(){
    int indent = 0;
    int iter = 0;

    list_size = 0;
    BUF_LEN = 127;
    file_desc = open(DEVICE_FILE_NAME, 0);
    init_list();
    move_current();

    set_buflen();
    do{
        int pid;
        char *name;
        int res;

        pid = get_currpid();
        name = get_currname();
        add_item(pid, name);
        if(pid == 0) break;
    }while(move_parent() != FAIL);

    while(list_size){
        int i, pid;
        char *name;
        for(i=0; i<indent; i++) printf(" ");
        if(iter){
            printf("\\-");
            indent += 2;
        }

        pid = item_pid();
        name = item_name();

        printf("%s(%d)\n", name, pid);
        pop_item();
        iter ++;
    }

    return 0;
}
예제 #15
0
파일: nchgdc.c 프로젝트: Eeketh/hgd
int
hgd_unpost_and_free_content_menu(struct ui *u, int which)
{
	ITEM			**items;
	int			  n_items, i;

	if (u->content_menus[which] == NULL)
		return (HGD_OK);

	DPRINTF(HGD_D_INFO, "free menu: %s", window_names[which]);

	if ((n_items = item_count(u->content_menus[which])) == ERR) {
		DPRINTF(HGD_D_ERROR, "Couldn't get item count");
		return (HGD_FAIL);
	}

	if ((items = menu_items(u->content_menus[which])) == NULL) {
		DPRINTF(HGD_D_ERROR, "Got NULL items array");
		return (HGD_FAIL);
	}

	if (unpost_menu(u->content_menus[which]) != E_OK)
		DPRINTF(HGD_D_ERROR, "could not unpost menu %d", errno);

	/* must come before freeing items */
	if (free_menu(u->content_menus[which]) != E_OK)
		DPRINTF(HGD_D_ERROR, "could not free menu");

	for (i = 0; i < n_items; i++) {
		free((char *) item_name(items[i]));
		free((char *) item_description(items[i]));
		free(item_userptr(items[i]));
		if (free_item(items[i]) != OK)
			DPRINTF(HGD_D_ERROR, "can't free item");
	}

	free(items);
	u->content_menus[which] = NULL;

	return (HGD_OK);
}
예제 #16
0
void drop_item(player_info_t * player, level_t * level, item_t ** item)
{
    char item_n[100];
    char msg[MSGLEN];

    //TODO: Make sure this item is acutally in the inventory..

    item_name(item_n, *item);

    snprintf(msg, MSGLEN, "Okay, you drop %s.", item_n);
    print_msg(msg);
    wait();
    clear_msg();

    level->map[player->mob->position.y * level->width + player->mob->position.x].item =
        *item;

    *item = NULL;

    return;
}
예제 #17
0
void
selection_free_or_die(struct selection *selection)
{
    if (!selection) return;
    
    if (selection->menu) {
        unpost_menu(selection->menu);
        free_menu(selection->menu);
    }
    if (selection->sub_window) delwin(selection->sub_window);
    if (selection->window) delwin(selection->window);
    
    for (int i = 0; i < selection->items_count; ++i) {
        free_or_die((char *)item_name(selection->items[i]));
        free_or_die((char *)item_description(selection->items[i]));
        free_or_die(item_userptr(selection->items[i]));
        free_item(selection->items[i]);
    }
    free_or_die(selection->items);
    free_or_die(selection->title);
    free_or_die(selection);
}
예제 #18
0
파일: gui.c 프로젝트: gmy987/zoltar
void destroyGui() {
  int i;

  i=0; while(item_name(mainMenuItems[i]) != NULL)            { free_item(mainMenuItems[i]); i++; }
  i=0; while(item_name(opmodeMenuItems[i]) != NULL)          { free_item(opmodeMenuItems[i]); i++; }
  i=0; while(item_name(spectraMenuItems[i]) != NULL)         { free_item(spectraMenuItems[i]); i++; }
  i=0; while(item_name(spectraOpMenuItems[i]) != NULL)       { free_item(spectraOpMenuItems[i]); i++; }
  i=0; while(item_name(sflCoeffMenuItems[i]) != NULL)        { free_item(sflCoeffMenuItems[i]); i++; }
  i=0; while(item_name(invariantTypesMenuItems[i]) != NULL)  { free_item(invariantTypesMenuItems[i]); i++; }

  free_menu(mainMenu);
  free_menu(opmodeMenu);
  free_menu(spectraMenu);
  free_menu(sflCoeffMenu);
  free_menu(spectraOpMenu);
  free_menu(invariantTypesMenu);
}
예제 #19
0
static struct result
get_selection(struct selection *selection)
{
    while (true) {
        int ch = wgetch(selection->window);
        if (ERR == ch) return result_ncurses_err();
        
        if (KEY_DOWN == ch) {
            int result = menu_driver(selection->menu, REQ_DOWN_ITEM);
            if (E_OK != result && E_REQUEST_DENIED != result) {
                return result_ncurses_error(result);
            }
        }
        
        if (KEY_UP == ch) {
            int result = menu_driver(selection->menu, REQ_UP_ITEM);
            if (E_OK != result && E_REQUEST_DENIED != result) {
                return result_ncurses_error(result);
            }
        }
        
        if ('\r' == ch) break;
        
        if (!isalnum(ch)) continue;
        
        for (int i = 0; i < selection->items_count; ++i) {
            char const *name = item_name(selection->items[i]);
            if (name && ch == name[0]) {
                set_current_item(selection->menu, selection->items[i]);
                return result_success();
            }
        }
    }
    
    return result_success();
}
예제 #20
0
void draw_menu(char ** menu_liste, void (*ptrfonction)(int,const char *, char *), char * folder, int taille_menu){
        ITEM **my_items;
	int c;		
        WINDOW *my_menu_win;
	MENU *my_menu;
	int i;
	ITEM *cur_item;
        my_items = (ITEM **)calloc(taille_menu + 1, sizeof(ITEM *));
        int menu_alrdy_dlt = 0; //pour ne pas supprimer le menu 2 fois --> évite les erreur de segmentation lorsqu'on quitte
        char ** files; //pour le cas ou on utilise F2 (ouvrir un fichier)
        
        int num_choix;
        char choix[FILE_MAX];

	for(i = 0; i < taille_menu; ++i){
	        my_items[i] = new_item(menu_liste[i], ""); //ajoute les éléments dans mon tableau d'item
        }
	//my_items[taille_menu+1] = (ITEM *)NULL; //ajoute un item vide à la fin du tableau
        my_menu = new_menu((ITEM **)my_items); //creer un menu contenan les items
	mvprintw(LINES - 2, 0, "F9 to close the menu"); //affiche un pied de page pour fermer le menu
        
        my_menu_win = newwin(10, 45, (LINES-10)/2, (COLS-45)/2); //créer une nouvelle fenetre
        keypad(my_menu_win, TRUE); //active le clavier pour le menu
       
        
        
        
        /* Set main window and sub window */
        set_menu_win(my_menu, my_menu_win); //set main menu
        set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); // set sub window
        set_menu_format(my_menu, 5, 1);
        
       /* Set menu mark to the string " * " */
        set_menu_mark(my_menu, " * ");
        
        /* Print a border around the main window and print a title */
        box(my_menu_win, 0, 0);
        print_in_middle(my_menu_win, 1, 0, 45, "Menu Principal", COLOR_PAIR(1));
	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
	mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
	refresh();
        
	post_menu(my_menu);
	wrefresh(my_menu_win);
       

	while((c = getch()) != KEY_F(9) && c != 27)
	{   switch(c)
	    {	case KEY_F(5):
                        mvprintw(LINES-2, 0, "Exiting...");
                        endwin();			/* End curses mode		  */
                        exit(0);
            
                case KEY_F(2):
                        files = list_file("", &i);
                        clean_menu(my_menu);
                        clean_window(my_menu_win);
                        draw_menu(files, execute_file_menu, "", i);
                        return;
                    
                case KEY_DOWN:
		        menu_driver(my_menu, REQ_DOWN_ITEM);
			break;
		case KEY_UP:
			menu_driver(my_menu, REQ_UP_ITEM);
			break;
                
            
                case KEY_NPAGE:
			menu_driver(my_menu, REQ_SCR_DPAGE);
			break;
                case KEY_PPAGE:
			menu_driver(my_menu, REQ_SCR_UPAGE);
			break;
        
            
                case 10:
                        move(20, 0);
			clrtoeol();
                        num_choix = item_index(current_item(my_menu));
                        strcpy(choix, item_name(current_item(my_menu)));
			//mvprintw(5, 0, "Item selected is : %s", item_name(current_item(my_menu)));
                        clean_menu(my_menu);
                        menu_alrdy_dlt = 1;
                        clean_window(my_menu_win);
                        (*ptrfonction)(num_choix, choix, folder);
			pos_menu_cursor(my_menu);
			break;
                 

		}
                wrefresh(my_menu_win);
	}
        if(menu_alrdy_dlt == 0)
                clean_menu(my_menu);
        clean_window(my_menu_win);
        
       
        
    
}
예제 #21
0
/*

    returns 1 if yes, 0 if no
*/
int confirm(const char *title, const char *text, chtype forecolor,
        chtype backcolor, int def)
{
    int retval = 0;
    ITEM **menu_items;
    MENU *confirm_menu;
    PANEL *my_panels[1];
    WINDOW *confirm_win, *dw;
    ITEM *cur;

    int height = 7, width = 25, startx = 5, starty = 5, max_x = 0, max_y = 0;
    const char *choices[] = {STR_YES, STR_NO};

    size_t n_choices = 2, i = 0;

    int ch, quit = 0;

    char *print_title;

    /* safety */
    vrmr_fatal_if_null(title);
    vrmr_fatal_if_null(text);

    if (width - 4 < (int)StrLen(text))
        width = (int)StrLen(text) + 4;
    if (width - 6 < (int)StrLen(title))
        width = (int)StrLen(title) + 6;
    getmaxyx(stdscr, max_y, max_x);
    startx = (max_x - width) / 2;
    starty = (max_y - height) / 2;

    print_title = malloc(StrMemLen(title) + 3);
    vrmr_fatal_alloc("malloc", print_title);
    snprintf(print_title, StrMemLen(title) + 3, " %s ", title);

    menu_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
    vrmr_fatal_alloc("calloc", menu_items);
    for (i = 0; i < n_choices; ++i) {
        menu_items[i] = new_item(choices[i], NULL);
    }
    menu_items[n_choices] = (ITEM *)NULL;
    confirm_menu = new_menu((ITEM **)menu_items);
    vrmr_fatal_if_null(confirm_menu);
    confirm_win = newwin(height, width, starty, startx);
    wbkgd(confirm_win, backcolor);
    keypad(confirm_win, TRUE);
    wrefresh(confirm_win);
    my_panels[0] = new_panel(confirm_win);
    set_menu_win(confirm_menu, confirm_win);
    dw = derwin(confirm_win, height - 4, 10, 4, (width) / 2 - 5);
    set_menu_sub(confirm_menu, dw);
    set_menu_format(confirm_menu, height - 4, 2);
    box(confirm_win, 0, 0);
    print_in_middle(confirm_win, 0, 0, width, print_title, backcolor);
    print_in_middle(confirm_win, 2, 0, width, text, backcolor);
    set_menu_back(confirm_menu, backcolor);
    set_menu_fore(confirm_menu, forecolor);
    post_menu(confirm_menu);

    /* set the cursor to the 'no' position */
    if (!def) {
        menu_driver(confirm_menu, REQ_RIGHT_ITEM);
    }
    update_panels();
    doupdate();

    while (quit == 0) {
        ch = wgetch(confirm_win);
        switch (ch) {
            case KEY_DOWN:
                menu_driver(confirm_menu, REQ_LEFT_ITEM);
                break;
            case KEY_UP:
                menu_driver(confirm_menu, REQ_RIGHT_ITEM);
                break;
            case KEY_LEFT:
                menu_driver(confirm_menu, REQ_LEFT_ITEM);
                break;
            case KEY_RIGHT:
                menu_driver(confirm_menu, REQ_RIGHT_ITEM);
                break;

            case 10: // enter
            {
                cur = current_item(confirm_menu);
                vrmr_fatal_if_null(cur);
                if (strcmp((char *)item_name(cur), STR_YES) == 0) {
                    retval = 1;
                }
                quit = 1;
                break;
            }

            case 'y':
            case 'Y':
                retval = 1;
                quit = 1;
                break;

            case 'n':
            case 'N':
                retval = 0;
                quit = 1;
                break;

            case 27:
            case KEY_F(10):
            case 'q':
            case 'Q':
                quit = 1;
                break;
        }
    }

    unpost_menu(confirm_menu);
    free_menu(confirm_menu);
    for (i = 0; i < n_choices; ++i)
        free_item(menu_items[i]);
    free(menu_items);
    destroy_win(dw);
    del_panel(my_panels[0]);
    destroy_win(confirm_win);
    free(print_title);
    update_panels();
    doupdate();
    return (retval);
}
예제 #22
0
void viewEditTeamProperties(FootBallGame::TeamNumber teamNumber) {
  const char *fieldBuffer;
  const ITEM *currentItem;
  const char *itemName;
  ITEM **items;

  const int window_nlines = 10,
            window_ncols  = 90;
  
  char *choices[] = {
    "Ok",
    "Cancel",
  };

  for(;;) {
    // Create new window.
    WINDOW *window = newwin(window_nlines, 
                            window_ncols, 
                            headerWindow_begin_y + headerWindow_nlines + 1,
                            0);
    // Set new window options.
    keypad(window, TRUE);
  
    // Team the team
    FootBallTeam *team = game.getFootBallTeam(teamNumber);

    // Create the form fields
    FIELD *field[2];
    field[0] = new_field(1, 20, 2, 22, 0, 0);
    field[1] = NULL;
  
    // Set feild options 
    set_field_back(field[0], A_UNDERLINE);
    field_opts_off(field[0], O_AUTOSKIP);
    set_field_type(field[0], TYPE_REGEXP, "^[A-Za-z ]*$");
    if (team) {
      String teamName = team->getTeamName();
      set_field_buffer(field[0], 0, teamName.c_str());
    }
    
    // Create the form
    FORM *form = new_form(field);

    // Attach the form to the window
    set_form_win(form, window);
    set_form_sub(form, derwin(window, 4, 90, 0, 0));

    // Setup the menu
    int nChoices = ARRAY_SIZE(choices)+1;
    items = new ITEM* [nChoices];
    for (int i = 0; i < nChoices-1; i++)
      items[i] = new_item(choices[i], NULL);
    items[nChoices-1] = NULL;
  
    // Create the menu
    MENU *menu = new_menu(items);
    // Menu options
    set_menu_format(menu, 1, 2);
    set_menu_mark(menu, NULL);
    // Attach the menu to the window
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 1, 20, 4, 17));

    // Make window and menu visible;
    post_form(form);
    post_menu(menu);
    mvwprintw(window, 0, 10, "Team Properties: ");
    mvwprintw(window, 2, 10, "Team Name: ");
    wrefresh(window);
    refresh();
    
    // Start user interaction loop.
    int c;
    // The restart variable is used to tell the function to rebuild the
    // menu by starting at the top of the for(;;) loop above.
    bool restart = false;
    while (!restart && (c = wgetch(window))) {
      switch(c) {
        case KEY_DOWN:
        case 0x09:
          // Go to next field
          form_driver(form, REQ_NEXT_FIELD);
          // GO to the end of the presend buffer
          // Leaves nicely at the last character
          form_driver(form, REQ_END_LINE);
          break;
        case KEY_UP:
          // Go to previous field
          form_driver(form, REQ_PREV_FIELD);
          form_driver(form, REQ_END_LINE);
          break;
        case 0x7F:
          form_driver(form, REQ_DEL_PREV);
          break;
        case KEY_LEFT:
          menu_driver(menu, REQ_LEFT_ITEM);
          break;
        case KEY_RIGHT:
          menu_driver(menu, REQ_RIGHT_ITEM);
          break;
        case 10: // Enter
          // When the user hits enter determine the currently selected
          // item and do nessary actions. 
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          if (strcmp(itemName, choices[0]) == 0) {
            form_driver(form, REQ_VALIDATION);
            fieldBuffer = field_buffer(field[0], 0);
            if (fieldBuffer != NULL && strcmp(fieldBuffer, "") != 0) {
              if (team == NULL) {
                team = new FootBallTeam;
                game.setFootBallTeam(teamNumber, team);
              }
              team->setTeamName(fieldBuffer);
            }
          }
          // Delete allocated data
          delwin(window);
          unpost_form(form); 
          free_form(form); 
          unpost_menu(menu); 
          free_menu(menu); 
          for (unsigned i = 0; i < ARRAY_SIZE(field); i++) 
            free_field(field[i]); 
          for (int i = 0; i < nChoices-1; i++) 
            free_item(items[i]); 
          delete[] items;
          return;
        default:
          // If this is a normal character, it gets printed.
          form_driver(form, c);
          break;
      }
    }
  }
}
예제 #23
0
void viewPlayer(FootBallTeam *team, const String &name, int pid) {
  const char *itemName;
  const ITEM *currentItem;
  String playerName, playerPosition;
  float height, weight;
  int number;

  const int window_nlines = 20,
            window_ncols  = 90;
  
  char *choices[] = {
    "Ok",
    "Delete",
  };

  for(;;) {
    FootBallPlayer *player = (FootBallPlayer*)team->getPlayer(name, pid);
    if (player) {
      player->getName(playerName);
      player->getPosition(playerPosition);
      height = player->getHeight(); 
      weight = player->getWeight();
      number = player->getNumber();
    } else {
      playerName = "";
      playerPosition = "";
      height = -1;
      weight = -1;
      number = -1;
    }

    // Create new window.
    WINDOW *window = newwin(window_nlines, 
                            window_ncols, 
                            headerWindow_begin_y + headerWindow_nlines + 1,
                            0);
    // Set new window options.
    keypad(window, TRUE);
    
    // Setup the menu
    int nChoices = ARRAY_SIZE(choices)+1;
    ITEM **items = new ITEM* [nChoices];
    for (int i = 0; i < nChoices; i++)
      items[i] = new_item(choices[i], NULL);
    items[nChoices-1] = NULL;

    // Create the menu
    MENU *menu = new_menu(items);
    // Menu options
    set_menu_format(menu, 1, 2);
    set_menu_mark(menu, NULL);
    // Attach the menu to the window
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 1, 20, 7, 17));
  
    // Make window and menu visible;
    post_menu(menu);
    mvwprintw(window, 0, 10, "Name: %s\n", playerName.c_str());
    mvwprintw(window, 1, 10, "Number: %d\n", number);
    mvwprintw(window, 2, 10, "Position: %s\n", playerPosition.c_str());
    mvwprintw(window, 3, 10, "Height: %.2fcm\n", height);
    mvwprintw(window, 4, 10, "Weight: %.2fkg\n", weight);
    wrefresh(window);
    refresh();

    // Start user interaction loop.
    int c;
    // The restart variable is used to tell the function to rebuild the
    // menu by starting at the top of the for(;;) loop above.
    bool restart = false;
    while (!restart && (c = wgetch(window))) {
      switch(c) {
        case KEY_LEFT:
          menu_driver(menu, REQ_LEFT_ITEM);
          break;
        case KEY_RIGHT:
          menu_driver(menu, REQ_RIGHT_ITEM);
          break;
        case 10:
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          refresh();
          if (strcmp(itemName, choices[1]) == 0)
            team->removePlayer(playerName, pid);
          // Delete allocated data
          unpost_menu(menu); 
          free_menu(menu); 
          for (int i = 0; i < nChoices; i++) 
            free_item(items[i]); 
          delete[] items;
          delwin(window);
          return;
      }
    }
  }
}
예제 #24
0
void viewMainMenu() {

  const int window_nlines = 10,
            window_ncols  = 90;

  const char *choices[] = {
    "Team 1: ",
    "Team 2: ",
    "Exit",
  };

  for(;;) {
    // Create new window.
    WINDOW *window = newwin(window_nlines, 
                            window_ncols, 
                            headerWindow_begin_y + headerWindow_nlines + 1,
                            0);
    // Set new window options.
    keypad(window, TRUE);

    // Get the teams (used in menu items).
    FootBallTeam *team[2];
    team[0] = game.getFootBallTeam(FootBallGame::TEAM_ONE);
    team[1] = game.getFootBallTeam(FootBallGame::TEAM_TWO);
    String teamName[2];
    
    // Create the menu items
    int nChoices = ARRAY_SIZE(choices) + 1;
    ITEM **items = new ITEM* [nChoices];
    for (int i = 0; i < 2; i++ ) {
      if (team[i] == NULL)
        items[i] = new_item(choices[i], "Empty");
      else {
        teamName[i] = team[i]->getTeamName();
        items[i] = new_item(choices[i], teamName[i].c_str());
      }
    }
    items[2] = new_item(choices[2], NULL);
    items[nChoices-1] = NULL;

    // Create the menu
    MENU *menu = new_menu(items);
    // Menu options
    set_menu_mark(menu, NULL);
    // Attach the menu to the window
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 10, 80, 0, 10));
    
    // Make window and menu visible;
    post_menu(menu);
    wrefresh(window);
    refresh();
    
    // Start user interaction loop.
    int c;
    // The restart variable is used to tell the function to rebuild the
    // menu by starting at the top of the for(;;) loop above.
    bool restart = false;
    while (!restart && (c = wgetch(window))) {
      switch (c) {
        case KEY_DOWN:
          menu_driver(menu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(menu, REQ_UP_ITEM);
          break;
        case 10: // Enter
          // When the user hits enter determine the currently selected
          // item and do nessary actions. 
          const ITEM *currentItem = current_item(menu);
          const char *itemName = item_name(currentItem);
          // Delete allocated data
          unpost_menu(menu); 
          free_menu(menu); 
          delwin(window); 
          for (int i = 0; i < nChoices; i++) 
            free_item(items[i]);
          delete[] items; 
          if (strcmp(itemName, choices[2]) == 0) {
            return;
          // Edit/View Team 1
          } else if (strcmp(itemName, choices[0]) == 0)  {
            restart = true;
            viewTeam(FootBallGame::TEAM_ONE);
          // Edit/View Team 2
          } else if (strcmp(itemName, choices[1]) == 0)  {
            restart = true;
            viewTeam(FootBallGame::TEAM_TWO);
          }
      }
    }
  }
}
예제 #25
0
void viewListPlayers(FootBallGame::TeamNumber teamNumber) {
  String teamName;
  int nChoices;
  ITEM **items;
  const char *itemName;
  const ITEM *currentItem;
  LinkedList<String*> names = LinkedList<String*>(deleteString);
  LinkedList<int*> pids = LinkedList<int*>(deleteInt);

  const int window_nlines = 10,
            window_ncols  = 90;

  for(;;) {
    // Create new window.
    WINDOW *window = newwin(window_nlines, 
                            window_ncols, 
                            headerWindow_begin_y + headerWindow_nlines + 1,
                            0);
    // Set new window options.
    keypad(window, TRUE);

    // Set up the items of menu.
    FootBallTeam *team = game.getFootBallTeam(teamNumber);
    if (team != NULL) {
      nChoices = team->getPlayerCount() + 2;
      items = new ITEM* [nChoices];

      TeamIterator iterator, end;
      team->begin(iterator);
      team->end(end);
      for (int i = 0; iterator != end; i++, iterator++) {
        Player *player = *iterator;
        String *playerName = new String;
        int *pid = new int;
        player->getName(*playerName);
        *pid = player->getPid();
        names.append(playerName);
        pids.append(pid);
        items[i] = new_item(playerName->c_str(), NULL);
        set_item_userptr(items[i], pid);
      }
    } else  {
      nChoices = 2;
      items = new ITEM* [nChoices];
    }
    items[nChoices-2] = new_item("Exit", NULL);
    items[nChoices-1] = NULL;

    // Create the menu
    MENU *menu = new_menu((ITEM **)items);
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 10, 80, 0, 10));
    set_menu_mark(menu, NULL);
    // Do not Show the item descritpions
    menu_opts_off(menu, O_SHOWDESC);

    post_menu(menu);
    wrefresh(window);
    refresh();
    
    int c;
    bool restart = false;
    while (!restart && (c = wgetch(window))) {
      switch (c) {
        case KEY_DOWN:
          menu_driver(menu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(menu, REQ_UP_ITEM);
          break;
        case 10: // Enter
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          if (itemName != NULL) {
            if (strcmp(itemName, "Exit") == 0) {
              // Delete allocated data
              unpost_menu(menu);
              free_menu(menu); 
              for (int i = 0; i < nChoices-1; i++) 
                free_item(items[i]);
              delete[] items;
              delwin(window); 
              return;
            } else  {
              int *pid = (int*)item_userptr(currentItem);
              // Delete allocated data
              unpost_menu(menu);
              free_menu(menu); 
              for (int i = 0; i < nChoices-1; i++) 
                free_item(items[i]);
              delete[] items;
              delwin(window); 
              viewPlayer(team, itemName, *pid);
              restart = true;
            }
          }
      }
    }
  }
}
예제 #26
0
void viewTeam(FootBallGame::TeamNumber teamNumber) {
  const int window_nlines = 10,
            window_ncols  = 90;

  char *choices[] = {
    "Team Properties",
    "List Players",
    "Add Player",
    "Return",
  };

  for (;;) {
    // Create new window.
    WINDOW *window = newwin(window_nlines, 
                            window_ncols, 
                            headerWindow_begin_y + headerWindow_nlines + 1,
                            0);
    // Set new window options.
    keypad(window, TRUE);

    // Set up the items of menuMain.
    int nChoices = ARRAY_SIZE(choices) + 1;
    ITEM **items = new ITEM* [nChoices];
    for (unsigned i = 0; i < ARRAY_SIZE(choices); i++)
      items[i] = new_item(choices[i], NULL);
    items[nChoices-1] = NULL;

    // Create the menu
    MENU *menu = new_menu(items);
    // Menu options
    set_menu_mark(menu, NULL);
    // Attach the menu to the window
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 10, 80, 0, 10));

    // Make window and menu visible;
    post_menu(menu);
    wrefresh(window);
    refresh();
  
    // Start user interaction loop.
    int c;
    // The restart variable is used to tell the function to rebuild the
    // menu by starting at the top of the for(;;) loop above.
    bool restart = false;
    while (!restart && (c = wgetch(window))) {
      switch (c) {
        case KEY_DOWN:
          menu_driver(menu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(menu, REQ_UP_ITEM);
          break;
        case 10: // Enter
          // When the user hits enter determine the currently selected
          // item and do nessary actions. 
          const ITEM *currentItem = current_item(menu);
          const char *itemName = item_name(currentItem);
          // Delete allocated data
          unpost_menu(menu); 
          free_menu(menu); 
          delwin(window); 
          for (unsigned i = 0; i < ARRAY_SIZE(choices); i++)
            free_item(items[i]);
          delete [] items;
          // Edit/View Team Name
          if (strcmp(itemName, choices[0]) == 0) {
            viewEditTeamProperties(teamNumber);
            restart = true;
          // View/Remove Players
          } else if (strcmp(itemName, choices[1]) == 0)  {
            viewListPlayers(teamNumber);
            restart = true;
          // Add new Player
          } else if (strcmp(itemName, choices[2]) == 0)  {
            viewNewPlayer(teamNumber);
            restart = true;
          // Return
          } else if (strcmp(itemName, choices[3]) == 0)  {
            delwin(window);
            return;
          }
      }
    }
  }
}
예제 #27
0
/** \brief Populate a displayed menu
 *
 * This method peruses an array of menu items, calling the pure virtual methods
 * which the derived class should build a displayed menu.
 *
 * \param[in] path Path to this menu
 * \param[in] array An array of menu items
 *
 * \sa PopulateMenu
 */
void moMenuManager::PopulateMenu( const moWCString& path, moPropArrayRef array )
{
	const moNamePool& pool   = moNamePool::GetNamePool();
	const mo_name_t	menuName = pool.Get("Menu");
	const mo_name_t	itemName = pool.Get("Item");
	const mo_name_t sepName  = pool.Get("Separator");
	//const mo_name_t tbName   = pool.Get("Toolbar");

	unsigned long idx = 0;
	const unsigned long end = array.CountIndexes();

	for( ; idx < end; idx++ )
	{
		moPropSPtr		itemProp	= array.GetAtIndex( idx );
		moProp::prop_type_t	type		= itemProp->GetType();
		moName			name		= itemProp->GetName();
		mo_name_t		name_t		= (mo_name_t) name;

		switch( type )
		{
		case moProp::MO_PROP_TYPE_PROP_BAG:
		    {
			moPropBagRef	itemRef(name);
			itemRef.NewProp();
			itemRef.GetProperty()->Copy(*itemProp);

			moMenuItemSPtr	menu_item = new moMenuItem( itemRef );

			if( name_t == menuName )
			{
				// Signal menu start
				//
				Menu( path, menu_item );

				// Populate the menu
				//
				moWCString	item_name( menu_item->Value("Name") );
				moWCString	p = path + "/" + item_name;
				PopulateMenu( p, itemRef );

				// Signal menu finish
				//
				EndMenu( path, menu_item );
			}
			else if( name_t == itemName )
			{
				Item( path, menu_item );
			}
			else if( name_t == sepName )
			{
				menu_item->IsSeparator( true );
				Separator( path, menu_item );
			}
		    }
		    break;

		default:
		    std::cerr << "PopulateMenu(): Unsupported property type for this structure!" << std::endl;
		}
	}

}
예제 #28
0
void viewNewPlayer(FootBallGame::TeamNumber teamNumber) {
  const char *itemName;
  const ITEM *currentItem;

  const int window_nlines = 10,
            window_ncols  = 90;

  char *choices[] = {
    "Add",
    "Cancel",
  };


  for (;;) {
    // Create new window.
    WINDOW *window = newwin(window_nlines, 
        window_ncols, 
        headerWindow_begin_y + headerWindow_nlines + 1,
        0);
    // Set new window options.
    keypad(window, TRUE);


    // Create the form fields
    FIELD *field[6];
    for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++)
      field[i] = new_field(1, 26, i+2, 23, 0, 0);
    field[ARRAY_SIZE(field)-1] = NULL;
    // Set feild options 
    for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) {
      set_field_back(field[i], A_UNDERLINE);
      field_opts_off(field[i], O_AUTOSKIP);
    }
    // Set the field types
    set_field_type(field[0], TYPE_REGEXP, "^[A-Za-z ]*$");
    set_field_type(field[1], TYPE_INTEGER, 0, 1, 999);
    set_field_type(field[2], TYPE_REGEXP, "^[A-Za-z ]*$");
    set_field_type(field[3], TYPE_NUMERIC, 2, 1.00, 1500.00);
    set_field_type(field[4], TYPE_NUMERIC, 2, 1.00, 300.00);
    // Create the form
    FORM *form = new_form(field);
    set_form_win(form, window);
    set_form_sub(form, derwin(window, 10, 90, 0, 0));

    // Setup the menu items
    int nChoices = ARRAY_SIZE(choices)+1;
    ITEM **items = new ITEM* [nChoices];
    for (int i = 0; i < nChoices-1; i++)
      items[i] = new_item(choices[i], NULL);
    items[nChoices-1] = NULL;
    // Create the menu
    MENU *menu = new_menu(items);
    // Menu options
    set_menu_format(menu, 1, 2);
    set_menu_mark(menu, NULL);
    // Attach the menu to the window
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 1, 20, 8, 17));

    // Make window and menu visible;
    post_form(form);
    post_menu(menu);
    mvwprintw(window, 0, 10, "Player Properties: ");
    mvwprintw(window, 2, 10, "Name: ");
    mvwprintw(window, 3, 10, "Number: ");
    mvwprintw(window, 4, 10, "Position: ");
    mvwprintw(window, 5, 10, "weight (kg): ");
    mvwprintw(window, 6, 10, "height (cm): ");
    wrefresh(window);
    refresh();

    // Start user interaction loop.
    int c;
    // The restart variable is used to tell the function to rebuild the
    // menu by starting at the top of the for(;;) loop above.
    bool restart = false;
    while (!restart && (c = wgetch(window))) {
      mvprintw(LINES-1, 0, "                                         ");
      refresh();
      switch(c) {
        case KEY_DOWN:
        case 0x09:
          // Go to next field
          form_driver(form, REQ_NEXT_FIELD);
          // GO to the end of the presend buffer
          // Leaves nicely at the last character
          form_driver(form, REQ_END_LINE);
          break;
        case KEY_UP:
          // Go to previous field
          form_driver(form, REQ_PREV_FIELD);
          form_driver(form, REQ_END_LINE);
          break;
        case 0x7F:
          form_driver(form, REQ_DEL_PREV);
          break;
        case KEY_LEFT:
          menu_driver(menu, REQ_LEFT_ITEM);
          break;
        case KEY_RIGHT:
          menu_driver(menu, REQ_RIGHT_ITEM);
          break;
        case 10:
          // When the user hits enter determine the currently selected
          // item and do nessary actions. 
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          // Cancel
          if (strncmp(itemName, choices[1], strlen(choices[1])) == 0) {
            // Delete allocated data
            unpost_form(form); 
            unpost_menu(menu); 
            free_form(form); 
            free_menu(menu); 
            for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) 
              free_field(field[i]); 
            for (int i = 0; i < nChoices; i++)
              free_item(items[i]);
            delete [] items; 
            delwin(window);
            return;
          } else if (strncmp(itemName, choices[0], strlen(choices[0])) == 0) {
            form_driver(form, REQ_VALIDATION);
            bool invalid = false;
            for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++)
              if (field_status(field[i])==false)
                invalid = true;;
            if (invalid == false) {
              FootBallPlayer *player = new FootBallPlayer;
              player->setName(field_buffer(field[0], 0));
              player->setNumber(atoi(field_buffer(field[1], 0)));
              player->setPosition(field_buffer(field[2], 0));
              player->setWeight(strtof(field_buffer(field[3], 0), NULL));
              player->setHeight(strtof(field_buffer(field[4], 0), NULL));
              FootBallTeam *team = game.getFootBallTeam(teamNumber);
              if (team == NULL) {
                team = new FootBallTeam;
                game.setFootBallTeam(teamNumber, team);
              }
              team->addFootBallPlayer(player);
              // Delete allocated data
              unpost_form(form); 
              unpost_menu(menu); 
              free_form(form); 
              free_menu(menu); 
              for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) 
                free_field(field[i]); 
              for (int i = 0; i < nChoices; i++)
                free_item(items[i]);
              delete [] items; 
              delwin(window);
              return;
            } else {
              mvprintw(LINES-1, 0, "Fill out the form correctly!!");
              refresh();
            }
          }
          break;
        default:
          // If this is a normal character, it gets
          // printed
          form_driver(form, c);
          break;
      }
    }
  }
}
예제 #29
0
파일: main.c 프로젝트: rghamilton3/ts
// Handle the user input
int handleUserInput() {
    char *editor, *newPath;
    // Get and process user input
    while ((inputChar = getch()) != 'q') {
        switch (inputChar) {
            case 'e':   // Edit
                // Create cmd string using env vars
                editor = getenv("EDITOR");
                if (editor != NULL) {
                    strcpy(cmd, editor);
                    strcat(cmd, " ");
                } else
                    strcpy(cmd, "nano ");
                strcat(cmd, item_name(current_item(menus[FILES])));

                // Temporarily leave curses mode and run syscall
                def_prog_mode();
                endwin();
                errNum = system(cmd);

                // Return to curses mode
                reset_prog_mode();
                refresh();

                if (errNum != 0) {
                    attron(COLOR_PAIR(1));
                    mvprintw(LINES - 1, 0, "Error editing file: %s\n", strerror(errNum));
                    attroff(COLOR_PAIR(1));
                }
                break;
            case 'r':   // Run
                // Temporarily leave curses mode and run syscall
                def_prog_mode();
                endwin();
                errNum = system(item_name(current_item(menus[FILES])));

                // Return to curses mode
                reset_prog_mode();
                refresh();

                if (errNum != 0) {
                    attron(COLOR_PAIR(1));
                    mvprintw(LINES - 1, 0, "Error running file: %s\n", strerror(errNum));
                    attroff(COLOR_PAIR(1));
                    refresh();
                    getch();
                }
                break;
            case 'c':   // Change directory
                strcpy(cmd, "cd ");
                strcat(cmd, item_name(current_item(menus[DIRS])));

                errNum = system(cmd);
                if (errNum != 0) {
                    attron(COLOR_PAIR(1));
                    mvprintw(LINES - 1, 0, "Error changing directory: %s\n", strerror(errNum));
                    attroff(COLOR_PAIR(1));
                } else {
                    newPath = getenv("PWD");
                    strcpy(path, newPath);
                    updateDisplay();
                }
                break;
            case KEY_DOWN:
                menu_driver(menus[current], REQ_DOWN_ITEM);
                wrefresh(cursesWins[current]);
                break;
            case KEY_UP:
                menu_driver(menus[current], REQ_UP_ITEM);
                wrefresh(cursesWins[current]);
                break;
            case KEY_NPAGE:
                menu_driver(menus[current], REQ_SCR_DPAGE);
                wrefresh(cursesWins[current]);
                break;
            case KEY_PPAGE:
                menu_driver(menus[current], REQ_SCR_UPAGE);
                wrefresh(cursesWins[current]);
                break;
            case '\t':
                if (current == FILES)
                    current = DIRS;
                else
                    current = FILES;
                break;
            default:
                move(LINES - 1, 0);
                clrtoeol();
                attron(COLOR_PAIR(1));
                mvprintw(LINES - 1, 0, "Invalid command");
                attroff(COLOR_PAIR(1));
                refresh();
                break;
        }
    }
}
예제 #30
0
void
column_select_save_columns(ui_t *ui)
{
    int column;
    FILE *fi, *fo;
    char columnopt[128];
    char line[1024];
    char *home = getenv("HOME");
    char userconf[128], tmpfile[128];

    // No home dir...
    if (!home)
        return;

    // Read current $HOME/.sngreprc file
    sprintf(userconf, "%s/.sngreprc", home);
    sprintf(tmpfile, "%s/.sngreprc.old", home);

    // Remove old config file
    unlink(tmpfile);

    // Move home file to temporal dir
    rename(userconf, tmpfile);

    // Create a new user conf file
    if (!(fo = fopen(userconf, "w"))) {
        dialog_run("Unable to open %s: %s", userconf, strerror(errno));
        return;
    }

    // Read all lines of old sngreprc file
    if ((fi = fopen(tmpfile, "r"))) {

        // Read all configuration file
        while (fgets(line, 1024, fi) != NULL) {
            // Ignore lines starting with set (but keep settings)
            if (strncmp(line, "set ", 4) || strncmp(line, "set cl.column", 13)) {
                // Put everyting in new .sngreprc file
                fputs(line, fo);
            }
        }
        fclose(fi);
    }

    // Get panel information
    column_select_info_t *info = column_select_info(ui);

    // Add all selected columns
    for (column = 0; column < item_count(info->menu); column++) {
        // If column is active
        if (!strncmp(item_name(info->items[column]), "[ ]", 3))
            continue;

        // Add the columns settings
        sprintf(columnopt, "set cl.column%d %s\n", column, (const char*) item_userptr(info->items[column]));
        fputs(columnopt, fo);
    }
    fclose(fo);

    // Show a information dialog
    dialog_run("Column layout successfully saved to %s", userconf);
}