📄 tparm.c
字号:
* if they appear as a %l or %s format following an explicit parameter * reference (e.g., %p2%s). All other parameters are numbers. * * 'number' counts coarsely the number of pop's we see in the string, and * 'popcount' shows the highest parameter number in the string. We would * like to simply use the latter count, but if we are reading termcap * strings, there may be cases that we cannot see the explicit parameter * numbers. */ for (cp = string; (cp - string) < (int) len2;) { if (*cp == '%') { cp++; cp = parse_format(cp, format, &len); switch (*cp) { default: break; case 'd': /* FALLTHRU */ case 'o': /* FALLTHRU */ case 'x': /* FALLTHRU */ case 'X': /* FALLTHRU */ case 'c': /* FALLTHRU */ number++; lastpop = -1; break; case 'l': case 's': if (lastpop > 0) p_is_s[lastpop - 1] = dummy; ++number; break; case 'p': cp++; i = (*cp - '0'); if (i >= 0 && i <= 9) { lastpop = i; if (lastpop > popcount) popcount = lastpop; } break; case 'P': case 'g': cp++; break; case '\'': cp += 2; lastpop = -1; break; case '{': cp++; while (*cp >= '0' && *cp <= '9') { cp++; } break; case '+': case '-': case '*': case '/': case 'm': case 'A': case 'O': case '&': case '|': case '^': case '=': case '<': case '>': case '!': case '~': lastpop = -1; number += 2; break; case 'i': lastpop = -1; if (popcount < 2) popcount = 2; break; } } if (*cp != '\0') cp++; } if (number > 9) number = 9; 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. */ if (p_is_s[i] != 0) { p_is_s[i] = (char *)(*(dataptr++)); } else { param[i] = (int)(*(dataptr++)); } } /* * 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]); } while (*string) { /* skip delay timings */ if (*string == '$' && *(string + 1) == '<') { while( *string && *string != '>') string++; if ( *string == '>' ) string++; } else if ( *string == '%') { string++; string = parse_format(string, format, &len); switch (*string) { default: break; case '%': save_char('%'); break; case 'd': /* FALLTHRU */ case 'o': /* FALLTHRU */ case 'x': /* FALLTHRU */ case 'X': /* FALLTHRU */ case 'c': /* FALLTHRU */ save_number(format, npop(), len); break; case 'l': save_number("%d", strlen(spop()), 0); break; case 's': save_text(format, spop(), len); break; case 'p': string++; i = (*string - '1'); if (i >= 0 && i < 9) { if (p_is_s[i]) spush(p_is_s[i]); else npush(param[i]); } break; case 'P': string++; if (isUPPER(*string)) { i = (*string - 'A'); static_vars[i] = npop(); } else if (isLOWER(*string)) { i = (*string - 'a'); dynamic_var[i] = npop(); } break; case 'g': string++; if (isUPPER(*string)) { i = (*string - 'A'); npush(static_vars[i]); } else if (isLOWER(*string)) { i = (*string - 'a'); npush(dynamic_var[i]); } break; case '\'': string++; npush(*string); string++; break; case '{': number = 0; string++; while (*string >= '0' && *string <= '9') { number = number * 10 + *string - '0'; string++; } 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 */ string++; level = 0; while (*string) { if (*string == '%') { string++; if (*string == '?') level++; else if (*string == ';') { if (level > 0) level--; else break; } else if (*string == 'e' && level == 0) break; } if (*string) string++; } } break; case 'e': /* scan forward for a %; at level zero */ string++; level = 0; while (*string) { if (*string == '%') { string++; if (*string == '?') level++; else if (*string == ';') { if (level > 0) level--; else break; } } if (*string) string++; } break; case ';': break; } /* endswitch (*string) */ } else { /* endelse (*string == '%') */ save_char(*string); } if (*string == '\0') break; string++; } /* endwhile (*string) */ get_space(1); out_buff[out_used] = '\0'; return (out_buff);}char *grub_tparm(const char *string,...){ char *result; int *dataptr = (int *) &string; dataptr++; result = tparam_internal(string, dataptr); return result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -