#include #include #include #include #include #include #include #include const unsigned int symbolGreekTranslation[256] = { /* 000 (00) */ 0xFFFD /*' '*/, 0xFFFD /*''*/, 0xFFFD /*''*/, 0xFFFD /*''*/, /* 004 (04) */ 0xFFFD /*''*/, 0xFFFD /*''*/, 0xFFFD /*''*/, 0xFFFD /*''*/, /* 008 (08) */ 0xFFFD /*'backspace? '*/, 0xFFFD /*'\t'*/, 0x000a /*\n*/, 0xFFFD /*' '*/, /* 012 (0c) */ 0xFFFD /*' '*/, 0x000d /*'\r'*/, 0xFFFD /*''*/, 0xFFFD /*''*/, /* 016 (10) */ 0xFFFD /*''*/, 0xFFFD /*''*/, 0xFFFD /*''*/, 0xFFFD /*''*/, /* 020 (14) */ 0xFFFD /*''*/, 0xFFFD /*''*/, 0xFFFD /*''*/, 0xFFFD /*''*/, /* 024 (18) */ 0xFFFD /*''*/, 0xFFFD /*''*/, 0xFFFD /*''*/, 0xFFFD /*''*/, /* 028 (1c) */ 0xFFFD /*''*/, 0xFFFD /*''*/, 0xFFFD /*''*/, 0xFFFD /*''*/, /* 032 (20) */ 0x0020 /*' '*/, 0x0021 /*'!'*/, 0x03C2 /*'"'*/, 0x0023 /*'#'*/, /* 036 (24) */ 0x0024 /*'$'*/, 0x0025 /*'%'*/, 0x0026 /*'&'*/, 0x0342 /* circumflex perispomeni'''*/, /* 040 (28) */ 0x0028 /*'('*/, 0x0029 /*')'*/, 0x002a /*'*'*/, 0x002b /*'+'*/, /* 044 (2c) */ 0x002c /*','*/, 0x002d /*'-'*/, 0x002e /*'.'*/, 0x002f /*'/'*/, /* 048 (30) */ 0x0030 /*'0'*/, 0x0031 /*'1'*/, 0x0032 /*'2'*/, 0x0033 /*'3'*/, /* 052 (34) */ 0x0034 /*'4'*/, 0x0035 /*'5'*/, 0x0036 /*'6'*/, 0x0037 /*'7'*/, /* 056 (38) */ 0x0038 /*'8'*/, 0x0039 /*'9'*/, 0x00b7 /* middle dot ':'*/, ';' /* possibly a grave varia (see code below) */, /* 060 (3c) */ 0x003c /*'<'*/, 0x003d /*'='*/, 0x0308 /*'>'*/, 0x003f /*'?'*/, /* 064 (40) */ 0x0040 /*'@'*/, 0x0391 /*'A'*/, 0x0392 /*'B'*/, 0x03A7 /*'C'*/, /* 068 (44) */ 0x0394 /*'D'*/, 0x0395 /*'E'*/, 0x03A6 /*'F'*/, 0x0393 /*'G'*/, /* 072 (48) */ 0x0397 /*'H'*/, 0x0399 /*'I'*/, 0x0314 /*'J'*/, 0x039a /*'K' bug in .py */, /* 076 (4c) */ 0x039b /*'L'*/, 0x039c /*'M'*/, 0x039d /*'N'*/, 0x039f /*'O'*/, /* 080 (50) */ 0x03a0 /*'P'*/, 0x0398 /*'Q'*/, 0x03a1 /*'R'*/, 0x03a3 /*'S'*/, /* 084 (54) */ 0x03a4 /*'T'*/, 0x03a5 /*'U'*/, 0x0384 /*'V'*/, 0x03a9 /*'W'*/, /* 088 (58) */ 0x039e /*'X'*/, 0x03a8 /*'Y'*/, 0x005a /*'Z'*/, 0x005b /*'['*/, /* 092 (5c) */ 0x005c /*'\'*/, 0x005d /*']'*/, 0x005e /*'^'*/, 0x005f /*'_'*/, /* 096 (60) */ 0x0060 /*'`'*/, 0x03b1 /*'a'*/, 0x03b2 /*'b'*/, 0x03c7 /*'c'*/, /* 100 (64) */ 0x03b4 /*'d'*/, 0x03b5 /*'e'*/, 0x03c6 /*'f'*/, 0x03b3 /*'g'*/, /* 104 (68) */ 0x03b7 /*'h'*/, 0x03b9 /*'i'*/, 0x0313 /* smooth breathing 'j'*/, 0x03ba /*'k'*/, /* 108 (6c) */ 0x03bb /*'l'*/, 0x03bc /*'m'*/, 0x03bd /*'n'*/, 0x03bf /*'o'*/, /* 112 (70) */ 0x03c0 /*'p'*/, 0x03b8 /*'q'*/, 0x03c1 /*'r'*/, 0x03c3 /*'s'*/, /* 116 (74) */ 0x03c4 /*'t'*/, 0x03c5 /*'u'*/, 0x0301 /* acute tonos 'v'*/, 0x03c9 /*'w'*/, /* 120 (78) */ 0x03be /*'x'*/, 0x03c8 /*'y'*/, 0x03b6 /*'z'*/, 0x007b /*'{'*/, /* 124 (7c) */ 0x007c /*'|'*/, 0x007d /*'}'*/, 0x03c2 /*'~'*/, 0x007f /*''*/, /* 128 (80) */ ' ' /*'�'*/, 0x0081 /*'�'*/, 'C', 0x0083 /*'�'*/, /* 132 (84) */ 0x0084 /*'�'*/, 0x003e /* blockend '�'*/, 0x1fbd /*elusionszeichen'�'*/, 0x0087 /*'�'*/, /* 136 (88) */ 0x0088 /*'�'*/, 0x003b /*; '�'*/, ' ' /*'�'*/, 0x008b /*'�'*/, /* 140 (8c) */ 'a', 'c', 0x008e /*'�'*/, 0x008f /*'�'*/, /* 144 (90) */ 0x0090 /*'�'*/, 0x0091 /*'�'*/, 0x0092 /*'�'*/, 0x0093 /*'�'*/, /* 148 (94) */ 0x0094 /*'�'*/, 0x0095 /*'�'*/, 0x0096 /*'�'*/, 0x0056 /*'�'*/, /* 152 (98) */ 0x0098 /*'�'*/, 0x0099 /*'�'*/, 0x002f /* / '�'*/, 0x009b /*'�'*/, /* 156 (9c) */ 0x009c /*'�'*/, 0x009d /*'�'*/, 0x009e /*'�'*/, 0x009f /*'�'*/, /* 160 (a0) */ 't', 0x00a1 /*'�'*/, 0x00a2 /*'�'*/, 0x00a3 /*'�'*/, /* 164 (a4) */ 0x00a4 /*'�'*/, 0x00a5 /*'�'*/, 0x00a6 /*'�'*/, 's', /* 168 (a8) */ 'r', 'g', 0x00aa /*'�'*/, 'e', /* 172 (ac) */ 'u', 0x0047 /* G '�'*/, 0x00ae /*'�'*/, '}' /*'�'*/, /* 176 (b0) */ 0x00b0 /*'�'*/, 0x0306 /*'�'*/, 'j', 0x0323 /*unterpunkt'�'*/, /* 180 (b4) */ 'y', 'm', 'd', 'w', /* 184 (b8) */ 0x00b8 /*'�'*/, 'p', 'b' /*'�'*/, 0x005b /* [ '�'*/, /* 188 (bc) */ 0x005d /*]'�'*/, 0x00bd /*'�'*/, 0x00be /*'�'*/, '{' /*'�'*/, /* 192 (c0) */ 0x00c0 /*'�'*/, 0x00BA /* degree '�'*/, 'l'/* 0x006c */, 'v' /*'�'*/, /* 196 (c4) */ 'f', 'x', 0x02bc/* apostrophe */, 0x00c7 /*'�'*/, /* 200 (c8) */ 0x00c8 /*'�'*/, ';' /*'�'*/, ' ' /*'�'*/, 0x00cb /*'�'*/, /* 204 (cc) */ 0x00cc /*'�'*/, 0x00cd /*'�'*/, 'Q', 'q', /* 208 (d0) */ 0x0304, 0x0305 /* intf uses: 0x00af oberstrich'�'*/, 0x00d2 /*'�'*/, 0x00d3 /*'�'*/, /* 212 (d4) */ 0x00d4 /*'�'*/, 0x00d5 /*'�'*/, 0x00d6 /*'�'*/, 'V', /* 216 (d8) */ 0x00d8 /*'�'*/, 0x00d9 /*'�'*/, 0x007c /*|'�'*/, 0x005c /*`'�'*/, /* 220 (dc) */ 0x00dc /*'�'*/, 0x00dd /*'�'*/, 0x00de /*'�'*/, 0x0302 /*'�'*/, /* 224 (e0) */ 0x00e0 /*'�'*/, 0x00e1 /*'�'*/, ' ' /*'�'*/, 'W', /* 228 (e4) */ 0x00e4 /*'�'*/, 'R', 0x00e6 /*'�'*/, 'Y', /* 232 (e8) */ 'U', 'i', 'S', 'D', /* 236 (ec) */ 'F', 'G', 0x00ee /*'�'*/, ' ' /*'�'*/, /* 240 (f0) */ 0x00f0 /*'�'*/, 'L', ':' /*'�'*/, 0x00f3 /*'�'*/, /* 244 (f4) */ 0x00f4 /*'�'*/, 0x03DB /*stigma*/, 'n', 0x00f7 /*'�'*/, /* 248 (f8) */ 'J', 0x00f9 /*'�'*/, 'h', 'k', /* 252 (fc) */ 0x00fc /*'�'*/, 0x00fd /*'�'*/, 0x00fe /*'�'*/, 0x00ff /*'?'*/ }; const unsigned int isGreekLetter[256] = { /* 000 (00) */ 0 /*' '*/, 0 /*''*/, 0 /*''*/, 0 /*''*/, /* 004 (04) */ 0 /*''*/, 0 /*''*/, 0 /*''*/, 0 /*''*/, /* 008 (08) */ 0 /*'backspace? '*/, 0 /*'\t'*/, 0 /*\n*/, 0 /*' '*/, /* 012 (0c) */ 0 /*' '*/, 0 /*'\r'*/, 0 /*''*/, 0 /*''*/, /* 016 (10) */ 0 /*''*/, 0 /*''*/, 0 /*''*/, 0 /*''*/, /* 020 (14) */ 0 /*''*/, 0 /*''*/, 0 /*''*/, 0 /*''*/, /* 024 (18) */ 0 /*''*/, 0 /*''*/, 0 /*''*/, 0 /*''*/, /* 028 (1c) */ 0 /*''*/, 0 /*''*/, 0 /*''*/, 0 /*''*/, /* 032 (20) */ 0 /*' '*/, 0 /*'!'*/, 0x03C2 /*'"'*/, 0 /*'#'*/, /* 036 (24) */ 0 /*'$'*/, 0 /*'%'*/, 0 /*'&'*/, 0x0342 /* circumflex perispomeni'''*/, /* 040 (28) */ 0 /*'('*/, 0 /*')'*/, 0 /*'*'*/, 0 /*'+'*/, /* 044 (2c) */ 0 /*','*/, 0 /*'-'*/, 0 /*'.'*/, 0 /*'/'*/, /* 048 (30) */ 0 /*'0'*/, 0 /*'1'*/, 0 /*'2'*/, 0 /*'3'*/, /* 052 (34) */ 0 /*'4'*/, 0 /*'5'*/, 0 /*'6'*/, 0 /*'7'*/, /* 056 (38) */ 0 /*'8'*/, 0 /*'9'*/, 0 /* middle dot ':'*/, 0 /* possibly a grave varia (see code below) */, /* 060 (3c) */ 0 /*'<'*/, 0 /*'='*/, 0x0308 /*'>'*/, 0 /*'?'*/, /* 064 (40) */ 0 /*'@'*/, 0x0391 /*'A'*/, 0x0392 /*'B'*/, 0x03A7 /*'C'*/, /* 068 (44) */ 0x0394 /*'D'*/, 0x0395 /*'E'*/, 0x03A6 /*'F'*/, 0x0393 /*'G'*/, /* 072 (48) */ 0x0397 /*'H'*/, 0x0399 /*'I'*/, 0x0314 /*'J'*/, 0x039a /*'K' bug in .py */, /* 076 (4c) */ 0x039b /*'L'*/, 0x039c /*'M'*/, 0x039d /*'N'*/, 0x039f /*'O'*/, /* 080 (50) */ 0x03a0 /*'P'*/, 0x0398 /*'Q'*/, 0x03a1 /*'R'*/, 0x03a3 /*'S'*/, /* 084 (54) */ 0x03a4 /*'T'*/, 0x03a5 /*'U'*/, 0x0384 /*'V'*/, 0x03a9 /*'W'*/, /* 088 (58) */ 0x039e /*'X'*/, 0x03a8 /*'Y'*/, 0 /*'Z'*/, 0 /*'['*/, /* 092 (5c) */ 0 /*'\'*/, 0 /*']'*/, 0 /*'^'*/, 0 /*'_'*/, /* 096 (60) */ 0 /*'`'*/, 0x03b1 /*'a'*/, 0x03b2 /*'b'*/, 0x03c7 /*'c'*/, /* 100 (64) */ 0x03b4 /*'d'*/, 0x03b5 /*'e'*/, 0x03c6 /*'f'*/, 0x03b3 /*'g'*/, /* 104 (68) */ 0x03b7 /*'h'*/, 0x03b9 /*'i'*/, 0x0313 /* smooth breathing 'j'*/, 0x03ba /*'k'*/, /* 108 (6c) */ 0x03bb /*'l'*/, 0x03bc /*'m'*/, 0x03bd /*'n'*/, 0x03bf /*'o'*/, /* 112 (70) */ 0x03c0 /*'p'*/, 0x03b8 /*'q'*/, 0x03c1 /*'r'*/, 0x03c3 /*'s'*/, /* 116 (74) */ 0x03c4 /*'t'*/, 0x03c5 /*'u'*/, 0x0301 /* acute tonos 'v'*/, 0x03c9 /*'w'*/, /* 120 (78) */ 0x03be /*'x'*/, 0x03c8 /*'y'*/, 0x03b6 /*'z'*/, 0 /*'{'*/, /* 124 (7c) */ 0 /*'|'*/, 0 /*'}'*/, 0x03c2 /*'~'*/, 0 /*''*/, /* 128 (80) */ 0 /*'�'*/, 0 /*'�'*/, 0, 0 /*'�'*/, /* 132 (84) */ 0 /*'�'*/, 0 /* blockend '�'*/, 0 /*elusionszeichen'�'*/, 0 /*'�'*/, /* 136 (88) */ 0 /*'�'*/, 0 /*; '�'*/, 0 /*'�'*/, 0 /*'�'*/, /* 140 (8c) */ 0, 0, 0 /*'�'*/, 0 /*'�'*/, /* 144 (90) */ 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, /* 148 (94) */ 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, /* 152 (98) */ 0 /*'�'*/, 0 /*'�'*/, 0 /* / '�'*/, 0 /*'�'*/, /* 156 (9c) */ 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, /* 160 (a0) */ 0, 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, /* 164 (a4) */ 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, 0, /* 168 (a8) */ 0, 0, 0 /*'�'*/, 0, /* 172 (ac) */ 0, 0 /* G '�'*/, 0 /*'�'*/, 0 /*'�'*/, /* 176 (b0) */ 0 /*'�'*/, 0x0306 /*'�'*/, 'j', 0 /*unterpunkt'�'*/, /* 180 (b4) */ 0, 0, 0, 0, /* 184 (b8) */ 0 /*'�'*/, 0, 0 /*'�'*/, 0 /* [ '�'*/, /* 188 (bc) */ 0 /*]'�'*/, 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, /* 192 (c0) */ 0 /*'�'*/, 0 /* degree '�'*/, 0 /* 0x006c */, 0 /*'�'*/, /* 196 (c4) */ 0, 0, 0/* apostrophe */, 0 /*'�'*/, /* 200 (c8) */ 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, /* 204 (cc) */ 0 /*'�'*/, 0 /*'�'*/, 0, 0, /* 208 (d0) */ 0x0304, 0 /* intf uses: 0x00af oberstrich'�'*/, 0 /*'�'*/, 0 /*'�'*/, /* 212 (d4) */ 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, 0, /* 216 (d8) */ 0 /*'�'*/, 0 /*'�'*/, 0 /*|'�'*/, 0 /*`'�'*/, /* 220 (dc) */ 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, 0x0302 /*'�'*/, /* 224 (e0) */ 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, 0, /* 228 (e4) */ 0 /*'�'*/, 0, 0 /*'�'*/, 0, /* 232 (e8) */ 0, 0, 0, 0, /* 236 (ec) */ 0, 0, 0 /*'�'*/, 0 /*'�'*/, /* 240 (f0) */ 0 /*'�'*/, 0, 0 /*'�'*/, 0 /*'�'*/, /* 244 (f4) */ 0 /*'�'*/, 0x03DB /*stigma*/, 0, 0 /*'�'*/, /* 248 (f8) */ 0, 0 /*'�'*/, 0, 0, /* 252 (fc) */ 0 /*'�'*/, 0 /*'�'*/, 0 /*'�'*/, 0 /*'?'*/ }; /* c equiv to put_file_str_in_hndl */ int readLongString(int fd, char **txt) { if (*txt) free(*txt); size_t n_writ; unsigned int size; n_writ = read(fd, &size, 4); size = ntohl(size); if (n_writ != 4) return -1; *txt = (char *)calloc(1, size+1); n_writ = read(fd, *txt, size); if (n_writ != size) return -1; (*txt)[size] = 0; return size; } const char *toUTF8(unsigned long unicode) { static char result[8]; int x = 0; if (unicode < 0x80) { x = 1; result[0] = unicode; } else if (unicode < 0x800) { x = 2; result[0] = 0xc0 | (unicode >> 6); } else if (unicode < 0x10000) { x = 3; result[0] = 0xe0 | (unicode >> 12); } else if (unicode < 0x200000) { x = 4; result[0] = 0xf0 | (unicode >> 18); } if (x > 1) { int y, i=0; for (y = x; y > 1; y--) { result[++i] = 0x80 | (unicode & (0x3f << ((y-2)*6))); } } result[x] = 0; return result; } void symbolGreekToUTF8(char **txt) { bool nomSac = false; for (int i = 0; (*txt)[i]; ++i) if ((unsigned char)(*txt)[i] == 209) { nomSac = true; break; } char *buf = (char *)calloc(6, strlen(*txt)+1); for (int i = 0; (*txt)[i]; ++i) { if ((unsigned char)(*txt)[i] != 209) { strcat(buf, toUTF8(symbolGreekTranslation[(unsigned char)(*txt)[i]])); if (nomSac && isGreekLetter[(unsigned char)(*txt)[i]]) strcat(buf, toUTF8(0x0305)); } } free(*txt); *txt = buf; } int main(int argc, char **argv) { long ioError = 0; int fd; char *p = 0, *q = 0; char another; int count; char *sel_mss = 0, *sel_plcs = 0; short mss, blocks, places; if (argc < 2) { fd = dup(0); /* fprintf(stderr, "usage: %s \n", *argv); exit(-1); */ } else fd = open(argv[1], O_RDONLY); if (fd < 0) { fprintf(stderr, "file not found: %s\n", argv[1]); exit(-1); } printf("\n"); printf("\n"); count = sizeof(char); ioError = (read(fd, &another, count) != count); while ((!ioError) && (another)) { readLongString(fd, &p); symbolGreekToUTF8(&p); readLongString(fd, &q); symbolGreekToUTF8(&q); count = sizeof(short); read(fd, &mss, count); mss = ntohs(mss); read(fd, &blocks, count); blocks = ntohs(blocks); read(fd, &places, count); places = ntohs(places); readLongString(fd, &sel_mss); symbolGreekToUTF8(&sel_mss); readLongString(fd, &sel_plcs); symbolGreekToUTF8(&sel_plcs); printf("\t\n", places); printf("\t\t

%s

\n", p); printf("\t\t%s\n", q); printf("\t\t%s\n", sel_mss); printf("\t\t%s\n", sel_plcs); printf("\t\n"); count = sizeof(char); ioError = (read(fd, &another, count) != count); } printf("
\n"); if (p) free(p); if (q) free(q); if (sel_mss) free(sel_mss); if (sel_plcs) free(sel_plcs); close(fd); return 0; }