2 * stream filter to change printable ascii from "btoa" back into 8 bit bytes
3 * if bad chars, or Csums do not match: exit(1) [and NO output]
5 * Paul Rutter Joe Orost
6 * philabs!per petsd!joe
13 #define streq(s0, s1) strcmp(s0, s1) == 0
15 #define times85(x) ((((((x<<2)+x)<<2)+x)<<2)+x)
24 fprintf(stderr, "bad format or Csum to atob\n");
28 #define DE(c) ((c) - '!')
42 } else if ((c >= '!') && (c < ('!' + 85))) {
46 } else if (bcount < 4) {
51 word = times85(word) + DE(c);
52 byteout((int)((word >> 24) & 255));
53 byteout((int)((word >> 16) & 255));
54 byteout((int)((word >> 8) & 255));
55 byteout((int)(word & 255));
72 if ((Crot & 0x80000000)) {
89 long int n1, n2, oeor, osum, orot;
92 fprintf(stderr,"bad args to %s\n", argv[0]);
95 sprintf(tmp_name, "/usr/tmp/atob.%x", getpid());
96 tmp_file = fopen(tmp_name, "w+");
97 if (tmp_file == NULL) {
100 unlink(tmp_name); /* Make file disappear */
101 /*search for header line*/
103 if (fgets(buf, sizeof buf, stdin) == NULL) {
106 if (streq(buf, "xbtoa Begin\n")) {
111 while ((c = getchar()) != EOF) {
114 } else if (c == 'x') {
120 if(scanf("btoa End N %ld %lx E %lx S %lx R %lx\n",
121 &n1, &n2, &oeor, &osum, &orot) != 5) {
124 if ((n1 != n2) || (oeor != Ceor) || (osum != Csum) || (orot != Crot)) {
127 /*copy OK tmp file to stdout*/;
128 fseek(tmp_file, 0L, 0);
129 for (i = n1; --i >= 0;) {
130 putchar(getc(tmp_file));