[git] GnuPG - branch, master, updated. gnupg-2.1.21-105-gf17862d

by Marcus Brinkmann cvs at cvs.gnupg.org
Tue Jul 18 18:13:03 CEST 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  f17862d47d184d7f6ef883778cf63801365599a0 (commit)
      from  2e1342b78b020f5b28359b08a4f63cf11479602f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f17862d47d184d7f6ef883778cf63801365599a0
Author: Marcus Brinkmann <marcus.brinkmann at ruhr-uni-bochum.de>
Date:   Tue Jul 18 18:08:25 2017 +0200

    common: Allow abbreviations of standard options.
    
    * argparse.h (ARGPARSE_SHORTOPT_HELP, ARGPARSE_SHORTOPT_VERSION,
    ARGPARSE_SHORTOPT_WARRANTY, ARGPARSE_SHORTOPT_DUMP_OPTIONS): New
    macros.
    (ARGPARSE_end): Add some placeholders for standard options.
    * argparse.c (arg_parse): Fill in missing standard options so
    default machinery works.  Check for standard options in new way.
    Do not write out standard options for --dump-options.
    
    Signed-off-by: Marcus Brinkmann <mb at g10code.com>
    GnuPG-bug-id: 1747

diff --git a/common/argparse.c b/common/argparse.c
index 2540894..590e6e9 100644
--- a/common/argparse.c
+++ b/common/argparse.c
@@ -918,6 +918,41 @@ arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts)
   char *s, *s2;
   int i;
 
+  /* Fill in missing standard options: help, version, warranty and dump-options.  */
+  ARGPARSE_OPTS help_opt = ARGPARSE_s_n(ARGPARSE_SHORTOPT_HELP, "help", "@");
+  ARGPARSE_OPTS version_opt = ARGPARSE_s_n(ARGPARSE_SHORTOPT_VERSION, "version", "@");
+  ARGPARSE_OPTS warranty_opt = ARGPARSE_s_n(ARGPARSE_SHORTOPT_WARRANTY, "warranty", "@");
+  ARGPARSE_OPTS dump_options_opt = ARGPARSE_s_n(ARGPARSE_SHORTOPT_DUMP_OPTIONS, "dump-options", "@");
+  int seen_help = 0;
+  int seen_version = 0;
+  int seen_warranty = 0;
+  int seen_dump_options = 0;
+
+  i = 0;
+  while (opts[i].short_opt)
+    {
+      if (opts[i].long_opt)
+	{
+	  if (!strcmp(opts[i].long_opt, help_opt.long_opt))
+	    seen_help = 1;
+	  else if (!strcmp(opts[i].long_opt, version_opt.long_opt))
+	    seen_version = 1;
+	  else if (!strcmp(opts[i].long_opt, warranty_opt.long_opt))
+	    seen_warranty = 1;
+	  else if (!strcmp(opts[i].long_opt, dump_options_opt.long_opt))
+	    seen_dump_options = 1;
+	}
+      i++;
+    }
+  if (! seen_help)
+    opts[i++] = help_opt;
+  if (! seen_version)
+    opts[i++] = version_opt;
+  if (! seen_warranty)
+    opts[i++] = warranty_opt;
+  if (! seen_dump_options)
+    opts[i++] = dump_options_opt;
+
   initialize( arg, NULL, NULL );
   argc = *arg->argc;
   argv = *arg->argv;
@@ -974,9 +1009,9 @@ arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts)
       if ( argpos )
         *argpos = '=';
 
-      if ( i < 0 && !strcmp ( "help", s+2) )
+      if (i > 0 && opts[i].short_opt == ARGPARSE_SHORTOPT_HELP)
         show_help (opts, arg->flags);
-      else if ( i < 0 && !strcmp ( "version", s+2) )
+      else if (i > 0 && opts[i].short_opt == ARGPARSE_SHORTOPT_VERSION)
         {
           if (!(arg->flags & ARGPARSE_FLAG_NOVERSION))
             {
@@ -984,20 +1019,18 @@ arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts)
               exit(0);
             }
 	}
-      else if ( i < 0 && !strcmp( "warranty", s+2))
+      else if (i > 0 && opts[i].short_opt == ARGPARSE_SHORTOPT_WARRANTY)
         {
           writestrings (0, strusage (16), "\n", NULL);
           exit (0);
 	}
-      else if ( i < 0 && !strcmp( "dump-options", s+2) )
+      else if (i > 0 && opts[i].short_opt == ARGPARSE_SHORTOPT_DUMP_OPTIONS)
         {
           for (i=0; opts[i].short_opt; i++ )
             {
               if (opts[i].long_opt && !(opts[i].flags & ARGPARSE_OPT_IGNORE))
                 writestrings (0, "--", opts[i].long_opt, "\n", NULL);
 	    }
-          writestrings (0, "--dump-options\n--help\n--version\n--warranty\n",
-                        NULL);
           exit (0);
 	}
 
diff --git a/common/argparse.h b/common/argparse.h
index d75b49f..cdd18d9 100644
--- a/common/argparse.h
+++ b/common/argparse.h
@@ -71,6 +71,12 @@ typedef struct
   const char  *description; /* Optional option description. */
 } ARGPARSE_OPTS;
 
+/* Short options.  */
+#define ARGPARSE_SHORTOPT_HELP 32768
+#define ARGPARSE_SHORTOPT_VERSION 32769
+#define ARGPARSE_SHORTOPT_WARRANTY 32770
+#define ARGPARSE_SHORTOPT_DUMP_OPTIONS 32771
+
 
 /* Global flags (ARGPARSE_ARGS).  */
 #define ARGPARSE_FLAG_KEEP       1   /* Do not remove options form argv.     */
@@ -169,7 +175,13 @@ typedef struct
 #define ARGPARSE_group(s,d) \
      { (s), NULL, 0, (d) }
 
-#define ARGPARSE_end()  { 0, NULL, 0, NULL }
+/* Placeholder options for help, version, warranty and dump-options.  See arg_parse(). */
+#define ARGPARSE_end() \
+     { 0, NULL, 0, NULL }, \
+     { 0, NULL, 0, NULL }, \
+     { 0, NULL, 0, NULL }, \
+     { 0, NULL, 0, NULL }, \
+     { 0, NULL, 0, NULL }
 
 
 /* Other constants.  */

-----------------------------------------------------------------------

Summary of changes:
 common/argparse.c | 45 +++++++++++++++++++++++++++++++++++++++------
 common/argparse.h | 14 +++++++++++++-
 2 files changed, 52 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list