【问题标题】:If else expression in terminfo parameterized stringsterminfo 参数化字符串中的 if else 表达式
【发布时间】:2017-05-27 05:32:19
【问题描述】:

我正在 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.

所以,我的问题是:
正如man page所说,字符串中的expr部分可以通常将值压入堆栈,那么expr部分还可以做什么,也就是还有什么其他操作可以在 expr 部分执行,除了将值压入堆栈?

【问题讨论】:

    标签: terminal c++14 terminfo termcap


    【解决方案1】:

    简短:“任何东西”

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

    在给定的示例中,

    %? expr %t thenpart %e elsepart %;

    把它想象成一个程序

    %?
    <em>expr</em><br><strong>%t
    <em>thenpart </em><br><strong>%e
    <em>elsepart</em><br><strong>%;

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

    xterm 在 setfsetbsgr 中使用了该功能(参见"xterm-basic" 的链接)。

    【讨论】:

    • 这些可以嵌套吗?即 expr/thenpart/elsepart 可以包含更多这些吗?
    • 是的,例如 hp2382awy350 一样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 2018-03-25
    • 1970-01-01
    相关资源
    最近更新 更多