/* b2t : binary -> T3 converter for Taipei-100 and TaipeiTerm. written by Pai Chou */ #include #define COLUMNS 80 typedef unsigned char uchar; void C2A_(c, a) uchar *c, *a; { uchar temp; if (c[1] >= 0xB0) { a[0] = '^'; } else { a[0] = '`'; } temp = c[0] - 0xA1 + 0x21; if (temp >= '^') temp += 3; a[1] = temp; temp = c[1]; if (temp >= 0xA0) temp -= 0x20; temp = (temp & 0xF) + (((temp >>4) - 4) % 5) * 0x10 + 0x21; if (temp >= '^') temp += 3; a[2] = temp; } main() { uchar c[2], d[4]; int thisLen, len = 0; while (!feof(stdin)) { c[0] = getchar(); if (c[0] >= 0x80) { /* a hanzi */ if (feof(stdin)) exit(-1); /* unmatched - file not complete */ c[1] = getchar(); C2A_(c, d); thisLen = 3; } else { /* a nonhanzi */ if (c[0]=='\n') { len = -1; } thisLen = 1; d[0] = c[0]; } len += thisLen; if (len >= COLUMNS) { putchar('\n'); len = 0; } d[thisLen] = '\0'; printf("%s",d); } }