如果elsefo表达在terminfo参数化字符串

时间:2017-05-26 09:05:22

标签: terminal c++14 terminfo termcap

我在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部分执行哪些其他操作?

1 个答案:

答案 0 :(得分:1)

简短:"任何事情"

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

在给定的例子中,

  

%? expr %t thenpart {{1} } elsepart %e

将其视为一个程序

  

%;
%? expr

%t thenpart

%e elsepart <无线电通信/>的

可以包含其他 if-then-else 部分。但是,terminfo的目的是将这些参数转换为字符串以发送到终端。文字字符将是&#34;输出&#34;。您可以将文字字符作为 thenpart ,并将其用于输出。或者你可以计算一些表达式并暂时保存,例如,在堆栈上。在 thenpart elsepart 中执行此操作可让您在 if-then-else 之后弹出堆栈,并将其用于输出,或者在某些进一步表达。

xterm使用 %; setf setb 中的功能(请参阅链接到"xterm-basic")。