Commit graph

20 commits

Author SHA1 Message Date
David Lamparter acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
David Lamparter 54929fd38a *: use semicolon after printfrr_ext_autoreg_{p,d}
Mostly to make clang-format not format these to peak ugly.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-14 13:33:57 +01:00
David Lamparter 2c76ba433f lib: add time formatting printfrr exts
Refer to docs in doc/developer for details.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-14 13:33:57 +01:00
Igor Ryzhov faaa943137 tests: fix build warning
FMT_NSTD_BEGIN should be before the first use of "expr".

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-04-29 03:28:04 +03:00
David Lamparter 7798203f5c lib: add %pSQ and %pSE string escape formats
These are for string quoting (`%pSQ`) and string escaping (`%pSE`); the
sets / escape methods are currently rather "basic" and might be extended
in the future.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-30 22:34:56 +02:00
David Lamparter a4cb97a6c1 lib: add %*pHX + %*pHS hexdump in printfrr
(I'll get to `zlog_hexdump()` in a separate pass.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-30 22:34:51 +02:00
David Lamparter bb12115e0b lib: add %pFB extension to print struct fbuf *
Useful to insert output from another bprintfrr() call.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-30 22:32:59 +02:00
David Lamparter 9c4380daee lib: add %pVA recursive printfrr
Analogous to Linux kernel `%pV` (but our mechanism expects 2 specifier
chars and `%pVA` is clearer anyway.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-30 22:32:59 +02:00
David Lamparter cb4928ce77 lib: add FMT_NSTD() for non-standard printf exts
... to suppress the warnings when using something that isn't quite ISO C
compatible and would otherwise cause compiler warnings from `-Wformat`.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-30 22:32:59 +02:00
David Lamparter 2d9a4e2931 lib: allow discerning unspec width in printfrr ext
With 0 currently the default value for the width specifier, it's not
possible to discern that from a %*p where 0 was passed as the length
parameter.  Use -1 to allow for that.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-30 22:32:59 +02:00
David Lamparter 3ea7943059 lib: put printfrr extension args into struct
... for easier extensibility.  Add width, # and - flags while at it.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-30 22:32:55 +02:00
David Lamparter 487eefcfbe lib: record output positions in printfrr
This replaces `%n` with a safe, out-of-band option that simply records
the start and end offset of the output produced for each `%...`
specifier.

The old `%n` code is removed.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-27 17:01:29 +01:00
David Lamparter 212e04e5a7 lib: rework printfrr extensions to output directly
Allowing printfrr extensions to directly write to the output buffer has
a few advantages:
- there is no arbitrary length limit imposed (previously 64)
- the output doesn't need to be copied another time
- the extension can directly use bprintfrr() to put together pieces

The downside is that the theoretical length (regardless of available
buffer space) must be computed correctly.

Extended unit tests to test these paths a bit more thoroughly.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-27 16:56:55 +01:00
David Lamparter e6b3732e90 lib: add bputs/bputch fbuf (bprintfrr) helpers
Just small utilities for when you already have a struct fbuf (i.e. when
bprintfrr() is used to construct longer text from multiple pieces.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-22 12:50:27 +01:00
Renato Westphal 17e38209a5 lib, zebra: add missing extern "C" {} blocks to new header files
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-04-22 23:49:22 -03:00
David Lamparter fb84c629b8 tests: use printfrr-based printf()
Just a small hack to use printfrr() in tests, since otherwise the
redefined PRId64 trips some warnings.

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-03-29 10:45:46 +02:00
David Lamparter 07ef3e34ae lib: prepare for plugin-based frr_format check
Signed-off-by: David Lamparter <equinox@diac24.net>
2020-03-29 10:45:46 +02:00
David Lamparter 2b64873d24 *: generously apply const
const const const your boat, merrily down the stream...

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-12-02 15:01:29 +01:00
David Lamparter bf4d3d8021 lib/printf: add extension support
Inspired by the Linux kernel, this allows us to do %pI4 and similar
things.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:45:01 +02:00
David Lamparter 5c25bd87b5 lib/printf: integrate
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:51 +02:00