On 16-Mar-00 Fitzpatrick, Joe wrote:
> UUEncoding is pretty trivial. Here is a routine to UUEncode and a
> routine to calculate the destination size so you can allocate a buffer.
Here is also a base64 function. You call it with three byte multiples unless
you want it padded, i.e. as the last line of the transmission.
char base64[]=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ ";
/*
* This is just a queue structure that I use to hold outgoing data.
*/
struct ssq {
char *sendq;
short sendqin, sendqout;
};
/*
* This encodes with base-64 as it sticks data into the queue. Make sure
* you call it with 3 byte multiples, unless you want it padded -- like at
* the end of a transmission. Also this must be guaranteed to fit in the
* sendq.. so you must've known to check if 4/3 * len will fit.
*/
short writeallb64(struct ssq *sq, char *str, short len)
{
short i1, i2;
unsigned long l1, l2, l3;
i1 = MIN(SENDQSIZE-sq->sendqin, len);
if (i1 <= 0) return 0;
for (i2=0; i2 <= (len-3); i2=i2+3) {
l1 = str[i2] & 0xff;
l2 = str[i2+1] & 0xff;
l3 = str[i2+2] & 0xff;
l1 = (l1 << 16)|(l2 << 8)|l3;
sq->sendq[sq->sendqin++] = base64[(l1 >> 18) & 0x3f];
sq->sendq[sq->sendqin++] = base64[(l1 >> 12) & 0x3f];
sq->sendq[sq->sendqin++] = base64[(l1 >> 6) & 0x3f];
sq->sendq[sq->sendqin++] = base64[l1 & 0x3f];
}
/* pad the remainder with = */
switch(len % 3) {
case 2:
l1 = str[len-2] & 0xff;
l2 = str[len-1] & 0xff;
l1 = (l1 << 8)|l2;
sq->sendq[sq->sendqin++] = base64[(l1 >> 10) & 0x3f];
sq->sendq[sq->sendqin++] = base64[(l1 >> 4) & 0x3f];
sq->sendq[sq->sendqin++] = base64[(l1 << 2) & 0x3c];
sq->sendq[sq->sendqin++] = '=';
break;
case 1:
l1 = str[len-1] & 0xff;
sq->sendq[sq->sendqin++] = base64[(l1 >> 2) & 0x3f];
sq->sendq[sq->sendqin++] = base64[(l1 << 4) & 0x30];
sq->sendq[sq->sendqin++] = '=';
sq->sendq[sq->sendqin++] = '=';
}
return len;
}
If you want the entire code (it makes headers and does SMTP mailing etc):
http://rallypilot.sourceforge.net
/* Chris Faherty <[EMAIL PROTECTED]> */
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html