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.
 
 
 
 

37 lines
883 B

  1. #include "fmt.h"
  2. #include "textcode.h"
  3. #include "haveinline.h"
  4. static inline unsigned int enc(unsigned char x) {
  5. return ((x-1)&077)+'!';
  6. }
  7. unsigned int fmt_uuencoded(char* dest,const char* src,unsigned int len) {
  8. unsigned int i;
  9. register const unsigned char* s=(const unsigned char*) src;
  10. const char* orig=dest;
  11. unsigned long tmp;
  12. while (len) {
  13. {
  14. register unsigned int diff;
  15. if (len>45) { i=15; diff=45; } else { i=(len+2)/3; diff=len; }
  16. if (orig) *dest=enc(diff); ++dest;
  17. len-=diff;
  18. }
  19. for (; i; --i) {
  20. tmp=((unsigned long)s[0] << 16) +
  21. ((unsigned long)s[1] << 8) +
  22. ((unsigned long)s[2]);
  23. if (orig) {
  24. dest[0]=enc((tmp>>(3*6))&077);
  25. dest[1]=enc((tmp>>(2*6))&077);
  26. dest[2]=enc((tmp>>(1*6))&077);
  27. dest[3]=enc(tmp&077);
  28. }
  29. dest+=4; s+=3;
  30. }
  31. if (orig) *dest='\n'; ++dest;
  32. }
  33. return dest-orig;
  34. }