From: Oskari Pirhonen <xxc3ncoredxx@gmail.com>
To: Alejandro Colomar <alx.manpages@gmail.com>
Cc: Alejandro Colomar <alx@kernel.org>, linux-man@vger.kernel.org
Subject: Re: [PATCH] bin/stdc: Improve output formatting
Date: Sat, 15 Apr 2023 02:21:05 -0500 [thread overview]
Message-ID: <ZDpQYWOGbOEyDEuz@dj3ntoo> (raw)
In-Reply-To: <852b1842-3d1b-2b40-7e88-a8a34d00d264@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2402 bytes --]
Hi Alex,
On Fri, Apr 14, 2023 at 13:26:59 +0200, Alejandro Colomar wrote:
> 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) :(
>
Awww man, but I even left the optional semicolons in...
> But I like the idea. I implemented the same using sed(1) after your
> suggestion. Does the below patch look good to you?
>
I actually had an earlier version with sed(1), but it used
looping/branching to handle the multi-line bits, so I figured it was a
bit ugly and didn't send it. I didn't think to try `-z`.
It seems to do the same thing, so LGTM.
> Cheers,
> Alex
>
> P.S.: I forgot about writing a man page. I'll start now.
>
I was about to say "and license file and appropriate blurb" but then I
saw your commit. I've got some suggestions for the man page, so I'll
send some patches sometime soon.
- Oskari
Since you said you can't read awk, then just to satisfy your curiosity,
here's what was going on:
BEGIN {
RS = ";\n"
ORS = RS
}
This block is run at the start before any records are processed.
The default Record Separator is "\n", but here we set it to ";\n". In
(g)awk, a value of `RS` that is >1 char is actually a regex, but we only
need to match a literal string. The Output Record Separator is by
default also "\n".
{
gsub(/\n/, " ")
sub(/^ +/, "")
gsub(/ +/, " ")
print
}
This block is run on all records, since it doesn't have any patterns for
contitional execution attached to it.
`gsub()` does an in-place global regex replace on a string, similar to
the `s/regex/replace/g` you're familiar with. It takes an optional third
arg, but if it's left out then it has an implicit `$0` which means the
entire current record. `sub()` is like `gsub()`, but only does the first
match, similar to `s/regex/replace/`.
`print`, without any args, prints the current record followed by `ORS`.
This was set earlier because the `RS` is consumed from the input as it
is being processed record by record, but we want to keep the output
looking intact.
Hopefully not so bad after all. Awk is pretty nice IMO (and gawk in
particular), and I would recommend checking it out if you find yourself
borded one day :)
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2023-04-15 7:21 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
2023-04-15 7:21 ` Oskari Pirhonen [this message]
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=ZDpQYWOGbOEyDEuz@dj3ntoo \
--to=xxc3ncoredxx@gmail.com \
--cc=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