From c775ee2259ff84bb9797e214870e5cfe74f1c070 Mon Sep 17 00:00:00 2001 From: наб Date: Fri, 21 Apr 2023 04:48:59 +0200 Subject: regex.3: Finalise move of reg*.3type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They're inextricably linked, not cross-referenced at all, and not used anywhere else. Now that they (realistically) exist to the reader, add a note on how big nmatch can be; POSIX even says "The application developer should note that there is probably no reason for using a value of nmatch that is larger than preg−>re_nsub+1.". Also remove the now-duplicate regmatch_t declaration. Signed-off-by: Ahelenia Ziemiańska Signed-off-by: Alejandro Colomar --- man3/regex.3 | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/man3/regex.3 b/man3/regex.3 index 9d4b274e2..702a7645c 100644 --- a/man3/regex.3 +++ b/man3/regex.3 @@ -60,6 +60,21 @@ is a null-terminated string. The locale must be the same when running .BR regexec (). .PP +After +.BR regcomp () +succeeds, +.I preg->re_nsub +holds the number of subexpressions in +.IR regex . +Thus, a value of +.I preg->re_nsub ++ 1 +passed as +.I nmatch +to +.BR regexec () +is sufficient to capture all matches. +.PP .I cflags is the bitwise OR @@ -192,22 +207,6 @@ must be at least .IR N+1 .) Any unused structure elements will contain the value \-1. .PP -The -.I regmatch_t -structure which is the type of -.I pmatch -is defined in -.IR . -.PP -.in +4n -.EX -typedef struct { - regoff_t rm_so; - regoff_t rm_eo; -} regmatch_t; -.EE -.in -.PP Each .I rm_so element that is not \-1 indicates the start offset of the next largest @@ -218,7 +217,7 @@ element indicates the end offset of the match, which is the offset of the first character after the matching text. .PP .I regoff_t -It is a signed integer type +is a signed integer type capable of storing the largest value that can be stored in either an .I ptrdiff_t type or a @@ -348,12 +347,27 @@ POSIX.1-2008. POSIX.1-2001. .PP Prior to POSIX.1-2008, -the type was +.I regoff_t +was required to be capable of storing the largest value that can be stored in either an .I off_t type or a .I ssize_t type. +.SH CAVEATS +.I re_nsub +is only required to be initialized if +.B REG_NOSUB +wasn't specified, but all known implementations initialize it regardless. +.\" glibc, musl, 4.4BSD, illumos +.PP +Both +.I regex_t +and +.I regmatch_t +may (and do) have more members, in any order. +Always reference them by name. +.\" illumos has two more start/end pairs and the first one is of pointers .SH EXAMPLES .EX #include -- cgit v1.2.3