Pro un explication, vide illac.
/* Le . Converter un texto in interlingua del scriptura latin al scriptura armenie. Autor: Ruud Harmsen, https://rudhar.com/lingtics/intrlnga/scrptura/ */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <ctype.h> int conv_table[] = { /* Base value: 0530 */ /* Loosely based on Classical/Eastern Armenian pronunciation, see https://en.wikipedia.org/wiki/Armenian_alphabet */ /* a */ 0x01, /* b */ 0x02, /* c */ 0x0e, /* d */ 0x04, /* e */ 0x05, /* f */ 0x26, /* g */ 0x03, /* h */ 0x10, /* i */ 0x0b, /* j */ 0x0a, /* k */ 0x0f, /* l */ 0x0c, /* m */ 0x14, /* n */ 0x16, /* o */ 0x18, /* p */ 0x1a, /* q */ 0x12, /* r */ 0x1c, /* s */ 0x1d, /* t */ 0x1f, /* u */ 0x25, /* v */ 0x1e, /* w */ 0x22, /* x */ 0x0d, /* y */ 0x15, /* z */ 0x06, /* safety stop */ -1, }; static int convert (int c, FILE *fpi, FILE *fpo); static int baseval = 0x0530; int main (int argc, char **argv) { FILE *fpi = stdin, *fpo = stdout; int c; int intag = 0, inentity = 0; while ((c = getc(fpi)) != EOF) { if (!intag && c == '<') intag = 1; else if (intag && c == '>') intag = 0; else if (!inentity && c == '&') inentity = 1; else if (inentity && c == ';') inentity = 0; if (intag || inentity) putc(c, fpo); else convert(c, fpi, fpo); } return 0; } static int convert (int c, FILE *fpi, FILE *fpo) { if (c == '.') { fprintf(fpo, "&#x%04x;", 0x0589); } else if (c == ',') { fprintf(fpo, "&#x%04x;", 0x055d); } else if (!isascii(c) || !isalpha(c)) { putc(c, fpo); } else { int tabval, index, extra_for_lowercase = 0; if (isupper(c)) { index = c - 'A'; } else { index = c - 'a'; extra_for_lowercase = 0x30; } /* Safety first */ if (index >= 26) index = 26; tabval = conv_table[index]; if (tabval < 0) { putc(c, fpo); } else { tabval += baseval + extra_for_lowercase; fprintf(fpo, "&#x%04x;", tabval); } } return 0; }