|
|
``Sample menu program to create a menu in ETI'' shows the ETI code necessary for generating the menu of colors in ``A sample menu''.
#include <menu.h>char * colors[13] = { "Black", "Charcoal", "Light Gray", "Brown", "Camel", "Navy", "Light Blue", "Hunter Green", "Gold", "Burgundy", "Rust", "White", (char *) 0 };
ITEM * items[13];
main () { MENU * m; ITEM ** i = items; char * c = colors;
/* low-level ETI (curses) initialization */
initscr (); nonl (); raw (); noecho (); wclear (stdscr);
/* create items */
while (*c) *i++ = new_item (*c++, ""); *i = (ITEM *) 0;
/* create and display menu */
m = new_menu (i = items); post_menu (m); refresh; sleep (5);
/* erase menu and free both menu and items */
unpost_menu (m); refresh; free_menu (m);
while (*i) free_item (*i++);
/* low-level ETI (curses) termination */ endwin (); exit (0); }
Sample menu program to create a menu in ETI
To get an overview of ETI menu routines, we will now briefly walk through this menu program. In later sections, we discuss these and remaining ETI routines in detail.
Every menu program should have the line
#include <menu.h>to instruct the C preprocessor to make the file of ETI menu declarations available. The initial low-level ETI routines establish the best terminal characteristics for working with the ETI menu routines.
The while loop creates each item for the menu using the ETI function new_item. This function takes as its name argument a color from array colors[]. The optional description argument is here the null string. The new item pointers are assigned to a NULL-terminated array.
Next, the menu is created and connected to the item pointer array using function new_menu. The menu is then posted to stdscr and the screen is refreshed to display the menu. The sleep command makes the menu visible for five seconds.
To erase the menu, you unpost it and refresh the screen. Function free_menu disconnects the menu from its item pointer array and deallocates the space for the menu. The last while loop uses function free_item to free the space allocated for each item.
Finally, functions endwin and exit terminate low-level ETI and the program itself.
The following sections explain how to use all ETI menu routines. Program fragments illustrating the menu routines occur throughout this section. Many of these fragments are portions of a larger program example. The current example and others are included in the set of high-level ETI demonstration programs delivered with the ETI product. Low-level ETI demonstration programs are reproduced in the last section of this guide.