/* * Transliterate UTF-8 russian input into all possible latin * implementations, see hardcoded table below. * Data is taken from stdin and is returned to stdout. * * Licensed under GPL-3. * ® 2012 - 2015 Andrew Savchenko */ #include #include #include # define ALPHA_CNT 33 # define TRANSL_CNT 6 // conversion table // all lines must be NULL-terminated // first two rows must always be defined and not NULL const char *const ct[ALPHA_CNT][TRANSL_CNT]={ {"а", "a", NULL}, {"б", "b", NULL}, {"в", "v", NULL}, {"г", "g", "h", NULL}, {"д", "d", NULL}, {"е", "e", "je", "ye", NULL}, {"ё", "e", "jo", "yo", NULL}, {"ж", "j", "z", "zh", NULL}, {"з", "z", NULL}, {"и", "i", NULL}, {"й", "j", "i", NULL}, {"к", "k", NULL}, {"л", "l", NULL}, {"м", "m", NULL}, {"н", "n", NULL}, {"о", "o", NULL}, {"п", "p", NULL}, {"р", "r", "p", NULL}, {"с", "s", "c", NULL}, {"т", "t", NULL}, {"у", "u", "y", NULL}, {"ф", "f", NULL}, {"х", "h", "x", NULL}, {"ц", "ts", "s", NULL}, {"ч", "ch", "4", NULL}, {"ш", "sh", NULL}, {"щ", "sh", "sh'", "sh`", NULL}, {"ъ", "b", "'b", "`b", "", NULL}, {"ы", "y", "bl", "b1", NULL}, {"ь", "b", "", NULL}, {"э", "e", "3", NULL}, {"ю", "ju", "yu", "u", NULL}, {"я", "ya", "ja", NULL}, }; // recursion similar to fork + exec; // only forward scan of the input data void convline(char *in, char *out, size_t out_start, size_t out_len) { size_t tr_len; // length of translated sequence char *fork; // forked output data (for multiple matches) size_t fork_len; int match; // set this flag if we found something // scan input line while (*in != '\0' && *in != '\n' && *in != '\r') { match = 0; for (int i=0; i