]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
doc: support highlighting printf formatted options
authorPádraig Brady <P@draigBrady.com>
Fri, 16 Jan 2026 12:36:36 +0000 (12:36 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 21 Jan 2026 13:51:39 +0000 (13:51 +0000)
* src/system.h (oprintf): Add a printf wrapper that
calls oputs_() to markup the formatted text.

src/system.h

index 46eb4e2ea48545029f340729cd0666f698988964..d3677f6750121aacdb035dcd3f6447d02e8ecf39 100644 (file)
@@ -543,6 +543,7 @@ is_nul (void const *buf, size_t length)
    formatted with ANSI format and hyperlink codes.
    Any postprocessors like help2man etc. are expected to handle this,
    though it can be disabled in edge cases with the HELP_NO_MARKUP env var.  */
+
 #define oputs(option) oputs_ (PROGRAM_NAME, option)
 static inline void
 oputs_ (MAYBE_UNUSED char const* program, char const *option)
@@ -611,6 +612,34 @@ oputs_ (MAYBE_UNUSED char const* program, char const *option)
   fputs (desc_text, stdout);
 }
 
+/* If required and possible,
+   call oputs with printf formatted message.  */
+
+#define oprintf(...) oprintf_ (PROGRAM_NAME, __VA_ARGS__)
+ATTRIBUTE_FORMAT ((printf, 2, 3))
+static inline void
+oprintf_ (char const* program, char const *message, ...)
+{
+  va_list args;
+  char *buf;
+  int buflen = -1;
+
+#if defined MANUAL_URL || defined BOLD_MAN_REFS
+  va_start (args, message);
+  buflen = vasprintf (&buf, message, args);
+  va_end (args);
+#endif
+
+  if (buflen < 0)
+    {
+      vprintf (message, args);
+      return;
+    }
+
+  oputs_ (program, buf);
+  free (buf);
+}
+
 static inline void
 emit_stdin_note (void)
 {