?? lib_tparm.c
字號:
break; case 'l': case 's': if (lastpop > 0) p_is_s[lastpop - 1] = dummy; ++number; break; case 'p': cp++; i = (UChar(*cp) - '0'); if (i >= 0 && i <= NUM_PARM) { lastpop = i; if (lastpop > *popcount) *popcount = lastpop; } break; case 'P': ++number; ++cp; break; case 'g': cp++; break; case S_QUOTE: cp += 2; lastpop = -1; break; case L_BRACE: cp++; while (isdigit(UChar(*cp))) { cp++; } break; case '+': case '-': case '*': case '/': case 'm': case 'A': case 'O': case '&': case '|': case '^': case '=': case '<': case '>': lastpop = -1; number += 2; break; case '!': case '~': lastpop = -1; ++number; break; case 'i': /* will add 1 to first (usually two) parameters */ break; } } if (*cp != '\0') cp++; } if (number > NUM_PARM) number = NUM_PARM; return number;}static inline char *tparam_internal(const char *string, va_list ap){#define NUM_VARS 26 char *p_is_s[NUM_PARM]; long param[NUM_PARM]; int popcount; int number; int len; int level; int x, y; int i; const char *cp = string; size_t len2; static int dynamic_var[NUM_VARS]; static int static_vars[NUM_VARS]; if (cp == NULL) return NULL; out_used = 0; len2 = strlen(cp); /* * Find the highest parameter-number referred to in the format string. * Use this value to limit the number of arguments copied from the * variable-length argument list. */ number = _nc_tparm_analyze(cp, p_is_s, &popcount); if (fmt_buff == 0) return NULL; for (i = 0; i < max(popcount, number); i++) { /* * A few caps (such as plab_norm) have string-valued parms. * We'll have to assume that the caller knows the difference, since * a char* and an int may not be the same size on the stack. The * normal prototype for this uses 9 long's, which is consistent with * our va_arg() usage. */ if (p_is_s[i] != 0) { p_is_s[i] = va_arg(ap, char *); } else { param[i] = va_arg(ap, long int); } } /* * This is a termcap compatibility hack. If there are no explicit pop * operations in the string, load the stack in such a way that * successive pops will grab successive parameters. That will make * the expansion of (for example) \E[%d;%dH work correctly in termcap * style, which means tparam() will expand termcap strings OK. */ stack_ptr = 0; if (popcount == 0) { popcount = number; for (i = number - 1; i >= 0; i--) npush(param[i]); }#ifdef TRACE if (_nc_tracing & TRACE_CALLS) { for (i = 0; i < popcount; i++) { if (p_is_s[i] != 0) save_text(", %s", _nc_visbuf(p_is_s[i]), 0); else save_number(", %d", param[i], 0); } _tracef(T_CALLED("%s(%s%s)"), tname, _nc_visbuf(cp), out_buff); out_used = 0; }#endif /* TRACE */ while ((cp - string) < (int) len2) { if (*cp != '%') { save_char(UChar(*cp)); } else { tparam_base = cp++; cp = parse_format(cp, fmt_buff, &len); switch (*cp) { default: break; case '%': save_char('%'); break; case 'd': /* FALLTHRU */ case 'o': /* FALLTHRU */ case 'x': /* FALLTHRU */ case 'X': /* FALLTHRU */ save_number(fmt_buff, npop(), len); break; case 'c': /* FALLTHRU */ save_char(npop()); break; case 'l': save_number("%d", (int) strlen(spop()), 0); break; case 's': save_text(fmt_buff, spop(), len); break; case 'p': cp++; i = (UChar(*cp) - '1'); if (i >= 0 && i < NUM_PARM) { if (p_is_s[i]) spush(p_is_s[i]); else npush(param[i]); } break; case 'P': cp++; if (isUPPER(*cp)) { i = (UChar(*cp) - 'A'); static_vars[i] = npop(); } else if (isLOWER(*cp)) { i = (UChar(*cp) - 'a'); dynamic_var[i] = npop(); } break; case 'g': cp++; if (isUPPER(*cp)) { i = (UChar(*cp) - 'A'); npush(static_vars[i]); } else if (isLOWER(*cp)) { i = (UChar(*cp) - 'a'); npush(dynamic_var[i]); } break; case S_QUOTE: cp++; npush(UChar(*cp)); cp++; break; case L_BRACE: number = 0; cp++; while (isdigit(UChar(*cp))) { number = (number * 10) + (UChar(*cp) - '0'); cp++; } npush(number); break; case '+': npush(npop() + npop()); break; case '-': y = npop(); x = npop(); npush(x - y); break; case '*': npush(npop() * npop()); break; case '/': y = npop(); x = npop(); npush(y ? (x / y) : 0); break; case 'm': y = npop(); x = npop(); npush(y ? (x % y) : 0); break; case 'A': npush(npop() && npop()); break; case 'O': npush(npop() || npop()); break; case '&': npush(npop() & npop()); break; case '|': npush(npop() | npop()); break; case '^': npush(npop() ^ npop()); break; case '=': y = npop(); x = npop(); npush(x == y); break; case '<': y = npop(); x = npop(); npush(x < y); break; case '>': y = npop(); x = npop(); npush(x > y); break; case '!': npush(!npop()); break; case '~': npush(~npop()); break; case 'i': if (p_is_s[0] == 0) param[0]++; if (p_is_s[1] == 0) param[1]++; break; case '?': break; case 't': x = npop(); if (!x) { /* scan forward for %e or %; at level zero */ cp++; level = 0; while (*cp) { if (*cp == '%') { cp++; if (*cp == '?') level++; else if (*cp == ';') { if (level > 0) level--; else break; } else if (*cp == 'e' && level == 0) break; } if (*cp) cp++; } } break; case 'e': /* scan forward for a %; at level zero */ cp++; level = 0; while (*cp) { if (*cp == '%') { cp++; if (*cp == '?') level++; else if (*cp == ';') { if (level > 0) level--; else break; } } if (*cp) cp++; } break; case ';': break; } /* endswitch (*cp) */ } /* endelse (*cp == '%') */ if (*cp == '\0') break; cp++; } /* endwhile (*cp) */ get_space(1); out_buff[out_used] = '\0'; T((T_RETURN("%s"), _nc_visbuf(out_buff))); return (out_buff);}NCURSES_EXPORT(char *)tparm(NCURSES_CONST char *string,...){ va_list ap; char *result; _nc_tparm_err = 0; va_start(ap, string);#ifdef TRACE tname = "tparm";#endif /* TRACE */ result = tparam_internal(string, ap); va_end(ap); return result;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -