Re: [PATCH] bin/stdc: Improve output formatting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
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@xxxxxxxxx>
    Signed-off-by: Alejandro Colomar <alx@xxxxxxxxxx>

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@xxxxxxxxx>
> ---
> 
> 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: OpenPGP_signature
Description: OpenPGP digital signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux