[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: menu problems
From: |
Rob Benton |
Subject: |
Re: menu problems |
Date: |
09 May 2003 10:19:11 -0500 |
Well I will try another approach to endwin() then. The PREV/NEXT work
pretty well for me but is there any reason that my call to free_menu()
is ending with a SIGSEGV ? This is the error gdb returns:
Program received signal SIGSEGV, Segmentation fault.
0x400268e2 in _nc_Disconnect_Items () from /usr/lib/libmenu.so.5
On Thu, May 08, 2003 at 05:26:21PM -0500, Rob Benton wrote:
> I hope this is the right place to be asking this question. If not
> please let me know.
>
> Because I was having problems w/menu functions in one of my programs I
> decided to write the simplest program I could w/a menu. 3 options on
> the menu and all it does is move the selection up or down if the up or
> down arrow keys are pressed or quit the program if 'q' is pressed.
>
> menu_driver() returns E_REQUEST_DENIED when I send the REQ_UP or
> REQ_DOWN arguments. And the program ends with a segmentation fault
when
> I call free_menu().
>
> I must be doing something wrong but I can't figure out what. I'd
> appreciate any input. (sorry for the ugly tabs)
offhand - the example 'menu_test()' function in test/ncurses.c uses
REQ_NEXT_ITEM and REQ_PREV_ITEM rather than REQ_UP/REQ_DOWN.
you shouldn't have to try to do endwin() in a signal handler (ncurses
already tries ;-). It's possible to overload signal handlers, e.g.,
by calling the result of
foo = signal(SIGINT, finish);
when 'foo' isn't one of the magic values. I guess atexit() is more
reliable
though.
>
>
>
> #include <curses.h>
> #include <menu.h>
> #include <signal.h>
>
> void finish(int signal);
>
> int main() {
> int ch, rcode;
> ITEM * flash, * beep, * quit;
> MENU * mainmenu;
> ITEM * mlist[3];
>
> initscr();
> keypad(stdscr, true);
> noecho();
>
> signal(SIGINT, finish);
>
> flash = new_item("flash", "");
> beep = new_item("beep", "");
> quit = new_item("quit", "");
> mlist[0] = flash;
> mlist[1] = beep;
> mlist[2] = quit;
> mlist[3] = NULL;
>
> mainmenu = new_menu(mlist);
> set_menu_win(mainmenu, stdscr);
> set_menu_sub(mainmenu, stdscr);
> post_menu(mainmenu);
> refresh();
>
> while(1) {
> ch = getch();
> switch(ch) {
> case 'q':
> unpost_menu(mainmenu);
> free_menu(mainmenu);
> free_item(flash);
> free_item(beep);
> free_item(quit);
> finish(0);
> break;
> case KEY_UP:
> rcode = menu_driver(mainmenu, REQ_PREV_ITEM);
> break;
> case KEY_DOWN:
> rcode = menu_driver(mainmenu, REQ_NEXT_ITEM);
> break;
> default:
> rcode = E_OK;
> }
> if (rcode != E_OK) {
> finish(rcode);
> }
> }
> }
>
> void finish(int signal) {
> endwin();
> if (signal != 0) {
> printf("err:%d\n", signal);
> }
> exit(signal);
> }
- menu problems, Rob Benton, 2003/05/08
- Re: menu problems,
Rob Benton <=