8 int main(int argc, char **argv)
12 char *decbuf, *encbuf;
14 char *(*decfn)(char *, size_t *);
15 char *(*encfn)(char *, size_t);
18 fprintf(stderr, "usage: baseconv [4568] [4568]\n");
19 fprintf(stderr, "\tenter data on stdin\n");
23 if(!strcmp(argv[1], "4")) {
25 } else if(!strcmp(argv[1], "5")) {
27 } else if(!strcmp(argv[1], "6")) {
29 } else if(!strcmp(argv[1], "8")) {
32 fprintf(stderr, "unknown decoding: %s\n", argv[1]);
35 if(!strcmp(argv[2], "4")) {
37 } else if(!strcmp(argv[2], "5")) {
39 } else if(!strcmp(argv[2], "6")) {
41 } else if(!strcmp(argv[2], "8")) {
44 fprintf(stderr, "unknown encoding: %s\n", argv[1]);
48 while((ret = read(0, buf + data, 24 - data)) >= 0) {
49 if(((data += ret) == 24) || (ret == 0)) {
51 decbuf = memcpy(smalloc(data), buf, data);
55 if((decbuf = decfn(buf, &buflen)) == NULL) {
56 fprintf(stderr, "invalid input\n");
61 encbuf = memcpy(smalloc(buflen), decbuf, buflen);
62 fwrite(encbuf, 1, buflen, stdout);
64 encbuf = encfn(decbuf, buflen);
65 buflen = strlen(encbuf);
66 if(linelen + buflen > 60) {
67 fwrite(encbuf, 1, 60 - linelen, stdout);
68 fwrite("\n", 1, 1, stdout);
69 memmove(encbuf, encbuf + 60 - linelen, buflen -= 60 - linelen);
71 fwrite(encbuf, 1, buflen, stdout);