/* t2b : T3 -> binary converter. T3 is the protocol used by Taipei-100 and TaipeiTerm. It uses three 7-bit Ascii's to represent one BIG-5 code. written by Pai Chou */ #include #define LINESIZE 1000 typedef unsigned char uchar; char line_in[LINESIZE], line_out[LINESIZE]; int inLen, outLen; int /* boolean */ A2C_ (a, index, c) uchar *a, *c; int *index; { unsigned int t, uppr, lowr, val, x, y, z; x = a[*index]; if ((x=='^') || (x=='`')) { y = a[*index+1]; if ((y > 0x20) && (y < 0x7F) && (y != 0x5E) && (y != 0x60)) { z = a[*index+2]; if ((z > 0x20) && (z < 0x7F) && (z != 0x5E) && (z != 0x60)) { if (y > 0x60) /* ` */ y -= 3; if (z > 0x60) z -= 3; c[0] = y - 0x21 + 0xA1; t = z - 0x21; uppr = t / 0x10; lowr = t - uppr * 0x10; if (x=='^') { val = uppr + 9; } else { val = uppr + 4; } c[1] = lowr + (val << 4); if (c[1] >= 0x80) c[1] += 0x20; *index += 3; return 1; } else return 0; } else return 0; } else return 0; } void A2C_line_(src, dest, sLen, dLen) uchar *src, *dest; int sLen, *dLen; { int i; for (i=0, *dLen = 0;i < sLen-2; ) { if (A2C_(src, &i, dest + *dLen)) { (*dLen) += 2; } else { dest[*dLen] = src[i]; (*dLen)++; i++; } } /* copy leftovers */ while (i < sLen) { dest[*dLen] = src[i]; i++; (*dLen)++; } } main() { while (gets(line_in) != NULL) { inLen = strlen(line_in); A2C_line_(line_in, line_out, inLen, &outLen); line_out[outLen] = '\0'; printf("%s\n",line_out); } }