xref: /openbsd-src/lib/libform/frm_req_name.c (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: frm_req_name.c,v 1.5 2001/01/22 18:02:16 millert Exp $	*/
2 
3 /****************************************************************************
4  * Copyright (c) 1998,2000 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 <juergen.pfeifer@gmx.net> 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("$From: frm_req_name.c,v 1.8 2000/12/10 02:09:37 tom Exp $")
43 
44 static const char *request_names[ MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1 ] = {
45   "NEXT_PAGE"	 ,
46   "PREV_PAGE"	 ,
47   "FIRST_PAGE"	 ,
48   "LAST_PAGE"	 ,
49 
50   "NEXT_FIELD"	 ,
51   "PREV_FIELD"	 ,
52   "FIRST_FIELD"	 ,
53   "LAST_FIELD"	 ,
54   "SNEXT_FIELD"	 ,
55   "SPREV_FIELD"	 ,
56   "SFIRST_FIELD" ,
57   "SLAST_FIELD"	 ,
58   "LEFT_FIELD"	 ,
59   "RIGHT_FIELD"	 ,
60   "UP_FIELD"	 ,
61   "DOWN_FIELD"	 ,
62 
63   "NEXT_CHAR"	 ,
64   "PREV_CHAR"	 ,
65   "NEXT_LINE"	 ,
66   "PREV_LINE"	 ,
67   "NEXT_WORD"	 ,
68   "PREV_WORD"	 ,
69   "BEG_FIELD"	 ,
70   "END_FIELD"	 ,
71   "BEG_LINE"	 ,
72   "END_LINE"	 ,
73   "LEFT_CHAR"	 ,
74   "RIGHT_CHAR"	 ,
75   "UP_CHAR"	 ,
76   "DOWN_CHAR"	 ,
77 
78   "NEW_LINE"	 ,
79   "INS_CHAR"	 ,
80   "INS_LINE"	 ,
81   "DEL_CHAR"	 ,
82   "DEL_PREV"	 ,
83   "DEL_LINE"	 ,
84   "DEL_WORD"	 ,
85   "CLR_EOL"	 ,
86   "CLR_EOF"	 ,
87   "CLR_FIELD"	 ,
88   "OVL_MODE"	 ,
89   "INS_MODE"	 ,
90   "SCR_FLINE"	 ,
91   "SCR_BLINE"	 ,
92   "SCR_FPAGE"	 ,
93   "SCR_BPAGE"	 ,
94   "SCR_FHPAGE"   ,
95   "SCR_BHPAGE"   ,
96   "SCR_FCHAR"    ,
97   "SCR_BCHAR"    ,
98   "SCR_HFLINE"   ,
99   "SCR_HBLINE"   ,
100   "SCR_HFHALF"   ,
101   "SCR_HBHALF"   ,
102 
103   "VALIDATION"	 ,
104   "NEXT_CHOICE"	 ,
105   "PREV_CHOICE"
106 };
107 #define A_SIZE (sizeof(request_names)/sizeof(request_names[0]))
108 
109 /*---------------------------------------------------------------------------
110 |   Facility      :  libnform
111 |   Function      :  const char * form_request_name (int request);
112 |
113 |   Description   :  Get the external name of a form request.
114 |
115 |   Return Values :  Pointer to name      - on success
116 |                    NULL                 - on invalid request code
117 +--------------------------------------------------------------------------*/
118 NCURSES_EXPORT(const char *)
119 form_request_name ( int request )
120 {
121   if ( (request < MIN_FORM_COMMAND) || (request > MAX_FORM_COMMAND) )
122     {
123       SET_ERROR (E_BAD_ARGUMENT);
124       return (const char *)0;
125     }
126   else
127     return request_names[ request - MIN_FORM_COMMAND ];
128 }
129 
130 
131 /*---------------------------------------------------------------------------
132 |   Facility      :  libnform
133 |   Function      :  int form_request_by_name (const char *str);
134 |
135 |   Description   :  Search for a request with this name.
136 |
137 |   Return Values :  Request Id       - on success
138 |                    E_NO_MATCH       - request not found
139 +--------------------------------------------------------------------------*/
140 NCURSES_EXPORT(int)
141 form_request_by_name ( const char *str )
142 {
143   /* because the table is so small, it doesn't really hurt
144      to run sequentially through it.
145   */
146   unsigned int i = 0;
147   char buf[16];
148 
149   if (str)
150     {
151       strncpy(buf,str,sizeof(buf));
152       while( (i<sizeof(buf)) && (buf[i] != '\0') )
153 	{
154 	  buf[i] = toupper(buf[i]);
155 	  i++;
156 	}
157 
158       for (i=0; i < A_SIZE; i++)
159 	{
160 	  if (strncmp(request_names[i],buf,sizeof(buf))==0)
161 	    return MIN_FORM_COMMAND + i;
162 	}
163     }
164   RETURN(E_NO_MATCH);
165 }
166 
167 /* frm_req_name.c ends here */
168