Debian Codegraph @

modules/gcide/tests/exgrk.c

raw
1 /* Extract greek transliterations from GCIDE. 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 /* This program extracts greek transliterations from input GCIDE dictionaries.
18 Sample usage:
19
20 cat CIDE.[A-Z] | exgrk | sort | uniq
21 */
22
23 #include <stdio.h>
24
25 enum {
26 S_INIT,
27 S_OPEN,
28 S_OG,
29 S_OR,
30 S_OK,
31 S_GRK
32 };
33
34 int
35 main(int argc, char **argv)
36 {
37 int c;
38 int state = S_INIT;
39
40 while ((c = getc(stdin)) > 0) {
41 switch (state) {
42 case S_INIT:
43 if (c == '<')
44 state = S_OPEN;
45 break;
46
47 case S_OPEN:
48 if (c == 'g')
49 state = S_OG;
50 else
51 state = S_INIT;
52 break;
53
54 case S_OG:
55 if (c == 'r')
56 state = S_OR;
57 else
58 state = S_INIT;
59 break;
60
61 case S_OR:
62 if (c == 'k')
63 state = S_OK;
64 else
65 state = S_INIT;
66 break;
67
68 case S_OK:
69 if (c == '>')
70 state = S_GRK;
71 else
72 state = S_INIT;
73 break;
74
75 case S_GRK:
76 if (c == '<') {
77 state = S_INIT;
78 c = '\n';
79 }
80 putchar(c);
81 break;
82 }
83 }
84 return 0;
85 }