1*c7ef0cfcSnicm /* $OpenBSD: frm_req_name.c,v 1.8 2023/10/17 09:52:10 nicm Exp $ */
202f2426aSmillert /****************************************************************************
3*c7ef0cfcSnicm * Copyright 2020,2021 Thomas E. Dickey *
4*c7ef0cfcSnicm * Copyright 1998-2012,2015 Free Software Foundation, Inc. *
502f2426aSmillert * *
602f2426aSmillert * Permission is hereby granted, free of charge, to any person obtaining a *
702f2426aSmillert * copy of this software and associated documentation files (the *
802f2426aSmillert * "Software"), to deal in the Software without restriction, including *
902f2426aSmillert * without limitation the rights to use, copy, modify, merge, publish, *
1002f2426aSmillert * distribute, distribute with modifications, sublicense, and/or sell *
1102f2426aSmillert * copies of the Software, and to permit persons to whom the Software is *
1202f2426aSmillert * furnished to do so, subject to the following conditions: *
1302f2426aSmillert * *
1402f2426aSmillert * The above copyright notice and this permission notice shall be included *
1502f2426aSmillert * in all copies or substantial portions of the Software. *
1602f2426aSmillert * *
1702f2426aSmillert * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
1802f2426aSmillert * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
1902f2426aSmillert * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
2002f2426aSmillert * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
2102f2426aSmillert * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
2202f2426aSmillert * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
2302f2426aSmillert * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
2402f2426aSmillert * *
2502f2426aSmillert * Except as contained in this notice, the name(s) of the above copyright *
2602f2426aSmillert * holders shall not be used in advertising or otherwise to promote the *
2702f2426aSmillert * sale, use or other dealings in this Software without prior written *
2802f2426aSmillert * authorization. *
2902f2426aSmillert ****************************************************************************/
3002f2426aSmillert
3102f2426aSmillert /****************************************************************************
3281d8c4e1Snicm * Author: Juergen Pfeifer, 1995,1997 *
3302f2426aSmillert ****************************************************************************/
346cd90de4Smillert
356cd90de4Smillert /***************************************************************************
366cd90de4Smillert * Module form_request_name *
376cd90de4Smillert * Routines to handle external names of menu requests *
386cd90de4Smillert ***************************************************************************/
396cd90de4Smillert
406cd90de4Smillert #include "form.priv.h"
416cd90de4Smillert
42*c7ef0cfcSnicm MODULE_ID("$Id: frm_req_name.c,v 1.8 2023/10/17 09:52:10 nicm Exp $")
436cd90de4Smillert
44*c7ef0cfcSnicm #define DATA(s) { s }
45*c7ef0cfcSnicm
46*c7ef0cfcSnicm static const char request_names[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1][13] =
4781d8c4e1Snicm {
48*c7ef0cfcSnicm DATA("NEXT_PAGE"),
49*c7ef0cfcSnicm DATA("PREV_PAGE"),
50*c7ef0cfcSnicm DATA("FIRST_PAGE"),
51*c7ef0cfcSnicm DATA("LAST_PAGE"),
526cd90de4Smillert
53*c7ef0cfcSnicm DATA("NEXT_FIELD"),
54*c7ef0cfcSnicm DATA("PREV_FIELD"),
55*c7ef0cfcSnicm DATA("FIRST_FIELD"),
56*c7ef0cfcSnicm DATA("LAST_FIELD"),
57*c7ef0cfcSnicm DATA("SNEXT_FIELD"),
58*c7ef0cfcSnicm DATA("SPREV_FIELD"),
59*c7ef0cfcSnicm DATA("SFIRST_FIELD"),
60*c7ef0cfcSnicm DATA("SLAST_FIELD"),
61*c7ef0cfcSnicm DATA("LEFT_FIELD"),
62*c7ef0cfcSnicm DATA("RIGHT_FIELD"),
63*c7ef0cfcSnicm DATA("UP_FIELD"),
64*c7ef0cfcSnicm DATA("DOWN_FIELD"),
656cd90de4Smillert
66*c7ef0cfcSnicm DATA("NEXT_CHAR"),
67*c7ef0cfcSnicm DATA("PREV_CHAR"),
68*c7ef0cfcSnicm DATA("NEXT_LINE"),
69*c7ef0cfcSnicm DATA("PREV_LINE"),
70*c7ef0cfcSnicm DATA("NEXT_WORD"),
71*c7ef0cfcSnicm DATA("PREV_WORD"),
72*c7ef0cfcSnicm DATA("BEG_FIELD"),
73*c7ef0cfcSnicm DATA("END_FIELD"),
74*c7ef0cfcSnicm DATA("BEG_LINE"),
75*c7ef0cfcSnicm DATA("END_LINE"),
76*c7ef0cfcSnicm DATA("LEFT_CHAR"),
77*c7ef0cfcSnicm DATA("RIGHT_CHAR"),
78*c7ef0cfcSnicm DATA("UP_CHAR"),
79*c7ef0cfcSnicm DATA("DOWN_CHAR"),
806cd90de4Smillert
81*c7ef0cfcSnicm DATA("NEW_LINE"),
82*c7ef0cfcSnicm DATA("INS_CHAR"),
83*c7ef0cfcSnicm DATA("INS_LINE"),
84*c7ef0cfcSnicm DATA("DEL_CHAR"),
85*c7ef0cfcSnicm DATA("DEL_PREV"),
86*c7ef0cfcSnicm DATA("DEL_LINE"),
87*c7ef0cfcSnicm DATA("DEL_WORD"),
88*c7ef0cfcSnicm DATA("CLR_EOL"),
89*c7ef0cfcSnicm DATA("CLR_EOF"),
90*c7ef0cfcSnicm DATA("CLR_FIELD"),
91*c7ef0cfcSnicm DATA("OVL_MODE"),
92*c7ef0cfcSnicm DATA("INS_MODE"),
93*c7ef0cfcSnicm DATA("SCR_FLINE"),
94*c7ef0cfcSnicm DATA("SCR_BLINE"),
95*c7ef0cfcSnicm DATA("SCR_FPAGE"),
96*c7ef0cfcSnicm DATA("SCR_BPAGE"),
97*c7ef0cfcSnicm DATA("SCR_FHPAGE"),
98*c7ef0cfcSnicm DATA("SCR_BHPAGE"),
99*c7ef0cfcSnicm DATA("SCR_FCHAR"),
100*c7ef0cfcSnicm DATA("SCR_BCHAR"),
101*c7ef0cfcSnicm DATA("SCR_HFLINE"),
102*c7ef0cfcSnicm DATA("SCR_HBLINE"),
103*c7ef0cfcSnicm DATA("SCR_HFHALF"),
104*c7ef0cfcSnicm DATA("SCR_HBHALF"),
1056cd90de4Smillert
106*c7ef0cfcSnicm DATA("VALIDATION"),
107*c7ef0cfcSnicm DATA("NEXT_CHOICE"),
108*c7ef0cfcSnicm DATA("PREV_CHOICE")
1096cd90de4Smillert };
11081d8c4e1Snicm
111*c7ef0cfcSnicm #undef DATA
112*c7ef0cfcSnicm
1136cd90de4Smillert #define A_SIZE (sizeof(request_names)/sizeof(request_names[0]))
1146cd90de4Smillert
1156cd90de4Smillert /*---------------------------------------------------------------------------
1166cd90de4Smillert | Facility : libnform
1176cd90de4Smillert | Function : const char * form_request_name (int request);
1186cd90de4Smillert |
1196cd90de4Smillert | Description : Get the external name of a form request.
1206cd90de4Smillert |
1216cd90de4Smillert | Return Values : Pointer to name - on success
1226cd90de4Smillert | NULL - on invalid request code
1236cd90de4Smillert +--------------------------------------------------------------------------*/
124*c7ef0cfcSnicm FORM_EXPORT(const char *)
form_request_name(int request)12584af20ceSmillert form_request_name(int request)
1266cd90de4Smillert {
12781d8c4e1Snicm T((T_CALLED("form_request_name(%d)"), request));
12881d8c4e1Snicm
1296cd90de4Smillert if ((request < MIN_FORM_COMMAND) || (request > MAX_FORM_COMMAND))
1306cd90de4Smillert {
1316cd90de4Smillert SET_ERROR(E_BAD_ARGUMENT);
13281d8c4e1Snicm returnCPtr((const char *)0);
1336cd90de4Smillert }
1346cd90de4Smillert else
13581d8c4e1Snicm returnCPtr(request_names[request - MIN_FORM_COMMAND]);
1366cd90de4Smillert }
1376cd90de4Smillert
1386cd90de4Smillert /*---------------------------------------------------------------------------
1396cd90de4Smillert | Facility : libnform
1406cd90de4Smillert | Function : int form_request_by_name (const char *str);
1416cd90de4Smillert |
1426cd90de4Smillert | Description : Search for a request with this name.
1436cd90de4Smillert |
1446cd90de4Smillert | Return Values : Request Id - on success
1456cd90de4Smillert | E_NO_MATCH - request not found
1466cd90de4Smillert +--------------------------------------------------------------------------*/
147*c7ef0cfcSnicm FORM_EXPORT(int)
form_request_by_name(const char * str)14884af20ceSmillert form_request_by_name(const char *str)
1496cd90de4Smillert {
1506cd90de4Smillert /* because the table is so small, it doesn't really hurt
1516cd90de4Smillert to run sequentially through it.
1526cd90de4Smillert */
153*c7ef0cfcSnicm size_t i = 0;
1546cd90de4Smillert
15581d8c4e1Snicm T((T_CALLED("form_request_by_name(%s)"), _nc_visbuf(str)));
15681d8c4e1Snicm
157*c7ef0cfcSnicm if (str != 0 && (i = strlen(str)) != 0)
1586cd90de4Smillert {
159*c7ef0cfcSnicm char buf[16]; /* longest name is 10 chars */
160*c7ef0cfcSnicm
161*c7ef0cfcSnicm if (i > sizeof(buf) - 2)
162*c7ef0cfcSnicm i = sizeof(buf) - 2;
163*c7ef0cfcSnicm memcpy(buf, str, i);
164*c7ef0cfcSnicm buf[i] = '\0';
165*c7ef0cfcSnicm
166*c7ef0cfcSnicm for (i = 0; buf[i] != '\0'; ++i)
1676cd90de4Smillert {
168*c7ef0cfcSnicm buf[i] = (char)toupper(UChar(buf[i]));
1696cd90de4Smillert }
1706cd90de4Smillert
1716cd90de4Smillert for (i = 0; i < A_SIZE; i++)
1726cd90de4Smillert {
173*c7ef0cfcSnicm if (strcmp(request_names[i], buf) == 0)
17481d8c4e1Snicm returnCode(MIN_FORM_COMMAND + (int)i);
1756cd90de4Smillert }
1766cd90de4Smillert }
1776cd90de4Smillert RETURN(E_NO_MATCH);
1786cd90de4Smillert }
1796cd90de4Smillert
1806cd90de4Smillert /* frm_req_name.c ends here */
181