]> ncurses.scripts.mit.edu Git - ncurses.git/blob - form/frm_req_name.c
ncurses 4.1
[ncurses.git] / form / frm_req_name.c
1 /*-----------------------------------------------------------------------------+
2 |           The ncurses form library is  Copyright (C) 1995-1997               |
3 |             by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de>                 |
4 |                          All Rights Reserved.                                |
5 |                                                                              |
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.                         | 
13 |                                                                              |
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 +-----------------------------------------------------------------------------*/
22
23 /***************************************************************************
24 * Module form_request_name                                                 *
25 * Routines to handle external names of menu requests                       *
26 ***************************************************************************/
27
28 #include "form.priv.h"
29
30 MODULE_ID("$Id: frm_req_name.c,v 1.4 1997/05/01 16:47:54 juergen Exp $")
31
32 static const char *request_names[ MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1 ] = {
33   "NEXT_PAGE"    ,
34   "PREV_PAGE"    ,
35   "FIRST_PAGE"   ,
36   "LAST_PAGE"    ,
37
38   "NEXT_FIELD"   ,
39   "PREV_FIELD"   ,
40   "FIRST_FIELD"  ,
41   "LAST_FIELD"   ,
42   "SNEXT_FIELD"  ,
43   "SPREV_FIELD"  ,
44   "SFIRST_FIELD" ,
45   "SLAST_FIELD"  ,
46   "LEFT_FIELD"   ,
47   "RIGHT_FIELD"  ,
48   "UP_FIELD"     ,
49   "DOWN_FIELD"   ,
50
51   "NEXT_CHAR"    ,
52   "PREV_CHAR"    ,
53   "NEXT_LINE"    ,
54   "PREV_LINE"    ,
55   "NEXT_WORD"    ,
56   "PREV_WORD"    ,
57   "BEG_FIELD"    ,
58   "END_FIELD"    ,
59   "BEG_LINE"     ,
60   "END_LINE"     ,
61   "LEFT_CHAR"    ,
62   "RIGHT_CHAR"   ,
63   "UP_CHAR"      ,
64   "DOWN_CHAR"    ,
65
66   "NEW_LINE"     ,
67   "INS_CHAR"     ,
68   "INS_LINE"     ,
69   "DEL_CHAR"     ,
70   "DEL_PREV"     ,
71   "DEL_LINE"     ,
72   "DEL_WORD"     ,
73   "CLR_EOL"      ,
74   "CLR_EOF"      ,
75   "CLR_FIELD"    ,
76   "OVL_MODE"     ,
77   "INS_MODE"     ,
78   "SCR_FLINE"    ,
79   "SCR_BLINE"    ,
80   "SCR_FPAGE"    ,
81   "SCR_BPAGE"    ,
82   "SCR_FHPAGE"   ,
83   "SCR_BHPAGE"   ,
84   "SCR_FCHAR"    ,
85   "SCR_BCHAR"    ,
86   "SCR_HFLINE"   ,
87   "SCR_HBLINE"   ,
88   "SCR_HFHALF"   ,
89   "SCR_HBHALF"   ,
90
91   "VALIDATION"   ,
92   "NEXT_CHOICE"  ,
93   "PREV_CHOICE"  
94 };
95 #define A_SIZE (sizeof(request_names)/sizeof(request_names[0]))
96
97 /*---------------------------------------------------------------------------
98 |   Facility      :  libnform  
99 |   Function      :  const char * form_request_name (int request);
100 |   
101 |   Description   :  Get the external name of a form request.
102 |
103 |   Return Values :  Pointer to name      - on success
104 |                    NULL                 - on invalid request code
105 +--------------------------------------------------------------------------*/
106 const char *form_request_name( int request )
107 {
108   if ( (request < MIN_FORM_COMMAND) || (request > MAX_FORM_COMMAND) )
109     {
110       SET_ERROR (E_BAD_ARGUMENT);
111       return (const char *)0;
112     }
113   else
114     return request_names[ request - MIN_FORM_COMMAND ];
115 }
116
117
118 /*---------------------------------------------------------------------------
119 |   Facility      :  libnform  
120 |   Function      :  int form_request_by_name (const char *str);
121 |   
122 |   Description   :  Search for a request with this name.
123 |
124 |   Return Values :  Request Id       - on success
125 |                    E_NO_MATCH       - request not found
126 +--------------------------------------------------------------------------*/
127 int form_request_by_name( const char *str )
128
129   /* because the table is so small, it doesn't really hurt
130      to run sequentially through it.
131   */
132   unsigned int i = 0;
133   char buf[16];
134   
135   if (str)
136     {
137       strncpy(buf,str,sizeof(buf));
138       while( (i<sizeof(buf)) && (buf[i] != '\0') )
139         {
140           buf[i] = toupper(buf[i]);
141           i++;
142         }
143       
144       for (i=0; i < A_SIZE; i++)
145         {
146           if (strncmp(request_names[i],buf,sizeof(buf))==0)
147             return MIN_FORM_COMMAND + i;
148         } 
149     }
150   RETURN(E_NO_MATCH);
151 }
152
153 /* frm_req_name.c ends here */