xref: /freebsd/contrib/ncurses/progs/tparm_type.c (revision 7a656419)
1aae38d10SBaptiste Daroussin /****************************************************************************
2e1865124SBaptiste Daroussin  * Copyright 2020 Thomas E. Dickey                                          *
3e1865124SBaptiste Daroussin  * Copyright 2014,2015 Free Software Foundation, Inc.                       *
4aae38d10SBaptiste Daroussin  *                                                                          *
5aae38d10SBaptiste Daroussin  * Permission is hereby granted, free of charge, to any person obtaining a  *
6aae38d10SBaptiste Daroussin  * copy of this software and associated documentation files (the            *
7aae38d10SBaptiste Daroussin  * "Software"), to deal in the Software without restriction, including      *
8aae38d10SBaptiste Daroussin  * without limitation the rights to use, copy, modify, merge, publish,      *
9aae38d10SBaptiste Daroussin  * distribute, distribute with modifications, sublicense, and/or sell       *
10aae38d10SBaptiste Daroussin  * copies of the Software, and to permit persons to whom the Software is    *
11aae38d10SBaptiste Daroussin  * furnished to do so, subject to the following conditions:                 *
12aae38d10SBaptiste Daroussin  *                                                                          *
13aae38d10SBaptiste Daroussin  * The above copyright notice and this permission notice shall be included  *
14aae38d10SBaptiste Daroussin  * in all copies or substantial portions of the Software.                   *
15aae38d10SBaptiste Daroussin  *                                                                          *
16aae38d10SBaptiste Daroussin  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17aae38d10SBaptiste Daroussin  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18aae38d10SBaptiste Daroussin  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19aae38d10SBaptiste Daroussin  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20aae38d10SBaptiste Daroussin  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21aae38d10SBaptiste Daroussin  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22aae38d10SBaptiste Daroussin  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23aae38d10SBaptiste Daroussin  *                                                                          *
24aae38d10SBaptiste Daroussin  * Except as contained in this notice, the name(s) of the above copyright   *
25aae38d10SBaptiste Daroussin  * holders shall not be used in advertising or otherwise to promote the     *
26aae38d10SBaptiste Daroussin  * sale, use or other dealings in this Software without prior written       *
27aae38d10SBaptiste Daroussin  * authorization.                                                           *
28aae38d10SBaptiste Daroussin  ****************************************************************************/
29aae38d10SBaptiste Daroussin 
30aae38d10SBaptiste Daroussin /****************************************************************************
31aae38d10SBaptiste Daroussin  *  Author: Thomas E. Dickey                                                *
32aae38d10SBaptiste Daroussin  ****************************************************************************/
33aae38d10SBaptiste Daroussin 
34aae38d10SBaptiste Daroussin #include <tparm_type.h>
35aae38d10SBaptiste Daroussin 
36*7a656419SBaptiste Daroussin MODULE_ID("$Id: tparm_type.c,v 1.4 2020/10/24 17:30:32 tom Exp $")
37aae38d10SBaptiste Daroussin 
38aae38d10SBaptiste Daroussin /*
39aae38d10SBaptiste Daroussin  * Lookup the type of call we should make to tparm().  This ignores the actual
40aae38d10SBaptiste Daroussin  * terminfo capability (bad, because it is not extensible), but makes this
41aae38d10SBaptiste Daroussin  * code portable to platforms where sizeof(int) != sizeof(char *).
42aae38d10SBaptiste Daroussin  */
43aae38d10SBaptiste Daroussin TParams
tparm_type(const char * name)44aae38d10SBaptiste Daroussin tparm_type(const char *name)
45aae38d10SBaptiste Daroussin {
46aae38d10SBaptiste Daroussin #define TD(code, longname, ti, tc) \
47aae38d10SBaptiste Daroussin     	{code, {longname} }, \
48aae38d10SBaptiste Daroussin 	{code, {ti} }, \
49aae38d10SBaptiste Daroussin 	{code, {tc} }
50aae38d10SBaptiste Daroussin     TParams result = Numbers;
51aae38d10SBaptiste Daroussin     /* *INDENT-OFF* */
52aae38d10SBaptiste Daroussin     static const struct {
53aae38d10SBaptiste Daroussin 	TParams code;
54aae38d10SBaptiste Daroussin 	const char name[12];
55aae38d10SBaptiste Daroussin     } table[] = {
56aae38d10SBaptiste Daroussin 	TD(Num_Str,	"pkey_key",	"pfkey",	"pk"),
57aae38d10SBaptiste Daroussin 	TD(Num_Str,	"pkey_local",	"pfloc",	"pl"),
58aae38d10SBaptiste Daroussin 	TD(Num_Str,	"pkey_xmit",	"pfx",		"px"),
59aae38d10SBaptiste Daroussin 	TD(Num_Str,	"plab_norm",	"pln",		"pn"),
60aae38d10SBaptiste Daroussin 	TD(Num_Str_Str, "pkey_plab",	"pfxl",		"xl"),
61aae38d10SBaptiste Daroussin     };
62aae38d10SBaptiste Daroussin     /* *INDENT-ON* */
63aae38d10SBaptiste Daroussin 
64aae38d10SBaptiste Daroussin     unsigned n;
65aae38d10SBaptiste Daroussin     for (n = 0; n < SIZEOF(table); n++) {
66aae38d10SBaptiste Daroussin 	if (!strcmp(name, table[n].name)) {
67aae38d10SBaptiste Daroussin 	    result = table[n].code;
68aae38d10SBaptiste Daroussin 	    break;
69aae38d10SBaptiste Daroussin 	}
70aae38d10SBaptiste Daroussin     }
71aae38d10SBaptiste Daroussin     return result;
72aae38d10SBaptiste Daroussin }
73*7a656419SBaptiste Daroussin 
74*7a656419SBaptiste Daroussin TParams
guess_tparm_type(int nparam,char ** p_is_s)75*7a656419SBaptiste Daroussin guess_tparm_type(int nparam, char **p_is_s)
76*7a656419SBaptiste Daroussin {
77*7a656419SBaptiste Daroussin     TParams result = Other;
78*7a656419SBaptiste Daroussin     switch (nparam) {
79*7a656419SBaptiste Daroussin     case 0:
80*7a656419SBaptiste Daroussin     case 1:
81*7a656419SBaptiste Daroussin 	if (!p_is_s[0])
82*7a656419SBaptiste Daroussin 	    result = Numbers;
83*7a656419SBaptiste Daroussin 	break;
84*7a656419SBaptiste Daroussin     case 2:
85*7a656419SBaptiste Daroussin 	if (!p_is_s[0] && !p_is_s[1])
86*7a656419SBaptiste Daroussin 	    result = Numbers;
87*7a656419SBaptiste Daroussin 	if (!p_is_s[0] && p_is_s[1])
88*7a656419SBaptiste Daroussin 	    result = Num_Str;
89*7a656419SBaptiste Daroussin 	break;
90*7a656419SBaptiste Daroussin     case 3:
91*7a656419SBaptiste Daroussin 	if (!p_is_s[0] && !p_is_s[1] && !p_is_s[2])
92*7a656419SBaptiste Daroussin 	    result = Numbers;
93*7a656419SBaptiste Daroussin 	if (!p_is_s[0] && p_is_s[1] && p_is_s[2])
94*7a656419SBaptiste Daroussin 	    result = Num_Str_Str;
95*7a656419SBaptiste Daroussin 	break;
96*7a656419SBaptiste Daroussin     default:
97*7a656419SBaptiste Daroussin 	break;
98*7a656419SBaptiste Daroussin     }
99*7a656419SBaptiste Daroussin     return result;
100*7a656419SBaptiste Daroussin }
101