X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fcaptoinfo.c;h=a0da44dea98938ed79abf6b3396810c595b860f6;hp=0d7944f36fa7003851b2f391dcd4f2b0558d1a5d;hb=96d6b16de0d487e5d3aed0302a179dbce11b5d96;hpb=c04d54322f7835ed42e597967d8fa5471025fcac diff --git a/ncurses/tinfo/captoinfo.c b/ncurses/tinfo/captoinfo.c index 0d7944f3..a0da44de 100644 --- a/ncurses/tinfo/captoinfo.c +++ b/ncurses/tinfo/captoinfo.c @@ -93,7 +93,7 @@ #include #include -MODULE_ID("$Id: captoinfo.c,v 1.54 2010/01/16 17:12:19 tom Exp $") +MODULE_ID("$Id: captoinfo.c,v 1.58 2010/12/04 20:08:19 tom Exp $") #define MAX_PUSHED 16 /* max # args we can push onto the stack */ @@ -643,6 +643,7 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0; const char *padding; const char *trimmed = 0; + int in0, in1, in2; char ch1 = 0, ch2 = 0; char *bufptr = init_string(); int len; @@ -666,8 +667,27 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz int c1, c2; char *cp = 0; - if (str[0] == '\\' && (str[1] == '^' || str[1] == ',')) { - bufptr = save_char(bufptr, *++str); + 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 { + bufptr = save_char(bufptr, *str++); + bufptr = save_char(bufptr, *str); + } } else if (str[0] == '$' && str[1] == '<') { /* discard padding */ str += 2; while (isdigit(UChar(*str)) @@ -677,6 +697,19 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz || *str == '>') 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"); + } } else if (str[0] == '%' && str[1] == '%') { /* escaped '%' */ bufptr = save_string(bufptr, "%%"); ++str;