add yenc
parent
f688af068b
commit
e0437a77ff
@ -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…
Reference in New Issue