| 189 | } |
| 190 | |
| 191 | RESTORE_WARNINGS |
| 192 | |
| 193 | /* |
| 194 | * copy from in to out, decoding as you go along. |
| 195 | */ |
| 196 | void |
| 197 | decode(FILE *in, FILE *out) |
| 198 | { |
| 199 | char buf[80]; |
| 200 | char *bp; |
| 201 | int n, i, expected; |
| 202 | |
| 203 | for (;;) { |
| 204 | /* for each input line */ |
| 205 | if (fgets(buf, sizeof buf, in) == NULL) { |
| 206 | printf("Short file\n"); |
| 207 | exit(10); |
| 208 | } |
| 209 | n = DEC(buf[0]); |
| 210 | if ((n <= 0) || (buf[0] == '\n')) |
| 211 | break; |
| 212 | |
| 213 | /* Calculate expected # of chars and pad if necessary */ |
| 214 | expected = ((n + 2) / 3) << 2; |
| 215 | for (i = (int) strlen(buf) - 1; i <= expected; i++) |
| 216 | buf[i] = ' '; |
| 217 | |
| 218 | bp = &buf[1]; |
| 219 | while (n > 0) { |
| 220 | outdec(bp, out, n); |
| 221 | bp += 4; |
| 222 | n -= 3; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /* |
| 228 | * output a group of 3 bytes (4 input characters). |