/****************************************************************************
- * Copyright (c) 2000 Free Software Foundation, Inc. *
+ * Copyright (c) 2000-2012,2018 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
#include <ctype.h>
#include <termcap.h>
-MODULE_ID("$Id: lib_tgoto.c,v 1.2 2000/09/24 00:19:14 tom Exp $")
+MODULE_ID("$Id: lib_tgoto.c,v 1.17 2018/04/07 21:11:48 tom Exp $")
#if !PURE_TERMINFO
static bool
{
bool result = TRUE;
- while ((*string != '\0') && result) {
- if (*string == '%') {
- switch (*++string) {
- case 'p':
+ if (string == 0 || *string == '\0') {
+ result = FALSE; /* tparm() handles empty strings */
+ } else {
+ while ((*string != '\0') && result) {
+ if (*string == '%') {
+ switch (*++string) {
+ case 'p':
+ result = FALSE;
+ break;
+ case '\0':
+ string--;
+ break;
+ }
+ } else if (string[0] == '$' && string[1] == '<') {
result = FALSE;
- break;
- case '\0':
- string--;
- break;
}
- } else if (string[0] == '$' && string[1] == '<') {
- result = FALSE;
+ string++;
}
- string++;
}
return result;
}
while (*string != 0) {
if ((used + need) > length) {
length += (used + need);
- if ((result = _nc_doalloc(result, length)) == 0) {
+ if ((result = typeRealloc(char, length, result)) == 0) {
length = 0;
break;
}
}
if (*string == '%') {
- char *fmt = 0;
+ const char *fmt = 0;
switch (*++string) {
case '\0':
*value %= 1000;
break;
case '+':
- *value += (*++string & 0xff);
+ *value += UChar(*++string);
/* FALLTHRU */
case '.':
/*
*value = 0200; /* tputs will treat this as \0 */
}
}
- result[used++] = *value++;
+ result[used++] = (char) *value++;
break;
case '%':
result[used++] = *string;
*value = 16 * (*value / 10) + (*value % 10);
break;
case 'D': /* Reverse coding (Delta Data) */
- *value -= 2 * (*value / 16);
+ *value -= 2 * (*value % 16);
break;
}
if (fmt != 0) {
- sprintf(result + used, fmt, *value++);
+ _nc_SPRINTF(result + used, _nc_SLIMIT(length - used)
+ fmt, *value++);
used += strlen(result + used);
fmt = 0;
}
}
string++;
}
- if (need_BC) {
- strcpy(result + used, BC);
- used += strlen(BC);
+ if (result != 0) {
+ if (need_BC) {
+ _nc_STRCPY(result + used, BC, length - used);
+ used += strlen(BC);
+ }
+ result[used] = '\0';
}
- result[used] = '\0';
return result;
}
#endif
* Retained solely for upward compatibility. Note the intentional reversing of
* the last two arguments when invoking tparm().
*/
-char *
+NCURSES_EXPORT(char *)
tgoto(const char *string, int x, int y)
{
char *result;
result = tgoto_internal(string, x, y);
else
#endif
- result = tparm((NCURSES_CONST char *) string, y, x);
+ result = TPARM_2(string, y, x);
returnPtr(result);
}