/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Generate APL ASCII correspondence list and Quail rules in UTF-8. Written Oct. 5 2006, Markus Triska (triska@gmx.at) Public domain code. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #include #include /* translation table based on code from "aplencode.c" by Arthur O'Dwyer Changes: introduced tilde/not (0x223C) introduced diamond (0x22C4) nor/nand changed to down/up caret tilde (0x2371/0x2372) quad changed from 0x25AF to 0x2395 */ static struct { char *word; unsigned long int chr; } braced_keywords[] = { {"leftbrace", '{'}, {"rightbrace", '}'}, {"scan", '\\'}, {"expand", '\\'}, {"reduce", '/'}, {"compress", '/'}, {"replicate", '/'}, {"ravel", ','}, {"catenate", ','}, {"laminate", ','}, {"roll", '?'}, {"deal", '?'}, {"diaeresis", 0x00A8}, {"each", 0x00A8}, {"\"", 0x00A8}, {"times", 0x00D7}, {"signum", 0x00D7}, {"x", 0x00D7}, {"reciprocal", 0x00F7}, {"divide", 0x00F7}, {"%", 0x00F7}, {"left-arrow", 0x2190}, {"gets", 0x2190}, {"assign", 0x2190}, {"up-arrow", 0x2191}, {"first", 0x2191}, {"take", 0x2191}, {"right-arrow", 0x2192}, {"branch", 0x2192}, {"goto", 0x2192}, {"down-arrow", 0x2193}, {"drop", 0x2193}, {"delta", 0x2206}, {"/\\", 0x2206}, {"del", 0x2207}, {"nabla", 0x2207}, {"epsilon", 0x2208}, {"member-of", 0x2208}, {"member", 0x2208}, {"enlist", 0x2208}, {"type", 0x2208}, {"negative", 0x2212}, {"minus", 0x2212}, {"-", 0x2212}, {"jot", 0x2218}, {"ring", 0x2218}, {"o", 0x2218}, {"nazg", 0x2218}, {"stile", 0x2223}, {"abs", 0x2223}, {"residue", 0x2223}, {"up-caret", 0x2227}, {"and", 0x2227}, {"caret", 0x2227}, {"down-caret", 0x2228}, {"or", 0x2228}, {"inverted-caret", 0x2228}, {"intersection", 0x2229}, {"intersect", 0x2229}, {"up-shoe", 0x2229}, {"union", 0x222A}, {"down-shoe", 0x222A}, {"diaresis-dot", 0x2235}, {"paw", 0x2235}, {"not-equal", 0x2260}, {"/=", 0x2260}, {"match", 0x2261}, {"depth", 0x2261}, {"=_", 0x2261}, {"not-match", 0x2262}, {"/match", 0x2262}, {"/=_", 0x2262}, {"<=", 0x2264}, {"less-than-equal", 0x2264}, {">=", 0x2265}, {"greater-than-equal", 0x2265}, {"left-shoe", 0x2282}, {"enclose", 0x2282}, {"partition", 0x2282}, {"right-shoe", 0x2283}, {"disclose", 0x2283}, {"pick", 0x2283}, {"circle-dash", 0x2296}, {"rotate", 0x2296}, {"O-", 0x2296}, {"right-tack", 0x22A2}, {"lev", 0x22A2}, {"|-", 0x22A2}, {"left-tack", 0x22A3}, {"dex", 0x22A3}, {"-|", 0x22A3}, {"down-tack", 0x22A4}, {"represent", 0x22A4}, {"T", 0x22A4}, {"encode", 0x22A4}, {"up-tack", 0x22A5}, {"base", 0x22A5}, {"decode", 0x22A5}, {"and-overbar", 0x22BC}, {"nand", 0x2372}, {"~^", 0x2372}, {"or-overbar", 0x22BD}, {"nor", 0x2371}, {"~v", 0x2371}, {"star", 0x22C6}, {"pow", 0x22C6}, {"exp", 0x22C6}, {"ceiling", 0x2308}, {"greater-of", 0x2308}, {"max", 0x2308}, {"floor", 0x230A}, {"lesser-of", 0x230A}, {"min", 0x230A}, {"I-beam", 0x2336}, {"I", 0x2336}, {"squish-quad", 0x2337}, {"squad", 0x2337}, {"index", 0x2337}, {"quad-equal", 0x2338}, {"#=", 0x2338}, {"quad-divide", 0x2339}, {"#%", 0x2339}, {"mat-inverse", 0x2339}, {"mat-divide", 0x2339}, {"domino", 0x2339}, {"quad-diamond", 0x233A}, {"#&", 0x233A}, {"quad-jot", 0x233B}, {"#o", 0x233B}, {"quad-circle", 0x233C}, {"#O", 0x233C}, {"circle-stile", 0x233D}, {"reverse", 0x233D}, {"rotate", 0x233D}, {"circle-jot", 0x233E}, {"slash-bar", 0x233F}, {"compress1", 0x233F}, {"reduce1", 0x233F}, {"replicate1", 0x233F}, {"slope-bar", 0x2340}, {"expand1", 0x2340}, {"scan1", 0x2340}, {"backslash-bar", 0x2340}, {"quad-slash", 0x2341}, {"#/", 0x2341}, {"quad-backslash", 0x2342}, {"#\\", 0x2342}, {"quad-less-than", 0x2343}, {"#<", 0x2343}, {"quad<", 0x2343}, {"quad-greater-than", 0x2344}, {"#>", 0x2344}, {"quad>", 0x2344}, {"leftwards-vane", 0x2345}, {"left-vane", 0x2345}, {"rightwards-vane", 0x2346}, {"right-vane", 0x2346}, {"quad<-", 0x2347}, {"quad-left-arrow", 0x2347}, {"quad->", 0x2348}, {"quad-right-arrow", 0x2348}, {"circle-backslash", 0x2349}, {"transpose", 0x2349}, {"O\\", 0x2349}, {"uptack-underbar", 0x234A}, {"delta-stile", 0x234B}, {"/\\|", 0x234B}, {"grade-up", 0x234B}, {"#v", 0x234C}, {"quad-downcaret", 0x234C}, {"#/\\", 0x234D}, {"quad-delta", 0x234D}, {"uptack-jot", 0x234E}, {"execute", 0x234E}, {"upwards-vane", 0x234F}, {"up-vane", 0x234F}, {"quad-up-arrow", 0x2350}, {"downtack-overbar", 0x2351}, {"del-stile", 0x2352}, {"grade-down", 0x2352}, {"#^", 0x2353}, {"quad-up-caret", 0x2353}, {"#\\/", 0x2354}, {"quad-del", 0x2354}, {"quad-nabla", 0x2354}, {"format", 0x2355}, {"downtack-jot", 0x2355}, {"downwards-vane", 0x2356}, {"down-vane", 0x2356}, {"quad-down-arrow", 0x2357}, {"quote_", 0x2358}, {"quote-underbar", 0x2358}, {"'_", 0x2358}, {"delta_", 0x2359}, {"delta-underbar", 0x2359}, {"/\\_", 0x2359}, {"diamond_", 0x235A}, {"diamond-underbar", 0x235A}, {"&_", 0x235A}, {"jot_", 0x235B}, {"jot-underbar", 0x235B}, {"o_", 0x235B}, {"circle_", 0x235C}, {"circle-underbar", 0x235C}, {"O_", 0x235C}, {"upshoe-jot", 0x235D}, {"lamp", 0x235D}, {"comment", 0x235D}, {"quote-quad", 0x235E}, {"circle-star", 0x235F}, {"log", 0x235F}, {"ln", 0x235F}, {"O*", 0x235F}, {"quad-colon", 0x2360}, {"#:", 0x2360}, {"snout", 0x2361}, {"downtack-diaeresis", 0x2361}, {"frog", 0x2362}, {"del-diaeresis", 0x2362}, {"sourpuss", 0x2363}, {"star-diaeresis", 0x2363}, {"hoot", 0x2364}, {"jot-diaeresis", 0x2364}, {"rank", 0x2364}, {"o\"", 0x2364}, {"holler", 0x2365}, {"circle-diaeresis", 0x2365}, {"O\"", 0x2365}, {"downshoe-stile", 0x2366}, {"leftshoe-stile", 0x2367}, {"smirk", 0x2368}, {"tilde-diaeresis", 0x2368}, {"~\"", 0x2368}, {">\"", 0x2369}, {"greater-than-diaeresis", 0x2369}, {"comma-bar", 0x236A}, {"cat-bar", 0x236A}, {"catenate1", 0x236A}, {"laminate1", 0x236A}, {",-", 0x236A}, {"del-tilde", 0x236B}, {"\\/~", 0x236B}, {"zilde", 0x236C}, {"0~", 0x236C}, {"stile-tilde", 0x236D}, {"|~", 0x236D}, {"semicolon-underbar", 0x236E}, {";_", 0x236E}, {"#/=", 0x236F}, {"quad-not-equal", 0x236F}, {"#?", 0x2370}, {"quad-question", 0x2370}, {"downcaret-tilde", 0x2371}, {"upcaret-tilde", 0x2372}, {"iota", 0x2373}, {"index", 0x2373}, {"index-of", 0x2373}, {"rho", 0x2374}, {"shape", 0x2374}, {"reshape", 0x2374}, {"omega", 0x2375}, {"w", 0x2375}, {"alpha-underbar", 0x2376}, {"alpha_", 0x2376}, {"epsilon-underbar", 0x2377}, {"epsilon_", 0x2377}, {"find", 0x2377}, {"iota_", 0x2378}, {"iota-underbar", 0x2378}, {"omega_", 0x2379}, {"omega-underbar", 0x2379}, {"alpha", 0x237A}, {"quad", 0x2395}, {"box", 0x2395}, {"circle", 0x25CB}, {"pi-times", 0x25CB}, {"O", 0x25CB}, {"tilde", 0x223C}, {"not", 0x223C}, {"diamond", 0x22C4}, {0, 0} }; /** * Prints a single 32-bit Unicode code point as UTF-8. */ int putUTF8(unsigned long ucp, FILE *outfp) { if (ucp < 0x80) { putc(ucp & 0xFF, outfp); return 1; } else if (ucp < 0x800) { putc((ucp >> 6) | 0xC0, outfp); putc((ucp & 0x3F) | 0x80, outfp); return 2; } else if (ucp < 0x10000) { putc((ucp >> 12) | 0xE0, outfp); putc(((ucp >> 6) & 0x3F) | 0x80, outfp); putc((ucp & 0x3F) | 0x80, outfp); return 3; } else { putc((ucp >> 18) | 0xF0, outfp); putc(((ucp >> 12) & 0x3F) | 0x80, outfp); putc(((ucp >> 6) & 0x3F) | 0x80, outfp); putc((ucp & 0x3F) | 0x80, outfp); return 4; } } using namespace std; int main() { int i = -1; // LaTeX symbol list while (braced_keywords[++i].word) { cout << braced_keywords[i].word << " "; putUTF8(braced_keywords[i].chr, stdout); cout << endl; } cout << endl << endl; // Quail rules i = -1; while (braced_keywords[++i].word) { cout << "(\"{"; for (int j = 0; j < strlen(braced_keywords[i].word); j++) { if (braced_keywords[i].word[j] == '"') { cout << "\\\""; } else if (braced_keywords[i].word[j] == '\\') { cout << "\\\\"; } else { cout << braced_keywords[i].word[j]; } } cout << "}\" ?"; if (braced_keywords[i].chr == '\\') { cout << "\\\\"; } else { putUTF8(braced_keywords[i].chr, stdout); } cout << ")" << endl; } return 1; }