/* btoa: version 4.0 * stream filter to change 8 bit bytes into printable ascii * computes the number of bytes, and three kinds of simple checksums * incoming bytes are collected into 32-bit words, then printed in base 85 * exp(85,5) > exp(2,32) * the characters used are between '!' and 'u' (in ASCII sequence) * 'z' encodes 32-bit zero; 'x' is used to mark the end of encoded data. * * Paul Rutter Joe Orost * philabs!per petsd!joe * * WARNING: this version is not compatible with the original as sent out * on the net. The original encoded from ' ' to 't'; which cause problems * with some mailers (stripping off trailing blanks). * * Hacked on somewhat by der Mouse to (a) remove ASCII dependency, (b) port * to gcc -Wstrict-prototypes -Wmissing-prototypes, and (c) generally clean * up the code. It should now work right on >32-bit machines. */ #include #include #include #if defined(__GNUC__) && \ ( (__GNUC__ > 2) || \ ( (__GNUC__ == 2) && \ defined(__GNUC_MINOR__) && \ (__GNUC_MINOR__ >= 7) ) ) #define UNUSED_ARG(x) x __attribute__((__unused__)) #else #define UNUSED_ARG(x) x #endif #define MAXPERLINE 72 extern const char *__progname; #include "common.h" static long int ccount = 0; static long int bcount = 0; static unsigned long int word; static void charout(char c) { putchar(c); ccount ++; if (ccount >= MAXPERLINE) { putchar('\n'); ccount = 0; } } static void wordout(unsigned long int word) { if (word == 0) { charout(zdig); } else { charout(digits[word/(85UL*85UL*85UL*85UL)]); word %= 85UL*85UL*85UL*85UL; charout(digits[word/(85UL*85UL*85UL)]); word %= 85UL*85UL*85UL; charout(digits[word/(85UL*85UL)]); word %= 85UL*85UL; charout(digits[word/(85UL)]); word %= 85UL; charout(digits[word]); } } static void encode(int c) { dochecksum(c); word = (word << 8) | c; if (bcount == 3) { wordout(word&0xffffffff); bcount = 0; } else { bcount ++; } } int main(int, char **); int main(int ac, UNUSED_ARG(char **av)) { int ch; long int n; if (ac != 1) { fprintf(stderr,"%s: bad args (usage: %s)\n",__progname,__progname); exit(1); } printf("xbtoa Begin\n"); n = 0; while ((ch=getchar()) != EOF) { encode(ch); n ++; } while (bcount != 0) encode(0); printf("\n%cbtoa End N %ld %lx E %lx S %lx R %lx\n",endmarker,n,n,Ceor,Csum,Crot); exit(0); }