1 /* $NetBSD: ti.c,v 1.2 2010/02/04 09:46:26 roy Exp $ */
4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
6 * This id is derived from software contributed to The NetBSD Foundation
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.2 2010/02/04 09:46:26 roy Exp $");
35 #include <term_private.h>
39 ti_getflag(const TERMINAL
*term
, const char *id
)
45 _DIAGASSERT(term
!= NULL
);
46 _DIAGASSERT(id
!= NULL
);
48 ind
= _ti_flagindex(id
);
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)
56 return ABSENT_BOOLEAN
;
60 tigetflag(const char *id
)
63 _DIAGASSERT(id
!= NULL
);
65 return ti_getflag(cur_term
, id
);
66 return ABSENT_BOOLEAN
;
70 ti_getnum(const TERMINAL
*term
, const char *id
)
76 _DIAGASSERT(term
!= NULL
);
77 _DIAGASSERT(id
!= NULL
);
79 ind
= _ti_numindex(id
);
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
;
93 return CANCELLED_NUMERIC
;
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
;
107 ti_getstr(const TERMINAL
*term
, const char *id
)
113 _DIAGASSERT(term
!= NULL
);
114 _DIAGASSERT(id
!= NULL
);
116 ind
= _ti_strindex(id
);
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)
124 return (const char *)CANCELLED_STRING
;
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
;