[Top][All Lists]

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

Re: [Nmh-workers] repl*comps and and non-ascii characters

From: Peter Maydell
Subject: Re: [Nmh-workers] repl*comps and and non-ascii characters
Date: Sun, 03 Aug 2008 13:25:17 +0100

Eric Gillespie wrote:
>Glad to hear it.  When you do, you'll need this decode fix.  Or,
>as I admitted earlier, some other fix.  I admit to not fully
>understanding fmt_scan.c...

I've done some more investigation, and the problem seems to be wider
in scope than merely decode -- the %< (if) construct thinks that all
functions return a numeric value, so a line like this:

X-yzzy: %<(getenv FOO) found%|missing%>

will always result in "X-yzzy: missing" even if the environment variable
FOO is set.

The mh-format(5) manpage says:

# For integer valued functions or components, the condition is true if
# the function return or component value is non-zero, and false if zero.
# For string valued functions or components, the condition is true if
# the function return or component value is a non-empty string, and
# false for an empty string.

which sounds like the right behaviour but isn't what the code does.

So I think the bug here is that fmt_compile.c:do_if() needs to
distinguish functions which set value from ones which set str, and
output an FT_IF_V_NE or FT_IF_S appropriately.

This is the patch I'm going to commit to CVS to fix this. It seems
to make Eric's test case pass OK. (One issue with that test case is
that it relies on the en_US.utf8 locale existing, or it fails. So since
the bug isn't actually decode-specific I might do a test case using
getenv instead to sidestep the locale issue.)

--- sbr/fmt_compile.c.orig      2008-08-03 12:58:54.000000000 +0100
+++ sbr/fmt_compile.c   2008-08-03 13:02:53.000000000 +0100
@@ -53,6 +53,9 @@
 #define        TF_NOP     8        /* like expr but no result            */
 /* ftable->flags */
+/* NB that TFL_PUTS is also used to decide whether the test
+ * in a "%<(function)..." should be a string or numeric one.
+ */
 #define        TFL_PUTS   1        /* implicit putstr if top level */
 #define        TFL_PUTN   2        /* implicit putnum if top level */
@@ -610,7 +613,14 @@
                if (ftbl->f_type >= IF_FUNCS)
                    fp->f_type = ftbl->extra;
                else {
-                   LV (FT_IF_V_NE, 0);
+                   /* Put out a string test or a value test depending
+                    * on what this function's return type is.
+                    */
+                   if (ftbl->flags & TFL_PUTS) {
+                       LV (FT_IF_S, 0);
+                   } else {
+                       LV (FT_IF_V_NE, 0);
+                   }
            else {

-- PMM

reply via email to

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