ncursesw-morphos/ncurses/tinfo/captoinfo.c

907 lines
22 KiB
C
Raw Normal View History

1998-03-01 12:21:12 +08:00
/****************************************************************************
* Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. *
1998-03-01 12:21:12 +08:00
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
2005-10-10 02:41:57 +08:00
* and: Thomas E. Dickey 1996-on *
1998-03-01 12:21:12 +08:00
****************************************************************************/
1997-05-15 12:00:00 +08:00
/*
* captoinfo.c --- conversion between termcap and terminfo formats
*
* The captoinfo() code was swiped from Ross Ridge's mytinfo package,
* adapted to fit ncurses by Eric S. Raymond <esr@snark.thyrsus.com>.
*
* There is just one entry point:
*
2004-02-09 10:15:26 +08:00
* char *_nc_captoinfo(n, s, parameterized)
1997-05-15 12:00:00 +08:00
*
* Convert value s for termcap string capability named n into terminfo
* format.
*
* This code recognizes all the standard 4.4BSD %-escapes:
*
* %% output `%'
* %d output value as in printf %d
* %2 output value as in printf %2d
* %3 output value as in printf %3d
* %. output value as in printf %c
* %+x add x to value, then do %.
* %>xy if value > x then add y, no output
* %r reverse order of two parameters, no output
* %i increment by one, no output
* %n exclusive-or all parameters with 0140 (Datamedia 2500)
* %B BCD (16*(value/10)) + (value%10), no output
* %D Reverse coding (value - 2*(value%16)), no output (Delta Data).
*
* Also, %02 and %03 are accepted as synonyms for %2 and %3.
*
* Besides all the standard termcap escapes, this translator understands
* the following extended escapes:
*
* used by GNU Emacs termcap libraries
* %a[+*-/=][cp]x GNU arithmetic.
* %m xor the first two parameters by 0177
* %b backup to previous parameter
* %f skip this parameter
*
* used by the University of Waterloo (MFCF) termcap libraries
* %-x subtract parameter FROM char x and output it as a char
* %ax add the character x to parameter
*
* If #define WATERLOO is on, also enable these translations:
*
* %sx subtract parameter FROM the character x
*
* By default, this Waterloo translations are not compiled in, because
* the Waterloo %s conflicts with the way terminfo uses %s in strings for
* function programming.
*
* Note the two definitions of %a: the GNU definition is translated if the
* characters after the 'a' are valid for it, otherwise the UW definition
* is translated.
*/
#include <curses.priv.h>
#include <ctype.h>
#include <tic.h>
MODULE_ID("$Id: captoinfo.c,v 1.70 2011/10/22 14:59:34 tom Exp $")
1997-05-15 12:00:00 +08:00
#define MAX_PUSHED 16 /* max # args we can push onto the stack */
static int stack[MAX_PUSHED]; /* the stack */
static int stackptr; /* the next empty place on the stack */
static int onstack; /* the top of stack */
static int seenm; /* seen a %m */
static int seenn; /* seen a %n */
static int seenr; /* seen a %r */
static int param; /* current parameter */
static char *dp; /* pointer to end of the converted string */
2000-07-09 10:46:08 +08:00
static char *my_string;
1997-05-15 12:00:00 +08:00
static size_t my_length;
2000-07-09 10:46:08 +08:00
static char *
init_string(void)
1997-05-15 12:00:00 +08:00
/* initialize 'my_string', 'my_length' */
{
2000-07-09 10:46:08 +08:00
if (my_string == 0)
my_string = typeMalloc(char, my_length = 256);
if (my_string == 0)
2002-10-13 11:35:53 +08:00
_nc_err_abort(MSG_NO_MEMORY);
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
*my_string = '\0';
return my_string;
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
static char *
save_string(char *d, const char *const s)
1997-05-15 12:00:00 +08:00
{
size_t have = (size_t) (d - my_string);
2000-07-09 10:46:08 +08:00
size_t need = have + strlen(s) + 2;
if (need > my_length) {
ncurses 5.7 - patch 20090328 + extend ansi.sys pfkey capability from kf1-kf10 to kf1-kf48, moving function key definitions from emx-base for consistency -TD + correct missing final 'p' in pfkey capability of ansi.sys-old (report by Kalle Olavi Niemitalo). + improve test/ncurses.c 'F' test, show combining characters in color. + quiet a false report by cppcheck in c++/cursesw.cc by eliminating a temporary variable. + use _nc_doalloc() rather than realloc() in a few places in ncurses library to avoid leak in out-of-memory condition (reports by William Egert and Martin Ettl based on cppcheck tool). + add --with-ncurses-wrap-prefix option to test/configure (discussion with Charles Wilson). + use ncurses*-config scripts if available for test/configure. + update test/aclocal.m4 and test/configure > patches by Charles Wilson: + modify CF_WITH_LIBTOOL configure check to allow unreleased libtool version numbers (e.g. which include alphabetic chars, as well as digits, after the final '.'). + improve use of -no-undefined option for libtool by setting an intermediate variable LT_UNDEF in the configure script, and then using that in the libtool link-commands. + fix an missing use of NCURSES_PUBLIC_VAR() in tinfo/MKcodes.awk from 2009031 changes. + improve mk-1st.awk script by writing separate cases for the LIBTOOL_LINK command, depending on which library (ncurses, ticlib, termlib) is to be linked. + modify configure.in to allow broken-linker configurations, not just enable-reentrant, to set public wrap prefix.
2009-03-29 08:06:57 +08:00
my_string = (char *) _nc_doalloc(my_string, my_length = (need + need));
2000-07-09 10:46:08 +08:00
if (my_string == 0)
2002-10-13 11:35:53 +08:00
_nc_err_abort(MSG_NO_MEMORY);
2000-07-09 10:46:08 +08:00
d = my_string + have;
}
(void) strcpy(d, s);
return d + strlen(d);
1997-05-15 12:00:00 +08:00
}
2006-12-18 12:32:42 +08:00
static NCURSES_INLINE char *
2002-10-13 11:35:53 +08:00
save_char(char *s, int c)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
static char temp[2];
2002-10-13 11:35:53 +08:00
temp[0] = (char) c;
2000-07-09 10:46:08 +08:00
return save_string(s, temp);
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
static void
push(void)
1997-05-15 12:00:00 +08:00
/* push onstack on to the stack */
{
if (stackptr >= MAX_PUSHED)
1997-05-15 12:00:00 +08:00
_nc_warning("string too complex to convert");
else
stack[stackptr++] = onstack;
}
2000-07-09 10:46:08 +08:00
static void
pop(void)
1997-05-15 12:00:00 +08:00
/* pop the top of the stack into onstack */
{
1999-10-24 12:32:42 +08:00
if (stackptr == 0) {
1997-05-15 12:00:00 +08:00
if (onstack == 0)
_nc_warning("I'm confused");
else
onstack = 0;
2000-07-09 10:46:08 +08:00
} else
1997-05-15 12:00:00 +08:00
onstack = stack[--stackptr];
param++;
}
2000-07-09 10:46:08 +08:00
static int
cvtchar(register const char *sp)
1997-05-15 12:00:00 +08:00
/* convert a character to a terminfo push */
{
unsigned char c = 0;
int len;
2000-07-09 10:46:08 +08:00
switch (*sp) {
1997-05-15 12:00:00 +08:00
case '\\':
2000-07-09 10:46:08 +08:00
switch (*++sp) {
1997-05-15 12:00:00 +08:00
case '\'':
case '$':
case '\\':
case '%':
c = (unsigned char) (*sp);
1997-05-15 12:00:00 +08:00
len = 2;
break;
case '\0':
c = '\\';
len = 1;
break;
case '0':
case '1':
case '2':
case '3':
len = 1;
2002-10-13 11:35:53 +08:00
while (isdigit(UChar(*sp))) {
c = (unsigned char) (8 * c + (*sp++ - '0'));
1997-05-15 12:00:00 +08:00
len++;
}
break;
default:
c = (unsigned char) (*sp);
1997-05-15 12:00:00 +08:00
len = 2;
break;
}
break;
case '^':
c = (unsigned char) (*++sp & 0x1f);
1997-05-15 12:00:00 +08:00
len = 2;
break;
default:
c = (unsigned char) (*sp);
1997-05-15 12:00:00 +08:00
len = 1;
}
if (isgraph(c) && c != ',' && c != '\'' && c != '\\' && c != ':') {
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%\'");
dp = save_char(dp, c);
dp = save_char(dp, '\'');
1997-05-15 12:00:00 +08:00
} else {
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%{");
1997-05-15 12:00:00 +08:00
if (c > 99)
2000-07-09 10:46:08 +08:00
dp = save_char(dp, c / 100 + '0');
1997-05-15 12:00:00 +08:00
if (c > 9)
2000-07-09 10:46:08 +08:00
dp = save_char(dp, ((int) (c / 10)) % 10 + '0');
dp = save_char(dp, c % 10 + '0');
dp = save_char(dp, '}');
1997-05-15 12:00:00 +08:00
}
return len;
}
2000-07-09 10:46:08 +08:00
static void
getparm(int parm, int n)
1997-05-15 12:00:00 +08:00
/* push n copies of param on the terminfo stack if not already there */
{
2000-07-09 10:46:08 +08:00
if (seenr) {
if (parm == 1)
parm = 2;
else if (parm == 2)
parm = 1;
}
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
while (n--) {
dp = save_string(dp, "%p");
dp = save_char(dp, '0' + parm);
}
2000-07-09 10:46:08 +08:00
if (onstack == parm) {
if (n > 1) {
_nc_warning("string may not be optimal");
dp = save_string(dp, "%Pa");
while (n--) {
dp = save_string(dp, "%ga");
}
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
return;
}
if (onstack != 0)
push();
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
onstack = parm;
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (seenn && parm < 3) {
dp = save_string(dp, "%{96}%^");
}
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (seenm && parm < 3) {
dp = save_string(dp, "%{127}%^");
}
1997-05-15 12:00:00 +08:00
}
2002-10-13 11:35:53 +08:00
/*
* Convert a termcap string to terminfo format.
* 'cap' is the relevant terminfo capability index.
* 's' is the string value of the capability.
2004-02-09 10:15:26 +08:00
* 'parameterized' tells what type of translations to do:
2002-10-13 11:35:53 +08:00
* % translations if 1
* pad translations if >=0
*/
2005-10-10 02:41:57 +08:00
NCURSES_EXPORT(char *)
2004-02-09 10:15:26 +08:00
_nc_captoinfo(const char *cap, const char *s, int const parameterized)
1997-05-15 12:00:00 +08:00
{
1998-03-01 12:21:12 +08:00
const char *capstart;
1997-05-15 12:00:00 +08:00
stackptr = 0;
onstack = 0;
seenm = 0;
seenn = 0;
seenr = 0;
param = 1;
2000-07-09 10:46:08 +08:00
dp = init_string();
1997-05-15 12:00:00 +08:00
/* skip the initial padding (if we haven't been told not to) */
1998-03-01 12:21:12 +08:00
capstart = 0;
1997-05-15 12:00:00 +08:00
if (s == 0)
s = "";
2004-02-09 10:15:26 +08:00
if (parameterized >= 0 && isdigit(UChar(*s)))
2000-07-09 10:46:08 +08:00
for (capstart = s;; s++)
2002-10-13 11:35:53 +08:00
if (!(isdigit(UChar(*s)) || *s == '*' || *s == '.'))
1997-05-15 12:00:00 +08:00
break;
2000-07-09 10:46:08 +08:00
while (*s != '\0') {
switch (*s) {
1997-05-15 12:00:00 +08:00
case '%':
s++;
2004-02-09 10:15:26 +08:00
if (parameterized < 1) {
2000-07-09 10:46:08 +08:00
dp = save_char(dp, '%');
1997-05-15 12:00:00 +08:00
break;
}
2000-07-09 10:46:08 +08:00
switch (*s++) {
case '%':
dp = save_char(dp, '%');
break;
1997-05-15 12:00:00 +08:00
case 'r':
if (seenr++ == 1) {
_nc_warning("saw %%r twice in %s", cap);
}
break;
case 'm':
if (seenm++ == 1) {
_nc_warning("saw %%m twice in %s", cap);
}
break;
case 'n':
if (seenn++ == 1) {
_nc_warning("saw %%n twice in %s", cap);
}
break;
2000-07-09 10:46:08 +08:00
case 'i':
dp = save_string(dp, "%i");
break;
1997-05-15 12:00:00 +08:00
case '6':
case 'B':
2000-07-09 10:46:08 +08:00
getparm(param, 1);
dp = save_string(dp, "%{10}%/%{16}%*");
getparm(param, 1);
dp = save_string(dp, "%{10}%m%+");
1997-05-15 12:00:00 +08:00
break;
case '8':
case 'D':
getparm(param, 2);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%{2}%*%-");
1997-05-15 12:00:00 +08:00
break;
case '>':
getparm(param, 2);
/* %?%{x}%>%t%{y}%+%; */
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%?");
1997-05-15 12:00:00 +08:00
s += cvtchar(s);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%>%t");
1997-05-15 12:00:00 +08:00
s += cvtchar(s);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%+%;");
1997-05-15 12:00:00 +08:00
break;
case 'a':
if ((*s == '=' || *s == '+' || *s == '-'
2002-10-13 11:35:53 +08:00
|| *s == '*' || *s == '/')
1997-05-15 12:00:00 +08:00
&& (s[1] == 'p' || s[1] == 'c')
&& s[2] != '\0') {
int l;
l = 2;
if (*s != '=')
getparm(param, 1);
if (s[1] == 'p') {
getparm(param + s[2] - '@', 1);
if (param != onstack) {
pop();
param--;
}
l++;
} else
l += cvtchar(s + 2);
2000-07-09 10:46:08 +08:00
switch (*s) {
1997-05-15 12:00:00 +08:00
case '+':
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%+");
1997-05-15 12:00:00 +08:00
break;
case '-':
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%-");
1997-05-15 12:00:00 +08:00
break;
case '*':
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%*");
1997-05-15 12:00:00 +08:00
break;
case '/':
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%/");
1997-05-15 12:00:00 +08:00
break;
case '=':
1999-10-24 12:32:42 +08:00
if (seenr) {
1997-05-15 12:00:00 +08:00
if (param == 1)
onstack = 2;
else if (param == 2)
onstack = 1;
else
onstack = param;
2000-07-09 10:46:08 +08:00
} else
1997-05-15 12:00:00 +08:00
onstack = param;
break;
}
s += l;
break;
}
getparm(param, 1);
s += cvtchar(s);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%+");
1997-05-15 12:00:00 +08:00
break;
case '+':
getparm(param, 1);
s += cvtchar(s);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%+%c");
1997-05-15 12:00:00 +08:00
pop();
break;
case 's':
#ifdef WATERLOO
s += cvtchar(s);
getparm(param, 1);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%-");
1997-05-15 12:00:00 +08:00
#else
getparm(param, 1);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%s");
1997-05-15 12:00:00 +08:00
pop();
#endif /* WATERLOO */
break;
case '-':
s += cvtchar(s);
getparm(param, 1);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%-%c");
1997-05-15 12:00:00 +08:00
pop();
break;
case '.':
getparm(param, 1);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%c");
1997-05-15 12:00:00 +08:00
pop();
break;
2000-07-09 10:46:08 +08:00
case '0': /* not clear any of the historical termcaps did this */
1999-10-24 12:32:42 +08:00
if (*s == '3')
1997-05-15 12:00:00 +08:00
goto see03;
else if (*s != '2')
goto invalid;
/* FALLTHRU */
case '2':
getparm(param, 1);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%2d");
1997-05-15 12:00:00 +08:00
pop();
break;
2000-07-09 10:46:08 +08:00
case '3':
see03:
1997-05-15 12:00:00 +08:00
getparm(param, 1);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%3d");
1997-05-15 12:00:00 +08:00
pop();
break;
case 'd':
getparm(param, 1);
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%d");
1997-05-15 12:00:00 +08:00
pop();
break;
case 'f':
param++;
break;
case 'b':
param--;
break;
case '\\':
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "%\\");
1997-05-15 12:00:00 +08:00
break;
2000-07-09 10:46:08 +08:00
default:
invalid:
dp = save_char(dp, '%');
1997-05-15 12:00:00 +08:00
s--;
2000-07-09 10:46:08 +08:00
_nc_warning("unknown %% code %s (%#x) in %s",
2002-10-13 11:35:53 +08:00
unctrl((chtype) *s), UChar(*s), cap);
1997-05-15 12:00:00 +08:00
break;
}
break;
default:
2000-07-09 10:46:08 +08:00
dp = save_char(dp, *s++);
1997-05-15 12:00:00 +08:00
break;
}
}
/*
* Now, if we stripped off some leading padding, add it at the end
* of the string as mandatory padding.
*/
2000-07-09 10:46:08 +08:00
if (capstart) {
dp = save_string(dp, "$<");
for (s = capstart;; s++)
2002-10-13 11:35:53 +08:00
if (isdigit(UChar(*s)) || *s == '*' || *s == '.')
2000-07-09 10:46:08 +08:00
dp = save_char(dp, *s);
1997-05-15 12:00:00 +08:00
else
break;
2000-07-09 10:46:08 +08:00
dp = save_string(dp, "/>");
}
(void) save_char(dp, '\0');
return (my_string);
}
/*
* Check for an expression that corresponds to "%B" (BCD):
* (parameter / 10) * 16 + (parameter % 10)
*/
static int
bcd_expression(const char *str)
{
/* leave this non-const for HPUX */
static char fmt[] = "%%p%c%%{10}%%/%%{16}%%*%%p%c%%{10}%%m%%+";
int len = 0;
char ch1, ch2;
if (sscanf(str, fmt, &ch1, &ch2) == 2
2002-10-13 11:35:53 +08:00
&& isdigit(UChar(ch1))
&& isdigit(UChar(ch2))
2000-07-09 10:46:08 +08:00
&& (ch1 == ch2)) {
len = 28;
#ifndef NDEBUG
{
char buffer[80];
int tst;
sprintf(buffer, fmt, ch1, ch2);
tst = strlen(buffer) - 1;
assert(len == tst);
}
#endif
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
return len;
}
static char *
save_tc_char(char *bufptr, int c1)
{
char temp[80];
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (is7bits(c1) && isprint(c1)) {
if (c1 == ':' || c1 == '\\')
bufptr = save_char(bufptr, '\\');
bufptr = save_char(bufptr, c1);
} else {
if (c1 == (c1 & 0x1f)) /* iscntrl() returns T on 255 */
2002-10-13 11:35:53 +08:00
(void) strcpy(temp, unctrl((chtype) c1));
2000-07-09 10:46:08 +08:00
else
(void) sprintf(temp, "\\%03o", c1);
bufptr = save_string(bufptr, temp);
}
return bufptr;
}
static char *
save_tc_inequality(char *bufptr, int c1, int c2)
{
bufptr = save_string(bufptr, "%>");
bufptr = save_tc_char(bufptr, c1);
bufptr = save_tc_char(bufptr, c2);
return bufptr;
1997-05-15 12:00:00 +08:00
}
/*
* Here are the capabilities infotocap assumes it can translate to:
*
* %% output `%'
* %d output value as in printf %d
* %2 output value as in printf %2d
* %3 output value as in printf %3d
* %. output value as in printf %c
* %+c add character c to value, then do %.
* %>xy if value > x then add y, no output
* %r reverse order of two parameters, no output
* %i increment by one, no output
* %n exclusive-or all parameters with 0140 (Datamedia 2500)
* %B BCD (16*(value/10)) + (value%10), no output
* %D Reverse coding (value - 2*(value%16)), no output (Delta Data).
* %m exclusive-or all parameters with 0177 (not in 4.4BSD)
*/
2002-10-13 11:35:53 +08:00
/*
* Convert a terminfo string to termcap format. Parameters are as in
* _nc_captoinfo().
*/
2005-10-10 02:41:57 +08:00
NCURSES_EXPORT(char *)
2004-02-09 10:15:26 +08:00
_nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameterized)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0;
1998-03-01 12:21:12 +08:00
const char *padding;
const char *trimmed = 0;
int in0, in1, in2;
1998-03-01 12:21:12 +08:00
char ch1 = 0, ch2 = 0;
1997-05-15 12:00:00 +08:00
char *bufptr = init_string();
char octal[4];
2000-07-09 10:46:08 +08:00
int len;
bool syntax_error = FALSE;
1997-05-15 12:00:00 +08:00
/* we may have to move some trailing mandatory padding up front */
padding = str + strlen(str) - 1;
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
if (padding > str && *padding == '>') {
if (*--padding == '/')
--padding;
2002-10-13 11:35:53 +08:00
while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*')
1997-05-15 12:00:00 +08:00
padding--;
2004-02-09 10:15:26 +08:00
if (padding > str && *padding == '<' && *--padding == '$')
1998-03-01 12:21:12 +08:00
trimmed = padding;
1997-05-15 12:00:00 +08:00
padding += 2;
2002-10-13 11:35:53 +08:00
while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*')
1997-05-15 12:00:00 +08:00
bufptr = save_char(bufptr, *padding++);
}
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
for (; *str && ((trimmed == 0) || (str < trimmed)); str++) {
2000-07-09 10:46:08 +08:00
int c1, c2;
char *cp = 0;
1997-05-15 12:00:00 +08:00
if (str[0] == '^') {
if (str[1] == '\0' || (str + 1) == trimmed) {
bufptr = save_string(bufptr, "\\136");
++str;
} else {
bufptr = save_char(bufptr, *str++);
bufptr = save_char(bufptr, *str);
}
} else if (str[0] == '\\') {
if (str[1] == '\0' || (str + 1) == trimmed) {
bufptr = save_string(bufptr, "\\134");
++str;
} else if (str[1] == '^') {
bufptr = save_string(bufptr, "\\136");
++str;
} else if (str[1] == ',') {
bufptr = save_char(bufptr, *++str);
} else {
int xx1, xx2;
bufptr = save_char(bufptr, *str++);
xx1 = *str;
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
if (_nc_strict_bsd) {
if (isdigit(UChar(xx1))) {
int pad = 0;
if (!isdigit(UChar(str[1])))
pad = 2;
else if (str[1] && !isdigit(UChar(str[2])))
pad = 1;
/*
* Test for "\0", "\00" or "\000" and transform those
* into "\200".
*/
if (xx1 == '0'
&& ((pad == 2) || (str[1] == '0'))
&& ((pad >= 1) || (str[2] == '0'))) {
xx2 = '2';
} else {
xx2 = '0';
pad = 0; /* FIXME - optionally pad to 3 digits */
}
while (pad-- > 0) {
bufptr = save_char(bufptr, xx2);
xx2 = '0';
}
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
} else if (strchr("E\\nrtbf", xx1) == 0) {
switch (xx1) {
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
case 'e':
xx1 = 'E';
break;
case 'l':
xx1 = 'n';
break;
case 's':
bufptr = save_char(bufptr, '0');
bufptr = save_char(bufptr, '4');
xx1 = '0';
break;
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
case ':':
/*
* Note: termcap documentation claims that ":"
* must be escaped as "\072", however the
* documentation is incorrect - read the code.
* The replacement does not work reliably,
* so the advice is not helpful.
*/
bufptr = save_char(bufptr, '0');
bufptr = save_char(bufptr, '7');
xx1 = '2';
break;
default:
/* should not happen, but handle this anyway */
sprintf(octal, "%03o", UChar(xx1));
bufptr = save_char(bufptr, octal[0]);
bufptr = save_char(bufptr, octal[1]);
xx1 = octal[2];
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
break;
}
}
}
bufptr = save_char(bufptr, xx1);
}
2000-07-09 10:46:08 +08:00
} else if (str[0] == '$' && str[1] == '<') { /* discard padding */
1997-05-15 12:00:00 +08:00
str += 2;
2002-10-13 11:35:53 +08:00
while (isdigit(UChar(*str))
|| *str == '.'
|| *str == '*'
|| *str == '/'
|| *str == '>')
1997-05-15 12:00:00 +08:00
str++;
--str;
} else if (sscanf(str,
"[%%?%%p1%%{8}%%<%%t%d%%p1%%d%%e%%p1%%{16}%%<%%t%d%%p1%%{8}%%-%%d%%e%d;5;%%p1%%d%%;m",
&in0, &in1, &in2) == 3
&& ((in0 == 4 && in1 == 10 && in2 == 48)
|| (in0 == 3 && in1 == 9 && in2 == 38))) {
/* dumb-down an optimized case from xterm-256color for termcap */
str = strstr(str, ";m");
++str;
if (in2 == 48) {
bufptr = save_string(bufptr, "[48;5;%dm");
} else {
bufptr = save_string(bufptr, "[38;5;%dm");
}
2000-07-09 10:46:08 +08:00
} else if (str[0] == '%' && str[1] == '%') { /* escaped '%' */
bufptr = save_string(bufptr, "%%");
2005-10-10 02:41:57 +08:00
++str;
2004-02-09 10:15:26 +08:00
} else if (*str != '%' || (parameterized < 1)) {
1997-05-15 12:00:00 +08:00
bufptr = save_char(bufptr, *str);
2000-07-09 10:46:08 +08:00
} else if (sscanf(str, "%%?%%{%d}%%>%%t%%{%d}%%+%%;", &c1, &c2) == 2) {
1997-05-15 12:00:00 +08:00
str = strchr(str, ';');
2000-07-09 10:46:08 +08:00
bufptr = save_tc_inequality(bufptr, c1, c2);
} else if (sscanf(str, "%%?%%{%d}%%>%%t%%'%c'%%+%%;", &c1, &ch2) == 2) {
1997-05-15 12:00:00 +08:00
str = strchr(str, ';');
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
bufptr = save_tc_inequality(bufptr, c1, ch2);
2000-07-09 10:46:08 +08:00
} else if (sscanf(str, "%%?%%'%c'%%>%%t%%{%d}%%+%%;", &ch1, &c2) == 2) {
1997-05-15 12:00:00 +08:00
str = strchr(str, ';');
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
bufptr = save_tc_inequality(bufptr, ch1, c2);
2000-07-09 10:46:08 +08:00
} else if (sscanf(str, "%%?%%'%c'%%>%%t%%'%c'%%+%%;", &ch1, &ch2) == 2) {
1997-05-15 12:00:00 +08:00
str = strchr(str, ';');
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
bufptr = save_tc_inequality(bufptr, ch1, ch2);
2000-07-09 10:46:08 +08:00
} else if ((len = bcd_expression(str)) != 0) {
str += len;
bufptr = save_string(bufptr, "%B");
} else if ((sscanf(str, "%%{%d}%%+%%c", &c1) == 1
|| sscanf(str, "%%'%c'%%+%%c", &ch1) == 1)
2002-10-13 11:35:53 +08:00
&& (cp = strchr(str, '+'))) {
1997-05-15 12:00:00 +08:00
str = cp + 2;
2000-07-09 10:46:08 +08:00
bufptr = save_string(bufptr, "%+");
1997-05-15 12:00:00 +08:00
if (ch1)
c1 = ch1;
2000-07-09 10:46:08 +08:00
bufptr = save_tc_char(bufptr, c1);
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
/* FIXME: this "works" for 'delta' */
else if (strncmp(str, "%{2}%*%-", (size_t) 8) == 0) {
1997-05-15 12:00:00 +08:00
str += 7;
2000-07-09 10:46:08 +08:00
bufptr = save_string(bufptr, "%D");
} else if (strncmp(str, "%{96}%^", (size_t) 7) == 0) {
1997-05-15 12:00:00 +08:00
str += 6;
2000-07-09 10:46:08 +08:00
if (saw_m++ == 0) {
bufptr = save_string(bufptr, "%n");
1997-05-15 12:00:00 +08:00
}
} else if (strncmp(str, "%{127}%^", (size_t) 8) == 0) {
1997-05-15 12:00:00 +08:00
str += 7;
2000-07-09 10:46:08 +08:00
if (saw_n++ == 0) {
bufptr = save_string(bufptr, "%m");
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
} else { /* cm-style format element */
1997-05-15 12:00:00 +08:00
str++;
switch (*str) {
case '%':
bufptr = save_char(bufptr, '%');
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
bufptr = save_char(bufptr, '%');
ch1 = 0;
ch2 = 0;
while (isdigit(UChar(*str))) {
ch2 = ch1;
ch1 = *str++;
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
if (_nc_strict_bsd) {
if (ch1 > '3')
return 0;
} else {
bufptr = save_char(bufptr, ch1);
}
}
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
if (_nc_strict_bsd) {
if (ch2 != 0 && ch2 != '0')
return 0;
if (ch1 < '2')
ch1 = 'd';
bufptr = save_char(bufptr, ch1);
}
2000-07-09 10:46:08 +08:00
if (strchr("doxX.", *str)) {
if (*str != 'd') /* termcap doesn't have octal, hex */
return 0;
}
1997-05-15 12:00:00 +08:00
break;
case 'd':
2000-07-09 10:46:08 +08:00
bufptr = save_string(bufptr, "%d");
1997-05-15 12:00:00 +08:00
break;
case 'c':
2000-07-09 10:46:08 +08:00
bufptr = save_string(bufptr, "%.");
1997-05-15 12:00:00 +08:00
break;
2000-07-09 10:46:08 +08:00
/*
* %s isn't in termcap, but it's convenient to pass it through
* so we can represent things like terminfo pfkey strings in
* termcap notation.
*/
1997-05-15 12:00:00 +08:00
case 's':
ncurses 5.9 - patch 20110730 + modify configure script and makefiles in c++ and progs to allow the directory used for rpath option to be overridden, e.g., to work around updates to the variables used by tic during an install. + add -K option to tic/infocmp, to provide stricter BSD-compatibility for termcap output. + add _nc_strict_bsd variable in tic library which controls the "strict" BSD termcap compatibility from 20110723, plus these features: + allow escapes such as "\8" and "\9" when reading termcap + disallow "\a", "\e", "\l", "\s" and "\:" escapes when reading termcap files, passing through "a", "e", etc. + expand "\:" as "\072" on output. + modify _nc_get_token() to reset the token's string value in case there is a string-typed token lacking the "=" marker. + fix a few memory leaks in _nc_tgetent. + fix a few places where reading from a termcap file could refer to freed memory. + add an overflow check when converting terminfo/termcap numeric values, since terminfo stores those in a short, and they must be positive. + correct internal variables used for translating to termcap "%>" feature, and translating from termcap %B to terminfo, needed by tctest (cf: 19991211). + amend a minor fix to acsc when loading a termcap file to separate it from warnings needed for tic (cf: 20040710) + modify logic in _nc_read_entry() and _nc_read_tic_entry() to allow a termcap file to be handled via TERMINFO_DIRS. + modify _nc_infotocap() to include non-mandatory padding when translating to termcap. + modify _nc_read_termcap_entry(), passing a flag in the case where getcap is used, to reduce interactive warning messages.
2011-07-31 09:15:59 +08:00
if (_nc_strict_bsd)
return 0;
2000-07-09 10:46:08 +08:00
bufptr = save_string(bufptr, "%s");
1997-05-15 12:00:00 +08:00
break;
case 'p':
str++;
if (*str == '1')
seenone = 1;
2000-07-09 10:46:08 +08:00
else if (*str == '2') {
if (!seenone && !seentwo) {
bufptr = save_string(bufptr, "%r");
1997-05-15 12:00:00 +08:00
seentwo++;
}
2000-07-09 10:46:08 +08:00
} else if (*str >= '3')
return (0);
1997-05-15 12:00:00 +08:00
break;
case 'i':
2000-07-09 10:46:08 +08:00
bufptr = save_string(bufptr, "%i");
1997-05-15 12:00:00 +08:00
break;
default:
2000-07-09 10:46:08 +08:00
bufptr = save_char(bufptr, *str);
syntax_error = TRUE;
break;
} /* endswitch (*str) */
} /* endelse (*str == '%') */
1997-05-15 12:00:00 +08:00
/*
* 'str' always points to the end of what was scanned in this step,
* but that may not be the end of the string.
*/
assert(str != 0);
1997-05-15 12:00:00 +08:00
if (*str == '\0')
break;
2000-07-09 10:46:08 +08:00
} /* endwhile (*str) */
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
return (syntax_error ? NULL : my_string);
1997-05-15 12:00:00 +08:00
}
#ifdef MAIN
int curr_line;
2000-07-09 10:46:08 +08:00
int
main(int argc, char *argv[])
1997-05-15 12:00:00 +08:00
{
int c, tc = FALSE;
while ((c = getopt(argc, argv, "c")) != EOF)
2000-07-09 10:46:08 +08:00
switch (c) {
1997-05-15 12:00:00 +08:00
case 'c':
tc = TRUE;
break;
}
curr_line = 0;
2000-07-09 10:46:08 +08:00
for (;;) {
char buf[BUFSIZ];
1997-05-15 12:00:00 +08:00
++curr_line;
1998-03-01 12:21:12 +08:00
if (fgets(buf, sizeof(buf), stdin) == 0)
1997-05-15 12:00:00 +08:00
break;
buf[strlen(buf) - 1] = '\0';
_nc_set_source(buf);
2000-07-09 10:46:08 +08:00
if (tc) {
char *cp = _nc_infotocap("to termcap", buf, 1);
1997-05-15 12:00:00 +08:00
if (cp)
(void) fputs(cp, stdout);
2000-07-09 10:46:08 +08:00
} else
1997-05-15 12:00:00 +08:00
(void) fputs(_nc_captoinfo("to terminfo", buf, 1), stdout);
(void) putchar('\n');
}
2000-07-09 10:46:08 +08:00
return (0);
1997-05-15 12:00:00 +08:00
}
#endif /* MAIN */
2005-10-10 02:41:57 +08:00
#if NO_LEAKS
NCURSES_EXPORT(void)
_nc_captoinfo_leaks(void)
{
2006-12-18 12:32:42 +08:00
if (my_string != 0) {
FreeAndNull(my_string);
}
2005-10-10 02:41:57 +08:00
my_length = 0;
}
#endif