1

我正在 C++ 中为参数化字符串实现解析器(用于为终端指定一些终端功能)。然后我在 terminfo 的手册页上遇到了这个:

%? expr %t thenpart %e elsepart %;
   This forms an if-then-else.  The %e elsepart is optional.  Usually the %? expr part  pushes
   a value onto the stack, and %t pops it from the stack, testing if it is nonzero (true).  If
   it is zero (false), control passes to the %e (else) part.

所以,我的问题是:
正如手册页所说,expr字符串中的部分通常可以将值压入堆栈,那么在该部分中还可以做哪些其他事情expr,即在expr部分可以进行哪些其他操作除了将值压入堆栈?

4

1 回答 1

1

简短:“任何东西”

long:terminfo 表达式最多使用 9 个参数(出于显而易见的原因,数字1-9反过来可能是sgr使用 9 个参数的原因)。

在给定的示例中,

%? expr thenpart elsepart%t %e %;

把它想象成一个程序

%?
expr thenpart elsepart
%t

%e

%;

可以包含其他if-then-else片段。但是,terminfo 的目的是将这些参数转换为字符串以发送到终端。文字字符将是“输出”。您可以将文字字符作为thenpart,这些字符将用于输出。或者您可以计算一些表达式并将其临时保存,例如,在堆栈上。在thenpartelsepart中都这样做可以让您在if-then-else之后弹出堆栈,并将其用于输出或其他表达式。

xterm 使用setf,setb和中的特性sgr(参见“xterm-basic”的链接)。

于 2017-05-26T21:14:50.147 回答