diff --git a/doc/ctlseqs.texi b/doc/ctlseqs.texi index 6382ca7..dc6d793 100644 --- a/doc/ctlseqs.texi +++ b/doc/ctlseqs.texi @@ -83,7 +83,8 @@ and implementation of a control sequence is up to the user. The C API provided by ctlseqs is composed of three major parts: The helper macros, the control sequence matcher, and the control sequence reader. Any of -them can be used separatedly or combined. +them can be used separatedly or combined, after including the header file +@code{ctlseqs.h} in a source file. @menu * Contributing:: Contributing to ctlseqs. @@ -188,20 +189,37 @@ For example, @code{CTLSEQS_CSI} expands to @code{"\x1b["}. The following code snippet is an example usage of helper macros: @example -#include -#include -int main() @{ - printf(CTLSEQS_BEL); - printf(CTLSEQS_XTVERSION()); - printf(CTLSEQS_CUP("%d", "%d"), 3, 4); - fflush(stdout); -@} +printf(CTLSEQS_BEL); +printf(CTLSEQS_XTVERSION()); +printf(CTLSEQS_CUP("%d", "%d"), 3, 4); @end example +Rememeber that the standard output stream is line buffered within a terminal. +Either @code{fflush(stdout)} after printing, or disable output buffering with +@code{setvbuf(stdout, NULL, _IONBF, 0)}. + @node Control Sequence Matching @chapter Control Sequence Matching +Given a character string, checking whether it matches a control sequence is +quite trivial, with only the standard C library: + +@example +char const *str /* = ... */; +int row, col; +if (0 == strcmp(str, CTLSEQS_XTVERSION())) @{ + // ... +@} else if (2 == sscanf(str, CTLSEQS_CUP("%d", "%d"), &row, &col)) @{ + // ... +@} else /* ... */ +@end example + +However, as the number of possible matches grows, this naive implementation +becomes less efficient and harder to maintain. + +The control sequence matcher provided by ctlseqs aims at solving such problems. + @node Control Sequence Reading @chapter Control Sequence Reading