1 /****************************************************************************
2 * Copyright (c) 2000-2008,2012 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Thomas E. Dickey *
31 ****************************************************************************/
33 #include <curses.priv.h>
38 MODULE_ID("$Id: lib_tgoto.c,v 1.16 2012/02/24 02:08:08 tom Exp $")
42 is_termcap(const char *string
)
46 if (string
== 0 || *string
== '\0') {
47 result
= FALSE
; /* tparm() handles empty strings */
49 while ((*string
!= '\0') && result
) {
59 } else if (string
[0] == '$' && string
[1] == '<') {
69 tgoto_internal(const char *string
, int x
, int y
)
88 while (*string
!= 0) {
89 if ((used
+ need
) > length
) {
90 length
+= (used
+ need
);
91 if ((result
= typeRealloc(char, length
, result
)) == 0) {
115 *value
+= UChar(*++string
);
119 * Guard against tputs() seeing a truncated string. The
120 * termcap documentation refers to a similar fixup for \n
121 * and \r, but I don't see that it could work -TD
128 *value
= 0200; /* tputs will treat this as \0 */
131 result
[used
++] = (char) *value
++;
134 result
[used
++] = *string
;
146 if (*value
> string
[1])
150 case 'n': /* Datamedia 2500 */
155 *value
= 16 * (*value
/ 10) + (*value
% 10);
157 case 'D': /* Reverse coding (Delta Data) */
158 *value
-= 2 * (*value
% 16);
162 _nc_SPRINTF(result
+ used
, _nc_SLIMIT(length
- used
)
164 used
+= strlen(result
+ used
);
167 if (value
- param
> 2) {
172 result
[used
++] = *string
;
178 _nc_STRCPY(result
+ used
, BC
, length
- used
);
188 * Retained solely for upward compatibility. Note the intentional reversing of
189 * the last two arguments when invoking tparm().
191 NCURSES_EXPORT(char *)
192 tgoto(const char *string
, int x
, int y
)
196 T((T_CALLED("tgoto(%s, %d, %d)"), _nc_visbuf(string
), x
, y
));
198 if (is_termcap(string
))
199 result
= tgoto_internal(string
, x
, y
);
202 result
= TPARM_2((NCURSES_CONST
char *) string
, y
, x
);