commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-2.2-771-gd4a938f


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-771-gd4a938f
Date: Thu, 13 Oct 2016 07:40:21 +0000 (UTC)

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 "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=d4a938f6d533981a77ddd55972e4c98b016d03d3

The branch, master has been updated
       via  d4a938f6d533981a77ddd55972e4c98b016d03d3 (commit)
       via  af83aaff0e41587fcdbe78983b6e116e442f17a1 (commit)
      from  d56b82437f909ff323d9cd87f2ed9f04322f9966 (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 d4a938f6d533981a77ddd55972e4c98b016d03d3
Author: Sergey Poznyakoff <address@hidden>
Date:   Thu Oct 13 10:38:33 2016 +0300

    Bugfixes in libmailutils/opt/opt.c

commit af83aaff0e41587fcdbe78983b6e116e442f17a1
Author: Sergey Poznyakoff <address@hidden>
Date:   Wed Oct 12 11:30:32 2016 +0300

    Fix some incompatibilities in the previous commit.
    
    * dotlock/dotlock.c (force): Change type to unsigned.
    Provide default value for --force.
    (cli): Set exit codes and extra docstring.
    
    * include/mailutils/cli.h (mu_cli_setup): New members: prog_extra_doc,
    ex_usage, ex_config.
    * include/mailutils/opt.h (mu_parseopt_getcolumn)
    (mu_parseopt_fmt_text): New prototypes.
    * libmailutils/cli/cli.c (extra_help_hook): New hook.
    (mu_cli): Set up customized exit codes.
    Pass pointer to struct mu_cli_setup in hints.data.
    All uses changed.
    Set up help hook if setup->prog_extra_doc is defined.
    
    * libmailutils/opt/help.c (mu_parseopt_getcolumn): New
    function.
    (print_option_descr): Honor explicit newlines.
    (mu_parseopt_fmt_text): New function.
    
    * mimeview/mimeview.c (cli): Provide extra docs.
    * sieve/sieve.c: Likewise.

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

Summary of changes:
 dotlock/dotlock.c       |   39 ++++++++++++++++++++++++++++++---------
 include/mailutils/cli.h |   13 +++++++++----
 include/mailutils/opt.h |    3 +++
 libmailutils/cli/cli.c  |   44 +++++++++++++++++++++++++++++++++++---------
 libmailutils/opt/help.c |   28 ++++++++++++++++++++++++++++
 libmailutils/opt/opt.c  |   30 +++++++++++++++++++-----------
 mimeview/mimeview.c     |   10 +++-------
 sieve/sieve.c           |    8 +++++++-
 8 files changed, 134 insertions(+), 41 deletions(-)

diff --git a/dotlock/dotlock.c b/dotlock/dotlock.c
index 0a8cfec..f0e07d6 100644
--- a/dotlock/dotlock.c
+++ b/dotlock/dotlock.c
@@ -31,9 +31,33 @@ static const char *file;
 static int unlock;
 static int flags;
 static int retries;
-static time_t force;
+static unsigned force;
 static int debug;
 
+static void
+cli_force (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  if (arg)
+    {
+      int rc;
+      char *errmsg;
+      rc = mu_str_to_c (arg, opt->opt_type, opt->opt_ptr, &errmsg);
+      if (rc)
+       {
+         if (opt->opt_long)
+           mu_parseopt_error (po, "--%s: %s", opt->opt_long,
+                              errmsg ? errmsg : mu_strerror (rc));
+         else
+           mu_parseopt_error (po, "-%c: %s", opt->opt_short,
+                              errmsg ? errmsg : mu_strerror (rc));
+         free (errmsg);
+         exit (po->po_exit_error);
+       }
+    }
+  else
+    *(unsigned*)opt->opt_ptr = 1;
+}
+
 static struct mu_option dotlock_options[] = {
   { "unlock", 'u', NULL, MU_OPTION_DEFAULT,
     N_("unlock"),
@@ -41,7 +65,7 @@ static struct mu_option dotlock_options[] = {
 
   { "force",  'f', N_("MINUTES"), MU_OPTION_ARG_OPTIONAL,
     N_("forcibly break an existing lock older than a certain time"),
-    mu_c_time, &force },//FIXME: Default value
+    mu_c_uint, &force, cli_force },
  
   { "retry",  'r', N_("RETRIES"), MU_OPTION_ARG_OPTIONAL,
     N_("retry the lock a few times"),
@@ -68,12 +92,11 @@ static struct mu_cli_setup cli = {
   options,
   dotlock_cfg_param,
   N_("GNU dotlock -- lock mail spool files."),
-  //FIXME:
-  /*
+  N_("FILE"),
   N_("Returns 0 on success, 3 if locking the file fails because\
- it's already locked, and 1 if some other kind of error occurred.");
-  */
-  N_("FILE")
+ it's already locked, and 1 if some other kind of error occurred."),
+  MU_DL_EX_ERROR,
+  MU_DL_EX_ERROR
 };
 
 
@@ -99,8 +122,6 @@ main (int argc, char *argv[])
   if (setegid (usergid) < 0)
     return MU_DL_EX_ERROR;
 
-  /* FIXME: Force mu_cli to exit with MU_DL_EX_ERROR on errors? */
-
   mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
   switch (argc)
diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h
index 2943bc4..8f31f7b 100644
--- a/include/mailutils/cli.h
+++ b/include/mailutils/cli.h
@@ -39,10 +39,15 @@ void mu_cli_capa_apply (char const *name, mu_list_t opts, 
mu_list_t commits);
 
 struct mu_cli_setup
 {
-  struct mu_option **optv;
-  struct mu_cfg_param *cfg;
-  char *prog_doc;
-  char *prog_args;
+  struct mu_option **optv;     /* Command-line options */
+  struct mu_cfg_param *cfg;    /* Configuration parameters */
+  char *prog_doc;              /* Program documentation string */
+  char *prog_args;             /* Program arguments string */
+  char *prog_extra_doc;        /* Extra documentation.  This will be
+                                 displayed after options. */
+  int ex_usage;                /* If not 0, exit code on usage errors */
+  int ex_config;               /* If not 0, exit code on configuration
+                                 errors */
 };
 
 void mu_version_func (struct mu_parseopt *po, FILE *stream);
diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index cc56342..68204b9 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -168,6 +168,9 @@ void mu_parseopt_error (struct mu_parseopt *po, char const 
*fmt, ...);
 int mu_parseopt_apply (struct mu_parseopt *p);
 void mu_parseopt_free (struct mu_parseopt *p);
 
+unsigned mu_parseopt_getcolumn (const char *name);
+void mu_parseopt_fmt_text (const char *text, size_t col);
+
 void mu_option_describe_options (struct mu_option **optbuf, size_t optcnt);
 void mu_program_help (struct mu_parseopt *p);
 void mu_program_usage (struct mu_parseopt *p);
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 597ac91..a75a684 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -77,7 +77,17 @@ There is NO WARRANTY, to the extent permitted by law.\n\
 
 static char gnu_general_help_url[] =
   N_("General help using GNU software: <http://www.gnu.org/gethelp/>");
-
+
+static void
+extra_help_hook (struct mu_parseopt *po, FILE *stream)
+{
+  struct mu_cfg_parse_hints *hints = po->po_data;
+  struct mu_cli_setup *setup = hints->data;
+  char *extra_doc = _(setup->prog_extra_doc);
+  /* FIXME: mu_parseopt help output should get FILE * argument */
+  mu_parseopt_fmt_text (extra_doc, 0);
+  fputc ('\n', stdout);
+}
 
 static void
 change_progname (struct mu_parseopt *po, struct mu_option *opt,
@@ -235,8 +245,12 @@ show_config_help (struct mu_parseopt *po, struct mu_option 
*opt,
   mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
                                        dummy_include_param, NULL);
   if (hints->data)
-    mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
-                                         hints->data, NULL);
+    {
+      struct mu_cli_setup *setup = hints->data;
+      mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
+                                           setup->cfg, NULL);
+    }
+  
   mu_cfg_format_container (stream, cont);
   mu_config_destroy_container (&cont);
       
@@ -325,6 +339,12 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, 
char **capa,
   struct mu_cfg_parse_hints hints;
   struct mu_option **optv;
   mu_list_t com_list;
+
+  /* Set up defaults */
+  if (setup->ex_usage == 0)
+    setup->ex_usage = EX_USAGE;
+  if (setup->ex_config == 0)
+    setup->ex_config = EX_CONFIG;
   
   /* Set program name */
   mu_set_program_name (argv[0]);
@@ -346,7 +366,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, 
char **capa,
   hints.flags |= MU_CFG_PARSE_PROGRAM;
   hints.program = (char*) mu_program_name;
 
-  hints.data = setup->cfg;
+  hints.data = setup;
   
   /* Initialize po */
   if (setup->prog_doc)
@@ -376,10 +396,16 @@ mu_cli (int argc, char **argv, struct mu_cli_setup 
*setup, char **capa,
   po.po_version_hook = mu_version_func;
   flags |= MU_PARSEOPT_VERSION_HOOK;
 
+  if (setup->prog_extra_doc)
+    {
+      po.po_help_hook = extra_help_hook;
+      flags |= MU_PARSEOPT_HELP_HOOK;
+    }
+  
   po.po_data = &hints;
   flags |= MU_PARSEOPT_DATA;
 
-  po.po_exit_error = EX_USAGE;
+  po.po_exit_error = setup->ex_usage;
 
   optv = init_options (capa, setup, &com_list);
 
@@ -398,13 +424,13 @@ mu_cli (int argc, char **argv, struct mu_cli_setup 
*setup, char **capa,
     mu_parseopt_error (&po, "%s", _("unexpected arguments"));
 
   if (mu_cfg_parse_config (&parse_tree, &hints))
-    exit (EX_CONFIG);
+    exit (setup->ex_config);
 
   if (mu_cfg_tree_reduce (parse_tree, &hints, setup->cfg, data))
-    exit (EX_CONFIG);
+    exit (setup->ex_config);
 
-  if (mu_cfg_error_count) //FIXME
-    exit (EX_CONFIG);
+  if (mu_cfg_error_count)
+    exit (setup->ex_config);
   
   mu_parseopt_apply (&po);
 
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
index f91c126..96ab1dc 100644
--- a/libmailutils/opt/help.c
+++ b/libmailutils/opt/help.c
@@ -63,6 +63,23 @@ static struct usage_var
   { NULL }
 };
 
+unsigned
+mu_parseopt_getcolumn (const char *name)
+{
+  struct usage_var *p;
+  unsigned retval = 0;
+  for (p = usage_var; p->name; p++)
+    {
+      if (strcmp (p->name, name) == 0)
+       {
+         if (p->valptr)
+           retval = *p->valptr;
+         break;
+       }
+    }
+  return retval;
+}
+
 static void
 set_usage_var (struct mu_parseopt *po, char const *id)
 {
@@ -195,6 +212,11 @@ print_option_descr (const char *descr, size_t lmargin, 
size_t rmargin)
              if (descr[i] == 0)
                break;
            }
+         else if (descr[i] == '\n')
+           {
+             s = i;
+             break;
+           }
        }
       fwrite (descr, 1, s, stdout);
       fputc ('\n', stdout);
@@ -207,6 +229,12 @@ print_option_descr (const char *descr, size_t lmargin, 
size_t rmargin)
     }
 }
 
+void
+mu_parseopt_fmt_text (const char *text, size_t col)
+{
+  print_option_descr (text, col, rmargin);
+}
+
 
 static size_t
 print_opt_arg (struct mu_option *opt, int delim)
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index 37c22ab..0e31a47 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -34,21 +34,29 @@ optcmp (const void *a, const void *b)
 {
   struct mu_option const *ap = *(struct mu_option const **)a;
   struct mu_option const *bp = *(struct mu_option const **)b;
-
+  
   while (ap->opt_flags & MU_OPTION_ALIAS)
     ap--;
   while (bp->opt_flags & MU_OPTION_ALIAS)
     bp--;
-  
-  if (MU_OPTION_IS_VALID_SHORT_OPTION (ap)
-      && MU_OPTION_IS_VALID_SHORT_OPTION (bp))
-    return ap->opt_short - bp->opt_short;
-  if (MU_OPTION_IS_VALID_LONG_OPTION (ap)
+
+  if (!MU_OPTION_IS_VALID_SHORT_OPTION (ap)
+      && MU_OPTION_IS_VALID_LONG_OPTION (ap)
+      && !MU_OPTION_IS_VALID_SHORT_OPTION (bp)
       && MU_OPTION_IS_VALID_LONG_OPTION (bp))
-    return strcmp (ap->opt_long, bp->opt_long);
-  if (MU_OPTION_IS_VALID_LONG_OPTION (ap))
-    return 1;
-  return -1;
+    return strcasecmp (ap->opt_long, bp->opt_long);
+  else
+    {
+      char afirst, bfirst;
+      int res;
+
+      afirst = ap->opt_short ? ap->opt_short : ap->opt_long ? *ap->opt_long : 
0;
+      bfirst = bp->opt_short ? bp->opt_short : bp->opt_long ? *bp->opt_long : 
0;
+
+      res = mu_tolower (afirst) - mu_tolower (bfirst);
+      
+      return res ? res : afirst - bfirst;
+    }
 }
 
 /* Sort a group of options in OPTBUF, starting at index START (first
@@ -545,7 +553,7 @@ parseopt_init (struct mu_parseopt *po, struct mu_option 
**options,
   /* Ensure sane start of options.  This is necessary, in particular,
      because optcmp backs up until it finds an element with cleared
      MU_OPTION_ALIAS bit. */
-  po->po_optv[0]->opt_flags &= MU_OPTION_ALIAS;
+  po->po_optv[0]->opt_flags &= ~MU_OPTION_ALIAS;
   if (!(flags & MU_PARSEOPT_NO_SORT))
     {
       /* Sort the options */
diff --git a/mimeview/mimeview.c b/mimeview/mimeview.c
index 0100f50..011c6af 100644
--- a/mimeview/mimeview.c
+++ b/mimeview/mimeview.c
@@ -144,15 +144,11 @@ struct mu_cli_setup cli = {
   options,
   mimeview_cfg_param,
   N_("GNU mimeview -- display files, using mailcap mechanism."),
-  //FIXME:
-  /*
-  N_("Default mime.types file is ") DEFAULT_CUPS_CONFDIR "/mime.types"
-N_("\n\nDebug flags are:\n\
+  N_("FILE [FILE ...]"),
+  N_("Debug flags are:\n\
   g - Mime.types parser traces\n\
   l - Mime.types lexical analyzer traces\n\
-  0-9 - Set debugging level\n");
-  */
-  N_("FILE [FILE ...]")
+  0-9 - Set debugging level\n")
 };
 
 static char *capa[] = {
diff --git a/sieve/sieve.c b/sieve/sieve.c
index 5de8e61..2627bd1 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -247,7 +247,13 @@ static struct mu_cli_setup cli = {
   options,
   sieve_cfg_param,
   N_("GNU sieve -- a mail filtering tool."),
-  "SCRIPT"
+  "SCRIPT",
+  N_("Debug flags:\n\
+  g - main parser traces\n\
+  T - mailutils traces (same as --debug-level=sieve.trace0-trace1)\n\
+  P - network protocols (same as --debug-level=sieve.=prot)\n\
+  t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
+  i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n")
 };
 
 static void


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]