trace(1): resolve all level-5 LLVM warnings
[minix3.git] / lib / libterminfo / ti.c
bloba4bb631eaf80c0c1e278fc68d0ff37eda9681290
1 /* $NetBSD: ti.c,v 1.3 2013/06/07 13:16:18 roy Exp $ */
3 /*
4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
6 * This id is derived from software contributed to The NetBSD Foundation
7 * by Roy Marples.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source id must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __RCSID("$NetBSD: ti.c,v 1.3 2013/06/07 13:16:18 roy Exp $");
33 #include <assert.h>
34 #include <string.h>
35 #include <term_private.h>
36 #include <term.h>
38 int
39 ti_getflag(const TERMINAL *term, const char *id)
41 ssize_t ind;
42 size_t i;
43 TERMUSERDEF *ud;
45 _DIAGASSERT(term != NULL);
46 _DIAGASSERT(id != NULL);
48 ind = _ti_flagindex(id);
49 if (ind != -1)
50 return term->flags[ind];
51 for (i = 0; i < term->_nuserdefs; i++) {
52 ud = &term->_userdefs[i];
53 if (ud->type == 'f' && strcmp(ud->id, id) == 0)
54 return ud->flag;
56 return ABSENT_BOOLEAN;
59 int
60 tigetflag(const char *id)
63 _DIAGASSERT(id != NULL);
64 if (cur_term != NULL)
65 return ti_getflag(cur_term, id);
66 return ABSENT_BOOLEAN;
69 int
70 ti_getnum(const TERMINAL *term, const char *id)
72 ssize_t ind;
73 size_t i;
74 TERMUSERDEF *ud;
76 _DIAGASSERT(term != NULL);
77 _DIAGASSERT(id != NULL);
79 ind = _ti_numindex(id);
80 if (ind != -1) {
81 if (!VALID_NUMERIC(term->nums[ind]))
82 return ABSENT_NUMERIC;
83 return term->nums[ind];
85 for (i = 0; i < term->_nuserdefs; i++) {
86 ud = &term->_userdefs[i];
87 if (ud->type == 'n' && strcmp(ud->id, id) == 0) {
88 if (!VALID_NUMERIC(ud->num))
89 return ABSENT_NUMERIC;
90 return ud->num;
93 return CANCELLED_NUMERIC;
96 int
97 tigetnum(const char *id)
100 _DIAGASSERT(id != NULL);
101 if (cur_term != NULL)
102 return ti_getnum(cur_term, id);
103 return CANCELLED_NUMERIC;
106 const char *
107 ti_getstr(const TERMINAL *term, const char *id)
109 ssize_t ind;
110 size_t i;
111 TERMUSERDEF *ud;
113 _DIAGASSERT(term != NULL);
114 _DIAGASSERT(id != NULL);
116 ind = _ti_strindex(id);
117 if (ind != -1)
118 return term->strs[ind];
119 for (i = 0; i < term->_nuserdefs; i++) {
120 ud = &term->_userdefs[i];
121 if (ud->type == 's' && strcmp(ud->id, id) == 0)
122 return ud->str;
124 return (const char *)CANCELLED_STRING;
127 char *
128 tigetstr(const char *id)
131 _DIAGASSERT(id != NULL);
132 if (cur_term != NULL)
133 return __UNCONST(ti_getstr(cur_term, id));
134 return (char *)CANCELLED_STRING;