Revision 4599,
2.3 KB
checked in by epeisach, 33 years ago
(diff) |
Fix for PS/2 register variable warnings.
|
Rev | Line | |
---|
[1134] | 1 | /* btoa: version 4.0 |
---|
| 2 | * stream filter to change 8 bit bytes into printable ascii |
---|
| 3 | * computes the number of bytes, and three kinds of simple checksums |
---|
| 4 | * incoming bytes are collected into 32-bit words, then printed in base 85 |
---|
| 5 | * exp(85,5) > exp(2,32) |
---|
| 6 | * the ASCII characters used are between '!' and 'u' |
---|
| 7 | * 'z' encodes 32-bit zero; 'x' is used to mark the end of encoded data. |
---|
| 8 | * |
---|
| 9 | * Paul Rutter Joe Orost |
---|
| 10 | * philabs!per petsd!joe |
---|
| 11 | * |
---|
| 12 | * WARNING: this version is not compatible with the original as sent out |
---|
| 13 | * on the net. The original encoded from ' ' to 't'; which cause problems |
---|
| 14 | * with some mailers (stripping off trailing blanks). |
---|
[8] | 15 | */ |
---|
| 16 | |
---|
| 17 | #include <stdio.h> |
---|
| 18 | |
---|
| 19 | #define reg register |
---|
| 20 | |
---|
| 21 | #define MAXPERLINE 78 |
---|
| 22 | |
---|
[1134] | 23 | long int Ceor = 0; |
---|
| 24 | long int Csum = 0; |
---|
| 25 | long int Crot = 0; |
---|
[8] | 26 | |
---|
[1134] | 27 | long int ccount = 0; |
---|
| 28 | long int bcount = 0; |
---|
| 29 | long int word; |
---|
[8] | 30 | |
---|
[1134] | 31 | #define EN(c) (int) ((c) + '!') |
---|
[8] | 32 | |
---|
[1134] | 33 | encode(c) |
---|
| 34 | reg c; |
---|
[8] | 35 | { |
---|
| 36 | Ceor ^= c; |
---|
| 37 | Csum += c; |
---|
| 38 | Csum += 1; |
---|
| 39 | if ((Crot & 0x80000000)) { |
---|
| 40 | Crot <<= 1; |
---|
| 41 | Crot += 1; |
---|
[1134] | 42 | } else { |
---|
[8] | 43 | Crot <<= 1; |
---|
| 44 | } |
---|
| 45 | Crot += c; |
---|
| 46 | |
---|
| 47 | word <<= 8; |
---|
| 48 | word |= c; |
---|
| 49 | if (bcount == 3) { |
---|
| 50 | wordout(word); |
---|
| 51 | bcount = 0; |
---|
[1134] | 52 | } else { |
---|
[8] | 53 | bcount += 1; |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
[1134] | 57 | wordout(word) |
---|
| 58 | reg long int word; |
---|
[8] | 59 | { |
---|
| 60 | if (word == 0) { |
---|
| 61 | charout('z'); |
---|
[1134] | 62 | } else { |
---|
| 63 | reg int tmp = 0; |
---|
| 64 | |
---|
| 65 | if(word < 0) { /* Because some don't support unsigned long */ |
---|
| 66 | tmp = 32; |
---|
| 67 | word = word - (long)(85 * 85 * 85 * 85 * 32); |
---|
| 68 | } |
---|
| 69 | if(word < 0) { |
---|
| 70 | tmp = 64; |
---|
| 71 | word = word - (long)(85 * 85 * 85 * 85 * 32); |
---|
| 72 | } |
---|
| 73 | charout(EN((word / (long)(85 * 85 * 85 * 85)) + tmp)); |
---|
| 74 | word %= (long)(85 * 85 * 85 * 85); |
---|
[8] | 75 | charout(EN(word / (85 * 85 * 85))); |
---|
| 76 | word %= (85 * 85 * 85); |
---|
| 77 | charout(EN(word / (85 * 85))); |
---|
| 78 | word %= (85 * 85); |
---|
| 79 | charout(EN(word / 85)); |
---|
| 80 | word %= 85; |
---|
| 81 | charout(EN(word)); |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | charout(c) { |
---|
| 86 | putchar(c); |
---|
| 87 | ccount += 1; |
---|
| 88 | if (ccount == MAXPERLINE) { |
---|
| 89 | putchar('\n'); |
---|
| 90 | ccount = 0; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
[1134] | 94 | main(argc,argv) |
---|
| 95 | char **argv; |
---|
[8] | 96 | { |
---|
[4599] | 97 | reg int c; |
---|
[1134] | 98 | reg long int n; |
---|
| 99 | |
---|
[8] | 100 | if (argc != 1) { |
---|
| 101 | fprintf(stderr,"bad args to %s\n", argv[0]); |
---|
| 102 | exit(2); |
---|
| 103 | } |
---|
| 104 | printf("xbtoa Begin\n"); |
---|
| 105 | n = 0; |
---|
| 106 | while ((c = getchar()) != EOF) { |
---|
| 107 | encode(c); |
---|
| 108 | n += 1; |
---|
| 109 | } |
---|
| 110 | while (bcount != 0) { |
---|
| 111 | encode(0); |
---|
| 112 | } |
---|
| 113 | /* n is written twice as crude cross check*/ |
---|
[1134] | 114 | printf("\nxbtoa End N %ld %lx E %lx S %lx R %lx\n", n, n, Ceor, Csum, Crot); |
---|
| 115 | exit(0); |
---|
[8] | 116 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.