Subversion Repositories svn1

Rev

Rev 46 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 root 1
/*************************************************************************
2
*           Copyright (C) 1995 Embedded Solutions
3
*                       All rights reserved
4
*
5
* file:     src\menudrv.c
6
*
7
* purpose:  Module that contains the table driven menu driver
8
*
9
*           The function that is called to do all the work is do_menu
10
*           This function requires a pointer to an array of menu drive entries
11
*           The function returns when an abort is requested.
12
*
13
* functions
14
*       do_menu                 - Produce menu
15
*
16
* programmer: David Purdie
17
*
18
* revision  date        by      reason
19
*   00.0    27/01/95    DDP     Tidies up the program and formatted the file
20
*
21
**************************************************************************/
22
 
23
#include    "consts.h"
24
#include    "structs.h"
25
#include    "proto.h"
26
 
27
/*========================================================================
28
 *
29
 *  Produce menu
30
 *
31
 *  Purpose:
32
 *      This function is called to process a menu structure and display
33
 *      a menu on the screen.
34
 *
35
 *  Parameters:
36
 *      header          Menu display title
37
 *      prompt          Operator prompt
38
 *      table           Drive table structure
39
 *      
40
 *
41
 *  Returns:
42
 *      Nothing
43
 *
44
 *========================================================================*/
45
 
46
void do_menu( char *header, char *prompt, menu_table * table )
47
{
48
    menu_table *curr;                            /* Current entry pointer */
49
    int         i;
50
    char        c;
51
    int         alldone = FALSE;
52
    int         found;
53
 
54
    /*
55
     * Clear the screen and display the menu 
56
     */
57
 
58
    do
59
    {
60
        abort_flag = FALSE;                      /* Reset global abort flag */
61
        curr = table;                            /* init the current pointer */
62
        i = 2;                                   /* init cursor position */
63
        clearscreen();
64
        cur( 10, i );
65
        printf( "%s", header );                  /* display header */
66
        i += 2;
67
        while( curr->key )
68
        {
69
            cur( 10, i );
70
            console_prompt ( curr->key  );
71
            printf( " %s", curr->prompt );
72
            i++;
73
            curr++;
74
        }
75
 
76
        /*
77
         * Prompt the operator to select an item 
78
         */
79
 
80
        found = FALSE;
81
        while( !found )
82
        {
83
            cur( 0, 2 + i );
84
            printf( "%s:", prompt );
85
            console_clreol();
86
            c = toupper( getinp() );
87
            if( abort_flag )
88
            {
89
                alldone = TRUE;
90
                break;
91
            }
92
            curr = table;
93
            while( curr->key )
94
            {
95
                if( toupper( ( int ) curr->key ) == c )
96
                {
97
                    found = TRUE;
98
                    /*
99
                     * Correct operation located 
100
                     */
101
                    if( curr->doit == NULL )
102
                    {
103
                        alldone = TRUE;
104
                        break;
105
                    }
106
                    else
107
                    {
108
                        clearscreen();
109
                        ( void ) ( *curr->doit ) ();
110
                        break;
111
                    }
112
                }
113
                curr++;
114
            }
115
            if( !found )
116
                beep();                        /* operator */
117
        }
118
    } while( !alldone );
119
}
120
 
121
/********************************* EOF ***********************************/