#include static const char* tokens[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "ε", "→", ")", ",", "(", "=", "≠", "<", "≤", ">", "≥", "+", "-", "*", "/", " nCr ", " nPr ", "\"", "IPart ", "Int ", "FPart ", "⁻", "abs ", "√", "³√", "ln ", "e^", "log ", "ю^", "sin ", "sin⁻¹ ", "cos ", "cos¹ ", "tan ", "tan⁻¹ ", "sinh ", "sinh¹ ", "cosh ", "cosh⁻¹ ", "tanh ", "tanh¹ ", "det", "?", "^", "¹", "²", "⸆", "³", "!", "ʳ", "°", "Round(", "R▸P(", "P▸R(", "RowSwap(", "Row+(", "*Row(", "*Row+(", "NDeriv(", "␣", "Ans", "Rand", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "θ", "Arow", "Acol", "Brow", "Bcol", "Crow", "Ccol", "Tmin", "Tmax", "Tstep", "Xmin", "Xmax", "Xscl", "Ymin", "Ymax", "Yscl", "Xres", "{x}(", "{y}(", "[A]", "[B]", "[C]", "Σx", "Σx²", "Σxy", "Σy", "Σy²", "n", "ẋ", "σx", "Sx", "ẏ", "σy", "Sy", "b", "a", "r", "Dim{x}", "π", "1-Var", "LinReg", "ExpReg", "LnReg", "PwrReg", "xSort", "ySort", "ClrStat", "RegEQ", "Hist", "xyLine", "Scatter", "Rad", "Deg", "Norm", "Sci", "Eng", "Float", "Fix ", "Function", "Param", "Connected", "Dot", "Sequence", "Simul", "Grid Off", "Grid On", "Rect", "Polar", "Disp ", "Input ", "Pause", "End", "Stop", "Lbl ", "Goto ", "If ", "IS>(", "DS<(", "Y₁", "Y₂", "Y₃", "Y₄", "X₁┬", "Y₁┬", "X₂┬", "Y₂┬", "X₃┬", "Y₃┬", "All-On", "Y₁-On", "Y₂-On", "Y₃-On", "Y₄-On", "X₁┬-On", "X₂┬-On", "X₃┬-On", "All-Off", "Y₁-Off", "Y₂-Off", "Y₃-Off", "Y₄-Off", "X₁┬-Off", "X₂┬-Off", "X₃┬-Off", "Line(", "PT-On(", "PT-Off(", "PT-Chg(", "DrawF ", "Shade(", "ClrDraw", "ClrHome", "DispHome", "DispGraph",0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static unsigned long read_utf8(const unsigned char** s) { int n; unsigned long v, min; if (**s < 0x80) { (*s)++; return (*s)[-1]; } if (**s < 0xc0) { (*s)++; return 0xffff; } if (**s < 0xe0) { n = 1; min = 0x80; v = (**s & 0x1f); } else if (**s < 0xf0) { n = 2; min = 0x800; v = (**s & 0x0f); } else if (**s < 0xf8) { n = 3; min = 0x10000; v = (**s & 0x07); } else if (**s < 0xfc) { n = 4; min = 0x200000; v = (**s & 0x03); } else if (**s < 0xfe) { n = 5; min = 0x4000000; v = (**s & 0x01); } else { (*s)++; return 0xffff; } while (n > 0) { (*s)++; if (**s < 0x80) { return 0xffff; } else if (**s >= 0xc0) return 0xffff; v <<= 6; v |= (**s & 0x3f); n--; } (*s)++; if (v < min) { return 0xffff; } else return v; } static int write_utf8(unsigned char* s, unsigned long c) { if (c > 0x1fffff) c = 0xfffd; if (c < 0x80) { s[0] = c; s[1] = 0; return 1; } else if (c < 0x800) { s[0] = (0xc0 | (c >> 6)); s[1] = (0x80 | (c & 0x3f)); s[2] = 0; return 2; } else if (c < 0x10000) { s[0] = (0xe0 | (c >> 12)); s[1] = (0x80 | ((c >> 6) & 0x3f)); s[2] = (0x80 | (c & 0x3f)); s[3] = 0; return 3; } else { s[0] = (0xf0 | (c >> 18)); s[1] = (0x80 | ((c >> 12) & 0x3f)); s[2] = (0x80 | ((c >> 6) & 0x3f)); s[3] = (0x80 | (c & 0x3f)); s[4] = 0; return 4; } } static int utf8strlen(const unsigned char* s) { int n = 0; while (*s) { read_utf8(&s); n++; } return n; } int main() { int b, n, i, j; int ok = 1; char tok[10], buf[5]; const char* p; const unsigned char* u8p; unsigned int linebuf[16], bytebuf[16], verblinebuf[128]; unsigned int wc; int lbx, vlbx, bbx; linebuf[0] = ':'; linebuf[1] = '"'; lbx = 2; verblinebuf[0] = '"'; verblinebuf[1] = ' '; vlbx = 2; bbx = 0; do { b = getchar(); if (b == EOF) { p = "\""; } else { bytebuf[bbx] = b; bbx++; if (tokens[b]) { p = tokens[b]; } else { p = tok; sprintf(tok, "#%02X#", b); ok = 0; } } u8p = (const unsigned char*) p; n = utf8strlen(u8p); for (i = 0; i < n; i++) { wc = read_utf8(&u8p); if (wc == 0x3B5) { verblinebuf[vlbx++] = 'E'; verblinebuf[vlbx++] = 'E'; } else if (wc == 0xB9) { verblinebuf[vlbx++] = 0x207B; verblinebuf[vlbx++] = 0xB9; } else if (wc == 0x044E) { verblinebuf[vlbx++] = '1'; verblinebuf[vlbx++] = '0'; } else if (wc == 0x1E8B) { verblinebuf[vlbx++] = 'x'; verblinebuf[vlbx++] = '\\'; } else if (wc == 0x1E8F) { verblinebuf[vlbx++] = 'y'; verblinebuf[vlbx++] = '\\'; } else if (wc == 0x207B) { verblinebuf[vlbx++] = '('; verblinebuf[vlbx++] = '-'; verblinebuf[vlbx++] = ')'; } else { verblinebuf[vlbx++] = wc; } } verblinebuf[vlbx++] = ' '; u8p = (const unsigned char*) p; for (i = 0; i < n; i++) { linebuf[lbx++] = read_utf8(&u8p); if (lbx == 16 || b == EOF) { for (j = 0; j < lbx; j++) { write_utf8((unsigned char*) buf, linebuf[j]); printf("%s", buf); } for (; j < 16; j++) { putchar(' '); } putchar('\t'); for (j = 0; j < vlbx; j++) { write_utf8((unsigned char*) buf, verblinebuf[j]); printf("%s", buf); } for (; j < 32; j++) { putchar(' '); } putchar('\t'); for (j = 0; j < bbx; j++) { printf("%02X", bytebuf[j]); } putchar('\n'); lbx = vlbx = bbx = 0; } } } while (b != EOF); return !ok; }