📄 captoinfo.c
字号:
dp = save_string(dp, "%-%c"); pop(); break; case '.': getparm(param, 1); dp = save_string(dp, "%c"); pop(); break; case '0': /* not clear any of the historical termcaps did this */ if (*s == '3') goto see03; else if (*s != '2') goto invalid; /* FALLTHRU */ case '2': getparm(param, 1); dp = save_string(dp, "%2d"); pop(); break; case '3': see03: getparm(param, 1); dp = save_string(dp, "%3d"); pop(); break; case 'd': getparm(param, 1); dp = save_string(dp, "%d"); pop(); break; case 'f': param++; break; case 'b': param--; break; case '\\': dp = save_string(dp, "%\\"); break; default: invalid: dp = save_char(dp, '%'); s--; _nc_warning("unknown %% code %s (%#x) in %s", unctrl((chtype) *s), UChar(*s), cap); 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 } } /* * Now, if we stripped off some leading padding, add it at the end * of the string as mandatory padding. */ if (capstart) { dp = save_string(dp, "$<"); for (s = capstart;; s++) if (isdigit(UChar(*s)) || *s == '*' || *s == '.') dp = save_char(dp, *s); else break; 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 intbcd_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 && isdigit(UChar(ch1)) && isdigit(UChar(ch2)) && (ch1 == ch2)) { len = 28;#ifndef NDEBUG { char buffer[80]; int tst; sprintf(buffer, fmt, ch1, ch2); tst = strlen(buffer) - 1; assert(len == tst); }#endif } return len;}static char *save_tc_char(char *bufptr, int c1){ char temp[80]; 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 */ (void) strcpy(temp, unctrl((chtype) c1)); 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;}/* * 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) *//* * Convert a terminfo string to termcap format. Parameters are as in * _nc_captoinfo(). */NCURSES_EXPORT(char *)_nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameterized){ int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0; const char *padding; const char *trimmed = 0; char ch1 = 0, ch2 = 0; char *bufptr = init_string(); 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; while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*') padding--; if (padding > str && *padding == '<' && *--padding == '$') trimmed = padding; padding += 2; while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*') bufptr = save_char(bufptr, *padding++); } for (; *str && str != trimmed; str++) { int c1, c2; char *cp = 0; if (str[0] == '\\' && (str[1] == '^' || str[1] == ',')) { bufptr = save_char(bufptr, *++str); } else if (str[0] == '$' && str[1] == '<') { /* discard padding */ str += 2; while (isdigit(UChar(*str)) || *str == '.' || *str == '*' || *str == '/' || *str == '>') str++; --str; } else if (str[0] == '%' && str[1] == '%') { /* escaped '%' */ bufptr = save_string(bufptr, "%%"); ++str; } else if (*str != '%' || (parameterized < 1)) { bufptr = save_char(bufptr, *str); } else if (sscanf(str, "%%?%%{%d}%%>%%t%%{%d}%%+%%;", &c1, &c2) == 2) { str = strchr(str, ';'); 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); } else if (sscanf(str, "%%?%%'%c'%%>%%t%%{%d}%%+%%;", &ch1, &c2) == 2) { str = strchr(str, ';'); bufptr = save_tc_inequality(bufptr, c1, c2); } else if (sscanf(str, "%%?%%'%c'%%>%%t%%'%c'%%+%%;", &ch1, &ch2) == 2) { str = strchr(str, ';'); bufptr = save_tc_inequality(bufptr, c1, c2); } 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) && (cp = strchr(str, '+'))) { str = cp + 2; bufptr = save_string(bufptr, "%+"); if (ch1) c1 = ch1; bufptr = save_tc_char(bufptr, c1); } /* FIXME: this "works" for 'delta' */ else if (strncmp(str, "%{2}%*%-", 8) == 0) { str += 7; bufptr = save_string(bufptr, "%D"); } else if (strncmp(str, "%{96}%^", 7) == 0) { str += 6; if (saw_m++ == 0) { bufptr = save_string(bufptr, "%n"); } } else if (strncmp(str, "%{127}%^", 8) == 0) { str += 7; if (saw_n++ == 0) { bufptr = save_string(bufptr, "%m"); } } else { /* cm-style format element */ 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, '%'); while (isdigit(UChar(*str))) bufptr = save_char(bufptr, *str++); if (strchr("doxX.", *str)) { if (*str != 'd') /* termcap doesn't have octal, hex */ return 0; } break; case 'd': bufptr = save_string(bufptr, "%d"); break; case 'c': bufptr = save_string(bufptr, "%."); break; /* * %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. */ case 's': bufptr = save_string(bufptr, "%s"); break; case 'p': str++; if (*str == '1') seenone = 1; else if (*str == '2') { if (!seenone && !seentwo) { bufptr = save_string(bufptr, "%r"); seentwo++; } } else if (*str >= '3') return (0); break; case 'i': bufptr = save_string(bufptr, "%i"); break; default: bufptr = save_char(bufptr, *str); syntax_error = TRUE; break; } /* endswitch (*str) */ } /* endelse (*str == '%') */ if (*str == '\0') break; } /* endwhile (*str) */ return (syntax_error ? NULL : my_string);}#ifdef MAINint curr_line;intmain(int argc, char *argv[]){ int c, tc = FALSE; while ((c = getopt(argc, argv, "c")) != EOF) switch (c) { case 'c': tc = TRUE; break; } curr_line = 0; for (;;) { char buf[BUFSIZ]; ++curr_line; if (fgets(buf, sizeof(buf), stdin) == 0) break; buf[strlen(buf) - 1] = '\0'; _nc_set_source(buf); if (tc) { char *cp = _nc_infotocap("to termcap", buf, 1); if (cp) (void) fputs(cp, stdout); } else (void) fputs(_nc_captoinfo("to terminfo", buf, 1), stdout); (void) putchar('\n'); } return (0);}#endif /* MAIN */#if NO_LEAKSNCURSES_EXPORT(void)_nc_captoinfo_leaks(void){ FreeAndNull(my_string); my_length = 0;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -