diff --git a/test/buffer_1.c b/test/buffer_1.c new file mode 100644 index 0000000..15ee957 --- /dev/null +++ b/test/buffer_1.c @@ -0,0 +1,16 @@ +#include "buffer.h" + +main() { + buffer_puts(buffer_1,"ulong: "); + buffer_putulong(buffer_1,23); + buffer_puts(buffer_1,"\nlong: "); + buffer_putlong(buffer_1,-23); + buffer_puts(buffer_1,"\n8long: "); + buffer_put8long(buffer_1,23); + buffer_puts(buffer_1,"\nxlong:"); + buffer_putspace(buffer_1); + buffer_putxlong(buffer_1,23); + buffer_putsflush(buffer_1,"\n"); + buffer_putsalign(buffer_1,"aligned\n"); + buffer_flush(buffer_1); +} diff --git a/test/uudecode.c b/test/uudecode.c new file mode 100644 index 0000000..ce00cd0 --- /dev/null +++ b/test/uudecode.c @@ -0,0 +1,45 @@ +#include +#include "textcode.h" +#include "str.h" +#include "buffer.h" + +int main(int argc,char* argv[]) { + char buf[4096]; + buffer filein; + int fd=1; + if (argc>1) { + fd=open_read(argv[1]); + if (fd<0) { + buffer_puts(buffer_2,"error: could not open \""); + buffer_puts(buffer_2,argv[1]); + buffer_putsflush(buffer_2,"\"\n"); + return 1; + } + } + buffer_init(&filein,read,fd,buf,sizeof buf); + /* skip to "^begin " */ + for (;;) { + char line[1000]; /* uuencoded lines can never be longer than 64 characters */ + int l; + if ((l=buffer_getline(&filein,line,(sizeof line)-1))==0) { + buffer_putsflush(buffer_2,"warning: hit end of file without finding any uuencoded data!\n"); + return 0; + } + if (l>0 && buf[l-1]=='\r') --l; /* kill DOS line endings */ + buf[l]=0; + if (!str_diffn(line,"begin ",6)) break; + } + /* read uuencoded lines */ + for (;;) { + char line[1000]; /* uuencoded lines can never be longer than 64 characters */ + int l; + if ((l=buffer_getline(&filein,line,(sizeof line)-1))==0) { + buffer_putsflush(buffer_2,"warning: hit end of file without finding \"end\"!\n"); + return 0; + } + if (l>0 && buf[l-1]=='\r') --l; /* kill DOS line endings */ + buf[l]=0; + if (!str_diffn(line,"begin ",6)) break; + } + /* TODO */ +} diff --git a/textcode.h b/textcode.h index 10afe6d..15e9c07 100644 --- a/textcode.h +++ b/textcode.h @@ -18,4 +18,6 @@ unsigned int scan_quotedprintable(const char *src,char *dest,unsigned int *destl unsigned int scan_urlencode(const char *src,char *dest,unsigned int *destlen); unsigned int scan_yenc(const char *src,char *dest,unsigned int *destlen); +extern const char base64[64]; + #endif diff --git a/textcode/base64.c b/textcode/base64.c new file mode 100644 index 0000000..fc16d64 --- /dev/null +++ b/textcode/base64.c @@ -0,0 +1 @@ +const char base64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; diff --git a/textcode/fmt_base64.c b/textcode/fmt_base64.c new file mode 100644 index 0000000..b0d2846 --- /dev/null +++ b/textcode/fmt_base64.c @@ -0,0 +1,27 @@ +#include "fmt.h" +#include "textcode.h" +#include "haveinline.h" + +static inline unsigned int enc(unsigned char x) { + return ((x-1)&077)+'!'; +} + +unsigned int fmt_base64(char* dest,const char* src,unsigned int len) { + register const unsigned char* s=(const unsigned char*) src; + unsigned short bits=0,temp=0; + unsigned long written=0,i; + for (i=0; i6) { + if (dest) dest[written]=base64[((temp>>(bits-6))&63)]; + ++written; bits-=6; + } + } + if (bits) { + temp<<=(6-bits); + if (dest) dest[written]=base64[temp&63]; + ++written; + } + while (written&3) { if (dest) dest[written]='='; ++written; } + return written; +}