uucode.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <sprog.h>
  2. #include <uucode.h>
  3. /* aaaa aa|aa bbbb|bbbb cc|cc cccc */
  4. int uuencode_line(const struct sprog_data *d, char *dst, int *offset, int *checksum) {
  5. char srcbuf[64];
  6. unsigned char sum;
  7. char *dstd;
  8. int b;
  9. int i;
  10. b = d->size - *offset;
  11. if(b>45) b = 45;
  12. sum = 0;
  13. for(i=0; i<b; i++) {
  14. srcbuf[i] = d->data[*offset + i];
  15. sum += srcbuf[i];
  16. *checksum += srcbuf[i];
  17. }
  18. for(i=0; i<(b & (4-1)); i++)
  19. srcbuf[b+i] = 0;
  20. dst[0] = ' ' + b;
  21. dstd = &dst[1];
  22. for(i=0; i<b; i+=3) {
  23. dstd[0] = srcbuf[i]>>2;
  24. dstd[1] = srcbuf[i]<<4 | srcbuf[i+1]>>4;
  25. dstd[2] = srcbuf[i+1]<<2 | srcbuf[i+2]>>6;
  26. dstd[3] = srcbuf[i];
  27. dstd += 4;
  28. }
  29. dstd[0] = sum;
  30. dstd[1] = 0;
  31. for(i=0; i<b+2; i++) {
  32. dst[i] &= 0x3f;
  33. if(dst[i])
  34. dst[i] += ' ';
  35. else
  36. dst[i] = '`';
  37. }
  38. if(*offset >= d->size)
  39. return 0;
  40. *offset += b;
  41. return 1;
  42. }
  43. void uudecode_line(struct sprog_data *d, const char *src, int *checksum) {
  44. d = 0;
  45. src = 0;
  46. checksum = 0;
  47. return;
  48. }