Re: add non-option reordering to in-tree getopt_long

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Cc: michael(at)paquier(dot)xyz, noah(at)leadboat(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: add non-option reordering to in-tree getopt_long
Date: 2023-06-16 18:28:47
Message-ID: 20230616182847.GA71216@nathanxps13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jun 16, 2023 at 04:51:38PM +0900, Kyotaro Horiguchi wrote:
> (Honestly, the rearrangement code looks somewhat tricky to grasp..)

Yeah, I think there's still some room for improvement here.

> It doesn't work properly if '--' is involved.
>
> For example, consider the following options (even though they don't
> work for the command).
>
> psql -t -T hoho -a hoge -- -1 hage hige huge
>
> After the function returns -1, the argv array looks like this. The
> "[..]" indicates the position of optind.
>
> psql -t -T hoho -a -- [-1] hage hige huge hoge
>
> This is clearly incorrect since "hoge" gets moved to the end. The
> rearrangement logic needs to take into account the '--'. For your
> information, the glibc version yields the following result for the
> same options.
>
> psql -t -T hoho -a -- [hoge] -1 hage hige huge

Ah, so it effectively retains the non-option ordering, even if there is a
'--'. I think this behavior is worth keeping. I attempted to fix this in
the attached patch.

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v4-0001-Teach-in-tree-getopt_long-to-move-non-options-to-.patch text/x-diff 4.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2023-06-16 20:20:14 Re: [PATCH] Missing dep on Catalog.pm in meson rules
Previous Message Masahiro Ikeda 2023-06-16 17:44:37 Re: Support to define custom wait events for extensions