1 /* This file is part of The New Aspell
2 Copyright (C) 2000,2001 Sergey Poznyakoff
3
4 This program 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 2 of the License, or
7 (at your option) any later version.
8
9 This program 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 this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 /* This file implements the loadable filter for *.po files.
19 It is an example of loadable dynamic filters for the Aspell. It
20 should be compiled into a shared library. The only symbol it is
21 expected to export is process(). */
22
23 #include <stdio.h>
24
25 enum state
26 {
27 st_init,
28 st_m,
29 st_s,
30 st_g,
31 st_s1,
32 st_t,
33 st_r,
34 st_bracket,
35 st_hide,
36 st_echo,
37 st_newline
38 };
39
40 int msgstr_count = 0;
41 enum state state = st_init;
42
43 int
process(char * start,char * stop)44 process (char *start, char *stop)
45 {
46 int c;
47
48 for ( ; start < stop; start++)
49 {
50 c = *start;
51 switch (state)
52 {
53 case st_init:
54 init:
55 switch (c)
56 {
57 default:
58 break;
59
60 case '#':
61 state = st_hide;
62 break;
63
64 case 'm':
65 state = st_m;
66 break;
67 }
68
69 c = ' ';
70 break;
71
72 case st_m:
73 state = (c == 's') ? st_s : st_hide;
74 c = ' ';
75 break;
76
77 case st_s:
78 state = (c == 'g') ? st_g : st_hide;
79 c = ' ';
80 break;
81
82 case st_g:
83 state = (c == 's') ? st_s1 : st_hide;
84 c = ' ';
85 break;
86
87 case st_s1:
88 state = (c == 't') ? st_t : st_hide;
89 c = ' ';
90 break;
91
92 case st_t:
93 state = (c == 'r') ? st_r : st_hide;
94 c = ' ';
95 break;
96
97 case st_r:
98 if (c == '[')
99 state = st_bracket;
100 else if (msgstr_count > 0)
101 state = st_echo;
102 else
103 state = st_hide;
104 msgstr_count++;
105 c = ' ';
106 break;
107
108 case st_bracket:
109 if (c == ']')
110 {
111 state = st_echo;
112 c = ' ';
113 break;
114 }
115 /*FALLTHROUGH*/
116 case st_hide:
117 if (c == '\n')
118 state = st_init;
119 else
120 c = ' ';
121 break;
122
123 case st_newline:
124 switch (c)
125 {
126 case '"':
127 state = st_echo;
128 break;
129
130 default:
131 goto init;
132 }
133 break;
134
135 case st_echo:
136 if (c == '\n')
137 state = st_newline;
138 break;
139 }
140
141 *start = c;
142 }
143
144 return 0;
145 }
146