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