diff --git a/CHANGES b/CHANGES index fb12860..d8ceea7 100644 --- a/CHANGES +++ b/CHANGES @@ -1,10 +1,6 @@ 0.12: add textcode api for uuencode/uudecode, base64, quoted printable, url-encoding and yenc. - implement fmt_uuencoded and scan_uuencoded. - implement fmt_base64, scan_base64. - implement fmt_quotedprintable, scan_quotedprintable - implement fmt_urlencoded, scan_urlencoded 0.11: fix fmt_long (didn't count the '-'), which in turn broke diff --git a/t.c b/t.c index 5f39e6b..e412b58 100644 --- a/t.c +++ b/t.c @@ -17,19 +17,30 @@ __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx") int main(int argc,char* argv[]) { + unsigned long size; + char* buf=mmap_read(argv[1],&size); + if (buf) { + unsigned int x=fmt_yenc(0,buf,size); + unsigned int y; + char* tmp=malloc(x+1); + y=fmt_yenc(tmp,buf,size); + write(1,tmp,x); + } +#if 0 char buf[100]; char buf2[100]; unsigned int len,len2; - buf[fmt_urlencoded(buf,"http://localhost/~fefe",22)]=0; + buf[fmt_yenc(buf,"http://localhost/~fefe",22)]=0; buffer_puts(buffer_1,buf); buffer_putsflush(buffer_1,"\n"); - if ((buf[len2=scan_urlencoded(buf,buf2,&len)])!=0) { + if ((buf[len2=scan_yenc(buf,buf2,&len)])!='\n') { buffer_putsflush(buffer_2,"parse error!\n"); return 1; } buffer_put(buffer_1,buf2,len2); buffer_putsflush(buffer_1,"\n"); return 0; +#endif #if 0 char buf[100]; char buf2[100]; diff --git a/textcode/fmt_yenc.c b/textcode/fmt_yenc.c new file mode 100644 index 0000000..4b91ca8 --- /dev/null +++ b/textcode/fmt_yenc.c @@ -0,0 +1,41 @@ +#include "fmt.h" +#include "textcode.h" + +unsigned int fmt_yenc(char* dest,const char* src,unsigned int len) { + register const unsigned char* s=(const unsigned char*) src; + unsigned long written=0,i; + int linelen=0; + for (i=0; i253) { + if (dest) dest[written]='\n'; ++written; linelen=0; + } + } + } + if (linelen) { + if (dest) dest[written]='\n'; ++written; linelen=0; + } + return written; +} diff --git a/textcode/scan_yenc.c b/textcode/scan_yenc.c new file mode 100644 index 0000000..b199f7c --- /dev/null +++ b/textcode/scan_yenc.c @@ -0,0 +1,20 @@ +#include "fmt.h" +#include "textcode.h" + +unsigned int scan_yenc(const char *src,char *dest,unsigned int *destlen) { + register const unsigned char* s=(const unsigned char*) src; + unsigned long written=0,i; + for (i=0; s[i]; ++i) { + if (s[i]=='=') { + ++i; + if (s[i]=='y') break; + dest[written]=s[i]-64-42; + } else if (s[i]=='\n' || s[i]=='\r' || s[i]=='\0') + break; + else + dest[written]=s[i]-42; + ++written; + } + *destlen=written; + return i; +}