argpar.git
2 years agoargpar.h: argpar_iter_create(): add iterator lifetime details
Philippe Proulx [Tue, 1 Jun 2021 15:30:15 +0000 (11:30 -0400)] 
argpar.h: argpar_iter_create(): add iterator lifetime details

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I57be39db6b3b5dd149ccdb82a5971fffa3c68264

2 years agoargpar.h: move argpar_item_destroy() close to other item functions
Philippe Proulx [Tue, 1 Jun 2021 14:21:08 +0000 (10:21 -0400)] 
argpar.h: move argpar_item_destroy() close to other item functions

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I444f39d5bbdc8498eaeff09c1b6c1f992bf36665

2 years agoRename argpar_iter_get_ingested_orig_args() -> argpar_iter_ingested_orig_args()
Philippe Proulx [Tue, 1 Jun 2021 14:19:54 +0000 (10:19 -0400)] 
Rename argpar_iter_get_ingested_orig_args() -> argpar_iter_ingested_orig_args()

Personal preference when naming property getters.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I8bb454da0bc12ce638bdea55d1eb9a4eb3fdfff7

2 years agoRename argpar_iter_parse_next() -> argpar_iter_next()
Philippe Proulx [Tue, 1 Jun 2021 14:18:21 +0000 (10:18 -0400)] 
Rename argpar_iter_parse_next() -> argpar_iter_next()

Also rename `enum argpar_iter_parse_next_status` to `enum
argpar_iter_next_status` and `ARGPAR_ITER_PARSE_NEXT_STATUS_*` to
`ARGPAR_ITER_NEXT_STATUS_*`.

Personal preference.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5e93bb9abe5e77e7e83622b3f868003a4fafb888

2 years agoAdd error enumerators to `enum argpar_iter_parse_next_status`
Philippe Proulx [Tue, 1 Jun 2021 14:13:08 +0000 (10:13 -0400)] 
Add error enumerators to `enum argpar_iter_parse_next_status`

This patch adds all the possible reasons for a failure of
argpar_iter_parse_next() as error enumerators to
`enum argpar_iter_parse_next_status`.

This will make it possible to convert the `error` parameter of
argpar_iter_parse_next() to a rich error, without any formatted error
message.

In `test_argpar.c`, test_fail() now accepts an expected
argpar_iter_parse_next() status which it forwards to
test_fail_argpar_iter() which ensures that argpar_iter_parse_next()
returns the expected error status.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9e8e91dea6066bd2ee935d6ca465569a6fd379aa

2 years agoargpar.c: add error enumerators to `enum parse_orig_arg_opt_ret`
Philippe Proulx [Tue, 1 Jun 2021 13:49:13 +0000 (09:49 -0400)] 
argpar.c: add error enumerators to `enum parse_orig_arg_opt_ret`

This patch changes `enum parse_orig_arg_opt_ret` to add

* `PARSE_ORIG_ARG_OPT_RET_ERROR_MISSING_OPT_ARG`
* `PARSE_ORIG_ARG_OPT_RET_ERROR_INVALID_OPT`
* `PARSE_ORIG_ARG_OPT_RET_ERROR_UNEXPECTED_OPT_ARG`
* `PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY`

and remove the general `PARSE_ORIG_ARG_OPT_RET_ERROR`.

No functional changes intended.

This will make it easier to switch to rich error reporting instead of
a formatted error string.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I2e68bea8b14ea1c0b16433df0cb8c01c1252283d

2 years agoargpar_iter_parse_next(): make the `error` parameter optional
Philippe Proulx [Mon, 31 May 2021 21:29:27 +0000 (17:29 -0400)] 
argpar_iter_parse_next(): make the `error` parameter optional

You don't want to know the details of the error? No problemo.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I82f024f3cc78554f5eaa8a72998e9226c5195a4b

2 years agoMake `struct argpar_item` opaque
Philippe Proulx [Mon, 31 May 2021 20:12:07 +0000 (16:12 -0400)] 
Make `struct argpar_item` opaque

This patch improves the encapsulation of argpar by making `struct
argpar_item` opaque, and publicly removing `struct argpar_item_opt` and
`struct argpar_item_non_opt`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I37ef6c386593e2bb8f817bf4d2bb464e9004615e

2 years agotests/test_argpar.c: fix coding style
Philippe Proulx [Sat, 29 May 2021 02:49:54 +0000 (22:49 -0400)] 
tests/test_argpar.c: fix coding style

Add missing `const`, clarify comments, harmonize test messages.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie0f4ca02786b1cc1167c0f2aa4be86d7a9e1a45b

2 years agoargpar.h: `BABELTRACE_ARGPAR_H` -> `ARGPAR_ARGPAR_H`
Philippe Proulx [Sat, 29 May 2021 02:08:54 +0000 (22:08 -0400)] 
argpar.h: `BABELTRACE_ARGPAR_H` -> `ARGPAR_ARGPAR_H`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Id85bcf2f4910af8f83a48333f0f04dd62970951b

2 years agoargpar/argpar.{c,h}: fix coding style
Philippe Proulx [Fri, 28 May 2021 19:21:48 +0000 (15:21 -0400)] 
argpar/argpar.{c,h}: fix coding style

Add missing `const`, use uppercase macro names, fix comments, fix names
of local functions.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I18c7a2b1d5572f6b696c72f0cfa12b68c1c5f949

2 years agoAdd iterator-style API
Simon Marchi [Sat, 10 Apr 2021 13:51:38 +0000 (09:51 -0400)] 
Add iterator-style API

The current API of argpar does not give the user control on when to stop
parsing the arguments.  It either stops at the end of the argument list
or at the first unknown option, if using `fail_on_unknown_opt`.

