Commit 1eeba80d 1eeba80dccd45eef3662054a2fd1c6152903e249 by Sergey Poznyakoff

Changed invocation of mh_argp_parse and updated the definition of opt_handler.

1 parent 9d449587
......@@ -56,7 +56,7 @@ static char *component; /* header field */
static char *anno_text; /* header field value */
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -111,7 +111,7 @@ main (int argc, char **argv)
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
mbox = mh_open_folder (current_folder, 0);
......
......@@ -85,7 +85,7 @@ static int query_mode = 0; /* --query flag */
static int use_draft = 0; /* --use flag */
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -132,7 +132,7 @@ opt_handler (int key, char *arg, void *unused)
case ARG_WHATNOWPROC:
case ARG_NOWHATNOWPROC:
mh_error (_("option is not yet implemented"));
argp_error (state, _("option is not yet implemented"));
exit (1);
default:
......@@ -223,7 +223,7 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
if (!wh_env.draftfolder)
......
......@@ -64,7 +64,7 @@ action_dump ()
static action_fp action = action_dump;
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -96,7 +96,7 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, NULL);
if (format_str && mh_format_parse (format_str, &format))
......
......@@ -108,7 +108,7 @@ char *mh_seq_name; /* Name of the mh sequence file (defaults to
.mh_sequences) */
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -503,7 +503,7 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
/* If folder is invoked by a name ending with "s" (e.g., folders),
......
......@@ -76,7 +76,7 @@ static int quiet = 0;
static char *append_folder;
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -118,7 +118,7 @@ opt_handler (int key, char *arg, void *unused)
width = strtoul (arg, NULL, 0);
if (!width)
{
mh_error (_("Invalid width"));
argp_error (state, _("Invalid width"));
exit (1);
}
break;
......@@ -166,7 +166,7 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, NULL);
if (!quiet && mh_format_parse (format_str, &format))
......
......@@ -38,7 +38,7 @@ struct mh_option mh_option[] = {
int automode;
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -64,7 +64,7 @@ main (int argc, char **argv)
mu_init_nls ();
mh_auto_install = 0;
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, NULL);
home = mu_get_homedir ();
......
......@@ -54,8 +54,8 @@ struct mh_option mh_option[] = {
};
static int action; /* Action to perform */
static int mode_public = 1; /* Create public sequences */
static int mode_zero = 1; /* Zero the sequence before addition */
static int seq_flags = 0; /* Create public sequences;
Do not zero the sequence before addition */
static list_t seq_list; /* List of sequence names to operate upon */
static char *mbox_dir;
......@@ -72,7 +72,7 @@ add_sequence (char *name)
}
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -92,19 +92,25 @@ opt_handler (int key, char *arg, void *unused)
break;
case ARG_PUBLIC:
mode_public = is_true (arg);
if (is_true (arg))
seq_flags &= ~SEQ_PRIVATE;
else
seq_flags |= SEQ_PRIVATE;
break;
case ARG_NOPUBLIC:
mode_public = 0;
seq_flags |= SEQ_PRIVATE;
break;
case ARG_ZERO:
mode_zero = is_true (arg);
if (is_true (arg))
seq_flags |= SEQ_ZERO;
else
seq_flags &= ~SEQ_ZERO;
break;
case ARG_NOZERO:
mode_zero = 0;
seq_flags &= ~SEQ_ZERO;
break;
default:
......@@ -113,152 +119,17 @@ opt_handler (int key, char *arg, void *unused)
return 0;
}
static char *
private_sequence_name (char *name)
{
char *p;
asprintf (&p, "atr-%s-%s", name, mbox_dir);
return p;
}
static char *
read_sequence (char *name, int public)
{
char *value;
if (public)
value = mh_global_sequences_get (name, NULL);
else
{
char *p = private_sequence_name (name);
value = mh_global_context_get (p, NULL);
free (p);
}
return value;
}
static void
write_sequence (char *name, char *value, int public)
{
if (public)
mh_global_sequences_set (name, value);
else
{
char *p = private_sequence_name (name);
mh_global_context_set (p, value);
free (p);
}
}
static void
delete_sequence (char *name, int public)
{
write_sequence (name, NULL, public);
}
static int
action_add (void *item, void *data)
{
char *name = item;
mh_msgset_t *mset = data;
char *value = read_sequence (name, mode_public);
char *new_value, *p;
char buf[64];
size_t i, len;
delete_sequence (name, !mode_public);
if (mode_zero)
value = NULL;
if (value)
len = strlen (value);
else
len = 0;
len++;
for (i = 0; i < mset->count; i++)
{
snprintf (buf, sizeof buf, "%lu", (unsigned long) mset->list[i]);
len += strlen (buf) + 1;
}
new_value = xmalloc (len + 1);
if (value)
strcpy (new_value, value);
else
new_value[0] = 0;
p = new_value + strlen (new_value);
*p++ = ' ';
for (i = 0; i < mset->count; i++)
{
p += sprintf (p, "%lu", (unsigned long) mset->list[i]);
*p++ = ' ';
}
*p = 0;
write_sequence (name, new_value, mode_public);
return 0;
}
static int
cmp_msgnum (const void *a, const void *b)
{
const size_t *as = a;
const size_t *bs = b;
if (*as < *bs)
return -1;
if (*as > *bs)
return 1;
mh_seq_add ((char *)item, (mh_msgset_t *)data, seq_flags);
return 0;
}
static int
action_delete (void *item, void *data)
{
char *name = item;
mh_msgset_t *mset = data;
char *value = read_sequence (name, mode_public);
char *p;
int argc, i;
char **argv;
if (!value)
return 0;
if (argcv_get (value, "", NULL, &argc, &argv))
return 0;
for (i = 0; i < argc; i++)
{
char *p;
size_t num = strtoul (argv[i], &p, 10);
if (*p)
continue;
if (bsearch (&num, mset->list, mset->count, sizeof (mset->list[0]),
cmp_msgnum))
{
free (argv[i]);
argv[i] = NULL;
}
}
p = value;
for (i = 0; i < argc; i++)
{
if (argv[i])
{
strcpy (p, argv[i]);
p += strlen (p);
*p++ = ' ';
}
}
*p = 0;
write_sequence (name, value, mode_public);
argcv_free (argc, argv);
mh_seq_delete ((char *)item, (mh_msgset_t *)data, seq_flags);
return 0;
}
......@@ -268,10 +139,10 @@ action_list (void *item, void *data)
char *name = item;
char *val;
val = read_sequence (name, 1);
val = mh_seq_read (name, 0);
if (val)
printf ("%s: %s\n", name, val);
else if ((val = read_sequence (name, 0)))
else if ((val = mh_seq_read (name, SEQ_PRIVATE)))
printf ("%s (%s): %s\n", name, _("private"), val);
return 0;
}
......@@ -317,7 +188,7 @@ main (int argc, char **argv)
url_t url;
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
mbox = mh_open_folder (current_folder, 0);
......
......@@ -73,7 +73,7 @@ static int nomoreproc;
static list_t format;
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -106,7 +106,7 @@ opt_handler (int key, char *arg, void *unused)
width = strtoul (arg, NULL, 0);
if (!width)
{
mh_error (_("Invalid width"));
argp_error (state, _("Invalid width"));
exit (1);
}
break;
......@@ -115,7 +115,7 @@ opt_handler (int key, char *arg, void *unused)
length = strtoul (arg, NULL, 0);
if (!length)
{
mh_error (_("Invalid length"));
argp_error (state, _("Invalid length"));
exit (1);
}
break;
......@@ -212,7 +212,7 @@ main (int argc, char **argv)
interactive = isatty (1) && isatty (0);
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
format = mhl_format_compile (formfile);
......
......@@ -37,7 +37,7 @@ struct mh_option mh_option[] = {
};
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -75,7 +75,7 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
/* If the only argument is `+', your MH Path is output; this
......
......@@ -145,7 +145,7 @@ close_folders ()
}
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -223,7 +223,7 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
open_folders ();
......
......@@ -123,7 +123,7 @@ decode_cc_flag (const char *opt, const char *arg)
}
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
char *s;
......@@ -172,7 +172,7 @@ opt_handler (int key, char *arg, void *unused)
width = strtoul (arg, NULL, 0);
if (!width)
{
mh_error (_("Invalid width"));
argp_error (state, _("Invalid width"));
exit (1);
}
break;
......@@ -198,7 +198,7 @@ opt_handler (int key, char *arg, void *unused)
case ARG_INPLACE:
case ARG_WHATNOWPROC:
case ARG_NOWHATNOWPROC:
mh_error (_("option is not yet implemented"));
argp_error (state, _("option is not yet implemented"));
exit (1);
default:
......@@ -318,7 +318,7 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
if (mh_format_parse (format_str, &format))
{
......
......@@ -55,7 +55,7 @@ int interactive; /* Ask for confirmation before deleting */
int recurse; /* Recursively process all the sub-directories */
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -134,7 +134,7 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, NULL);
if (!explicit_folder)
interactive = 1;
......
......@@ -37,7 +37,7 @@ struct mh_option mh_option[] = {
};
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -71,7 +71,7 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
mbox = mh_open_folder (current_folder, 0);
......
......@@ -84,7 +84,7 @@ void print_header __P((mailbox_t mbox));
void clear_screen __P((void));
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -113,7 +113,7 @@ opt_handler (int key, char *arg, void *unused)
width = strtoul (arg, NULL, 0);
if (!width)
{
mh_error (_("Invalid width"));
argp_error (state, _("Invalid width"));
exit (1);
}
break;
......@@ -123,7 +123,7 @@ opt_handler (int key, char *arg, void *unused)
break;
case ARG_FILE:
mh_error (_("option is not yet implemented"));
argp_error (state, _("option is not yet implemented"));
break;
case ARG_LICENSE:
......@@ -166,7 +166,7 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
if (mh_format_parse (format_str, &format))
......
......@@ -118,7 +118,7 @@ static unsigned width = 76; /* Maximum width of header fields */
} while (0)
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
char *p;
......@@ -194,7 +194,7 @@ opt_handler (int key, char *arg, void *unused)
split_interval = strtoul(arg, &p, 10);
if (*p)
{
mh_error (_("Invalid number"));
argp_error (state, _("Invalid number"));
exit (1);
}
break;
......@@ -219,7 +219,7 @@ opt_handler (int key, char *arg, void *unused)
width = strtoul(arg, &p, 10);
if (*p)
{
mh_error (_("Invalid number"));
argp_error (state, _("Invalid number"));
exit (1);
}
break;
......@@ -447,7 +447,7 @@ main (int argc, char **argv)
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
argc -= index;
......
......@@ -52,7 +52,7 @@ struct mh_whatnow_env wh_env = { 0 };
static int initial_edit = 1;
static int
opt_handler (int key, char *arg, void *unused)
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
......@@ -93,7 +93,7 @@ main (int argc, char **argv)
mu_init_nls ();
mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
wh_env.msg = getenv ("mhaltmsg");
......