Add documentation for control sequence matcher.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
43bb0d18a5
commit
91314246ff
|
@ -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
|
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
|
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
|
@menu
|
||||||
* Contributing:: Contributing to ctlseqs.
|
* 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:
|
The following code snippet is an example usage of helper macros:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
#include <stdio.h>
|
printf(CTLSEQS_BEL);
|
||||||
#include <ctlseqs.h>
|
printf(CTLSEQS_XTVERSION());
|
||||||
int main() @{
|
printf(CTLSEQS_CUP("%d", "%d"), 3, 4);
|
||||||
printf(CTLSEQS_BEL);
|
|
||||||
printf(CTLSEQS_XTVERSION());
|
|
||||||
printf(CTLSEQS_CUP("%d", "%d"), 3, 4);
|
|
||||||
fflush(stdout);
|
|
||||||
@}
|
|
||||||
@end example
|
@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
|
@node Control Sequence Matching
|
||||||
@chapter 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
|
@node Control Sequence Reading
|
||||||
@chapter Control Sequence Reading
|
@chapter Control Sequence Reading
|
||||||
|
|
Loading…
Reference in New Issue