diff --git a/CHANGES b/CHANGES index f2bdae9..6037cd8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +0.12: + add textcode api for uuencode/uudecode, base64, quoted printable, + url-encoding and yenc. + implement fmt_uuencoded and scan_uuencoded. + 0.11: fix fmt_long (didn't count the '-'), which in turn broke buffer_putlong diff --git a/Makefile b/Makefile index 63b291d..4fc93c9 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ MAN3DIR=${prefix}/man/man3 all: t byte.a fmt.a scan.a str.a uint.a open.a stralloc.a unix.a socket.a buffer.a mmap.a libowfat.a -VPATH=str:byte:fmt:scan:uint:open:stralloc:unix:socket:buffer:mmap +VPATH=str:byte:fmt:scan:uint:open:stralloc:unix:socket:buffer:mmap:textcode # comment out the following line if you don't want to build with the # diet libc (http://www.fefe.de/dietlibc/). @@ -25,6 +25,7 @@ UNIX_OBJS=$(patsubst unix/%.c,%.o,$(wildcard unix/*.c)) SOCKET_OBJS=$(patsubst socket/%.c,%.o,$(wildcard socket/*.c)) BUFFER_OBJS=$(patsubst buffer/%.c,%.o,$(wildcard buffer/*.c)) MMAP_OBJS=$(patsubst mmap/%.c,%.o,$(wildcard mmap/*.c)) +TEXTCODE_OBJS=$(patsubst textcode/%.c,%.o,$(wildcard textcode/*.c)) $(BYTE_OBJS): byte.h $(FMT_OBJS): fmt.h @@ -35,6 +36,7 @@ $(STRA_OBJS): stralloc.h $(SOCKET_OBJS): socket.h $(BUFFER_OBJS): buffer.h $(MMAP_OBJS): mmap.h +$(TEXTCODE_OBJS): textcode.h byte.a: $(BYTE_OBJS) fmt.a: $(FMT_OBJS) @@ -47,10 +49,11 @@ unix.a: $(UNIX_OBJS) socket.a: $(SOCKET_OBJS) buffer.a: $(BUFFER_OBJS) mmap.a: $(MMAP_OBJS) +textcode.a: $(TEXTCODE_OBJS) libowfat.a: $(BYTE_OBJS) $(FMT_OBJS) $(SCAN_OBJS) $(STR_OBJS) \ $(UINT_OBJS) $(OPEN_OBJS) $(STRA_OBJS) $(UNIX_OBJS) $(SOCKET_OBJS) \ -$(BUFFER_OBJS) $(MMAP_OBJS) +$(BUFFER_OBJS) $(MMAP_OBJS) $(TEXTCODE_OBJS) %.o: %.c $(DIET) $(CC) -c $< -o $@ $(CFLAGS) @@ -60,7 +63,7 @@ $(BUFFER_OBJS) $(MMAP_OBJS) -ranlib $@ t: t.o socket.a stralloc.a buffer.a scan.a uint.a mmap.a open.a fmt.a \ -str.a byte.a +str.a byte.a textcode.a $(DIET) $(CC) -g -o $@ $^ .PHONY: clean tar install rename @@ -112,4 +115,4 @@ socket_accept4.o socket_accept6.o socket_connected.o socket_local4.o \ socket_local6.o socket_recv4.o socket_recv6.o socket_remote4.o \ socket_remote6.o: havesl.h -fmt_xlong.o scan_xlong.o fmt_ip6_flat.o: haveinline.h +fmt_xlong.o scan_xlong.o fmt_ip6_flat.o $(TEXTCODE_OBJS): haveinline.h diff --git a/t.c b/t.c index 0bf1fa0..6dbc76f 100644 --- a/t.c +++ b/t.c @@ -9,6 +9,7 @@ #include "ip4.h" #include "mmap.h" #include "open.h" +#include "textcode.h" #include #include @@ -16,10 +17,48 @@ __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx") int main(int argc,char* argv[]) { + unsigned long size; + char* buf=mmap_read(argv[1],&size); + if (buf) { + const char* c=buf; + const char* max=buf+size; + while (c45) { i=15; diff=45; } else { i=(len+2)/3; diff=len; } + if (orig) *dest=enc(diff); ++dest; + len-=diff; + } + for (; i; --i) { + tmp=((unsigned long)s[0] << 16) + + ((unsigned long)s[1] << 8) + + ((unsigned long)s[2]); + if (orig) { + dest[0]=enc((tmp>>(3*6))&077); + dest[1]=enc((tmp>>(2*6))&077); + dest[2]=enc((tmp>>(1*6))&077); + dest[3]=enc(tmp&077); + } + dest+=4; s+=3; + } + if (orig) *dest='\n'; ++dest; + } + return dest-orig; +} diff --git a/textcode/scan_uuencoded.c b/textcode/scan_uuencoded.c new file mode 100644 index 0000000..245a3ba --- /dev/null +++ b/textcode/scan_uuencoded.c @@ -0,0 +1,24 @@ +#include "textcode.h" +#include "haveinline.h" + +unsigned int scan_uuencoded(const char *src,char *dest,unsigned int *destlen) { + unsigned int len; + unsigned long tmp; + register const unsigned char* s=(const unsigned char*) src; + const char* orig=dest; + if ((len=*s-' ')>64) return 0; + ++s; + while (len>0) { + if (s[0]-' '>64 || s[1]-' '>64 || s[2]-' '>64 || s[3]-' '>64) return 0; + tmp=(((s[0]-' ')&077) << (3*6)) + + (((s[1]-' ')&077) << (2*6)) + + (((s[2]-' ')&077) << (1*6)) + + (((s[3]-' ')&077)); + s+=4; + if (len) { *dest=tmp>>16; ++dest; --len; } + if (len) { *dest=tmp>>8; ++dest; --len; } + if (len) { *dest=tmp&0xff; ++dest; --len; } + } + *destlen=dest-orig; + return (const char*)s-src; +}