1 /****************************************************************************
2 * Copyright 2018-2019,2020 Thomas E. Dickey *
3 * Copyright 2000-2008,2012 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Thomas E. Dickey *
32 ****************************************************************************/
34 #include <curses.priv.h>
39 MODULE_ID("$Id: lib_tgoto.c,v 1.21 2020/05/27 23:55:56 tom Exp $")
43 is_termcap(const char *string)
47 if (string == 0 || *string == '\0') {
48 result = FALSE; /* tparm() handles empty strings */
50 while ((*string != '\0') && result) {
60 } else if (string[0] == '$' && string[1] == '<') {
70 tgoto_internal(const char *string, int x, int y)
89 while (*string != 0) {
90 if ((used + need) > length) {
91 length += (used + need);
92 if ((result = typeRealloc(char, length, result)) == 0) {
116 *value += UChar(*++string);
120 * Guard against tputs() seeing a truncated string. The
121 * termcap documentation refers to a similar fixup for \n
122 * and \r, but I don't see that it could work -TD
129 /* tputs will pretend this is \0, which will almost
130 * always work since ANSI-compatible terminals ignore
131 * the character. ECMA-48 does not document a C1
132 * control for this value. A few (obsolete) terminals
133 * can use this value in special cases, such as cursor
134 * addressing using single-byte coordinates.
139 result[used++] = (char) *value++;
142 result[used++] = *string;
154 if (*value > string[1])
158 case 'n': /* Datamedia 2500 */
163 *value = 16 * (*value / 10) + (*value % 10);
165 case 'D': /* Reverse coding (Delta Data) */
166 *value -= 2 * (*value % 16);
170 _nc_SPRINTF(result + used, _nc_SLIMIT(length - used)
172 used += strlen(result + used);
175 if (value - param > 2) {
180 result[used++] = *string;
186 _nc_STRCPY(result + used, BC, length - used);
196 * Retained solely for upward compatibility. Note the intentional reversing of
197 * the last two arguments when invoking tparm().
199 NCURSES_EXPORT(char *)
200 tgoto(const char *string, int x, int y)
204 T((T_CALLED("tgoto(%s, %d, %d)"), _nc_visbuf(string), x, y));
206 if (is_termcap(string))
207 result = tgoto_internal(string, x, y);
210 result = TIPARM_2(string, y, x);