nmh-workers
[Top][All Lists]
Advanced

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

Re: [Nmh-workers] corruption when attaching all-null files


From: Ralph Corderoy
Subject: Re: [Nmh-workers] corruption when attaching all-null files
Date: Wed, 21 May 2014 13:30:10 +0100

Hi Paul,

Sorry for the delay in replying, moving house...

> > >         case CT_TEXT:
> > >             if (contains8bit && !containsnul && !linelen && !linespace && 
> > > !checksw)
> > >                 ct->c_encoding = CE_8BIT;
> > >             else if (contains8bit || containsnul || linelen || linespace 
> > > || checksw)
> > >                 ct->c_encoding = CE_QUOTED;
> > >             else
> > >                 ct->c_encoding = CE_7BIT;
> > >             break;
> >
> >     case CT_TEXT:
> >         if (contains8bit)
> >             ct->c_encoding = (containsnul || linelen || linespace || 
> > checksw) ?
> >                 CE_QUOTED : CE_8BIT;
> >         else
> >             ct->c_encoding = CE_7BIT;
>
> i agree that the logic is cumbersome, but that doesn't look like a
> correct translation to me.  how about this:
>
>       needs_q_p = (containsnul || linelen || linespace || checksw);
>       case CT_TEXT:
>           if (needs_q_p)
>                  ct->c_encoding = CE_QUOTED;
>           else if (contains8bit)
>                  ct->c_encoding = CE_8BIT;
>           else
>                  ct->c_encoding = CE_7BIT;

I agree, mine was wrong, yours is correct and better expressed than the
original.  I blame sticking my oar in when I didn't have the time.  :-)
Out of interest, I followed Thompson's advice of "When in doubt, use
brute force";  it might entertain.

    $ gen() { b=$((2**5)) && seq $b $((2 * b - 1)) | sed 's/$/pc/; 1s/^/2o/' |
    >     dc | sed 's/./ &/g; s/...//'; }
    $
    $ assign='{contains8bit = $1; containsnul = $2; linelen = $3;
    >     linespace = $4; checksw = $5}'
    $ print='{print $0, c_encoding}'
    $
    $ orig='
    >     {
    >         if (contains8bit && !containsnul && !linelen && !linespace && 
!checksw)
    >             c_encoding = "CE_8BIT"
    >         else if (contains8bit || containsnul || linelen || linespace || 
checksw)
    >             c_encoding = "CE_QUOTED"
    >         else
    >             c_encoding = "CE_7BIT"
    >     }
    > '
    $
    $ ralph='
    >     {
    >         if (contains8bit)
    >             c_encoding = (containsnul || linelen || linespace || checksw) 
?
    >                 "CE_QUOTED" : "CE_8BIT"
    >         else
    >             c_encoding = "CE_7BIT"
    >     }
    > '
    $
    $ paul='
    >     {
    >         if (containsnul || linelen || linespace || checksw)
    >             c_encoding = "CE_QUOTED"
    >         else if (contains8bit)
    >             c_encoding = "CE_8BIT"
    >         else
    >             c_encoding = "CE_7BIT"
    >     }
    > '
    $
    $ gen | awk "$assign $orig $print"
    0 0 0 0 0 CE_7BIT
    0 0 0 0 1 CE_QUOTED
    0 0 0 1 0 CE_QUOTED
    0 0 0 1 1 CE_QUOTED
    0 0 1 0 0 CE_QUOTED
    0 0 1 0 1 CE_QUOTED
    0 0 1 1 0 CE_QUOTED
    0 0 1 1 1 CE_QUOTED
    0 1 0 0 0 CE_QUOTED
    0 1 0 0 1 CE_QUOTED
    0 1 0 1 0 CE_QUOTED
    0 1 0 1 1 CE_QUOTED
    0 1 1 0 0 CE_QUOTED
    0 1 1 0 1 CE_QUOTED
    0 1 1 1 0 CE_QUOTED
    0 1 1 1 1 CE_QUOTED
    1 0 0 0 0 CE_8BIT
    1 0 0 0 1 CE_QUOTED
    1 0 0 1 0 CE_QUOTED
    1 0 0 1 1 CE_QUOTED
    1 0 1 0 0 CE_QUOTED
    1 0 1 0 1 CE_QUOTED
    1 0 1 1 0 CE_QUOTED
    1 0 1 1 1 CE_QUOTED
    1 1 0 0 0 CE_QUOTED
    1 1 0 0 1 CE_QUOTED
    1 1 0 1 0 CE_QUOTED
    1 1 0 1 1 CE_QUOTED
    1 1 1 0 0 CE_QUOTED
    1 1 1 0 1 CE_QUOTED
    1 1 1 1 0 CE_QUOTED
    1 1 1 1 1 CE_QUOTED
    $
    $ gen | awk "$assign $ralph $print"
    0 0 0 0 0 CE_7BIT
    0 0 0 0 1 CE_7BIT
    0 0 0 1 0 CE_7BIT
    0 0 0 1 1 CE_7BIT
    0 0 1 0 0 CE_7BIT
    0 0 1 0 1 CE_7BIT
    0 0 1 1 0 CE_7BIT
    0 0 1 1 1 CE_7BIT
    0 1 0 0 0 CE_7BIT
    0 1 0 0 1 CE_7BIT
    0 1 0 1 0 CE_7BIT
    0 1 0 1 1 CE_7BIT
    0 1 1 0 0 CE_7BIT
    0 1 1 0 1 CE_7BIT
    0 1 1 1 0 CE_7BIT
    0 1 1 1 1 CE_7BIT
    1 0 0 0 0 CE_8BIT
    1 0 0 0 1 CE_QUOTED
    1 0 0 1 0 CE_QUOTED
    1 0 0 1 1 CE_QUOTED
    1 0 1 0 0 CE_QUOTED
    1 0 1 0 1 CE_QUOTED
    1 0 1 1 0 CE_QUOTED
    1 0 1 1 1 CE_QUOTED
    1 1 0 0 0 CE_QUOTED
    1 1 0 0 1 CE_QUOTED
    1 1 0 1 0 CE_QUOTED
    1 1 0 1 1 CE_QUOTED
    1 1 1 0 0 CE_QUOTED
    1 1 1 0 1 CE_QUOTED
    1 1 1 1 0 CE_QUOTED
    1 1 1 1 1 CE_QUOTED
    $
    $ gen | awk "$assign $orig $print" | sha1sum
    cc11d1f3c3f048242a134f0f54e434c6662878d7  -
    $ gen | awk "$assign $paul $print" | sha1sum
    cc11d1f3c3f048242a134f0f54e434c6662878d7  -
    $

Cheers, Ralph.



reply via email to

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