118 lines
2.9 KiB
Groff
118 lines
2.9 KiB
Groff
.TH CTLSEQS_MATCH 3 "Dec 23, 2020" 0.1.0 ctlseqs
|
|
.
|
|
.SH NAME
|
|
ctlseqs_match - match control sequence
|
|
.
|
|
.SH SYNOPSYS
|
|
.nf
|
|
.B #include <ctlseqs.h>
|
|
.PP
|
|
.B ssize_t ctlseqs_match(
|
|
.BI " struct ctlseqs_matcher const *" matcher ,
|
|
.BI " char const *" str ,
|
|
.BI " size_t " str_len ,
|
|
.BI " union ctlseqs_value *" result
|
|
.B );
|
|
.fi
|
|
.
|
|
.SH DESCRIPTION
|
|
Matches string
|
|
.I str
|
|
against the patterns specified in
|
|
.IR matcher ,
|
|
until a valid control sequence is found, or
|
|
.I str_len
|
|
number of characters are processed.
|
|
.PP
|
|
For a NULL
|
|
.IR matcher ,
|
|
the function behaves as if a matcher configured with 0
|
|
.I npatterns
|
|
is specified.
|
|
.PP
|
|
Argument
|
|
.I result
|
|
is the buffer where the function stores match results.
|
|
If
|
|
.I str
|
|
contains a control sequence (or part of a control sequence), the length of the
|
|
sequence is stored in
|
|
.I buffer
|
|
at offset 0, and the pointer to the starting ESC character at offset 1.
|
|
Otherwise,
|
|
.I buffer
|
|
value at offset 0 and 1 is unspecified.
|
|
.SS Match results
|
|
If the control sequence matches a pattern in
|
|
.IR matcher ,
|
|
a group of values is extracted from the sequence for each placeholder, and
|
|
stored into
|
|
.I result
|
|
sequentially, starting at offset 2.
|
|
.PP
|
|
An extracted value can be either a string (not guaranteed to be
|
|
NUL-terminated), or an unsigned integer, as in
|
|
.BR "union ctlseqs_value" :
|
|
.PP
|
|
.nf
|
|
.in +4n
|
|
.EX
|
|
union ctlseqs_value {
|
|
char const *str;
|
|
size_t len;
|
|
unsigned long num;
|
|
};
|
|
.EE
|
|
.in
|
|
.fi
|
|
.PP
|
|
A group can contain one or multiple values, depending on different
|
|
placeholders:
|
|
.TP
|
|
.BR CTLSEQS_PH_NUM ", " CTLSEQS_PH_HEXNUM
|
|
The integer is stored in field
|
|
.IR num .
|
|
.TP
|
|
.B CTLSEQS_PH_NUMS
|
|
The number of integers is stored in field
|
|
.IR len ,
|
|
followed by that many integers stored in field
|
|
.IR num .
|
|
.TP
|
|
.BR CTLSEQS_PH_STR ", " CTLSEQS_PH_CMDSTR ", " CTLSEQS_PH_CSI_PARAM ", " \
|
|
CTLSEQS_PH_CSI_INTMD ", " CTLSEQS_PH_CHRSTR
|
|
The length of the string is stored in field
|
|
.IR len ,
|
|
followed by a pointer to the first character of the string stored in field
|
|
.IR str .
|
|
.
|
|
.SH RETURN VALUES
|
|
If
|
|
.I str
|
|
contains a valid control sequence, and matches at least one pattern in
|
|
.IR matcher ,
|
|
returns a non-negative integer representing the offset of a matching pattern.
|
|
.PP
|
|
Otherwise, returns a negative value:
|
|
.TP
|
|
.B CTLSEQS_NOMATCH
|
|
A valid control sequence is found, but fails to match any pattern in
|
|
.IR matcher .
|
|
.TP
|
|
.B CTLSEQS_PARTIAL
|
|
The string can be recognized as part of a control sequence, but is not yet
|
|
terminated.
|
|
.TP
|
|
.B CTLSEQS_NOSEQ
|
|
No valid control sequence is found in the given string.
|
|
.
|
|
.SH COPYRIGHT
|
|
Copyright (c) 2020,2021,2022 CismonX <admin@cismon.net>
|
|
.PP
|
|
Copying and distribution of this file, with or without modification, are
|
|
permitted in any medium without royalty, provided the copyright notice and
|
|
this notice are preserved. This file is offered as-is, without any warranty.
|
|
.
|
|
.SH SEE ALSO
|
|
.BR ctlseqs_matcher_config (3)
|