summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-06-27 10:21:47 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2017-06-27 10:37:19 +0300
commit60e4bf01419da5d99a62c3dc69f5d118e6ca992f (patch)
treeee0ee5bdfbe3bf81fe3c8a68ceb360f596e8366e
parentff09676fdb8577c1ceafc8e10042c6f6ab26f9e5 (diff)
downloadmailutils-60e4bf01419da5d99a62c3dc69f5d118e6ca992f.tar.gz
mailutils-60e4bf01419da5d99a62c3dc69f5d118e6ca992f.tar.bz2
Further work on format vm
* mh/mh.h (mh_format): Change signature. (MH_FMT_FORCENL): New define. * mh/mh_format.h (MHA_OPT_CLEAR): Remove. (MHA_LITERAL,MHA_VOID): New flags. (mh_machine) <flags>: New member. * mh/mh_fmtgram.y (funcall production): Fix argument interpretation (else_part production): Allow for empty expression. (token_function): Use MU_CTYPE_IDENT instead of the more restrictive MU_CTYPE_ALPHA. * mh/mh_format.c (node_free): Accept NULL as argument (emit_funcall): Assign literal arguments to R_ARG registers (codegen_node): Fix coding the mhop_setn instruction. Clear both str and reg if the ELSE part of a conditional is empty. (mh_string_load): Fix size computation. (mh_string_move): Don't clear the source register. (mh_format): Reorder parameters, pass flags as 6th parameter. Emit final newline if MH_FMT_FORCENL is set, unless the last character output is newline. (mh_format_str): Rewrite function. (builtin_lit): Implement (builtin_friendly): Fix register assignment (builtin_addr): Pass R_ARG to R_REG verbatim, if it cannot be parsed as a RFC822 address. (builtin_decode): Don't clear str reg. (builtin_concat): Remove. The implementation contradcicts the principles of the format VM; besides, the same functionality could be easily achieved by using ctls (builtin_tab): Put additional flags * mh/fmtcheck.c (run): Update call to mh_format * mh/inc.c (list_message): Likewise. Emit warning about not-implemented audit feature. * mh/mh_list.c (_destroy_value): Remove spurious call to free(). * mh/repl.c: Fix calls to mh_format and mh_format_parse. * mh/scan.c: Likewise. * mh/sortm.c: Likewise.
-rw-r--r--mh/fmtcheck.c3
-rw-r--r--mh/inc.c15
-rw-r--r--mh/mh.h6
-rw-r--r--mh/mh_fmtgram.y85
-rw-r--r--mh/mh_format.c137
-rw-r--r--mh/mh_format.h11
-rw-r--r--mh/mh_list.c1
-rw-r--r--mh/repl.c10
-rw-r--r--mh/scan.c12
-rw-r--r--mh/sortm.c8
10 files changed, 166 insertions, 122 deletions
diff --git a/mh/fmtcheck.c b/mh/fmtcheck.c
index 53284b602..a5bf06714 100644
--- a/mh/fmtcheck.c
+++ b/mh/fmtcheck.c
@@ -62,8 +62,7 @@ static void
run (void)
{
mu_message_t msg = mh_file_to_message (NULL, input_file);
- mh_format (format, msg, msgno, width, mu_strout);
- mu_printf ("\n");
+ mh_format (mu_strout, format, msg, msgno, width, MH_FMT_FORCENL);
}
int
diff --git a/mh/inc.c b/mh/inc.c
index 6acd5f339..7c510a75a 100644
--- a/mh/inc.c
+++ b/mh/inc.c
@@ -126,18 +126,18 @@ static struct mu_option options[] = {
};
void
-list_message (mh_format_t *format, mu_mailbox_t mbox, size_t msgno,
+list_message (mh_format_t format, mu_mailbox_t mbox, size_t msgno,
size_t width)
{
mu_message_t msg;
- char *buf = NULL;
mu_mailbox_get_message (mbox, msgno, &msg);
- mh_format (format, msg, msgno, width, &buf);
- printf ("%s\n", buf);
+ mh_format (mu_strout, format, msg, msgno, width, MH_FMT_FORCENL);
+#warning "AUDIT not implemented"
+ /*
if (audit_fp)
fprintf (audit_fp, "%s\n", buf);
- free (buf);
+ */
}
struct incdat
@@ -281,7 +281,7 @@ incmbx (void *item, void *data)
++dp->lastmsg;
if (!quiet)
- list_message (&dp->format, dp->output, dp->lastmsg, width);
+ list_message (dp->format, dp->output, dp->lastmsg, width);
if (f_truncate)
{
@@ -360,7 +360,8 @@ main (int argc, char **argv)
mh_mailbox_cur_default = 1;
memset (&incdat, 0, sizeof (incdat));
- if (!quiet && mh_format_parse (format_str, &incdat.format))
+ if (!quiet
+ && mh_format_parse (&incdat.format, format_str, MH_FMT_PARSE_DEFAULT))
{
mu_error (_("Bad format string"));
exit (1);
diff --git a/mh/mh.h b/mh/mh.h
index 8b21dbe0e..0a78c6707 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -169,8 +169,10 @@ int mh_makedir (const char *p);
typedef struct mh_format *mh_format_t;
-int mh_format (mh_format_t fmt, mu_message_t msg, size_t msgno,
- size_t width, mu_stream_t str);
+#define MH_FMT_FORCENL 1
+int mh_format (mu_stream_t str, mh_format_t fmt,
+ mu_message_t msg, size_t msgno,
+ size_t width, int flags);
int mh_format_str (mh_format_t fmt, char *str, size_t width, char **pret);
void mh_format_dump_code (mh_format_t fmt);
diff --git a/mh/mh_fmtgram.y b/mh/mh_fmtgram.y
index 4db1fbe6e..59fe3b41b 100644
--- a/mh/mh_fmtgram.y
+++ b/mh/mh_fmtgram.y
@@ -214,32 +214,51 @@ component : COMPONENT
funcall : function argument EOFN
{
ctx_pop ();
- if ($1->optarg == MHA_VOID) /*FIXME*/
+ if ($1->optarg & MHA_VOID) /*FIXME*/
{
$2->noprint = 1;
$$ = $2;
}
else
{
+ struct node *arg = $2;
if ($1->argtype == mhtype_none)
{
- if ($2)
+ if (arg)
{
yyerror ("function doesn't take arguments");
YYABORT;
}
}
- else if ($2 == NULL)
+ else if (arg == NULL)
{
- if ($1->optarg != MHA_OPTARG)
+ if (($1->optarg & MHA_LITERAL)
+ && $1->argtype == mhtype_str)
+ {
+ arg = new_node (fmtnode_literal, mhtype_str);
+ arg->v.str = "";
+ }
+ else if ($1->optarg & MHA_OPTARG)
+ /* ok - ignore */;
+ else
{
yyerror ("required argument missing");
YYABORT;
}
}
+ else if ($1->optarg & MHA_LITERAL)
+ {
+ if (!(arg->nodetype == fmtnode_literal
+ || arg->nodetype == fmtnode_number))
+ {
+ yyerror ("argument must be literal");
+ YYABORT;
+ }
+ }
+
$$ = new_node (fmtnode_funcall, $1->type);
$$->v.funcall.builtin = $1;
- $$->v.funcall.arg = typecast ($2, $1->argtype);
+ $$->v.funcall.arg = typecast (arg, $1->argtype);
$$->noprint = $1->type == mhtype_none;
}
}
@@ -373,7 +392,7 @@ elif_list : elif cond zlist
}
;
-else_part : ELSE list
+else_part : ELSE zlist
{
$$ = $2.head;
}
@@ -456,7 +475,7 @@ token_function (void)
curp++;
start = curp;
- curp = mu_str_skip_class (start, MU_CTYPE_ALPHA);
+ curp = mu_str_skip_class (start, MU_CTYPE_IDENT);
if (start == curp || !strchr (" \t(){%", *curp))
{
yyerror ("expected function name");
@@ -724,6 +743,8 @@ static void node_list_free (struct node *node);
static void
node_free (struct node *node)
{
+ if (!node)
+ return;
switch (node->nodetype)
{
case fmtnode_print:
@@ -1065,14 +1086,40 @@ emit_funcall (struct mh_format *fmt, mh_builtin_t *builtin, struct node *arg)
{
if (arg)
{
- codegen_node (fmt, arg);
- emit_opcode_typed (fmt, arg->datatype, mhop_movn, mhop_movs);
+ if (builtin->optarg & MHA_LITERAL)
+ {
+ switch (arg->nodetype)
+ {
+ case fmtnode_literal:
+ emit_opcode (fmt, mhop_sets);
+ emit_instr (fmt, (mh_instr_t) (long) R_ARG);
+ emit_string (fmt, arg->v.str);
+ break;
+
+ case fmtnode_number:
+ emit_opcode (fmt, mhop_setn);
+ emit_instr (fmt, (mh_instr_t) (long) R_ARG);
+ emit_instr (fmt, (mh_instr_t) (long) arg->v.num);
+ break;
+
+ default:
+ abort ();
+ }
+ }
+ else
+ {
+ codegen_node (fmt, arg);
+ emit_opcode_typed (fmt, arg->datatype, mhop_movn, mhop_movs);
+ emit_instr (fmt, (mh_instr_t) (long) R_ARG);
+ emit_instr (fmt, (mh_instr_t) (long) R_REG);
+ }
}
else if (builtin->argtype != mhtype_none)
- emit_opcode_typed (fmt, builtin->type, mhop_movn, mhop_movs);
-
- emit_instr (fmt, (mh_instr_t) (long) R_ARG);
- emit_instr (fmt, (mh_instr_t) (long) R_REG);
+ {
+ emit_opcode_typed (fmt, builtin->type, mhop_movn, mhop_movs);
+ emit_instr (fmt, (mh_instr_t) (long) R_ARG);
+ emit_instr (fmt, (mh_instr_t) (long) R_REG);
+ }
emit_opcode (fmt, mhop_call);
emit_instr (fmt, (mh_instr_t) builtin->fun);
@@ -1105,6 +1152,7 @@ codegen_node (struct mh_format *fmt, struct node *node)
case fmtnode_number:
emit_opcode (fmt, mhop_setn);
emit_instr (fmt, (mh_instr_t) (long) R_REG);
+ emit_instr (fmt, (mh_instr_t) (long) node->v.num);
break;
case fmtnode_body:
@@ -1144,6 +1192,17 @@ codegen_node (struct mh_format *fmt, struct node *node)
{
codegen_nodelist (fmt, node->v.cntl.iffalse);
}
+ else
+ {
+ emit_opcode (fmt, mhop_setn);
+ emit_instr (fmt, (mh_instr_t) (long) R_REG);
+ emit_instr (fmt, (mh_instr_t) (long) 0);
+
+ emit_opcode (fmt, mhop_sets);
+ emit_instr (fmt, (mh_instr_t) (long) R_REG);
+ emit_string (fmt, "");
+ }
+
fmt->prog[pc[1]].num = fmt->progcnt - pc[1];
}
break;
diff --git a/mh/mh_format.c b/mh/mh_format.c
index ab12d7b9f..bdf0f8d49 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -91,7 +91,7 @@ mh_string_load (struct mh_string *s, char const *str)
mh_string_clear (s);
else
{
- mh_string_realloc (s, strlen (str));
+ mh_string_realloc (s, strlen (str) + 1);
strcpy (s->ptr, str);
}
}
@@ -100,7 +100,7 @@ static void
mh_string_move (struct mh_machine *mach, enum regid dst, enum regid src)
{
mh_string_load (&mach->str[dst], mach->str[src].ptr);
- mh_string_clear (&mach->str[src]);
+ // mh_string_clear (&mach->str[src]);
}
@@ -475,8 +475,9 @@ addrlist_destroy (mu_list_t *list)
/* Execute pre-compiled format on message msg with number msgno.
*/
int
-mh_format (mh_format_t fmt, mu_message_t msg, size_t msgno,
- size_t width, mu_stream_t output)
+mh_format (mu_stream_t output, mh_format_t fmt,
+ mu_message_t msg, size_t msgno,
+ size_t width, int flags)
{
struct mh_machine mach;
const char *charset = mh_global_profile_get ("Charset", NULL);
@@ -488,6 +489,7 @@ mh_format (mh_format_t fmt, mu_message_t msg, size_t msgno,
mach.message = msg;
mach.msgno = msgno;
mach.output = output;
+ mach.flags = flags;
if (width == 0)
width = mh_width ();
@@ -498,7 +500,6 @@ mh_format (mh_format_t fmt, mu_message_t msg, size_t msgno,
reset_fmt_defaults (&mach);
-#if HAVE_SETLOCALE
if (charset && strcmp (charset, "auto"))
{
/* Try to set LC_CTYPE according to the value of Charset variable.
@@ -523,7 +524,6 @@ mh_format (mh_format_t fmt, mu_message_t msg, size_t msgno,
mu_error (_("cannot set LC_CTYPE %s"), locale);
free (locale);
}
-#endif
while (!mach.stop)
{
@@ -682,31 +682,45 @@ mh_format (mh_format_t fmt, mu_message_t msg, size_t msgno,
abort ();
}
}
+ if ((mach.flags & MH_FMT_FORCENL) && mach.ind != 0)
+ put_string (&mach, "\n", 1);
+
mh_string_free (&mach.str[R_REG]);
mh_string_free (&mach.str[R_ARG]);
addrlist_destroy (&mach.addrlist);
return mach.ind;
}
-//FIXME
-#if 0
int
-mh_format_str (mh_format_t *fmt, char *str, size_t width, char **pret)
+mh_format_str (mh_format_t fmt, char *str, size_t width, char **pstr)
{
mu_message_t msg = NULL;
mu_header_t hdr = NULL;
- int rc;
+ int rc = 0;
+ mu_stream_t outstr;
+ char *buf;
+ mu_off_t size;
+
+ MU_ASSERT (mu_message_create (&msg, NULL));
+ MU_ASSERT (mu_message_get_header (msg, &hdr));
+ MU_ASSERT (mu_header_set_value (hdr, "text", str, 1));
+ MU_ASSERT (mu_memory_stream_create (&outstr, MU_STREAM_RDWR));
+
+ rc = mh_format (outstr, fmt, msg, 1, width, 0);
+
+ MU_ASSERT (mu_stream_size (outstr, &size));
+ buf = mu_alloc (size + 1);
+ MU_ASSERT (mu_stream_seek (outstr, 0, MU_SEEK_SET, NULL));
+ MU_ASSERT (mu_stream_read (outstr, buf, size, NULL));
+
+ *pstr = buf;
- if (mu_message_create (&msg, NULL))
- return -1;
- mu_message_get_header (msg, &hdr);
- mu_header_set_value (hdr, "text", str, 1);
- rc = mh_format (fmt, msg, 1, width, pret);
mu_message_destroy (&msg, NULL);
+ mu_stream_destroy (&outstr);
+
return rc;
}
-#endif
-
+
/* Built-in functions */
/* Handler for unimplemented functions */
@@ -868,7 +882,7 @@ builtin_num (struct mh_machine *mach)
static void
builtin_lit (struct mh_machine *mach)
{
- /* FIXME: do nothing */
+ mh_string_move (mach, R_REG, R_ARG);
}
static void
@@ -1402,7 +1416,7 @@ builtin_friendly (struct mh_machine *mach)
if (mu_address_sget_personal (addr, 1, &str) == 0 && str)
{
- mh_string_load (&mach->str[R_ARG], str);
+ mh_string_load (&mach->str[R_REG], str);
}
mu_address_destroy (&addr);
}
@@ -1411,29 +1425,34 @@ builtin_friendly (struct mh_machine *mach)
static void
builtin_addr (struct mh_machine *mach)
{
+ const char *arg = mh_string_value (&mach->str[R_ARG]);
mu_address_t addr;
const char *str;
int rc;
- rc = mu_address_create (&addr, mh_string_value (&mach->str[R_ARG]));
- mh_string_clear (&mach->str[R_REG]);
- if (rc)
- return;
-
- if (mu_address_sget_email (addr, 1, &str) == 0)
- mh_string_load (&mach->str[R_REG], str);
- mu_address_destroy (&addr);
+ rc = mu_address_create (&addr, arg);
+ if (rc == 0)
+ {
+ int rc = mu_address_sget_email (addr, 1, &str);
+ if (rc == 0)
+ mh_string_load (&mach->str[R_REG], str);
+ mu_address_destroy (&addr);
+ if (rc == 0)
+ return;
+ }
+ mh_string_load (&mach->str[R_REG], arg);
}
/* pers addr string the personal name**/
static void
builtin_pers (struct mh_machine *mach)
{
+ char const *arg = mh_string_value (&mach->str[R_ARG]);
mu_address_t addr;
const char *str;
int rc;
- rc = mu_address_create (&addr, mh_string_value (&mach->str[R_ARG]));
+ rc = mu_address_create (&addr, arg);
mh_string_clear (&mach->str[R_REG]);
if (rc)
return;
@@ -1677,7 +1696,7 @@ builtin_unre (struct mh_machine *mach)
char const *arg = mh_string_value (&mach->str[R_ARG]);
char const *p;
int rc = mu_unre_subject (arg, &p);
- mh_string_clear (&mach->str[R_REG]);
+
if (rc == 0 && p != arg)
{
char *q = mu_strdup (p); /* Create a copy, since mh_string_load can
@@ -1685,6 +1704,8 @@ builtin_unre (struct mh_machine *mach)
mh_string_load (&mach->str[R_REG], q);
free (q);
}
+ else
+ mh_string_load (&mach->str[R_REG], arg);
}
static void
@@ -1716,7 +1737,6 @@ builtin_decode (struct mh_machine *mach)
if (mh_string_is_null (&mach->str[R_ARG]))
return;
- mh_string_clear (&mach->str[R_REG]);
if (mh_decode_2047 (mh_string_value (&mach->str[R_ARG]), &tmp) == 0)
{
mh_string_load (&mach->str[R_REG], tmp);
@@ -1758,28 +1778,6 @@ builtin_rcpt (struct mh_machine *mach)
}
static void
-builtin_concat (struct mh_machine *mach)
-{
- if (mh_string_is_null (&mach->str[R_ARG]))
- return;
-
- compress_ws (mach, mach->str[R_ARG].ptr);
- if (mh_string_is_null (&mach->str[R_REG]))
- mh_string_move (mach, R_REG, R_ARG);
- else
- {
- size_t length = 1;
-
- length += 1 + mh_string_length (&mach->str[R_REG]);
- /* reserve en extra space */
- length += mh_string_length (&mach->str[R_ARG]);
- mh_string_realloc (&mach->str[R_REG], length);
- strcat (strcat (mach->str[R_REG].ptr, " "),
- mh_string_value (&mach->str[R_ARG]));
- }
-}
-
-static void
builtin_printhdr (struct mh_machine *mach)
{
char *tmp = NULL;
@@ -1852,7 +1850,7 @@ builtin_version (struct mh_machine *mach)
/* Builtin function table */
mh_builtin_t builtin_tab[] = {
- /* Name Handling function Return type Arg type Opt. arg */
+ /* Name Handling function Return type Arg type Flags */
{ "msg", builtin_msg, mhtype_num, mhtype_none },
{ "cur", builtin_cur, mhtype_num, mhtype_none },
{ "size", builtin_size, mhtype_num, mhtype_none },
@@ -1861,19 +1859,19 @@ mh_builtin_t builtin_tab[] = {
{ "charleft", builtin_charleft, mhtype_num, mhtype_none },
{ "timenow", builtin_timenow, mhtype_num, mhtype_none },
{ "me", builtin_me, mhtype_str, mhtype_none },
- { "eq", builtin_eq, mhtype_num, mhtype_num },
- { "ne", builtin_ne, mhtype_num, mhtype_num },
- { "gt", builtin_gt, mhtype_num, mhtype_num },
- { "match", builtin_match, mhtype_num, mhtype_str },
- { "amatch", builtin_amatch, mhtype_num, mhtype_str },
- { "plus", builtin_plus, mhtype_num, mhtype_num },
- { "minus", builtin_minus, mhtype_num, mhtype_num },
- { "divide", builtin_divide, mhtype_num, mhtype_num },
- { "modulo", builtin_modulo, mhtype_num, mhtype_num },
- { "num", builtin_num, mhtype_num, mhtype_num },
- { "lit", builtin_lit, mhtype_str, mhtype_str, MHA_OPT_CLEAR },
- { "getenv", builtin_getenv, mhtype_str, mhtype_str },
- { "profile", builtin_profile, mhtype_str, mhtype_str },
+ { "eq", builtin_eq, mhtype_num, mhtype_num, MHA_LITERAL },
+ { "ne", builtin_ne, mhtype_num, mhtype_num, MHA_LITERAL },
+ { "gt", builtin_gt, mhtype_num, mhtype_num, MHA_LITERAL },
+ { "match", builtin_match, mhtype_num, mhtype_str, MHA_LITERAL },
+ { "amatch", builtin_amatch, mhtype_num, mhtype_str, MHA_LITERAL },
+ { "plus", builtin_plus, mhtype_num, mhtype_num, MHA_LITERAL },
+ { "minus", builtin_minus, mhtype_num, mhtype_num, MHA_LITERAL },
+ { "divide", builtin_divide, mhtype_num, mhtype_num, MHA_LITERAL },
+ { "modulo", builtin_modulo, mhtype_num, mhtype_num, MHA_LITERAL },
+ { "num", builtin_num, mhtype_num, mhtype_num, MHA_LITERAL },
+ { "lit", builtin_lit, mhtype_str, mhtype_str, MHA_LITERAL },
+ { "getenv", builtin_getenv, mhtype_str, mhtype_str, MHA_LITERAL },
+ { "profile", builtin_profile, mhtype_str, mhtype_str, MHA_LITERAL },
{ "nonzero", builtin_nonzero, mhtype_num, mhtype_num, MHA_OPTARG },
{ "zero", builtin_zero, mhtype_num, mhtype_num, MHA_OPTARG },
{ "null", builtin_null, mhtype_num, mhtype_str, MHA_OPTARG },
@@ -1923,11 +1921,10 @@ mh_builtin_t builtin_tab[] = {
{ "ingrp", builtin_ingrp, mhtype_num, mhtype_str },
{ "gname", builtin_gname, mhtype_str, mhtype_str},
{ "formataddr", builtin_formataddr, mhtype_none, mhtype_str, MHA_OPTARG },
- { "putaddr", builtin_putaddr, mhtype_none, mhtype_str },
+ { "putaddr", builtin_putaddr, mhtype_none, mhtype_str, MHA_LITERAL },
{ "unre", builtin_unre, mhtype_str, mhtype_str },
{ "rcpt", builtin_rcpt, mhtype_num, mhtype_str },
- { "concat", builtin_concat, mhtype_none, mhtype_str, MHA_OPTARG },
- { "printhdr", builtin_printhdr, mhtype_none, mhtype_str },
+ { "printhdr", builtin_printhdr, mhtype_none, mhtype_str, MHA_LITERAL },
{ "in_reply_to", builtin_in_reply_to, mhtype_str, mhtype_none },
{ "references", builtin_references, mhtype_str, mhtype_none },
{ "package", builtin_package, mhtype_str, mhtype_none },
@@ -2030,7 +2027,7 @@ mh_format_dump_disass (mh_format_t fmt)
&prt));
pc += skip;
- printf ("setn %s, \"%s\"", regname[reg], prt);
+ printf ("sets %s, \"%s\"", regname[reg], prt);
free (prt);
}
break;
diff --git a/mh/mh_format.h b/mh/mh_format.h
index 32877c359..5d014e30b 100644
--- a/mh/mh_format.h
+++ b/mh/mh_format.h
@@ -120,10 +120,10 @@ struct mh_format
mu_opool_t pool;
};
-#define MHA_REQUIRED 0
-#define MHA_OPTARG 1
-#define MHA_OPT_CLEAR 2
-#define MHA_VOID 3
+#define MHA_DEFAULT 0
+#define MHA_OPTARG 0x1
+#define MHA_LITERAL 0x2
+#define MHA_VOID 0x4
typedef struct mh_builtin mh_builtin_t;
@@ -155,7 +155,8 @@ struct mh_machine
size_t width; /* Output line width */
size_t ind; /* Output line index */
mu_stream_t output; /* Output stream */
-
+ int flags;
+
mu_list_t addrlist; /* The list of email addresses output this far */
int fmtflags; /* Current formatting flags */
diff --git a/mh/mh_list.c b/mh/mh_list.c
index 56a552eec..1c54d1ed1 100644
--- a/mh/mh_list.c
+++ b/mh/mh_list.c
@@ -317,7 +317,6 @@ _destroy_value (enum mhl_datatype type, mhl_value_t *val)
case dt_format:
mh_format_free (val->fmt);
- free (val->fmt);
break;
default:
diff --git a/mh/repl.c b/mh/repl.c
index dd17ebb94..e1dca9681 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -227,7 +227,6 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
if (disp == DISP_REPLACE)
{
mu_stream_t str;
- char *buf;
rc = mu_file_stream_create (&str, wh->file,
MU_STREAM_WRITE|MU_STREAM_CREAT);
@@ -248,14 +247,12 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
mu_message_get_header (tmp_msg, &hdr);
text = mu_opool_finish (fcc_pool, NULL);
mu_header_set_value (hdr, MU_HEADER_FCC, text, 1);
- mh_format (&format, tmp_msg, msgno, width, &buf);
+ mh_format (str, format, tmp_msg, msgno, width, 0);
mu_message_destroy (&tmp_msg, NULL);
}
else
- mh_format (&format, msg, msgno, width, &buf);
+ mh_format (str, format, msg, msgno, width, 0);
- mu_stream_write (str, buf, strlen (buf), NULL);
-
if (mhl_filter)
{
mu_list_t filter = mhl_format_compile (mhl_filter);
@@ -266,7 +263,6 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
}
mu_stream_destroy (&str);
- free (buf);
}
{
@@ -306,7 +302,7 @@ main (int argc, char **argv)
if (!format_str)
format_str = default_format_str;
- if (mh_format_parse (format_str, &format))
+ if (mh_format_parse (&format, format_str, MH_FMT_PARSE_DEFAULT))
{
mu_error (_("Bad format string"));
exit (1);
diff --git a/mh/scan.c b/mh/scan.c
index f1cdcc419..3184faef4 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -106,7 +106,7 @@ main (int argc, char **argv)
mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
args_doc, prog_doc, NULL);
- if (mh_format_parse (format_str, &format))
+ if (mh_format_parse (&format, format_str, 0))
{
mu_error (_("Bad format string"));
exit (1);
@@ -214,14 +214,6 @@ clear_screen ()
static int
list_message (size_t num, mu_message_t msg, void *data)
{
- char *buffer;
- int len;
-
- mh_format (&format, msg, num, width, &buffer);
- printf ("%s", buffer);
- len = strlen (buffer);
- if (len > 0 && buffer[len-1] != '\n')
- printf("\n");
- free (buffer);
+ mh_format (mu_strout, format, msg, num, width, MH_FMT_FORCENL);
return 0;
}
diff --git a/mh/sortm.c b/mh/sortm.c
index 333634601..37ebcfba5 100644
--- a/mh/sortm.c
+++ b/mh/sortm.c
@@ -442,11 +442,8 @@ void
list_message (size_t num)
{
mu_message_t msg = NULL;
- char *buffer;
mu_mailbox_get_message (mbox, num, &msg);
- mh_format (&format, msg, num, width, &buffer);
- printf ("%s\n", buffer);
- free (buffer);
+ mh_format (mu_strout, format, msg, num, width, MH_FMT_FORCENL);
}
void
@@ -612,7 +609,8 @@ main (int argc, char **argv)
if (!oplist)
addop ("date", comp_date);
- if (action == ACTION_LIST && mh_format_parse (format_str, &format))
+ if (action == ACTION_LIST
+ && mh_format_parse (&format, format_str, MH_FMT_PARSE_DEFAULT))
{
mu_error (_("Bad format string"));
exit (1);

Return to:

Send suggestions and report system problems to the System administrator.