Path: blob/master/Source/CursesDialog/form/frm_req_name.c
5020 views
/****************************************************************************1* Copyright (c) 1998 Free Software Foundation, Inc. *2* *3* Permission is hereby granted, free of charge, to any person obtaining a *4* copy of this software and associated documentation files (the *5* "Software"), to deal in the Software without restriction, including *6* without limitation the rights to use, copy, modify, merge, publish, *7* distribute, distribute with modifications, sublicense, and/or sell *8* copies of the Software, and to permit persons to whom the Software is *9* furnished to do so, subject to the following conditions: *10* *11* The above copyright notice and this permission notice shall be included *12* in all copies or substantial portions of the Software. *13* *14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *15* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *17* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *20* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *21* *22* Except as contained in this notice, the name(s) of the above copyright *23* holders shall not be used in advertising or otherwise to promote the *24* sale, use or other dealings in this Software without prior written *25* authorization. *26****************************************************************************/2728/****************************************************************************29* Author: Juergen Pfeifer <[email protected]> 1995,1997 *30****************************************************************************/3132/***************************************************************************33* Module form_request_name *34* Routines to handle external names of menu requests *35***************************************************************************/3637#include "form.priv.h"3839MODULE_ID("$Id$")4041static const char *request_names[ MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1 ] = {42"NEXT_PAGE" ,43"PREV_PAGE" ,44"FIRST_PAGE" ,45"LAST_PAGE" ,4647"NEXT_FIELD" ,48"PREV_FIELD" ,49"FIRST_FIELD" ,50"LAST_FIELD" ,51"SNEXT_FIELD" ,52"SPREV_FIELD" ,53"SFIRST_FIELD" ,54"SLAST_FIELD" ,55"LEFT_FIELD" ,56"RIGHT_FIELD" ,57"UP_FIELD" ,58"DOWN_FIELD" ,5960"NEXT_CHAR" ,61"PREV_CHAR" ,62"NEXT_LINE" ,63"PREV_LINE" ,64"NEXT_WORD" ,65"PREV_WORD" ,66"BEG_FIELD" ,67"END_FIELD" ,68"BEG_LINE" ,69"END_LINE" ,70"LEFT_CHAR" ,71"RIGHT_CHAR" ,72"UP_CHAR" ,73"DOWN_CHAR" ,7475"NEW_LINE" ,76"INS_CHAR" ,77"INS_LINE" ,78"DEL_CHAR" ,79"DEL_PREV" ,80"DEL_LINE" ,81"DEL_WORD" ,82"CLR_EOL" ,83"CLR_EOF" ,84"CLR_FIELD" ,85"OVL_MODE" ,86"INS_MODE" ,87"SCR_FLINE" ,88"SCR_BLINE" ,89"SCR_FPAGE" ,90"SCR_BPAGE" ,91"SCR_FHPAGE" ,92"SCR_BHPAGE" ,93"SCR_FCHAR" ,94"SCR_BCHAR" ,95"SCR_HFLINE" ,96"SCR_HBLINE" ,97"SCR_HFHALF" ,98"SCR_HBHALF" ,99100"VALIDATION" ,101"NEXT_CHOICE" ,102"PREV_CHOICE"103};104#define A_SIZE (sizeof(request_names)/sizeof(request_names[0]))105106/*---------------------------------------------------------------------------107| Facility : libnform108| Function : const char * form_request_name (int request);109|110| Description : Get the external name of a form request.111|112| Return Values : Pointer to name - on success113| NULL - on invalid request code114+--------------------------------------------------------------------------*/115const char *form_request_name( int request )116{117if ( (request < MIN_FORM_COMMAND) || (request > MAX_FORM_COMMAND) )118{119SET_ERROR (E_BAD_ARGUMENT);120return (const char *)0;121}122else123return request_names[ request - MIN_FORM_COMMAND ];124}125126127/*---------------------------------------------------------------------------128| Facility : libnform129| Function : int form_request_by_name (const char *str);130|131| Description : Search for a request with this name.132|133| Return Values : Request Id - on success134| E_NO_MATCH - request not found135+--------------------------------------------------------------------------*/136int form_request_by_name( const char *str )137{138/* because the table is so small, it doesn't really hurt139to run sequentially through it.140*/141unsigned int i = 0;142char buf[16];143144if (str)145{146strncpy(buf,str,sizeof(buf));147while( (i<sizeof(buf)) && (buf[i] != '\0') )148{149buf[i] = toupper((unsigned char)(buf[i]));150i++;151}152153for (i=0; i < A_SIZE; i++)154{155if (strncmp(request_names[i],buf,sizeof(buf))==0)156return MIN_FORM_COMMAND + i;157}158}159RETURN(E_NO_MATCH);160}161162/* frm_req_name.c ends here */163164165