Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
1.1 KiB

  1. #include "fmt.h"
  2. #include "textcode.h"
  3. unsigned int fmt_yenc(char* dest,const char* src,unsigned int len) {
  4. register const unsigned char* s=(const unsigned char*) src;
  5. unsigned long written=0,i;
  6. int linelen=0;
  7. for (i=0; i<len; ++i) {
  8. unsigned char c=s[i]+42;
  9. switch (c) {
  10. case ' ': /* escape space at line ending */
  11. if (linelen==253) {
  12. if (dest) dest[written]='\n'; ++written; linelen=0;
  13. }
  14. goto dontescape;
  15. case 'F': /* escape "^From " */
  16. if (s[i+1]+42!='r' || s[i+2]+42!='o' || s[i+3]+42!='m' || s[i+4]+42!=' ') goto dontescape;
  17. case '.': /* dot at start of line needs to be escaped */
  18. if (!linelen) goto dontescape;
  19. /* fall through */
  20. case 0:
  21. case '\n':
  22. case '\r':
  23. case '=':
  24. if (dest) dest[written]='='; ++written;
  25. c+=64;
  26. /* fall through */
  27. default:
  28. dontescape:
  29. ++linelen;
  30. if (dest) dest[written]=c; ++written;
  31. if (linelen>253) {
  32. if (dest) dest[written]='\n'; ++written; linelen=0;
  33. }
  34. }
  35. }
  36. if (linelen) {
  37. if (dest) dest[written]='\n'; ++written; linelen=0;
  38. }
  39. return written;
  40. }