Hi,

I am trying to write a customize menu program for installation process of my 
software. But the menu options are not comming up properly. Also my intention 
is that when the user press / selects an option a new panel should be 
displayed asking param for input and then display the parms (side-by-side) 
along with the menu option:

#include <curses.h>
#include <menu.h>
#define ARRAY_ELEMENTS 31
#define CTRLD   4
char *choices[][31] = {
        {"-install|i","Install the RPM package (required)"},
        {"-erase|e","Erase the RPM package (required)"},
        {"-package|p","The RPM package to install/erase (required)"},
        {"-from|f","Publishing location (required)"},
        {"-recursive|r","Recursively searching publish area directories for 
packages"},
        {"-show|sh","Show available packages from publishing locations"},
        {"-help|he","Print this message and exit"},
        {"-host|h","Host to install the RPM package on"},
        {"-stage|s","Destination stage for the RPM package"},
        {"-quiet|q","Print only error messages"},
        {"-verbose|v","Print extra verbose information"},
        {"-n|n","Do not execute, just show the command"},
        {"-checkdep|d", "Check package dependencies (Default: don't check)"},
        {"-exact|ex","Use the exact package version number (E.g. 31.0-5, 
32.0-15)"},
        {"-force|fo","Force installation of package"},
        {"-group|g","Destination user/group for installed RPM package"},
        {"-nostart|no","Do not start the server after installation"},
        {"-command|c","Running as a command inside another program (hidden)"},
        {"-noproxy|np","Do not use a proxy in the ssh tunnel"},
        {"-port|po", "Remote host forward port (Default: 7000)"},
        {"-nix","Setup a tunnel to the live Equinix site"},
        {"-sc5","Setup a tunnel to the live sc5 site"},
        {"-den","Setup a tunnel to the live Denver site"},
        {"-preinstall|pre","Sync RPM images to host, Don't install them."},
        {"-localRPMS|local","Sync RPMs to hosts and install them."},
        {"-localRPMSDir","Directory to copy RPMS to."},
        {"-cleanupRPMS|cleanup","Remove RPM images after the install 
(default)"},
        {"-onpg","Install package on the playground machine."},
        {"Done","Done with selection (execute)"},
        {"Exit", "Exit from this menu"},
        {(char *)NULL, (char *)NULL}
};
void print_in_middle(WINDOW *win, int starty, int startx, int width, char 
*string, chtype color);
int main()
{       ITEM **my_items;
        int c;
        MENU *my_menu;
        WINDOW *my_menu_win;
        int n_choices, i;
        /* Initialize curses */
        initscr();
        start_color();
        cbreak();
        noecho();
        keypad(stdscr, TRUE);
        init_pair(1, COLOR_RED, COLOR_BLACK);
        init_pair(2, COLOR_CYAN, COLOR_BLACK);
        /* Create items */
        n_choices = ARRAY_ELEMENTS;
        my_items = (ITEM **)calloc(n_choices+1, sizeof(ITEM *));
        for(i = 0; i < n_choices; ++i)
                my_items[i] = new_item(choices[i][0], choices[i][1]);
        my_items[i] = new_item((char *)NULL, (char *) NULL);
        /* Crate menu */
        my_menu = new_menu((ITEM **)my_items);
        /* Create the window to be associated with the menu */
        my_menu_win = newwin(35, 70, 4, 4);
        keypad(my_menu_win, TRUE);
        /* Set main window and sub window */
        set_menu_win(my_menu, my_menu_win);
        set_menu_sub(my_menu, derwin(my_menu_win, 20, 60, 3, 1));
        set_menu_format(my_menu, 16, 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, 70, "InstallIamge", COLOR_PAIR(1));
        mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
        mvwhline(my_menu_win, 2, 1, ACS_HLINE, 68);
        mvwaddch(my_menu_win, 2, 69, ACS_RTEE);
        /* Post the menu */
        post_menu(my_menu);
        wrefresh(my_menu_win);
        attron(COLOR_PAIR(2));
        mvprintw(LINES - 2, 0, "Use PageUp and PageDown to scoll down or up a 
page of items");
        mvprintw(LINES - 1, 0, "Arrow Keys to navigate (F1 to Exit)");
        attroff(COLOR_PAIR(2));
        refresh();
        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;
                        case KEY_NPAGE:
                                menu_driver(my_menu, REQ_SCR_DPAGE);
                                break;
                        case KEY_PPAGE:
                                menu_driver(my_menu, REQ_SCR_UPAGE);
                                break;
                }
                wrefresh(my_menu_win);
        }
        /* Unpost and free all the memory taken up */
        unpost_menu(my_menu);
        free_menu(my_menu);
        for(i = 0; i < n_choices; ++i)
                free_item(my_items[i]);
        endwin();
}
void print_in_middle(WINDOW *win, int starty, int startx, int width, char 
*string, chtype color)
{       int length, x, y;
        float temp;
        if(win == NULL)
                win = stdscr;
        getyx(win, y, x);
        if(startx != 0)
                x = startx;
        if(starty != 0)
                y = starty;
        if(width == 0)
                width = 80;
        length = strlen(string);
        temp = (width - length)/ 2;
        x = startx + (int)temp;
        wattron(win, color);
        mvwprintw(win, y, x, "%s", string);
        wattroff(win, color);
        refresh();
}

Regards,
Prakash




________________________________
From: Tyler Littlefield <[email protected]>
To: [email protected]
Sent: Sunday, February 22, 2009 12:25:12 PM
Subject: Re: [c-prog] Re: I am new here.


>and get a copy of "Teach Yourself C in 21 days"
it is *not the best.* anything that says in 21 days is something worth running 
away from, far far away.
There is a book list that was supplied when you joined, I'd recommend using the 
books off of that.

----- Original Message ----- 
From: cupofjava1961@ aol.com 
To: c-p...@yahoogroups. com 
Sent: Sunday, February 22, 2009 10:23 AM
Subject: Re: [c-prog] Re: I am new here.

No, you have to teach yourself.
Get a C compiler for your computer
and get a copy of "Teach Yourself C in 21 days"
by Peter Aitken. It's probably the best C primer out there.
************ **You can't always choose whom you love, but you can choose how 
to find them. Start with AOL Personals. 
(http://personals. aol.com/? ncid=emlcntuslov e00000002)

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]





      

[Non-text portions of this message have been removed]

Reply via email to