Debian Codegraph @

modules/gcide/tests/greek.c

raw
1 /* This file is part of GNU Dico.
2 Copyright (C) 2012-2024 Sergey Poznyakoff
3
4 GNU Dico is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 GNU Dico is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18 #include <stdio.h>
19 #include <string.h>
20 #include <ctype.h>
21 #include "gcide.h"
22
23 static void
24 print_greek(const char *arg)
25 {
26 while (*arg) {
27 size_t rd;
28 const char *greek = gcide_grk_to_utf8(arg, &rd);
29
30 if (greek) {
31 printf("%s", greek);
32 arg += rd;
33 } else {
34 if (!(*arg == '-' || isspace(*arg)))
35 printf("<!>");
36 putchar(*arg);
37 arg++;
38 }
39 }
40 putchar('\n');
41 }
42
43 int
44 main(int argc, char **argv)
45 {
46 if (argc > 1) {
47 while (--argc)
48 print_greek(*++argv);
49 } else {
50 char buf[80];
51
52 while (fgets(buf, sizeof(buf), stdin)) {
53 buf[strlen(buf)-1] = 0;
54 print_greek(buf);
55 }
56 }
57 return 0;
58 }