bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

menu problems


From: Rob Benton
Subject: menu problems
Date: 08 May 2003 17:26:21 -0500

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)



#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_UP_ITEM);
                                break;
                        case KEY_DOWN:
                                rcode = menu_driver(mainmenu, REQ_UP_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);
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]