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

Kyotaro Horiguchi <horikyota.ntt@gmail.com>

From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: nathandbossart@gmail.com
Cc: michael@paquier.xyz, noah@leadboat.com, pgsql-hackers@postgresql.org
Date: 2023-07-10T07:57:11Z
Lists: pgsql-hackers
At Fri, 7 Jul 2023 20:52:24 -0700, Nathan Bossart <nathandbossart@gmail.com> wrote in 
> I spent some time tidying up the patch and adding a more detailed commit
> message.

The commit message and the change to TAP script looks good.


Two conditions are to be reversed and one of them look somewhat
unintuitive to me.

+			if (!force_nonopt && place[0] == '-' && place[1])
+			{
+				if (place[1] != '-' || place[2])
+					break;
+
+				optind++;
+				force_nonopt = true;
+				continue;
+			}

The first if looks good to me, but the second if is a bit hard to get the meaning at a glance. "!(place[1] == '-' && place[2] == 0)" is easier to read *to me*. Or I'm fine with the following structure here.

> if (!force_nonopt ... )
> {
>   if (place[1] == '-' && place[2] == 0)
>   {
>      optind+;
>      force_nonopt = true;
>      continue;
>   }
>   break;
> }

(To be honest, I see the goto looked clear than for(;;)..)

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center



Commits

  1. Simplify option handling in pg_ctl.

  2. Teach in-tree getopt_long() to move non-options to the end of argv.