OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [xscale/] [iq80310/] [v2_0/] [src/] [diag/] [test_menu.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//=============================================================================
2
//
3
//      test_menu.c - Cyclone Diagnostics
4
//
5
//=============================================================================
6
//####ECOSGPLCOPYRIGHTBEGIN####
7
// -------------------------------------------
8
// This file is part of eCos, the Embedded Configurable Operating System.
9
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
10
//
11
// eCos is free software; you can redistribute it and/or modify it under
12
// the terms of the GNU General Public License as published by the Free
13
// Software Foundation; either version 2 or (at your option) any later version.
14
//
15
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
16
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18
// for more details.
19
//
20
// You should have received a copy of the GNU General Public License along
21
// with eCos; if not, write to the Free Software Foundation, Inc.,
22
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23
//
24
// As a special exception, if other files instantiate templates or use macros
25
// or inline functions from this file, or you compile this file and link it
26
// with other works to produce a work based on this file, this file does not
27
// by itself cause the resulting work to be covered by the GNU General Public
28
// License. However the source code for this file must still be made available
29
// in accordance with section (3) of the GNU General Public License.
30
//
31
// This exception does not invalidate any other reasons why a work based on
32
// this file might be covered by the GNU General Public License.
33
//
34
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
35
// at http://sources.redhat.com/ecos/ecos-license/
36
// -------------------------------------------
37
//####ECOSGPLCOPYRIGHTEND####
38
//=============================================================================
39
//#####DESCRIPTIONBEGIN####
40
//
41
// Author(s):   Scott Coulter, Jeff Frazier, Eric Breeden
42
// Contributors:
43
// Date:        2001-01-25
44
// Purpose:     
45
// Description: 
46
//
47
//####DESCRIPTIONEND####
48
//
49
//===========================================================================*/
50
 
51
/*****************************************************************************
52
* test_menu.c - Menu dispatching routine
53
*
54
* modification history
55
* --------------------
56
* 30aug00 ejb Ported to IQ80310 Cygmon
57
*/
58
 
59
/*
60
DESCRIPTION:
61
 
62
A table-driven menu dispatcher
63
*/
64
 
65
#include "test_menu.h"
66
#include "iq80310.h"
67
 
68
#define QUIT                    -1
69
#define MAX_INPUT_LINE_SIZE     80
70
 
71
extern long decIn(void);
72
 
73
/*
74
 * Internal routines
75
 */
76
static int menuGetChoice (MENU_ITEM     menuTable[],
77
                          int           numMenuItems,
78
                          char          *title,
79
                          unsigned long options);
80
static void printMenu (MENU_ITEM        menuTable[],
81
                       int              numMenuItems,
82
                       char             *title);
83
 
84
 
85
/***************************************************************************
86
*
87
* menu - a table-driven menu dispatcher
88
*
89
* RETURNS:
90
*
91
*       The menu item argument, or NULL if the item chosen is QUIT.
92
*/
93
MENU_ARG menu (
94
    MENU_ITEM   menuTable[],
95
    int         numMenuItems,
96
    char                *title,
97
    unsigned long       options
98
    )
99
{
100
    int item;           /* User's menu item choice */
101
 
102
    /*
103
     * Get the user's first choice.  Always display the menu the first time.
104
     */
105
    item = menuGetChoice (menuTable, numMenuItems, title, MENU_OPT_NONE);
106
    if (item == QUIT)
107
        return (NULL);
108
 
109
    /*
110
     * If the user just wants a value returned, return the argument.  If the
111
     * argument is null, return the item number itself.
112
     */
113
    if (options & MENU_OPT_VALUE) {
114
        if (menuTable[item].arg == NULL)
115
            return ((void *)item);
116
        else
117
            return (menuTable[item].arg);
118
    }
119
 
120
    /*
121
     * Process menu items until the user selects QUIT
122
     */
123
    while (TRUE) {
124
        /*
125
         * Call the action routine for the chosen item.  If the argument is
126
         * NULL, pass the item number itself.
127
         */
128
        if (menuTable[item].actionRoutine != NULL) {
129
            if (menuTable[item].arg == NULL) {
130
                printf("\n");
131
                (*menuTable[item].actionRoutine) ((void *)item);
132
            } else {
133
                printf("\n");
134
                (*menuTable[item].actionRoutine)(menuTable[item].arg);
135
            }
136
        }
137
 
138
        /*
139
         * Get the next choice, using any display options the user specified.
140
         */
141
        item = menuGetChoice (menuTable, numMenuItems, title, options);
142
        if (item == QUIT)
143
            return (NULL);
144
    }
145
}
146
 
147
 
148
/***************************************************************************
149
*
150
* menuGetChoice - Get the user's menu choice.
151
*
152
* If display is not suppressed, display the menu, then prompt the user for
153
* a choice.  If the choice is out of range or invalid, display the menu and
154
* prompt again.  Continue to display and prompt until a valid choice is made.
155
*
156
* RETURNS:
157
*       The item number of the user's menu choice. (-1 if they chose QUIT)
158
*/
159
 
160
static int
161
menuGetChoice (MENU_ITEM        menuTable[],
162
               int              numMenuItems,
163
               char             *title,
164
               unsigned long    options
165
               )
166
{
167
    int choice;
168
 
169
    /*
170
     * Suppress display of the menu the first time if we're asked
171
     */
172
    if (!(options & MENU_OPT_SUPPRESS_DISP))
173
        printMenu (menuTable, numMenuItems, title);
174
 
175
    /*
176
     * Prompt for a selection.  Redisplay the menu and prompt again
177
     * if there's an error in the selection.
178
     */
179
    choice = -1;
180
 
181
    while (choice < 0 || choice > numMenuItems) {
182
        printf ("\nEnter the menu item number (0 to quit): ");
183
        choice = decIn ();
184
        if (choice < 0 || choice > numMenuItems)
185
            printMenu (menuTable, numMenuItems, title);
186
    }
187
 
188
    if (choice == 0)
189
        return (QUIT);
190
 
191
    return (choice - 1);
192
 
193
}
194
 
195
 
196
/***************************************************************************
197
*
198
* printMenu - Print the menu
199
*
200
*
201
*/
202
 
203
static void
204
printMenu (MENU_ITEM    menuTable[],
205
           int          numMenuItems,
206
           char         *title
207
           )
208
{
209
    int         i;
210
 
211
    printf("\n%s\n\n", title);
212
 
213
    for (i = 0; i < numMenuItems; i++)
214
        printf ("%2d - %s\n", i+1, menuTable[i].itemName);
215
 
216
    printf(" 0 - quit");
217
 
218
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.