GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libform/frm_req_name.c Lines: 0 14 0.0 %
Date: 2017-11-07 Branches: 0 12 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: frm_req_name.c,v 1.7 2015/01/23 22:48:51 krw Exp $	*/
2
/****************************************************************************
3
 * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc.              *
4
 *                                                                          *
5
 * Permission is hereby granted, free of charge, to any person obtaining a  *
6
 * copy of this software and associated documentation files (the            *
7
 * "Software"), to deal in the Software without restriction, including      *
8
 * without limitation the rights to use, copy, modify, merge, publish,      *
9
 * distribute, distribute with modifications, sublicense, and/or sell       *
10
 * copies of the Software, and to permit persons to whom the Software is    *
11
 * furnished to do so, subject to the following conditions:                 *
12
 *                                                                          *
13
 * The above copyright notice and this permission notice shall be included  *
14
 * in all copies or substantial portions of the Software.                   *
15
 *                                                                          *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19
 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23
 *                                                                          *
24
 * Except as contained in this notice, the name(s) of the above copyright   *
25
 * holders shall not be used in advertising or otherwise to promote the     *
26
 * sale, use or other dealings in this Software without prior written       *
27
 * authorization.                                                           *
28
 ****************************************************************************/
29
30
/****************************************************************************
31
 *   Author:  Juergen Pfeifer, 1995,1997                                    *
32
 ****************************************************************************/
33
34
/***************************************************************************
35
* Module form_request_name                                                 *
36
* Routines to handle external names of menu requests                       *
37
***************************************************************************/
38
39
#include "form.priv.h"
40
41
MODULE_ID("$Id: frm_req_name.c,v 1.7 2015/01/23 22:48:51 krw Exp $")
42
43
static const char *request_names[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
44
{
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
108
#define A_SIZE (sizeof(request_names)/sizeof(request_names[0]))
109
110
/*---------------------------------------------------------------------------
111
|   Facility      :  libnform
112
|   Function      :  const char * form_request_name (int request);
113
|
114
|   Description   :  Get the external name of a form request.
115
|
116
|   Return Values :  Pointer to name      - on success
117
|                    NULL                 - on invalid request code
118
+--------------------------------------------------------------------------*/
119
NCURSES_EXPORT(const char *)
120
form_request_name(int request)
121
{
122
  T((T_CALLED("form_request_name(%d)"), request));
123
124
  if ((request < MIN_FORM_COMMAND) || (request > MAX_FORM_COMMAND))
125
    {
126
      SET_ERROR(E_BAD_ARGUMENT);
127
      returnCPtr((const char *)0);
128
    }
129
  else
130
    returnCPtr(request_names[request - MIN_FORM_COMMAND]);
131
}
132
133
/*---------------------------------------------------------------------------
134
|   Facility      :  libnform
135
|   Function      :  int form_request_by_name (const char *str);
136
|
137
|   Description   :  Search for a request with this name.
138
|
139
|   Return Values :  Request Id       - on success
140
|                    E_NO_MATCH       - request not found
141
+--------------------------------------------------------------------------*/
142
NCURSES_EXPORT(int)
143
form_request_by_name(const char *str)
144
{
145
  /* because the table is so small, it doesn't really hurt
146
     to run sequentially through it.
147
   */
148
  unsigned int i = 0;
149
  char buf[16];
150
151
  T((T_CALLED("form_request_by_name(%s)"), _nc_visbuf(str)));
152
153
  if (str)
154
    {
155
      strncpy(buf, str, sizeof(buf));
156
      while ((i < sizeof(buf)) && (buf[i] != '\0'))
157
	{
158
	  buf[i] = toupper(UChar(buf[i]));
159
	  i++;
160
	}
161
162
      for (i = 0; i < A_SIZE; i++)
163
	{
164
	  if (strncmp(request_names[i], buf, sizeof(buf)) == 0)
165
	    returnCode(MIN_FORM_COMMAND + (int) i);
166
	}
167
    }
168
  RETURN(E_NO_MATCH);
169
}
170
171
/* frm_req_name.c ends here */