X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=miniexpect.pod;h=e93ff67ec24a1e949c973b44b857f010e5a7d614;hb=fcf73607913050d246dbcc4f39e7717d0960763f;hp=fe769791cae66c6beea54cd4c95bfb64d6bcff11;hpb=eba90008396f05e2c0fa752421793b797383fca7;p=miniexpect.git diff --git a/miniexpect.pod b/miniexpect.pod index fe76979..e93ff67 100644 --- a/miniexpect.pod +++ b/miniexpect.pod @@ -8,17 +8,18 @@ miniexpect - A very simple expect library for C. #include #include - #include + #define PCRE2_CODE_UNIT_WIDTH 8 + #include #include mexp_h *h; h = mexp_spawnl ("ssh", "ssh", "host", NULL); - switch (mexp_expect (h, regexps, ovector, ovecsize)) { + switch (mexp_expect (h, regexps, match_data)) { ... } mexp_close (h); - cc prog.c -o prog -lminiexpect -lpcre + cc prog.c -o prog -lminiexpect -lpcre2-8 =head1 DESCRIPTION @@ -30,10 +31,10 @@ Tcl. It is also thread safe, const-correct and uses modern C standards. Miniexpect is a standalone library, except for a single dependency: it -requires the PCRE (Perl Compatible Regular Expressions) library from -L. The PCRE dependency is fundamental because +requires the PCRE2 (Perl Compatible Regular Expressions) library from +L. The PCRE2 dependency is fundamental because we want to offer the most powerful regular expression syntax to match -on, but more importantly because PCRE has a convenient way to detect +on, but more importantly because PCRE2 has a convenient way to detect partial matches which made this library very simple to implement. This manual page documents the API. Examples of how to use the API @@ -152,30 +153,12 @@ The default is 1024. Most callers will not need to change this. B When C [see below] calls the PCRE function -L, it stashes the return value in the C +L, it stashes the return value in the C field in the handle, and that field is returned by this method. -There are two uses for this: - -=over 4 - -=item 1. - If C returns C, then the actual PCRE -error code returned by L is available by calling this -method. For a list of PCRE error codes, see L. - -=item 2. - -A more unusual use is if you ever need to get the captured substrings -from your regular expression (calling L). The -third parameter of that function (C) is the value -returned by L, and so you can call it like this: - - pcre_get_substring (h->buffer, ovector, - mexp_get_pcre_error (h), 1, &matched); - -=back +error code returned by L is available by calling this +method. For a list of PCRE error codes, see L. B @@ -278,10 +261,10 @@ This is how code should check for and print errors from C: =head1 EXPECT FUNCTION Miniexpect contains a powerful regular expression matching function -based on L: +based on L: B +pcre2_match_data *match_data);> The output of the subprocess is matched against the list of PCRE regular expressions in C. C is a list of regular @@ -289,8 +272,7 @@ expression structures: struct mexp_regexp { int r; - const pcre *re; - const pcre_extra *extra; + const pcre2_code *re; int options; }; typedef struct mexp_regexp mexp_regexp; @@ -320,7 +302,7 @@ returned in C. =item C -There was a C error. Cpcre_error> is set to the +There was a C error. Cpcre_error> is set to the error code. See L for a list of the C error codes and what they mean. @@ -343,8 +325,8 @@ for EOF or timeout. =item * -C, C, C, C -and C are passed through to the L function. +C, C and C are passed +through to the L function. =item * @@ -385,21 +367,22 @@ literal" and is available in C99. If you need to use an older compiler, you can just use a local variable instead. mexp_h *h; - char *errptr; + int errcode; int offset; - pcre *password_re, *prompt_re; - const int ovecsize = 12; - int ovector[ovecsize]; + pcre2_code *password_re, *prompt_re; + pcre2_match_data *match_data = pcre2_match_data_create (4, NULL); - password_re = pcre_compile ("assword", 0, &errptr, &offset, NULL); - prompt_re = pcre_compile ("[$#] ", 0, &errptr, &offset, NULL); + password_re = pcre2_compile ("assword", PCRE2_ZERO_TERMINATED, + 0, &errcode, &offset, NULL); + prompt_re = pcre2_compile ("[$#] ", PCRE2_ZERO_TERMINATED, + 0, &errcode, &offset, NULL); switch (mexp_expect (h, (mexp_regexp[]) { { 100, .re = password_re }, { 101, .re = prompt_re }, { 0 }, - }, ovector, ovecsize)) { + }, match_data)) { case 100: /* here you would send a password */ break; @@ -476,9 +459,9 @@ L =head1 SEE ALSO -L, -L, -L, +L, +L, +L, L, L. @@ -493,4 +476,4 @@ your option any later version. =head1 COPYRIGHT -Copyright (C) 2014 Red Hat Inc. +Copyright (C) 2014-2022 Red Hat Inc.