1 /* $OpenBSD: frm_req_name.c,v 1.8 2023/10/17 09:52:10 nicm Exp $ */ 2 /**************************************************************************** 3 * Copyright 2020,2021 Thomas E. Dickey * 4 * Copyright 1998-2012,2015 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31 /**************************************************************************** 32 * Author: Juergen Pfeifer, 1995,1997 * 33 ****************************************************************************/ 34 35 /*************************************************************************** 36 * Module form_request_name * 37 * Routines to handle external names of menu requests * 38 ***************************************************************************/ 39 40 #include "form.priv.h" 41 42 MODULE_ID("$Id: frm_req_name.c,v 1.8 2023/10/17 09:52:10 nicm Exp $") 43 44 #define DATA(s) { s } 45 46 static const char request_names[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1][13] = 47 { 48 DATA("NEXT_PAGE"), 49 DATA("PREV_PAGE"), 50 DATA("FIRST_PAGE"), 51 DATA("LAST_PAGE"), 52 53 DATA("NEXT_FIELD"), 54 DATA("PREV_FIELD"), 55 DATA("FIRST_FIELD"), 56 DATA("LAST_FIELD"), 57 DATA("SNEXT_FIELD"), 58 DATA("SPREV_FIELD"), 59 DATA("SFIRST_FIELD"), 60 DATA("SLAST_FIELD"), 61 DATA("LEFT_FIELD"), 62 DATA("RIGHT_FIELD"), 63 DATA("UP_FIELD"), 64 DATA("DOWN_FIELD"), 65 66 DATA("NEXT_CHAR"), 67 DATA("PREV_CHAR"), 68 DATA("NEXT_LINE"), 69 DATA("PREV_LINE"), 70 DATA("NEXT_WORD"), 71 DATA("PREV_WORD"), 72 DATA("BEG_FIELD"), 73 DATA("END_FIELD"), 74 DATA("BEG_LINE"), 75 DATA("END_LINE"), 76 DATA("LEFT_CHAR"), 77 DATA("RIGHT_CHAR"), 78 DATA("UP_CHAR"), 79 DATA("DOWN_CHAR"), 80 81 DATA("NEW_LINE"), 82 DATA("INS_CHAR"), 83 DATA("INS_LINE"), 84 DATA("DEL_CHAR"), 85 DATA("DEL_PREV"), 86 DATA("DEL_LINE"), 87 DATA("DEL_WORD"), 88 DATA("CLR_EOL"), 89 DATA("CLR_EOF"), 90 DATA("CLR_FIELD"), 91 DATA("OVL_MODE"), 92 DATA("INS_MODE"), 93 DATA("SCR_FLINE"), 94 DATA("SCR_BLINE"), 95 DATA("SCR_FPAGE"), 96 DATA("SCR_BPAGE"), 97 DATA("SCR_FHPAGE"), 98 DATA("SCR_BHPAGE"), 99 DATA("SCR_FCHAR"), 100 DATA("SCR_BCHAR"), 101 DATA("SCR_HFLINE"), 102 DATA("SCR_HBLINE"), 103 DATA("SCR_HFHALF"), 104 DATA("SCR_HBHALF"), 105 106 DATA("VALIDATION"), 107 DATA("NEXT_CHOICE"), 108 DATA("PREV_CHOICE") 109 }; 110 111 #undef DATA 112 113 #define A_SIZE (sizeof(request_names)/sizeof(request_names[0])) 114 115 /*--------------------------------------------------------------------------- 116 | Facility : libnform 117 | Function : const char * form_request_name (int request); 118 | 119 | Description : Get the external name of a form request. 120 | 121 | Return Values : Pointer to name - on success 122 | NULL - on invalid request code 123 +--------------------------------------------------------------------------*/ 124 FORM_EXPORT(const char *) 125 form_request_name(int request) 126 { 127 T((T_CALLED("form_request_name(%d)"), request)); 128 129 if ((request < MIN_FORM_COMMAND) || (request > MAX_FORM_COMMAND)) 130 { 131 SET_ERROR(E_BAD_ARGUMENT); 132 returnCPtr((const char *)0); 133 } 134 else 135 returnCPtr(request_names[request - MIN_FORM_COMMAND]); 136 } 137 138 /*--------------------------------------------------------------------------- 139 | Facility : libnform 140 | Function : int form_request_by_name (const char *str); 141 | 142 | Description : Search for a request with this name. 143 | 144 | Return Values : Request Id - on success 145 | E_NO_MATCH - request not found 146 +--------------------------------------------------------------------------*/ 147 FORM_EXPORT(int) 148 form_request_by_name(const char *str) 149 { 150 /* because the table is so small, it doesn't really hurt 151 to run sequentially through it. 152 */ 153 size_t i = 0; 154 155 T((T_CALLED("form_request_by_name(%s)"), _nc_visbuf(str))); 156 157 if (str != 0 && (i = strlen(str)) != 0) 158 { 159 char buf[16]; /* longest name is 10 chars */ 160 161 if (i > sizeof(buf) - 2) 162 i = sizeof(buf) - 2; 163 memcpy(buf, str, i); 164 buf[i] = '\0'; 165 166 for (i = 0; buf[i] != '\0'; ++i) 167 { 168 buf[i] = (char)toupper(UChar(buf[i])); 169 } 170 171 for (i = 0; i < A_SIZE; i++) 172 { 173 if (strcmp(request_names[i], buf) == 0) 174 returnCode(MIN_FORM_COMMAND + (int)i); 175 } 176 } 177 RETURN(E_NO_MATCH); 178 } 179 180 /* frm_req_name.c ends here */ 181