[Toybox] [CLEANUP] uudecode 838

Rob Landley rob at landley.net
Sat Jan 11 13:26:06 PST 2014


http://landley.net/hg/toybox/rev/838

Yank the "const" annotations.

uudecode_b64_1byte:

The old function had a giant (static) table, the new one is a set of 5 
if statements covering the same range. This includes removing a number 
of comments, because the if statements are reasonably self-explanatory 
in a way the table wasn't.

uudecode_b64_4bytes:

The old one had 4 separate calls to uudecode_b64_1byte, each reading a 
byte into 4 separate variables. Then it had individual tests for each 
variable not having fetched any data, then a line to bit shift and 
collate the 4 variables into one, and then a loop to output the 
converted data from that variable.

The new one has a single loop around the whole thing, the same sort of 
4/3 loop uuencode had. It loops 4 times, each time inputting a byte. 
Each input byte gets parsed by the same code (checking for "=" padding 
for length adjustment before trying to convert the value, and calling 
error_exit() if we expected a stanza and didn't get one), convert the 
data and shift it into place, and output a byte if we've got one. (Don't 
output a byte on the first cycle because we haven't filled up the first 
byte yet, we fetched 6 bits but need 8 before we can output anything. 
And don't output a byte if the length says we've input = characters 
indicating the end of the file and there aren't 3 full bytes to output 
this time.)

uudecode_uu_line:

Moving the while () to a for() with the test on the first line was 
mostly because it was late and I was grumpy. I don't like gcc's fussy 
"oh no, you can't have an assignment in a test, well you _can_ but put 
extra parentheses around it to show you _meant_ to do that because I 
don't trust you" warnings. (Hint: put the constant or function call on 
the left, then accidental assignments break. No need for the compiler to 
object to valid code.) I also don't like pointless tests for NULL when 
if (x) will already be true if x is nonzero, that's what tests in C 
MEAN. Between the two of them, I just chopped it into two lines to make 
that go away.

The '`' as the first character bit is odd. If you just ignore it, you 
get the right result.

Don't leak memory for the "end" line.

uudecode_main:

One more free(line) to avoid leaking memory.

 1389475566.0


More information about the Toybox mailing list