1 /****************************************************************************
2 * Copyright (c) 2000-2018,2019 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.18 2019/10/26 22:43:48 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 /* tputs will pretend this is \0, which will almost
129 * always work since ANSI-compatible terminals ignore
130 * the character. ECMA-48 does not document a C1
131 * control for this value. A few (obsolete) terminals
132 * can use this value in special cases, such as cursor
133 * addressing using single-byte coordinates.
138 result[used++] = (char) *value++;
141 result[used++] = *string;
153 if (*value > string[1])
157 case 'n': /* Datamedia 2500 */
162 *value = 16 * (*value / 10) + (*value % 10);
164 case 'D': /* Reverse coding (Delta Data) */
165 *value -= 2 * (*value % 16);
169 _nc_SPRINTF(result + used, _nc_SLIMIT(length - used)
171 used += strlen(result + used);
174 if (value - param > 2) {
179 result[used++] = *string;
185 _nc_STRCPY(result + used, BC, length - used);
195 * Retained solely for upward compatibility. Note the intentional reversing of
196 * the last two arguments when invoking tparm().
198 NCURSES_EXPORT(char *)
199 tgoto(const char *string, int x, int y)
203 T((T_CALLED("tgoto(%s, %d, %d)"), _nc_visbuf(string), x, y));
205 if (is_termcap(string))
206 result = tgoto_internal(string, x, y);
209 result = TPARM_2(string, y, x);