/************************************************************************* * Copyright (C) 1995 Embedded Solutions * All rights reserved * * file: src\menudrv.c * * purpose: Module that contains the table driven menu driver * * The function that is called to do all the work is do_menu * This function requires a pointer to an array of menu drive entries * The function returns when an abort is requested. * * functions * do_menu - Produce menu * * programmer: David Purdie * * revision date by reason * 00.0 27/01/95 DDP Tidies up the program and formatted the file * **************************************************************************/ #include "consts.h" #include "structs.h" #include "proto.h" /*======================================================================== * * Produce menu * * Purpose: * This function is called to process a menu structure and display * a menu on the screen. * * Parameters: * header Menu display title * prompt Operator prompt * table Drive table structure * * * Returns: * Nothing * *========================================================================*/ void do_menu( char *header, char *prompt, menu_table * table ) { menu_table *curr; /* Current entry pointer */ int i; char c; int alldone = FALSE; int found; /* * Clear the screen and display the menu */ do { abort_flag = FALSE; /* Reset global abort flag */ curr = table; /* init the current pointer */ i = 2; /* init cursor position */ clearscreen(); cur( 10, i ); printf( "%s", header ); /* display header */ i += 2; while( curr->key ) { cur( 10, i ); console_prompt ( curr->key ); printf( " %s", curr->prompt ); i++; curr++; } /* * Prompt the operator to select an item */ found = FALSE; while( !found ) { cur( 0, 2 + i ); printf( "%s:", prompt ); console_clreol(); c = toupper( getinp() ); if( abort_flag ) { alldone = TRUE; break; } curr = table; while( curr->key ) { if( toupper( ( int ) curr->key ) == c ) { found = TRUE; /* * Correct operation located */ if( curr->doit == NULL ) { alldone = TRUE; break; } else { clearscreen(); ( void ) ( *curr->doit ) (); break; } } curr++; } if( !found ) beep(); /* operator */ } } while( !alldone ); } /********************************* EOF ***********************************/