summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2017-07-07 22:34:09 +0300
committerSergey Poznyakoff <gray@gnu.org>2017-07-07 22:34:09 +0300
commit7fd25e1edf24dc4ba173b5d05021fd0dbcc2f07c (patch)
treeab22f2638a4f4fc9b5a5fcd99f89fc624191a85b
parent3360c4365757404cabb34895b3b77851d0266ce4 (diff)
downloadmailutils-7fd25e1edf24dc4ba173b5d05021fd0dbcc2f07c.tar.gz
mailutils-7fd25e1edf24dc4ba173b5d05021fd0dbcc2f07c.tar.bz2
Bugfixes in MH format code generator
* mh/mh_fmtgram.y (mh_read_formfile): Remove only the last trailing newline. (codegen_node): Don't emit spurious clear register statements at the end of the "else" branch. Optimize if no "else" branch is present. * mh/mh_format.c (mh_fvm_run) <mhop_brzn, mhop_brzs>: Leave the result of condition evaluation in num. (builtin_tab): rcpt takes literal argument. * mh/scan.c (action): Remove unused argument. * mh/tests/fmtcomp.at: Update the "if-else" test.
-rw-r--r--mh/mh_fmtgram.y27
-rw-r--r--mh/mh_format.c26
-rw-r--r--mh/scan.c1
-rw-r--r--mh/tests/fmtcomp.at5
4 files changed, 28 insertions, 31 deletions
diff --git a/mh/mh_fmtgram.y b/mh/mh_fmtgram.y
index 4b03d6090..2d2ffc70a 100644
--- a/mh/mh_fmtgram.y
+++ b/mh/mh_fmtgram.y
@@ -1004,7 +1004,8 @@ mh_read_formfile (char const *name, char **pformat)
free (file_name);
format_str[st.st_size] = 0;
- mu_rtrim_class (format_str, MU_CTYPE_ENDLN);
+ if (format_str[st.st_size-1] == '\n')
+ format_str[st.st_size-1] = 0;
fclose (fp);
*pformat = format_str;
return 0;
@@ -1564,27 +1565,19 @@ codegen_node (struct mh_format *fmt, struct node *node)
{
codegen_nodelist (fmt, node->v.cntl.iftrue);
}
- emit_opcode (fmt, mhop_branch);
- pc[1] = fmt->progcnt;
- emit_instr (fmt, (mh_instr_t) NULL);
-
- fmt->prog[pc[0]].num = fmt->progcnt - pc[0];
+
if (node->v.cntl.iffalse)
{
+ emit_opcode (fmt, mhop_branch);
+ pc[1] = fmt->progcnt;
+ emit_instr (fmt, (mh_instr_t) NULL);
+
+ fmt->prog[pc[0]].num = fmt->progcnt - pc[0];
codegen_nodelist (fmt, node->v.cntl.iffalse);
+ fmt->prog[pc[1]].num = fmt->progcnt - pc[1];
}
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];
+ fmt->prog[pc[0]].num = fmt->progcnt - pc[0];
}
break;
diff --git a/mh/mh_format.c b/mh/mh_format.c
index ee0f87378..9a4b07fc7 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -502,17 +502,25 @@ mh_fvm_run (mh_fvm_t mach, mu_message_t msg)
break;
case mhop_brzn:
- if (!mach->num[R_REG])
- mach->pc += MHI_NUM (mach->prog[mach->pc]);
- else
- mach->pc++;
+ {
+ int res = mach->num[R_REG] == 0;
+ if (res)
+ mach->pc += MHI_NUM (mach->prog[mach->pc]);
+ else
+ mach->pc++;
+ mach->num[R_REG] = !res;
+ }
break;
case mhop_brzs:
- if (mh_string_is_null (&mach->str[R_REG]))
- mach->pc += MHI_NUM (mach->prog[mach->pc]);
- else
- mach->pc++;
+ {
+ int res = mh_string_is_null (&mach->str[R_REG]);
+ if (res)
+ mach->pc += MHI_NUM (mach->prog[mach->pc]);
+ else
+ mach->pc++;
+ mach->num[R_REG] = !res;
+ }
break;
case mhop_setn:
@@ -1855,7 +1863,7 @@ mh_builtin_t builtin_tab[] = {
{ "formataddr", builtin_formataddr, mhtype_none, mhtype_str, MHA_ACC },
{ "putaddr", builtin_putaddr, mhtype_none, mhtype_str, MHA_LITERAL },
{ "unre", builtin_unre, mhtype_str, mhtype_str },
- { "rcpt", builtin_rcpt, mhtype_num, mhtype_str },
+ { "rcpt", builtin_rcpt, mhtype_num, mhtype_str, MHA_LITERAL },
{ "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 },
diff --git a/mh/scan.c b/mh/scan.c
index 7ff2519ef..1a664e022 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -82,7 +82,6 @@ action (mu_observer_t o, size_t type, void *data, void *action_data)
static int counter;
mu_mailbox_t mbox;
mu_message_t msg = NULL;
- size_t num;
if (type == MU_EVT_MESSAGE_ADD)
{
diff --git a/mh/tests/fmtcomp.at b/mh/tests/fmtcomp.at
index b0be1a20d..5b4694c2a 100644
--- a/mh/tests/fmtcomp.at
+++ b/mh/tests/fmtcomp.at
@@ -170,10 +170,7 @@ FI
ldcomp reg, "replied"
brzs L1
printlit "-"
- branch L2
-L1: setn reg, 0
- sets reg, ""
-L2: stop
+L1: stop
],[],[-format])
FMTCOMP([if-else],

Return to:

Send suggestions and report system problems to the System administrator.