miniexpect.git
5 months agoReturn int from mexp_expect master
Richard W.M. Jones [Thu, 16 Nov 2023 10:59:54 +0000 (10:59 +0000)]
Return int from mexp_expect

GCC 13 highlights the mismatch between int and enum in the declared vs
implemented return type.  The return types are in this case
compatible, but it's not generally safe to implicitly convert between
int and enum.

miniexpect.c:248:1: warning: conflicting types for ‘mexp_expect’ due to enum/integer mismatch; have ‘enum mexp_status(mexp_h *, const mexp_regexp *, pcre2_match_data_8 *)’ {aka ‘enum mexp_status(mexp_h *, const mexp_regexp *, struct pcre2_real_match_data_8 *)’} [-Wenum-int-mismatch]
  248 | mexp_expect (mexp_h *h, const mexp_regexp *regexps,
      | ^~~~~~~~~~~
In file included from miniexpect.c:41:
miniexpect.h:100:12: note: previous declaration of ‘mexp_expect’ with type ‘int(mexp_h *, const mexp_regexp *, pcre2_match_data_8 *)’ {aka ‘int(mexp_h *, const mexp_regexp *, struct pcre2_real_match_data_8 *)’}
  100 | extern int mexp_expect (mexp_h *h, const mexp_regexp *regexps,
      |            ^~~~~~~~~~~

19 months agoMakefile.am: add "-Wextra -Wshadow"
Laszlo Ersek [Sun, 11 Sep 2022 12:37:57 +0000 (14:37 +0200)]
Makefile.am: add "-Wextra -Wshadow"

Both of these options enable useful warnings; let's use them.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
19 months agotests: mark main()'s "argc" as unused
Laszlo Ersek [Sun, 11 Sep 2022 12:44:23 +0000 (14:44 +0200)]
tests: mark main()'s "argc" as unused

Otherwise gcc emits warnings such as

> test-spawn.c: In function ‘main’:
> test-spawn.c:30:11: warning: unused parameter ‘argc’ [-Wunused-parameter]
>    30 | main (int argc, char *argv[])
>       |       ~~~~^~~~

when "-Wextra" is combined with "-Wall", and "-Wextra" is useful.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
19 months agotests: add "missing" initializers
Laszlo Ersek [Sun, 11 Sep 2022 12:36:26 +0000 (14:36 +0200)]
tests: add "missing" initializers

With "-Wextra", gcc emits warnings such as:

> test-multi-match.c:58:24: warning: missing initializer for field
> ‘options’ of ‘mexp_regexp’ [-Wmissing-field-initializers]

Although the code is not incorrect, let's just shut up the warnings, so we
can enable "-Wextra" later (which did catch an actual bug; see the
previous patch).

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
19 months agominiexpect.c: fix always-true comparison
Laszlo Ersek [Sun, 11 Sep 2022 12:32:37 +0000 (14:32 +0200)]
miniexpect.c: fix always-true comparison

According to <http://www.pcre.org/current/doc/html/pcre2api.html#SEC15>:

> STRING LENGTHS AND OFFSETS
>
> The PCRE2 API uses string lengths and offsets into strings of code units
> in several places. These values are always of type PCRE2_SIZE, which is
> an unsigned integer type, currently always defined as size_t. The
> largest value that can be stored in such a type (that is ~(PCRE2_SIZE)0)
> is reserved as a special indicator for zero-terminated strings and unset
> offsets. Therefore, the longest string that can be handled is one less
> than this maximum.

Therefore check the validity of ovector[1] with

  ovector[1] != ~(PCRE2_SIZE)0

rather than the always-true

  ovector[1] >= 0

This was caught by gcc's

> miniexpect.c:359:45: warning: comparison of unsigned expression in ‘>=
> 0’ is always true [-Wtype-limits]

which is part of "-Wextra".

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
21 months agoAdd a bit of explanation of what "expect" is
Richard W.M. Jones [Tue, 26 Jul 2022 17:09:06 +0000 (18:09 +0100)]
Add a bit of explanation of what "expect" is

Kids these days.

21 months agodocs: Small revisions to the manual and readme file
Richard W.M. Jones [Tue, 26 Jul 2022 09:08:12 +0000 (10:08 +0100)]
docs: Small revisions to the manual and readme file

21 months agotests: test-multi-match.c: Fix memory leaks in test
Richard W.M. Jones [Tue, 26 Jul 2022 08:56:03 +0000 (09:56 +0100)]
tests: test-multi-match.c: Fix memory leaks in test

21 months agotests: valgrind: Rebuild tests before running them
Richard W.M. Jones [Tue, 26 Jul 2022 08:55:45 +0000 (09:55 +0100)]
tests: valgrind: Rebuild tests before running them

21 months agodocs: Fix example in the manual
Richard W.M. Jones [Mon, 25 Jul 2022 17:47:40 +0000 (18:47 +0100)]
docs: Fix example in the manual

It still contained references to PCRE functions pcre_exec and
pcre_compile.  Replace with PCRE2 equivalents.

Fixes: commit 9a43a3bea411be5de83c64a2f1d28f365de7133f

21 months agoPort to pcre2 v1.1
Richard W.M. Jones [Mon, 25 Jul 2022 13:21:23 +0000 (14:21 +0100)]
Port to pcre2

The last version of PCRE (v1) 8.45 is end of life and will receive no
more updates.  PCRE2 is its replacement and is widely available in
distros.  So port the library to PCRE2.

21 months agominiexpect: Debug next_match field
Richard W.M. Jones [Mon, 25 Jul 2022 15:01:10 +0000 (16:01 +0100)]
miniexpect: Debug next_match field

6 years agoAdd debugging capability at runtime.
Richard W.M. Jones [Wed, 11 Oct 2017 15:12:29 +0000 (16:12 +0100)]
Add debugging capability at runtime.

Debugging can now be enabled at runtime.

6 years agoWhen debugging, escape the buffer output.
Richard W.M. Jones [Wed, 11 Oct 2017 14:39:30 +0000 (15:39 +0100)]
When debugging, escape the buffer output.

7 years agodoc: Use -u (UTF8) flag when generating the man page.
Richard W.M. Jones [Sun, 18 Dec 2016 14:22:23 +0000 (14:22 +0000)]
doc: Use -u (UTF8) flag when generating the man page.

7 years agodocumentation: Fix markup in flags.
Richard W.M. Jones [Sun, 18 Dec 2016 14:21:04 +0000 (14:21 +0000)]
documentation: Fix markup in flags.

7 years agoFix documentation of mexp_spawnl to include terminating NULL.
Richard W.M. Jones [Sun, 18 Dec 2016 14:19:13 +0000 (14:19 +0000)]
Fix documentation of mexp_spawnl to include terminating NULL.

Code is correct, but the documentation was wrong.

7 years agoint -> const int
Richard W.M. Jones [Tue, 26 Jul 2016 10:18:33 +0000 (11:18 +0100)]
int -> const int

7 years agoAdd mexp_send_interrupt, mexp_spawnvf, mexp_spawnlf and various flags.
Richard W.M. Jones [Wed, 29 Jun 2016 20:18:20 +0000 (21:18 +0100)]
Add mexp_send_interrupt, mexp_spawnvf, mexp_spawnlf and various flags.

7 years agoSet signals to defaults and close other file descriptors after forking.
Richard W.M. Jones [Wed, 29 Jun 2016 14:23:35 +0000 (15:23 +0100)]
Set signals to defaults and close other file descriptors after forking.

8 years agoSmall fix to documentation.
Richard W.M. Jones [Sun, 24 Jan 2016 17:26:29 +0000 (17:26 +0000)]
Small fix to documentation.

8 years agoDocument use of mexp_get_pcre_error when calling pcre_get_substring.
Richard W.M. Jones [Sun, 24 Jan 2016 17:19:07 +0000 (17:19 +0000)]
Document use of mexp_get_pcre_error when calling pcre_get_substring.

virt-p2v uses this, and it surprised me as well.

8 years agoIntroduce methods to access some fields in the handle.
Richard W.M. Jones [Sun, 24 Jan 2016 14:59:55 +0000 (14:59 +0000)]
Introduce methods to access some fields in the handle.

Actually these are implemented as C macros.

8 years agoDocument how to handle errors from mexp_close.
Richard W.M. Jones [Sun, 24 Jan 2016 14:39:19 +0000 (14:39 +0000)]
Document how to handle errors from mexp_close.

9 years agop2v: properly call va_end
Pino Toscano [Fri, 25 Jul 2014 15:36:14 +0000 (17:36 +0200)]
p2v: properly call va_end

9 years agoRHEL 6: p2v: Add fix for older PCRE.
Richard W.M. Jones [Fri, 11 Jul 2014 09:38:53 +0000 (10:38 +0100)]
RHEL 6: p2v: Add fix for older PCRE.

RHEL 6 pcre did not define PCRE_PARTIAL_SOFT.  However PCRE_PARTIAL is
a synonym so use that.

9 years agop2v: close the mexp handle if mexp_spawnv fails
Pino Toscano [Fri, 25 Jul 2014 15:36:17 +0000 (17:36 +0200)]
p2v: close the mexp handle if mexp_spawnv fails

9 years agoDocument behaviour when matching against multiple regular expressions.
Richard W.M. Jones [Thu, 15 May 2014 19:13:28 +0000 (20:13 +0100)]
Document behaviour when matching against multiple regular expressions.

9 years agoImplement and test multi-matching on strings.
Richard W.M. Jones [Thu, 15 May 2014 18:29:50 +0000 (19:29 +0100)]
Implement and test multi-matching on strings.

If the subprocess prints multiple matching strings, and you call
mexp_expect repeatedly, the code now does the right thing.

10 years agotests: Add 'make check-valgrind' to run test suite under valgrind.
Richard W.M. Jones [Sat, 26 Apr 2014 18:38:22 +0000 (19:38 +0100)]
tests: Add 'make check-valgrind' to run test suite under valgrind.

10 years agoFree handle storage.
Richard W.M. Jones [Sat, 26 Apr 2014 18:40:57 +0000 (19:40 +0100)]
Free handle storage.

Memory leak found by valgrind.

10 years agoconfigure: Move AC_USE_SYSTEM_EXTENSIONS to avoid autoconf warning.
Richard W.M. Jones [Sat, 26 Apr 2014 18:24:36 +0000 (19:24 +0100)]
configure: Move AC_USE_SYSTEM_EXTENSIONS to avoid autoconf warning.

10 years agotests: Add a test of running 'ls --version' and matching the output.
Richard W.M. Jones [Sat, 26 Apr 2014 17:53:15 +0000 (18:53 +0100)]
tests: Add a test of running 'ls --version' and matching the output.

10 years agotests: Accurately list sources of test-spawn program.
Richard W.M. Jones [Sat, 26 Apr 2014 17:33:21 +0000 (18:33 +0100)]
tests: Accurately list sources of test-spawn program.

10 years agoMinor updates to the manual page.
Richard W.M. Jones [Sat, 26 Apr 2014 16:37:18 +0000 (17:37 +0100)]
Minor updates to the manual page.

10 years agoclean: Remove miniexpect.3 if we have pod2man, otherwise leave it.
Richard W.M. Jones [Sat, 26 Apr 2014 11:03:55 +0000 (12:03 +0100)]
clean: Remove miniexpect.3 if we have pod2man, otherwise leave it.

10 years agoAdd a note about clearing the input buffer in mexp_expect.
Richard W.M. Jones [Sat, 26 Apr 2014 10:51:25 +0000 (11:51 +0100)]
Add a note about clearing the input buffer in mexp_expect.

10 years agominiexpect.h: Change the error codes again.
Richard W.M. Jones [Sat, 26 Apr 2014 10:50:33 +0000 (11:50 +0100)]
miniexpect.h: Change the error codes again.

No functional change (although it changes the ABI).

10 years agoAdd a man page.
Richard W.M. Jones [Sat, 26 Apr 2014 10:50:13 +0000 (11:50 +0100)]
Add a man page.

Move all the documentation from the header file to the man page.

10 years agominiexpect.h: Just some tidying up.
Richard W.M. Jones [Fri, 25 Apr 2014 21:41:14 +0000 (22:41 +0100)]
miniexpect.h: Just some tidying up.

10 years agomexp_expect: Change the expect API to allow multiple regexps.
Richard W.M. Jones [Fri, 25 Apr 2014 21:19:03 +0000 (22:19 +0100)]
mexp_expect: Change the expect API to allow multiple regexps.

10 years agoAdd miniexpect library.
Richard W.M. Jones [Fri, 25 Apr 2014 13:09:02 +0000 (14:09 +0100)]
Add miniexpect library.