X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fcaptoinfo.c;h=f2575f8ac2ddff9e2314296721c4d24d7037ef33;hp=a0da44dea98938ed79abf6b3396810c595b860f6;hb=b9cd971c38eeeb2394d3da08edfd3c5dfc71694e;hpb=96d6b16de0d487e5d3aed0302a179dbce11b5d96 diff --git a/ncurses/tinfo/captoinfo.c b/ncurses/tinfo/captoinfo.c index a0da44de..f2575f8a 100644 --- a/ncurses/tinfo/captoinfo.c +++ b/ncurses/tinfo/captoinfo.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. * + * Copyright (c) 1998-2010,2011 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 * @@ -93,7 +93,7 @@ #include #include -MODULE_ID("$Id: captoinfo.c,v 1.58 2010/12/04 20:08:19 tom Exp $") +MODULE_ID("$Id: captoinfo.c,v 1.69 2011/07/30 21:33:42 tom Exp $") #define MAX_PUSHED 16 /* max # args we can push onto the stack */ @@ -240,6 +240,12 @@ getparm(int parm, int n) else if (parm == 2) parm = 1; } + + while (n--) { + dp = save_string(dp, "%p"); + dp = save_char(dp, '0' + parm); + } + if (onstack == parm) { if (n > 1) { _nc_warning("string may not be optimal"); @@ -255,11 +261,6 @@ getparm(int parm, int n) onstack = parm; - while (n--) { - dp = save_string(dp, "%p"); - dp = save_char(dp, '0' + parm); - } - if (seenn && parm < 3) { dp = save_string(dp, "%{96}%^"); } @@ -469,73 +470,9 @@ _nc_captoinfo(const char *cap, const char *s, int const parameterized) break; } break; -#ifdef REVISIBILIZE - case '\\': - dp = save_char(dp, *s++); - dp = save_char(dp, *s++); - break; - case '\n': - dp = save_string(dp, "\\n"); - s++; - break; - case '\t': - dp = save_string(dp, "\\t"); - s++; - break; - case '\r': - dp = save_string(dp, "\\r"); - s++; - break; - case '\200': - dp = save_string(dp, "\\0"); - s++; - break; - case '\f': - dp = save_string(dp, "\\f"); - s++; - break; - case '\b': - dp = save_string(dp, "\\b"); - s++; - break; - case ' ': - dp = save_string(dp, "\\s"); - s++; - break; - case '^': - dp = save_string(dp, "\\^"); - s++; - break; - case ':': - dp = save_string(dp, "\\:"); - s++; - break; - case ',': - dp = save_string(dp, "\\,"); - s++; - break; - default: - if (*s == '\033') { - dp = save_string(dp, "\\E"); - s++; - } else if (*s > 0 && *s < 32) { - dp = save_char(dp, '^'); - dp = save_char(dp, *s + '@'); - s++; - } else if (*s <= 0 || *s >= 127) { - dp = save_char(dp, '\\'); - dp = save_char(dp, ((*s & 0300) >> 6) + '0'); - dp = save_char(dp, ((*s & 0070) >> 3) + '0'); - dp = save_char(dp, (*s & 0007) + '0'); - s++; - } else - dp = save_char(dp, *s++); - break; -#else default: dp = save_char(dp, *s++); break; -#endif } } @@ -646,13 +583,15 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz int in0, in1, in2; char ch1 = 0, ch2 = 0; char *bufptr = init_string(); + char octal[4]; int len; bool syntax_error = FALSE; /* we may have to move some trailing mandatory padding up front */ padding = str + strlen(str) - 1; - if (padding > str && *padding == '>' && *--padding == '/') { - --padding; + if (padding > str && *padding == '>') { + if (*--padding == '/') + --padding; while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*') padding--; if (padding > str && *padding == '<' && *--padding == '$') @@ -663,7 +602,7 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz bufptr = save_char(bufptr, *padding++); } - for (; *str && str != trimmed; str++) { + for (; *str && ((trimmed == 0) || (str < trimmed)); str++) { int c1, c2; char *cp = 0; @@ -685,8 +624,71 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz } else if (str[1] == ',') { bufptr = save_char(bufptr, *++str); } else { + int xx1, xx2; + bufptr = save_char(bufptr, *str++); - bufptr = save_char(bufptr, *str); + xx1 = *str; + 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'; + } + } else if (strchr("E\\nrtbf", xx1) == 0) { + switch (xx1) { + 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; + 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]; + break; + } + } + } + bufptr = save_char(bufptr, xx1); } } else if (str[0] == '$' && str[1] == '<') { /* discard padding */ str += 2; @@ -720,13 +722,13 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz bufptr = save_tc_inequality(bufptr, c1, c2); } else if (sscanf(str, "%%?%%{%d}%%>%%t%%'%c'%%+%%;", &c1, &ch2) == 2) { str = strchr(str, ';'); - bufptr = save_tc_inequality(bufptr, c1, c2); + bufptr = save_tc_inequality(bufptr, c1, ch2); } else if (sscanf(str, "%%?%%'%c'%%>%%t%%{%d}%%+%%;", &ch1, &c2) == 2) { str = strchr(str, ';'); - bufptr = save_tc_inequality(bufptr, c1, c2); + bufptr = save_tc_inequality(bufptr, ch1, c2); } else if (sscanf(str, "%%?%%'%c'%%>%%t%%'%c'%%+%%;", &ch1, &ch2) == 2) { str = strchr(str, ';'); - bufptr = save_tc_inequality(bufptr, c1, c2); + bufptr = save_tc_inequality(bufptr, ch1, ch2); } else if ((len = bcd_expression(str)) != 0) { str += len; bufptr = save_string(bufptr, "%B"); @@ -772,8 +774,25 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz case '8': case '9': bufptr = save_char(bufptr, '%'); - while (isdigit(UChar(*str))) - bufptr = save_char(bufptr, *str++); + ch1 = 0; + ch2 = 0; + while (isdigit(UChar(*str))) { + ch2 = ch1; + ch1 = *str++; + if (_nc_strict_bsd) { + if (ch1 > '3') + return 0; + } else { + bufptr = save_char(bufptr, ch1); + } + } + if (_nc_strict_bsd) { + if (ch2 != 0 && ch2 != '0') + return 0; + if (ch1 < '2') + ch1 = 'd'; + bufptr = save_char(bufptr, ch1); + } if (strchr("doxX.", *str)) { if (*str != 'd') /* termcap doesn't have octal, hex */ return 0; @@ -794,6 +813,8 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz * termcap notation. */ case 's': + if (_nc_strict_bsd) + return 0; bufptr = save_string(bufptr, "%s"); break;