public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx.manpages@gmail.com>
To: Alejandro Colomar <alx@kernel.org>, linux-man@vger.kernel.org
Subject: Re: [PATCH] bin/stdc: Improve output formatting
Date: Fri, 14 Apr 2023 13:26:59 +0200	[thread overview]
Message-ID: <852b1842-3d1b-2b40-7e88-a8a34d00d264@gmail.com> (raw)
In-Reply-To: <ZDjGUp5t5Fefb+zW@dj3ntoo>


[-- Attachment #1.1: Type: text/plain, Size: 3811 bytes --]

Hi Oskari,

On 4/14/23 05:19, Oskari Pirhonen wrote:
> Remove leading whitespace and collapse multi-line declarations into a
> single line using (g)awk.

I can't reak awk(1) :(

But I like the idea.  I implemented the same using sed(1) after your
suggestion.  Does the below patch look good to you?

Cheers,
Alex

P.S.: I forgot about writing a man page.  I'll start now.


commit af1ab8cf11165dba56dc54bae7310aa7824fd89b (HEAD -> main)
Author: Alejandro Colomar <alx@kernel.org>
Date:   Fri Apr 14 13:21:27 2023 +0200

    bin/stdc: Improve output formatting
    
    Remove leading whitespace, and collapse multi-line declarations into a
    single line.
    
    Suggested-by: Oskari Pirhonen <xxc3ncoredxx@gmail.com>
    Signed-off-by: Alejandro Colomar <alx@kernel.org>

diff --git a/bin/stdc b/bin/stdc
index b685df8..54db0d7 100755
--- a/bin/stdc
+++ b/bin/stdc
@@ -14,7 +14,9 @@ err()
 
 grep_proto()
 {
-       pcre2grep -M "(?s)\b$1 *\([[:alnum:]*,._\s\(\)-]*\);$";
+       pcre2grep -M "(?s)\b$1 *\([[:alnum:]*,._\s\(\)-]*\);$" \
+       | sed 's/^ *//' \
+       | sed -z 's/\([^;]\)\n/\1 /g';
 }
 
 libc_summ_c89()



> 
> Signed-off-by: Oskari Pirhonen <xxc3ncoredxx@gmail.com>
> ---
> 
> Here's a snippet for comparison. I've manually removed some of the
> formatting repeats from C99 and C11 output for the sake of making this
> message shorter.
> 
> Original:
> 
>     $ ./stdc c89 '[[:alpha:]]*scanf'
>              int fscanf(FILE *stream, const char *format, ...);
>              int scanf(const char *format, ...);
>              int sscanf(const char *s, const char *format, ...);
> 
>     $ ./stdc c99 '[[:alpha:]]*scanf'
>           int fscanf(FILE * restrict stream,
>                const char * restrict format, ...);
>           int scanf(const char * restrict format, ...);
>             int fwscanf(FILE * restrict stream,
>                  const wchar_t * restrict format, ...);
>             int wscanf(const wchar_t * restrict format, ...);
> 
>     $ ./stdc c11 '[[:alpha:]]*scanf'
>           int fscanf(FILE * restrict stream,
>                const char * restrict format, ...);
>           int scanf(const char * restrict format, ...);
>             int vsscanf(const char * restrict s,
>                  const char * restrict format, va_list arg);
> 
> New:
> 
>     $ ./stdc c89 '[[:alpha:]]*scanf'
>     int fscanf(FILE *stream, const char *format, ...);
>     int scanf(const char *format, ...);
>     int sscanf(const char *s, const char *format, ...);
> 
>     $ ./stdc c99 '[[:alpha:]]*scanf'
>     int fscanf(FILE * restrict stream, const char * restrict format, ...);
>     int scanf(const char * restrict format, ...);
>     int fwscanf(FILE * restrict stream, const wchar_t * restrict format, ...);
>     int wscanf(const wchar_t * restrict format, ...);
> 
>     $ ./stdc c11 '[[:alpha:]]*scanf'
>     int fscanf(FILE * restrict stream, const char * restrict format, ...);
>     int scanf(const char * restrict format, ...);
>     int vsscanf(const char * restrict s, const char * restrict format, va_list arg);
> 
>  bin/stdc | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/bin/stdc b/bin/stdc
> index b685df8..8c07956 100755
> --- a/bin/stdc
> +++ b/bin/stdc
> @@ -14,7 +14,14 @@ err()
>  
>  grep_proto()
>  {
> -	pcre2grep -M "(?s)\b$1 *\([[:alnum:]*,._\s\(\)-]*\);$";
> +	pcre2grep -M "(?s)\b$1 *\([[:alnum:]*,._\s\(\)-]*\);$" \
> +	| awk -e 'BEGIN { RS=";\n"; ORS=RS; }
> +		{
> +			gsub(/\n/, " ");
> +			sub(/^ +/, "");
> +			gsub(/ +/, " ");
> +			print;
> +		}';
>  }
>  
>  libc_summ_c89()

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-04-14 11:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14  3:19 [PATCH] bin/stdc: Improve output formatting Oskari Pirhonen
2023-04-14 11:26 ` Alejandro Colomar [this message]
2023-04-15  7:21   ` Oskari Pirhonen
2023-04-17 17:51     ` Alejandro Colomar

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=852b1842-3d1b-2b40-7e88-a8a34d00d264@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=alx@kernel.org \
    --cc=linux-man@vger.kernel.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