Pro un explication, vide illac.
/* Le . Variante plus simplice de lfn-cyr.c Face solo interlingua al scriptura grec secunde le schema 3. Vide https://rudhar.com/lingtics/intrlnga/scrptura/ia023.htm#Schema3 . Usa entitates symbolic in vice de numeric, ubi possibile. */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <ctype.h> char *conv_table[] = { /* a */ "alpha", /* b */ "beta", /* c */ "#x3f2", /* lunate sigma */ /* d */ "delta", /* e */ "epsilon", /* f */ "phi", /* g */ "gamma", /* h */ "eta", /* i */ "iota", /* j */ "chi", /* k */ "kappa", /* l */ "lambda", /* m */ "mu", /* n */ "nu", /* o */ "omicron", /* p */ "pi", /* q */ "#x3d9", /* qoppa */ /* r */ "rho", /* s */ "sigma", /* t */ "tau", /* u */ "omega", /* v */ "upsilon", /* w */ "#x3dd", /* digamma */ /* x */ "xi", /* y */ "psi", /* z */ "zeta", /* safety stop */ NULL }; static int convert (int c, FILE *fpi, FILE *fpo); 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 (!isascii(c) || !isalpha(c)) { putc(c, fpo); } else { int index; char *tabval; char buf[16]; index = c - (isupper(c) ? 'A' : 'a'); /* Safety first */ if (index >= 26) index = 26; tabval = conv_table[index]; if (!tabval) { putc(c, fpo); } else { int n; sprintf(buf, "&%s;", tabval); if (isascii(c) && isupper(c)) { if (c == 'C') strcpy(buf, "Ϲ"); else if (c == 'Q') strcpy(buf, "Ϙ"); else if (c == 'W') strcpy(buf, "Ϝ"); else buf[1] = toupper(buf[1]); } if (c == 's') { n = getc(fpi); if (!isalpha(n)) { /* Final lowercase sigma as in real Greek */ strcpy(buf, "ς"); } ungetc(n, fpi); } fprintf(fpo, "%s", buf); } } return 0; }