From: Pádraig Brady Date: Thu, 1 Jan 2026 16:45:45 +0000 (+0000) Subject: doc: move oputs() to system.h to support all commands X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4555132f3c691e8923d27369a12feb4183056dab;p=thirdparty%2Fcoreutils.git doc: move oputs() to system.h to support all commands * src/ls.c: Move non ls specific helper to ... * src/system.h: ... here. --- diff --git a/src/ls.c b/src/ls.c index ed72057930..3fa04412aa 100644 --- 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) { diff --git a/src/system.h b/src/system.h index c93eef3530..3c18641348 100644 --- a/src/system.h +++ b/src/system.h @@ -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) {