To make it more convenient to implement "multi-level" command line
interfaces, add an iterator-style API where the user repeatedly calls a
function to get the next item.

By "multi-level" CLI, I mean something like git, where the top-level
command and a subcommand have their own set of options.

    $ top-level --hello there sub-command --hello

For most cases, we could probably work something out by using the
`fail_on_unknown_opt` option combined with the
`argpar_item_non_opt::orig_index` field.  Even if the parsing of the
top-level command goes too far, we can resume the parsing at the index
of the sub-command + 1.  But the example above shows a corner case where
top-level's `--hello` option takes an argument but sub-command's
`--hello` doesn't.  I don't think we could handle this today.

In any case, I think that it's simpler in the end to give a bit more
control to the user and let her get items one by one.  I think it
results in code that is easier to follow.

Using the proposed API, the user starts by creating an argpar_iter
object using argpar_iter_create.  It then calls argpar_iter_parse_next
as much as needed to get one argpar_item at a time.  The returned
argpar_items must be freed with argpar_item_destroy.  In the end, the
argpar_iter must be freed with argpar_iter_destroy.

Testing-wise, I adapted the existing tests to be executed with both
APIs, so the coverage should be pretty good.

Change-Id: I82685672977fbfa96f96bcc678a3e05c6adab76c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoImport warning flags and tap from Babeltrace
Simon Marchi [Fri, 21 May 2021 03:23:21 +0000 (23:23 -0400)] 
Import warning flags and tap from Babeltrace

Since we are going to use this code in Babeltrace, lttng-tools, and
perhaps other projects, I think it would be useful to use warning flags
at least as strict here as we do in these other projects, so we don't
have bad surprises when importing the code there.

Start by importing the warning flag checking system from Babeltrace, and
the list of warning flags used there.

Import the tap code as well, since the current tap code would generate
some errors with the new warning flags.

Change-Id: I86bf5a18bcbce35b887d3ef3285d5566b3f7c69f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
3 years agoUse SPDX-style license header
Simon Marchi [Sat, 10 Apr 2021 13:44:03 +0000 (09:44 -0400)] 
Use SPDX-style license header

This is copied from the lttng-tools repo.  In that repo, the comment is
above the header include guard, so I put it at the same place here.

Change-Id: If71e76e78fe2d4347b5ef24d37126ce7f33fb0a1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
3 years agoFix: Error out when passing an argument to long option that takes no argument
Simon Marchi [Fri, 9 Apr 2021 16:39:19 +0000 (12:39 -0400)] 
Fix: Error out when passing an argument to long option that takes no argument

If the user defines a long option `--foo` and passes `--foo=arg`, the
current behavior is that the option foo is recognized and the argument
is ignored.  Change that to be an error.

It is currently not possible to pass arguments to short options using an
equal sign, so this doesn't apply to short options.

Change-Id: I4b0c50398161aebc81789fdb3fce19a80a5f6646
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
4 years agoAdd format attributes to functions with format strings
Simon Marchi [Sun, 15 Mar 2020 19:36:10 +0000 (15:36 -0400)] 
Add format attributes to functions with format strings

Compiling with -Wsuggest-attribute=format shows that these functions
could use a format attribute, which helps the compiler validate format
strings.  This patch adds them.

Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
Change-Id: I2884d13b08d9ea67680289e59fb40ebdfecdc3d4

4 years agoAdd missing va_end in argpar_vasprintf
Simon Marchi [Fri, 6 Dec 2019 19:23:29 +0000 (14:23 -0500)] 
Add missing va_end in argpar_vasprintf

args2 is currently leaked, we need to call va_end on it.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
4 years agoRemove bt_/BT_ prefixes throughout
Simon Marchi [Thu, 5 Dec 2019 18:57:11 +0000 (13:57 -0500)] 
Remove bt_/BT_ prefixes throughout

Since this is not longer part of Babeltrace, remove the bt_/BT_
prefixes.  This was done mechanically using:

    sed -i -e 's/BT_ARGPAR/ARGPAR/g' -e 's/bt_argpar/argpar/g'

Hopefully there isn't too much collateral damage.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
4 years agoFix comments in bt_argpar_item_array, data -> items
Simon Marchi [Thu, 5 Dec 2019 18:27:09 +0000 (13:27 -0500)] 
Fix comments in bt_argpar_item_array, data -> items

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
4 years agoStrip trailing spaces
Simon Marchi [Wed, 4 Dec 2019 22:58:36 +0000 (17:58 -0500)] 
Strip trailing spaces

4 years agoAdd bootstrap script
Simon Marchi [Wed, 4 Dec 2019 22:33:56 +0000 (17:33 -0500)] 
Add bootstrap script

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
4 years agoAdd .gitignore
Simon Marchi [Wed, 4 Dec 2019 21:12:56 +0000 (16:12 -0500)] 
Add .gitignore

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
4 years agoAdd build system, remove dependency on glib, add TAP library
Simon Marchi [Wed, 4 Dec 2019 22:33:56 +0000 (17:33 -0500)] 
Add build system, remove dependency on glib, add TAP library

This commit...

 * adds an automake-based system.
 * removes glib dependencies from the library code (i.e. not from the tests),
   replacing them with home-grown code.
 * sets up the tests to run using the TAP library [1].

[1] https://github.com/shlomif/libtap-prev

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
4 years agoInitial commit
Simon Marchi [Wed, 4 Dec 2019 16:51:08 +0000 (11:51 -0500)] 
Initial commit

Copy source and tests from the babeltrace repository, commit:

    23256fd15c8ac7d1faaa3e37d0df2e225e90a6c6
    bt2: reverse order of printed causes in _Error.__str__

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
This page took 0.026601 seconds and 4 git commands to generate.