Re: fix in --help output - Mailing list pgsql-patches

From Zdenek Kotala
Subject Re: fix in --help output
Date
Msg-id 47BE9D8F.20707@sun.com
Whole thread Raw
In response to Re: fix in --help output  (Alvaro Herrera <alvherre@commandprompt.com>)
Responses Re: fix in --help output
Re: fix in --help output
List pgsql-patches
Alvaro Herrera napsal(a):
> Zdenek Kotala wrote:
>
>> If I looked correctly there is no getopt_long. There is only getopt with
>> - as a option. See PostmasterMain:
>>
>>
>>    while ((opt = getopt(argc, argv,
>> "A:B:c:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:")) != -1)
>>
>> If I understand correctly the POSIX standard "-" should not used in a
>> option list.
>
> Hmm, right.  Our current parsing of --long-opts is quite a hack, it
> seems :-(  Having to list all GUC options in the getopt_long array would
> be a mess.  Any other ideas?
>

I attached patch which replaces any "--..." occurrence with "-c..." on
command line.


        Zdenek
Index: src/backend/postmaster/postmaster.c
===================================================================
RCS file: /zfs_data/cvs_pgsql/cvsroot/pgsql/src/backend/postmaster/postmaster.c,v
retrieving revision 1.552
diff -c -r1.552 postmaster.c
*** src/backend/postmaster/postmaster.c    20 Feb 2008 22:46:24 -0000    1.552
--- src/backend/postmaster/postmaster.c    22 Feb 2008 09:32:15 -0000
***************
*** 483,490 ****
       * Parse command-line options.    CAUTION: keep this in sync with
       * tcop/postgres.c (the option sets should not conflict) and with the
       * common help() function in main/main.c.
       */
!     while ((opt = getopt(argc, argv, "A:B:c:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:")) != -1)
      {
          switch (opt)
          {
--- 483,511 ----
       * Parse command-line options.    CAUTION: keep this in sync with
       * tcop/postgres.c (the option sets should not conflict) and with the
       * common help() function in main/main.c.
+      *
+      * We want to support --NAME=VALUE args type, but getopt_long is not suitable
+      * for porcessing all GUC variables and we cannot use "-" as in a getopt option
+     * list, because it is not supported on some platforms.
+      * Regarding this issues a preprocessing which replaces "--" with "-c" is necessary.
       */
!
!     for(int n=0; n<argc ; n++)
!     {
!         int arglen;
!         arglen = strlen(argv[n]);
!         if(arglen >= 2)
!         {
!             if(argv[n][0] == '-' && argv[n][1] == '-')
!             {
!                 if(arglen == 2)
!                     break;    // we found -- end of option list
!                 argv[n][1]='c';
!             }
!         }
!     }
!
!     while ((opt = getopt(argc, argv, "A:B:c:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:")) != -1)
      {
          switch (opt)
          {
***************
*** 617,623 ****
                  break;

              case 'c':
-             case '-':
                  {
                      char       *name,
                                 *value;
--- 638,643 ----

pgsql-patches by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: fix in --help output
Next
From: Zdenek Kotala
Date:
Subject: Re: fix in --help output