ralph wrote:
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.
nice! i'm pretty sure i would not have thought of testing C code
by running it through an awk interpreter. :-)
fyi, i committed my version sometime last week, after taking a slightly
different approach to verifying correctness. i presented the three
versions to my wife as a code review challenge. ;-)
paul
$ 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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 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.
_______________________________________________
Nmh-workers mailing list
Nmh-workers(_at_)nongnu(_dot_)org
https://lists.nongnu.org/mailman/listinfo/nmh-workers
=----------------------
paul fox, pgf(_at_)foxharp(_dot_)boston(_dot_)ma(_dot_)us (arlington, ma,
where it's 56.8 degrees)
_______________________________________________
Nmh-workers mailing list
Nmh-workers(_at_)nongnu(_dot_)org
https://lists.nongnu.org/mailman/listinfo/nmh-workers