/* * Initialize and call all necessary functions */ int main(int argc, char *argv[]) { int i; strcpy(path, getenv("PWD")); // Usage and invalid command line args if (argc > 2) { usage(); return -1; } else if (argc == 2) { if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) usage(); else if (strlen(argv[1]) < PATH_MAX) { strcpy(path, argv[1]); errNum = chdir(path); if (errNum != 0) fprintf(stderr, "Error changing directory: %s\n", strerror(errNum)); } else fprintf(stderr, "Error: input path too long\n"); } initscr(); // Start curses mode if (stdscr == NULL) { fprintf(stderr, "Error: could not initialize curses\n"); exit(-1); } cbreak(); // Disable line buffering noecho(); // Disable user input echoing keypad(stdscr, TRUE); // Read function keys // Setup color start_color(); init_pair(1, COLOR_RED, COLOR_BLACK); current = FILES; updateDisplay(); handleUserInput(); // Clean up memory unpost_menu(menus[0]); free_menu(menus[0]); for (i = 0; i < numFiles; i++) free_item(fileItems[i]); unpost_menu(menus[1]); free_menu(menus[1]); for (i = 0; i < numDirs; i++) free_item(dirItems[i]); endwin(); return 0; }
/* * Free the menu and items memory. */ void __renderers_free_home_page(void) { int i; struct userptr_data *data; if (!main_menu) return; unpost_menu(main_menu); for (i = 0; i < nb_items; i++) { free((void *) main_items[i]->description.str); free((void *) main_items[i]->name.str); data = item_userptr(main_items[i]); free((void *) data->dbus_name); free((void *) data->pretty_name); free(data); free_item(main_items[i]); } free_menu(main_menu); free(main_items); nb_items = 0; main_menu = NULL; main_items = NULL; }
/* * delete the internal menu for the files */ static void wdg_file_menu_destroy(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_file_handle, ww); int i = 0; /* nothing to free */ if (ww->nitems == 0) return; unpost_menu(ww->m); free_menu(ww->m); /* free all the items */ while(ww->items[i] != NULL) free_item(ww->items[i++]); for (i = 0; i < ww->nlist; i++) WDG_SAFE_FREE(ww->namelist[i]); /* free the array */ WDG_SAFE_FREE(ww->items); WDG_SAFE_FREE(ww->namelist); /* reset the counter */ ww->nitems = 0; }
void free_term_gui(void) { if (menu_list) { unpost_menu(menu_list); free_menu(menu_list); } if (list_items) { for (int i = 0; i < choices_cnt; i++) { free_item(list_items[i]); } free(list_items); } unpost_form(form); if (form) free_form(form); free_field(field[0]); endwin(); }
void clean_menu(MENU * my_menu){ unpost_menu(my_menu); if(my_menu != NULL) free_menu(my_menu); mvprintw(LINES - 2, 0, " "); //efface pied de page pour fermer le menu refresh(); }
/* * Delete the popup allocated memory. * This *won't* free popup_btn_action. */ void popup_delete(void) { int i; if (popup_form) { unpost_form(popup_form); for (i = 0; popup_fields[i] != NULL; i++) { free(field_buffer(popup_fields[i], 0)); free_field(popup_fields[i]); } free_form(popup_form); free(popup_fields); } unpost_menu(popup_menu); free_menu(popup_menu); for (i = 0; popup_items[i] != NULL; i++) free_item(popup_items[i]); free(popup_items); delwin(win_form); delwin(win_menu); delwin(win_body); win_body = NULL; popup_btn_action = NULL; popup_menu = NULL; }
int main() { initscr(); start_color(); ITEM *menuitems[6]; MENU *menubar; WINDOW *win,*sub_win; int i,rows,cols; //initcolor(); menuitems[0]=new_item("File",""); menuitems[1]=new_item("Edit",""); menuitems[2]=new_item("Options",""); menuitems[3]=new_item("Window",""); menuitems[4]=new_item("Help",""); menuitems[5]=NULL; //menu_opts_off(menubar,O_ROWMAJOR); menubar=new_menu(menuitems); scale_menu(menubar,&rows,&cols); win=newwin(rows+2,cols+2,2,5); box(win,179,196); sub_win=derwin(win,rows,cols,1,1); set_menu_win(menubar,win); set_menu_sub(menubar,sub_win); post_menu(menubar); wrefresh(win); wgetch(sub_win); unpost_menu(menubar); free_menu(menubar); for(i=0;i<6;i++) free_item(menuitems[i]); endwin(); }
Err menu(t_info *info) { preload_menu(info); load_menu(info); info->exit = 0; info->menu_over = 0; while (!info->exit) { SDL_Delay(10); while (SDL_PollEvent(&(info->mysdl.event))) { if (info->mysdl.event.type == SDL_MOUSEMOTION) menu_mousemotion(info, info->mysdl.event); else if (info->mysdl.event.type == SDL_MOUSEBUTTONDOWN) menu_mousebutton(info, info->mysdl.event); else if (info->mysdl.event.type == SDL_KEYDOWN) menu_key(info, info->mysdl.event); else if (info->mysdl.event.type == SDL_VIDEORESIZE) { resize_window(info, info->mysdl.event.resize.w, info->mysdl.event.resize.h); update_menu(info); } else if (info->mysdl.event.type == SDL_QUIT) info->exit = 1; break; } } free_menu(info); SDL_Quit(); return (0); }
/* * The hash table is to keep track of leaves which have already been displayed * to the user. */ int main(int argc, char **argv) { int i; /* Initialize space for blacklist hash table */ if(hcreate(10000)==0) { fputs("Cannot create hash table.\n",stderr); return(EX_UNAVAILABLE); } i=0; do { if(read_pkglist(i++)) break; if(display_menu()) break; if(remove_packages()) break; free_menu(); } while(keep_going()); hdestroy(); fputs("\nProgram Terminated Successfully\n",stderr); return(0); }
int main(int argc, char const *argv[]) { ITEM **my_items; int c; MENU *my_menu; WINDOW *my_menu_win; int n_choices, i; initscr(); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); init_pair(1, COLOR_RED, COLOR_BLACK); n_choices = ARRAY_SIZE(choices); my_items = (ITEM **) calloc(n_choices, sizeof(ITEM *)); for (i = 0; i < n_choices; ++i) my_items[i] = new_item(choices[i], choices[i]); my_menu = new_menu((ITEM **) my_items); my_menu_win = newwin(10, 40, 4, 4); keypad(my_menu_win, TRUE); set_menu_win(my_menu, my_menu_win); set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); set_menu_mark(my_menu, " * "); box(my_menu_win, 0, 0); print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1)); mvwaddch(my_menu_win, 2, 0, ACS_LTEE); mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38); mvwaddch(my_menu_win, 2, 39, ACS_RTEE); mvprintw(LINES - 2, 0, "F1 to exit"); refresh(); post_menu(my_menu); wrefresh(my_menu_win); while ((c = wgetch(my_menu_win)) != 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; } wrefresh(my_menu_win); } unpost_menu(my_menu); free_menu(my_menu); for (i = 0; i < n_choices; ++i) free_item(my_items[i]); endwin(); return 0; }
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; }
int generic_menu::get_choice() { if (choices.size() == return_values.size()) { //create the menu and the item pointer vector MENU* my_menu; std::vector<ITEM*> my_items; WINDOW* menu_win = derwin(screen, choices.size(), 30, ypos, xpos); ITEM* cur = NULL; for (int x = 0; x < choices.size(); x++) { //populate the items vector with the string data in choices //c_str because ncurses is very old my_items.push_back(new_item(choices.at(x).c_str(), NULL)); } //pushback a null item for safety my_items.push_back((ITEM*)NULL); //create the menu and attach the items my_menu = new_menu((ITEM**)my_items.data()); //print the desc and post the menu mvwprintw(screen, LINES - 3, 0, "%s\n", desc.c_str()); //set_current_item(my_menu, lastItem); set_menu_win(my_menu, menu_win); keypad(menu_win, TRUE); post_menu(my_menu); touchwin(screen); wrefresh(menu_win); std::vector<int>::iterator return_iter = return_values.begin(); int c = 0; while((c = wgetch(menu_win)) != '\n') { touchwin(screen); wrefresh(menu_win); switch(c) { case KEY_DOWN: menu_driver(my_menu, REQ_DOWN_ITEM); if (return_iter != return_values.end()) { return_iter++; } break; case KEY_UP: menu_driver(my_menu, REQ_UP_ITEM); if (return_iter != return_values.begin()) { return_iter--; } break; } } unpost_menu(my_menu); for (int x = 0; x < my_items.size(); x++) { free_item(my_items[x]); } free_menu(my_menu); return *return_iter; } }
static void clear_menu(MENU* my_menu, ITEM** my_items) { unpost_menu(my_menu); free_menu(my_menu); for (int i =0; my_items[i]; ++i) free_item(my_items[i]); free(my_items); }
static VALUE rbncurs_c_free_menu(VALUE rb_menu) { VALUE menus_hash = rb_iv_get(mMenu, "@menus_hash"); MENU *menu = get_menu(rb_menu); VALUE menu_address = INT2NUM((long)(menu)); rb_funcall(menus_hash, rb_intern("delete"), 1, menu_address); rb_iv_set(rb_menu, "@destroyed", Qtrue); return INT2NUM(free_menu(menu)); }
int Zavrsi(MENU *menu, ITEM **items, int n_choices) { int i; Validiraj_menu(unpost_menu(menu)); Validiraj_menu(free_menu(menu)); for(i = 0; i < n_choices; ++i) Validiraj_menu(free_item(items[i])); Validiraj_ncurses(endwin()); return 0; }
void free_menu(menu *m) { int i; for(i = 1; i <= m->nb_choix; i++) free_menu(m->choix[i]); free(m->choix); free(m); }
void termit_config_deinit() { g_free(configs.default_window_title); g_free(configs.default_tab_name); termit_style_free(&configs.style); g_free(configs.default_command); g_free(configs.default_encoding); g_free(configs.default_word_chars); free_menu(configs.user_menus); g_array_free(configs.user_menus, TRUE); free_menu(configs.user_popup_menus); g_array_free(configs.user_popup_menus, TRUE); // name and default_binding are static (e.g. can be in readonly mempage) guint i = 0; for (; i<configs.key_bindings->len; ++i) { struct KeyBinding* kb = &g_array_index(configs.key_bindings, struct KeyBinding, i); termit_lua_unref(&kb->lua_callback); } g_array_free(configs.key_bindings, TRUE); i = 0; for (; i<configs.mouse_bindings->len; ++i) { struct MouseBinding* mb = &g_array_index(configs.mouse_bindings, struct MouseBinding, i); termit_lua_unref(&mb->lua_callback); } g_array_free(configs.mouse_bindings, TRUE); i = 0; for (; i<configs.matches->len; ++i) { struct Match* match = &g_array_index(configs.matches, struct Match, i); g_regex_unref(match->regex); g_free(match->pattern); } g_array_free(configs.matches, TRUE); termit_lua_unref(&configs.get_window_title_callback); termit_lua_unref(&configs.get_tab_title_callback); termit_lua_unref(&configs.get_statusbar_callback); }
void free_menu_and_items(MENU *m) { size_t i, n; ITEM **items; items = menu_items(m); n = (size_t) item_count(m); for (i = 0; i < n; i++) free_item(items[i]); free_menu(m); }
void quit(void) { int i; unpost_menu(me); free_menu(me); for (i = 0; i <= 4; i++) { free_item(it[i]); } free(it); endwin(); }
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(); }
void end_curses(void) { int i; for (i=0; i<n_choices[0]; ++i) free_item(file_items[i]); for (i=0; i<n_choices[1]; ++i) free_item(view_items[i]); for (i=0; i<n_choices[2]; ++i) free_item(opts_items[i]); for (i=0; i<n_choices[3]; ++i) free_item(help_items[i]); free_menu(file_menu); free_menu(view_menu); free_menu(opts_menu); free_menu(help_menu); endwin(); }
void menu_pan_free(MENUPAN *morituro) { assert(morituro); unpost_menu(morituro->menu); free_menu(morituro->menu); delwin(morituro->win->win); delwin(morituro->sub->win); del_panel(morituro->win); del_panel(morituro->sub); free(morituro); }
char *main_menu(t_term *term) { char buf[3]; t_menu *menu; int nb_read; int xmenu; int nb_key; char *str; xmenu = 0; menu = xmalloc(sizeof(*menu) * 4); xtputs(xtgetstr("vi", &term->area), 1, my_outc); xtputs(term->clstr, 1, my_outc); init_menu(menu); while (1) { show_menu(menu, xmenu, 9, term); empty_buf(buf, 3); nb_read = xread(0, buf, 3); if (nb_read == 1 && (buf[0] == 27)) break; else if ((nb_read == 3) && (nb_key = test_key(term, buf[2]))) xmenu = move_mkey(nb_key, xmenu); else if ((nb_read == 1) && (buf[0] == 32)) { if ((str = main_smenu(term, xmenu, menu))) { xtputs(xtgetstr("ve", &term->area), 1, my_outc); free_menu(menu); return (str); } } } xtputs(xtgetstr("ve", &term->area), 1, my_outc); free_menu(menu); return (0); }
void do_logging(void) { int menu_no; menu_no = new_menu(MSG_Logging_functions, logmenu, 2, -1, 12, 0, 20, MC_SCROLL, NULL, log_menu_label, NULL, MSG_Pick_an_option, NULL); if (menu_no < 0) { (void)fprintf(stderr, "Dynamic menu creation failed.\n"); if (logfp) (void)fprintf(logfp, "Dynamic menu creation failed.\n"); exit(EXIT_FAILURE); } process_menu(menu_no, NULL); free_menu(menu_no); }
/* unpost menu and unglue items allowing them to be freed / changed in sp */ static void release_menu(smsgloader *_this) { int i; VERBOSE_DEBUGPR("releasing scom menu requested\n"); if(!_this->loadmenu) { DEBUGPR("Trying to free menu which is not allocated!\n"); return; } unpost_menu(_this->loadmenu); for(i=0;i<_this->itemamnt;i++) free_item(_this->loaditems[i]); free(_this->loaditems); _this->loaditems=NULL; free_menu(_this->loadmenu); _this->loadmenu=NULL; if(_this->derwin) delwin(_this->derwin); }
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); mvprintw(LINES - 2, 0, "F1 to Exit"); 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; } } free_item(my_items[0]); free_item(my_items[1]); free_menu(my_menu); endwin(); }
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); }
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); }
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); }
static void TRANSACTION_PROCESSING_MENU() { RDAmenu *menu=NULL; char *defdir=NULL; menu=RDAmenuNEW("TRANSACTION PROCESSING","domenu.EXT DATABASE \"TRANSACTION PROCESSING\""); if(menu!=NULL) { defdir=Rmalloc(RDAstrlen(CURRENTDIRECTORY)+RDAstrlen(module)+10); #ifndef WIN32 sprintf(defdir,"%s/rda/%s.MNU",CURRENTDIRECTORY,module); #endif #ifdef WIN32 sprintf(defdir,"%s\\rda\\%s.MNU",CURRENTDIRECTORY,module); #endif if(writemenubin(defdir,menu)) { ERRORDIALOG("Cannot Save Menu","This menu may not be saved to the specified library. Check your permissions and re-try. Call your installer for further instructions.",NULL,FALSE); } if(defdir!=NULL) Rfree(defdir); if(menu!=NULL) free_menu(menu); } }