]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
doc: move oputs() to system.h to support all commands
authorPádraig Brady <P@draigBrady.com>
Thu, 1 Jan 2026 16:45:45 +0000 (16:45 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 21 Jan 2026 13:51:39 +0000 (13:51 +0000)
* src/ls.c: Move non ls specific helper to ...
* src/system.h: ... here.

src/ls.c
src/system.h

index ed720579309600fc44fd8c29687cab68d959c32e..3fa04412aaa745f3b21a9a3d19fe01b5c9805a87 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -5334,65 +5334,6 @@ calculate_columns (bool by_columns)
   return cols;
 }
 
-/* Output --option descriptions;
-   unconditionally formatted with ANSI format and hyperlink codes.
-   Any postprocessors like help2man etc. are expected to handle this.  */
-static void
-oputs (char const *option)
-{
-  static int help_no_sgr = -1;
-  if (help_no_sgr && (help_no_sgr = !!getenv ("HELP_NO_MARKUP")))
-    {
-      fputs (option, stdout);
-      return;
-    }
-
-  char const *option_text = strchr (option, '-');
-  assert (option_text);
-  size_t anchor_len = strcspn (option_text, ",=[ \n");
-
-  /* Set desc_text to spacing after the full option text */
-  char const *desc_text = option_text + anchor_len;
-  while (*desc_text && (! c_isspace (*desc_text) || *(desc_text + 1) == '-'))
-    desc_text++;
-
-  /* write spaces before option text. */
-  fwrite (option, 1, option_text - option, stdout);
-
-  /* write option text.  */
-#ifdef MANUAL_URL
-  char const *url_program = streq (PROGRAM_NAME, "[") ? "test" : PROGRAM_NAME;
-  /* Note single node manual doesn't work for ls, cksum, md5sum, sha*sum,
-     but use single node for --help or --version.. */
-  if (STREQ_LEN (option_text, "--help", 6)
-      || STREQ_LEN (option_text, "--version", 9))
-    {
-      printf ("\033]8;;%s%s#%s%.*s", PACKAGE_URL,
-              url_program, url_program, (int) anchor_len, option_text);
-    }
-  else
-    {
-      printf ("\033]8;;%s#%s%.*s", MANUAL_URL, url_program,
-              (int) anchor_len, option_text);
-    }
-  fputs ("\a", stdout);
-#endif
-#ifdef BOLD_MAN_REFS
-  /* Note help2man strips this and will reinstate with --bold-refs.  */
-  fputs ("\033[1m", stdout);
-#endif
-  fwrite (option_text, 1, desc_text - option_text, stdout);
-#ifdef BOLD_MAN_REFS
-  fputs ("\033[0m", stdout);
-#endif
-#ifdef MANUAL_URL
-  fputs ("\033]8;;\a", stdout);
-#endif
-
-  /* write description.  */
-  fputs (desc_text, stdout);
-}
-
 void
 usage (int status)
 {
index c93eef35306026a1af3bc10b3a33818b9676ec23..3c18641348e1b5e508ef24556f5adb14baebb390 100644 (file)
@@ -536,6 +536,73 @@ is_nul (void const *buf, size_t length)
 #define DECIMAL_DIGIT_ACCUMULATE(Accum, Digit_val)                     \
   (!ckd_mul (&(Accum), Accum, 10) && !ckd_add (&(Accum), Accum, Digit_val))
 
+
+/* Output --option descriptions;
+   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)
+{
+  static int help_no_sgr = -1;
+  if (help_no_sgr && (help_no_sgr = !!getenv ("HELP_NO_MARKUP")))
+    {
+      fputs (option, stdout);
+      return;
+    }
+
+  char const *option_text = strchr (option, '-');
+  if (!option_text)
+    {
+      fputs (option, stdout);
+      return;
+    }
+  size_t anchor_len = strcspn (option_text, ",=[ \n");
+
+  /* Set desc_text to spacing after the full option text */
+  char const *desc_text = option_text + anchor_len;
+  while (*desc_text && (! (*desc_text == ' ' || *desc_text == '\n')
+                        || *(desc_text + 1) == '-'))
+    desc_text++;
+
+  /* write spaces before option text. */
+  fwrite (option, 1, option_text - option, stdout);
+
+  /* write option text.  */
+#ifdef MANUAL_URL
+  char const *url_program = streq (program, "[") ? "test" : program;
+  /* Note single node manual doesn't work for ls, cksum, md5sum, sha*sum,
+     but use single node for --help or --version.. */
+  if (STREQ_LEN (option_text, "--help", 6)
+      || STREQ_LEN (option_text, "--version", 9))
+    {
+      printf ("\033]8;;%s%s#%s%.*s", PACKAGE_URL,
+              url_program, url_program, (int) anchor_len, option_text);
+    }
+  else
+    {
+      printf ("\033]8;;%s#%s%.*s", MANUAL_URL, url_program,
+              (int) anchor_len, option_text);
+    }
+  fputs ("\a", stdout);
+#endif
+#ifdef BOLD_MAN_REFS
+  /* Note help2man strips this and will reinstate with --bold-refs.  */
+  fputs ("\033[1m", stdout);
+#endif
+  fwrite (option_text, 1, desc_text - option_text, stdout);
+#ifdef BOLD_MAN_REFS
+  fputs ("\033[0m", stdout);
+#endif
+#ifdef MANUAL_URL
+  fputs ("\033]8;;\a", stdout);
+#endif
+
+  /* write description.  */
+  fputs (desc_text, stdout);
+}
+
 static inline void
 emit_stdin_note (void)
 {