1 /*-----------------------------------------------------------------------------+
2 | The ncurses menu library is Copyright (C) 1995-1997 |
3 | by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> |
4 | All Rights Reserved. |
6 | Permission to use, copy, modify, and distribute this software and its |
7 | documentation for any purpose and without fee is hereby granted, provided |
8 | that the above copyright notice appear in all copies and that both that |
9 | copyright notice and this permission notice appear in supporting |
10 | documentation, and that the name of the above listed copyright holder(s) not |
11 | be used in advertising or publicity pertaining to distribution of the |
12 | software without specific, written prior permission. |
14 | THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO |
15 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- |
16 | NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR |
17 | ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- |
18 | SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
19 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH |
20 | THE USE OR PERFORMANCE OF THIS SOFTWARE. |
21 +-----------------------------------------------------------------------------*/
23 /***************************************************************************
24 * Module menu_request_name *
25 * Routines to handle external names of menu requests *
26 ***************************************************************************/
28 #include "menu.priv.h"
30 MODULE_ID("$Id: m_req_name.c,v 1.8 1997/05/01 16:47:26 juergen Exp $")
32 static const char *request_names[ MAX_MENU_COMMAND - MIN_MENU_COMMAND + 1 ] = {
51 #define A_SIZE (sizeof(request_names)/sizeof(request_names[0]))
53 /*---------------------------------------------------------------------------
55 | Function : const char * menu_request_name (int request);
57 | Description : Get the external name of a menu request.
59 | Return Values : Pointer to name - on success
60 | NULL - on invalid request code
61 +--------------------------------------------------------------------------*/
62 const char *menu_request_name( int request )
64 if ( (request < MIN_MENU_COMMAND) || (request > MAX_MENU_COMMAND) )
66 SET_ERROR(E_BAD_ARGUMENT);
67 return (const char *)0;
70 return request_names[ request - MIN_MENU_COMMAND ];
74 /*---------------------------------------------------------------------------
76 | Function : int menu_request_by_name (const char *str);
78 | Description : Search for a request with this name.
80 | Return Values : Request Id - on success
81 | E_NO_MATCH - request not found
82 +--------------------------------------------------------------------------*/
83 int menu_request_by_name( const char *str )
85 /* because the table is so small, it doesn't really hurt
86 to run sequentially through it.
93 strncpy(buf,str,sizeof(buf));
94 while( (i<sizeof(buf)) && (buf[i] != '\0') )
96 buf[i] = toupper(buf[i]);
100 for (i=0; i < A_SIZE; i++)
102 if (strncmp(request_names[i],buf,sizeof(buf))==0)
103 return MIN_MENU_COMMAND + i;
109 /* m_req_name.c ends here */