Commit d2952d1c d2952d1c8f6ca4edc65e3c61a47c7a7154f5353b by Sergey Poznyakoff

Bugfixes in MH show

* mh/show.c: Set cur before returning.  Allow for arguments in
showproc settings.  Move to next or prev if invoked with the
corresponding argv[0]

* mh/mh.h (mh_msgset_parse): def argument is const.
(mh_msgset_first_current, mh_msgset_first_uid): Remove proto.
(mh_msgset_first): Change signature.
(mh_msgset_last): New function.
* mh/mh_msgset.c (mh_msgset_first): Return UID or message number
depending on the value of the second parameter.
(mh_msgset_first_current, mh_msgset_first_uid): Remove.
(mh_msgset_last): New function.

* mh/anno.c: Update.
* mh/comp.c: Update.
* mh/folder.c: Update.
* mh/mh_init.c: Update.
* mh/repl.c: Update.

* mh/Makefile.am (install-exec-hook): Link show to prev and next
1 parent 546831aa
......@@ -170,6 +170,8 @@ mh_alias_lex.c: $(srcdir)/mh_alias.l mh_alias.h
install-exec-hook:
@here=`pwd`; \
cd $(DESTDIR)$(bindir); \
rm -f folders; \
rm -f folders next prev; \
$(LN_S) folder folders; \
$(LN_S) show next; \
$(LN_S) show prev; \
cd $$here
......
......@@ -110,7 +110,7 @@ main (int argc, char **argv)
exit (1);
}
mh_msgset_first_current (mbox, msgset);
mh_mailbox_set_cur (mbox, mh_msgset_first (msgset, RET_UID));
mu_msgset_free (msgset);
mh_global_save_state ();
mu_mailbox_sync (mbox);
......
......@@ -189,7 +189,8 @@ main (int argc, char **argv)
mu_error (_("only one message at a time!"));
return 1;
}
draftmessage = (char*) mu_umaxtostr (0, mh_msgset_first_uid (msgset));
draftmessage =
(char*) mu_umaxtostr (0, mh_msgset_first (msgset, RET_UID));
mu_msgset_free (msgset);
mu_mailbox_destroy (&mbox);
}
......@@ -213,7 +214,7 @@ main (int argc, char **argv)
return 1;
}
unlink (wh_env.file);
copy_message (mbox, mh_msgset_first (msgset), wh_env.file);
copy_message (mbox, mh_msgset_first (msgset, RET_MSGNO), wh_env.file);
mu_mailbox_destroy (&mbox);
mu_msgset_free (msgset);
}
......
......@@ -914,7 +914,7 @@ main (int argc, char **argv)
mu_mailbox_t mbox = mh_open_folder (mh_current_folder (),
MU_STREAM_RDWR);
mh_msgset_parse (&msgset, mbox, argc - index, argv + index, "cur");
mh_msgset_first_current (mbox, msgset);
mh_mailbox_set_cur (mbox, mh_msgset_first (msgset, RET_UID));
mu_msgset_free (msgset);
mh_global_save_state ();
mu_mailbox_close (mbox);
......
......@@ -300,12 +300,13 @@ int mh_message_number (mu_message_t msg, size_t *pnum);
mu_mailbox_t mh_open_folder (const char *folder, int flags);
void mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox,
int argc, char **argv, char *def);
int argc, char **argv, const char *def);
void mh_msgset_parse_string (mu_msgset_t *msgset, mu_mailbox_t mbox,
const char *string, char *def);
void mh_msgset_first_current (mu_mailbox_t mbox, mu_msgset_t msgset);
size_t mh_msgset_first (mu_msgset_t msgset);
size_t mh_msgset_first_uid (mu_msgset_t msgset);
const char *string, const char *def);
#define RET_MSGNO 0
#define RET_UID 1
size_t mh_msgset_first (mu_msgset_t msgset, int uid);
size_t mh_msgset_last (mu_msgset_t msgset, int uid);
int mh_msgset_single_message (mu_msgset_t msgset);
#define NAME_ANY 0
......
......@@ -1026,7 +1026,7 @@ mh_draft_message (const char *name, const char *msgspec, char **pname)
if (!mh_msgset_single_message (msgset))
mu_error (_("only one message at a time!"));
else
uid = mh_msgset_first_uid (msgset);
uid = mh_msgset_first (msgset, RET_UID);
mu_msgset_free (msgset);
}
......
......@@ -21,51 +21,47 @@
#include <mailutils/sys/msgset.h>
size_t
mh_msgset_first (mu_msgset_t msgset)
mh_msgset_first (mu_msgset_t msgset, int uid)
{
mu_list_t list;
struct mu_msgrange *r;
int rc;
rc = mu_msgset_get_list (msgset, &list);
size_t n;
int rc = mu_msgset_first (msgset, &n);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_msgset_get_list", NULL, rc);
mu_diag_funcall (MU_DIAG_ERROR, "mu_msgset_first", NULL, rc);
exit (1);
}
rc = mu_list_head (list, (void**)&r);
if (rc)
if (uid)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_list_get", NULL, rc);
exit (1);
rc = mu_mailbox_translate (msgset->mbox, MU_MAILBOX_MSGNO_TO_UID, n, &n);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_translate", NULL, rc);
exit (1);
}
}
return r->msg_beg;
return n;
}
size_t
mh_msgset_first_uid (mu_msgset_t msgset)
mh_msgset_last (mu_msgset_t msgset, int uid)
{
int rc;
size_t cur;
cur = mh_msgset_first (msgset);
rc = mu_mailbox_translate (msgset->mbox, MU_MAILBOX_MSGNO_TO_UID, cur, &cur);
size_t n;
int rc = mu_msgset_last (msgset, &n);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_translate", NULL, rc);
mu_diag_funcall (MU_DIAG_ERROR, "mu_msgset_last", NULL, rc);
exit (1);
}
return cur;
}
/* Set the current message to that contained at position 0
in the given message set.
FIXME: mbox is superfluous
*/
void
mh_msgset_first_current (mu_mailbox_t mbox, mu_msgset_t msgset)
{
mh_mailbox_set_cur (mbox, mh_msgset_first_uid (msgset));
if (uid)
{
rc = mu_mailbox_translate (msgset->mbox, MU_MAILBOX_MSGNO_TO_UID, n, &n);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_translate", NULL, rc);
exit (1);
}
}
return n;
}
int
......@@ -617,7 +613,7 @@ msgset_parser_run (struct msgset_parser *parser)
/* Parse a message specification from (argc;argv). */
void
mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox,
int argc, char **argv, char *def)
int argc, char **argv, const char *def)
{
struct msgset_parser parser;
char *xargv[2];
......@@ -626,7 +622,7 @@ mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox,
{
argc = 1;
argv = xargv;
argv[0] = def ? def : "cur";
argv[0] = (char*) (def ? def : "cur");
argv[1] = NULL;
}
......@@ -646,7 +642,7 @@ mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox,
void
mh_msgset_parse_string (mu_msgset_t *msgset, mu_mailbox_t mbox,
const char *string, char *def)
const char *string, const char *def)
{
struct mu_wordsplit ws;
......
......@@ -208,7 +208,7 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
break;
}
msgno = mh_msgset_first (msgset);
msgno = mh_msgset_first (msgset, RET_MSGNO);
rc = mu_mailbox_get_message (mbox, msgno, &msg);
if (rc)
{
......
......@@ -54,6 +54,36 @@ insarg (char *arg)
showargv[1] = p;
}
}
static void
finisarg (void)
{
struct mu_wordsplit ws;
char *p;
mu_wordsplit (showproc, &ws, MU_WRDSF_DEFFLAGS);
if (ws.ws_wordc > 1)
{
size_t i;
if (showargc + ws.ws_wordc > showargmax)
{
showargmax = showargc + ws.ws_wordc;
showargv = mu_realloc (showargv, showargmax * sizeof showargv[0]);
}
memmove (showargv + ws.ws_wordc, showargv + 1,
sizeof (showargv[0]) * (showargc - 1));
for (i = 1; i < ws.ws_wordc; i++)
showargv[i] = ws.ws_wordv[i];
showargc += ws.ws_wordc - 1;
showproc = ws.ws_wordv[0];
}
p = strrchr (showproc, '/');
showargv[0] = (char*) (p ? p + 1 : showproc);
addarg (NULL);
}
static void
set_draft (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
......@@ -181,8 +211,9 @@ int
main (int argc, char **argv)
{
mu_mailbox_t mbox;
mu_msgset_t msgset;
mu_msgset_t msgset = NULL;
const char *p;
const char *mode = "cur";
showargmax = 2;
showargc = 1;
......@@ -191,6 +222,9 @@ main (int argc, char **argv)
mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
args_doc, prog_doc, NULL);
if (strcmp (mu_program_name, "next") == 0
|| strcmp (mu_program_name, "prev") == 0)
mode = mu_program_name;
mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
......@@ -203,7 +237,7 @@ main (int argc, char **argv)
}
}
else
mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
mh_msgset_parse (&msgset, mbox, argc, argv, mode);
/* 1. If !use_showproc set showproc to /bin/cat and go to X.
2. If -file or -draft is given
......@@ -241,7 +275,7 @@ main (int argc, char **argv)
mu_mailbox_close (mbox);
mu_mailbox_destroy (&mbox);
mbox = mh_open_folder (dfolder, MU_STREAM_RDWR);
mh_msgset_parse (&msgset, mbox, 0, NULL, "cur");
mh_msgset_parse (&msgset, mbox, 0, NULL, mode);
mu_msgset_foreach_message (msgset, resolve_mime, &ismime);
if (ismime)
......@@ -294,9 +328,12 @@ main (int argc, char **argv)
mu_msgset_foreach_msguid (msgset, printheader, (void*) path);
}
mu_stream_flush (mu_strout);
if (!mu_msgset_is_empty (msgset))
mh_mailbox_set_cur (mbox, mh_msgset_last (msgset, RET_UID));
mu_mailbox_close (mbox);
mu_mailbox_destroy (&mbox);
mu_stream_flush (mu_strout);
if (!showproc)
{
......@@ -304,10 +341,7 @@ main (int argc, char **argv)
if (!showproc)
showproc = "/usr/bin/more";
}
addarg (NULL);
p = strrchr (showproc, '/');
showargv[0] = (char*) (p ? p + 1 : showproc);
finisarg ();
execvp (showproc, showargv);
mu_error (_("unable to exec %s: %s"), showargv[0], mu_strerror (errno));
return 1;
......