home *** CD-ROM | disk | FTP | other *** search
- /*
- * FILE: menapp.c
- * AUTHOR: R. Gonzalez
- * CREATED: August 25, 1990
- *
- * Defines menu-driven application methods.
- */
-
- # include <stdio.h>
- # include "menapp.h"
- # include "morestr.h"
-
- # define MAX_LENGTH 80
-
- /************************************************************************
- * initialize application - programmer should override: first call
- * inherited method, then add new menu items
- ************************************************************************/
- boolean Menu_App::init(void)
- {
- return Generic_App::init();
- }
-
- /************************************************************************
- * execute application. No need to override.
- ************************************************************************/
- void Menu_App::run(void)
- {
- char line[MAX_LENGTH],
- number[MAX_LENGTH];
- int menu_num,
- item,
- i;
- comfunc command_ptr;
-
- while (!done)
- {
- respond("");
- for (i=1 ; i<= menu->num_menus ; i++)
- {
- sprintf(line,"%d\t%s",i,menu->command[i][0]);
- respond(line);
- }
- respond("");
- query("Enter main command number: ",number);
- menu_num = strtoint(number);
-
- if (menu_num > 0 && menu_num <= menu->num_menus)
- {
- respond("");
- for (i=1 ; i<menu->num_items[menu_num] ; i++)
- {
- sprintf(line,"%d\t%s",i,menu->command[menu_num][i]);
- respond(line);
- }
- respond("");
- query("Enter command number: ",number);
- item = strtoint(number);
- respond("");
-
- if (item > 0 && item < menu->num_items[menu_num])
- {
- command_ptr = menu->get_command_ptr(menu_num,item);
- if (!(*command_ptr)(this))
- respond("Illegal usage.");
- }
- else
- respond("Illegal command.");
- }
- else
- respond("Illegal command.");
- }
- }
-
- /************************************************************************
- * get string from user. No need to override.
- ************************************************************************/
- void Menu_App::query(char *question,char answer[])
- {
- printf("%s",question);
- get_line(stdin,answer,MAX_LENGTH);
- }
-
- /************************************************************************
- * reply to user. No need to override.
- ************************************************************************/
- void Menu_App::respond(char *response)
- {
- puts(response);
- }
-
- /************************************************************************
- * terminate application. Programmer should call inherited method
- * if the derived application overrides it.
- ************************************************************************/
- boolean Menu_App::destroy(void)
- {
- return Generic_App::destroy();
- }
-
-