Add documentation for control sequence matcher.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
CismonX 2021-02-24 21:13:03 +08:00
parent 43bb0d18a5
commit 91314246ff
Signed by: cismonx
GPG Key ID: 3094873E29A482FB
1 changed files with 27 additions and 9 deletions

View File

@ -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 <stdio.h>
#include <ctlseqs.h>
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