master
leitner 23 years ago
parent f688af068b
commit e0437a77ff

@ -1,10 +1,6 @@
0.12: 0.12:
add textcode api for uuencode/uudecode, base64, quoted printable, add textcode api for uuencode/uudecode, base64, quoted printable,
url-encoding and yenc. 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: 0.11:
fix fmt_long (didn't count the '-'), which in turn broke fix fmt_long (didn't count the '-'), which in turn broke

15
t.c

@ -17,19 +17,30 @@
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx") __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
int main(int argc,char* argv[]) { 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 buf[100];
char buf2[100]; char buf2[100];
unsigned int len,len2; 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_puts(buffer_1,buf);
buffer_putsflush(buffer_1,"\n"); 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"); buffer_putsflush(buffer_2,"parse error!\n");
return 1; return 1;
} }
buffer_put(buffer_1,buf2,len2); buffer_put(buffer_1,buf2,len2);
buffer_putsflush(buffer_1,"\n"); buffer_putsflush(buffer_1,"\n");
return 0; return 0;
#endif
#if 0 #if 0
char buf[100]; char buf[100];
char buf2[100]; char buf2[100];

@ -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; i<len; ++i) {
unsigned char c=s[i]+42;
switch (c) {
case ' ': /* escape space at line ending */
if (linelen==253) {
if (dest) dest[written]='\n'; ++written; linelen=0;
}
goto dontescape;
case 'F': /* escape "^From " */
if (s[i+1]+42!='r' || s[i+2]+42!='o' || s[i+3]+42!='m' || s[i+4]+42!=' ') goto dontescape;
case '.': /* dot at start of line needs to be escaped */
if (!linelen) goto dontescape;
/* fall through */
case 0:
case '\n':
case '\r':
case '=':
if (dest) dest[written]='='; ++written;
c+=64;
/* fall through */
default:
dontescape:
++linelen;
if (dest) dest[written]=c; ++written;
if (linelen>253) {
if (dest) dest[written]='\n'; ++written; linelen=0;
}
}
}
if (linelen) {
if (dest) dest[written]='\n'; ++written; linelen=0;
}
return written;
}

@ -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;
}
Loading…
Cancel
Save