X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fcaptoinfo.c;h=7e14731df3685b78269bbbf8e167e39144063a6e;hp=6a2252ee25406ede681d42f76d2ed7dda5aaba2e;hb=c0e5fbfcce224693b3effdd295ee49b6b761b754;hpb=9208e1bde56ebb9cc550fd93034f1d4650518b11 diff --git a/ncurses/tinfo/captoinfo.c b/ncurses/tinfo/captoinfo.c index 6a2252ee..7e14731d 100644 --- a/ncurses/tinfo/captoinfo.c +++ b/ncurses/tinfo/captoinfo.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2017,2018 Free Software Foundation, Inc. * + * Copyright 2018-2020,2021 Thomas E. Dickey * + * Copyright 1998-2016,2017 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 * @@ -97,7 +98,7 @@ #include #include -MODULE_ID("$Id: captoinfo.c,v 1.96 2018/05/12 16:46:55 tom Exp $") +MODULE_ID("$Id: captoinfo.c,v 1.102 2021/09/04 10:29:15 tom Exp $") #if 0 #define DEBUG_THIS(p) DEBUG(9, p) @@ -210,27 +211,30 @@ cvtchar(register const char *sp) break; default: c = UChar(*sp); - len = 2; + len = (c != '\0') ? 2 : 1; break; } break; case '^': + len = 2; c = UChar(*++sp); - if (c == '?') + if (c == '?') { c = 127; - else + } else if (c == '\0') { + len = 1; + } else { c &= 0x1f; - len = 2; + } break; default: c = UChar(*sp); - len = 1; + len = (c != '\0') ? 1 : 0; } if (isgraph(c) && c != ',' && c != '\'' && c != '\\' && c != ':') { dp = save_string(dp, "%\'"); dp = save_char(dp, c); dp = save_char(dp, '\''); - } else { + } else if (c != '\0') { dp = save_string(dp, "%{"); if (c > 99) dp = save_char(dp, c / 100 + '0'); @@ -313,7 +317,7 @@ _nc_captoinfo(const char *cap, const char *s, int const parameterized) if (s == 0) s = ""; if (parameterized >= 0 && isdigit(UChar(*s))) - for (capstart = s;; s++) + for (capstart = s; *s != '\0'; s++) if (!(isdigit(UChar(*s)) || *s == '*' || *s == '.')) break; @@ -360,13 +364,18 @@ _nc_captoinfo(const char *cap, const char *s, int const parameterized) dp = save_string(dp, "%{2}%*%-"); break; case '>': - getparm(param, 2); /* %?%{x}%>%t%{y}%+%; */ - dp = save_string(dp, "%?"); - s += cvtchar(s); - dp = save_string(dp, "%>%t"); - s += cvtchar(s); - dp = save_string(dp, "%+%;"); + if (s[0] && s[1]) { + getparm(param, 2); + dp = save_string(dp, "%?"); + s += cvtchar(s); + dp = save_string(dp, "%>%t"); + s += cvtchar(s); + dp = save_string(dp, "%+%;"); + } else { + _nc_warning("expected two characters after %%>"); + dp = save_string(dp, "%>"); + } break; case 'a': if ((*s == '=' || *s == '+' || *s == '-' @@ -492,7 +501,8 @@ _nc_captoinfo(const char *cap, const char *s, int const parameterized) } break; default: - dp = save_char(dp, *s++); + if (*s != '\0') + dp = save_char(dp, *s++); break; } } @@ -503,7 +513,7 @@ _nc_captoinfo(const char *cap, const char *s, int const parameterized) */ if (capstart) { dp = save_string(dp, "$<"); - for (s = capstart;; s++) + for (s = capstart; *s != '\0'; s++) if (isdigit(UChar(*s)) || *s == '*' || *s == '.') dp = save_char(dp, *s); else @@ -624,12 +634,15 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz int offset; } fixups[MAX_TC_FIXUPS]; - DEBUG_THIS(("_nc_infotocap params %d, %s", parameterized, str)); + DEBUG_THIS(("_nc_infotocap %s params %d, %s", + _nc_strict_bsd ? "strict" : "loose", + parameterized, + _nc_visbuf(str))); /* we may have to move some trailing mandatory padding up front */ padding = str + strlen(str) - 1; if (padding > str && *padding == '>') { - if (*--padding == '/') + if (padding > (str + 1) && *--padding == '/') --padding; while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*') padding--; @@ -663,6 +676,11 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz bufptr = save_char(bufptr, *str++); bufptr = save_char(bufptr, *str); } + } else if (str[0] == ':') { + bufptr = save_char(bufptr, '\\'); + bufptr = save_char(bufptr, '0'); + bufptr = save_char(bufptr, '7'); + bufptr = save_char(bufptr, '2'); } else if (str[0] == '\\') { if (str[1] == '\0' || (str + 1) == trimmed) { bufptr = save_string(bufptr, "\\134"); @@ -922,7 +940,7 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz break; /* - * %s isn't in termcap, but it's convenient to pass it through + * %s isn't in termcap, but it is convenient to pass it through * so we can represent things like terminfo pfkey strings in * termcap notation. */