public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Jonathan Corbet <corbet@lwn.net>,
	phone-devel@vger.kernel.org, linux-doc@vger.kernel.org,
	Luca Weiss <luca.weiss@fairphone.com>,
	linux-kernel@vger.kernel.org, Petr Mladek <pmladek@suse.com>
Subject: [PATCH] vsprintf/doc: Document format flags including field width and precision
Date: Mon, 22 May 2023 17:08:53 +0200	[thread overview]
Message-ID: <20230522150853.30417-1-pmladek@suse.com> (raw)
In-Reply-To: <CSSLOC8WDIPE.1WO9BXZQA7A12@otso>

The kernel implementation of vsprintf() tries to be as compatible with
the user space variant as possible. Though it does not implement all
features. On the other hand, it adds some special pointer printing
modifiers.

Most differences are described in Documentation/core-api/printk-formats.rst
Add the missing documentation of the supported flag characters
'#', '0', '-', ' ', '+' together with field width and precision modifiers.

Suggested-by: Luca Weiss <luca.weiss@fairphone.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
---
What about something like this, please?

 Documentation/core-api/printk-formats.rst | 69 +++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index dfe7e75a71de..79655b319658 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -8,6 +8,75 @@ How to get printk format specifiers right
 :Author: Andrew Murray <amurray@mpc-data.co.uk>
 
 
+Flag characters
+===============
+
+The character '%' might be followed by the following flags that modify
+the output:
+
+	- '#' - prepend '0', '0x', or 'OX for 'o', 'x', 'X' number conversions
+	- '0' - zero pad number conversions on the field boundary
+	- '-' - left adjust on the field boundary, blank pad on the right
+	- ' ' - prepend space on positive numbers
+	- '+' - prepend + for positive numbers when using signed formats
+
+Examples::
+
+	|%x|	|1a|
+	|%#x|	|0x1a|
+	|%d|	|26|
+	|% d|	| 26|
+	|%+d|	|+26|
+
+
+Field width
+===========
+
+A field width may be defined when '%' is optionally followed by the above flag
+characters and:
+
+	- 'number' - the decimal number defines the field width
+	- '*' the field width is defined by an extra parameter
+
+Values are never truncated when the filed width is not big enough.
+Spaces are used by default when a padding is needed.
+
+Examples::
+
+	|%6d|	|    26|
+	|%-6d|	|26    |
+	|%06d|	|000026|
+
+	printk("Dynamic table: |%*d|%*s|\n", id_width, id, max_name_len, name);
+
+The filed width value might have special meaning for some pointer formats.
+For example, it limits the size of the bitmap handled by %*pb format.
+
+
+
+Field precision:
+================
+
+A field width may be defined when '%' is optionally followed by the above flag
+characters:
+
+	- '.number' - the decimal number defines the field precision
+	- '.*' the field precision is defined by an extra parameter
+
+The precision defines:
+
+	- number of digits after the decimal point in float number conversions
+	- minimal number of digits in integer conversions
+	- maximum number of characters in string conversions
+
+Examples::
+
+	|%.3f|	|12.300|
+	|%.6d|	|    26|
+	|%.6s|	|Hi, th|
+
+	printk("Dynamic precision: %.*f\n", precision, value);
+
 Integer types
 =============
 
-- 
2.35.3


  reply	other threads:[~2023-05-22 15:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16  6:52 [PATCH] docs: printk-formats: Clarify %*pb format parameters Luca Weiss
2023-05-17 16:19 ` Andy Shevchenko
2023-05-22  6:41   ` Luca Weiss
2023-05-22 15:08     ` Petr Mladek [this message]
2023-05-22 21:04       ` [PATCH] vsprintf/doc: Document format flags including field width and precision Rasmus Villemoes
2023-05-24  8:08       ` John Ogness

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230522150853.30417-1-pmladek@suse.com \
    --to=pmladek@suse.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=john.ogness@linutronix.de \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=luca.weiss@fairphone.com \
    --cc=phone-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox