Package: aspell / 0.60.8-3

03_ddtp_filter.diff Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
## 03_ddtp_filter.diff by Christer Andersson <klamm@comhem.se>
##
## Filter for Debian DDTP-emails
--- a/Makefile.am
+++ b/Makefile.am
@@ -166,6 +166,7 @@ dynamic_optfiles =
 
 ### Add the .info file your filter comes with
 optfiles = \
+  modules/filter/ddtp-filter.info\
   modules/filter/debctrl-filter.info\
   modules/filter/email-filter.info\
   modules/filter/tex-filter.info\
@@ -178,6 +179,7 @@ optfiles = \
 
 ### Add all your aspell mode files ###
 fltfiles = \
+  modules/filter/modes/ddtp.amf \
   modules/filter/modes/debctrl.amf \
   modules/filter/modes/html.amf \
   modules/filter/modes/sgml.amf \
@@ -200,6 +202,7 @@ static_optfiles += ${optfiles}
 ### starting with file containing filter class definition followed by
 ### file containing filter member implementation.
 libaspell_la_SOURCES +=\
+  modules/filter/ddtp.cpp\
   modules/filter/debctrl.cpp\
   modules/filter/email.cpp\
   modules/filter/tex.cpp\
@@ -216,7 +219,7 @@ filter_ldflags = -module -avoid-version
 
 ### Add name of filter library containing your filter. Name always
 ### must look like lib<filtername>-filter.la see development manual
-filter_LTLIBRARIES = debctrl-filter.la\
+filter_LTLIBRARIES = debctrl-filter.la ddtp-filter.la\
 		     email-filter.la tex-filter.la\
 	             sgml-filter.la markdown-filter.la context-filter.la\
                      nroff-filter.la texinfo-filter.la
@@ -225,6 +228,10 @@ debctrl_filter_la_SOURCES = modules/filt
 debctrl_filter_la_LIBADD = libaspell.la
 debctrl_filter_la_LDFLAGS  = ${filter_ldflags}
 
+ddtp_filter_la_SOURCES  = modules/filter/ddtp.cpp
+ddtp_filter_la_LIBADD = libaspell.la
+ddtp_filter_la_LDFLAGS  = ${filter_ldflags}
+
 email_filter_la_SOURCES = modules/filter/email.cpp
 email_filter_la_LIBADD = libaspell.la 
 email_filter_la_LDFLAGS  = ${filter_ldflags}
@@ -253,6 +260,10 @@ texinfo_filter_la_SOURCES  = modules/fil
 texinfo_filter_la_LIBADD = libaspell.la
 texinfo_filter_la_LDFLAGS  = ${filter_ldflags}
 
+ddtp_filter_la_SOURCES  = modules/filter/ddtp.cpp
+ddtp_filter_la_LIBADD = libaspell.la
+ddtp_filter_la_LDFLAGS  = ${filter_ldflags}
+
 ### Before this line add the corresponding <yourfilterlibrary>_SOURCES and
 ### <yourfilterlibrary>_LIBADD lines.  The later at least has to look
 ### like <yourfilterlibrary>_LIBADD = ${top_builddir}/lib/libaspell.la
--- /dev/null
+++ b/modules/filter/ddtp-filter.info
@@ -0,0 +1,9 @@
+# ddtp filter option file
+
+#This Filter is usable with the following version(s) of Aspell
+ASPELL >=0.60.5
+
+#This line will be printed when typing `aspell help context'
+DESCRIPTION filter for Debian DDTP-emails
+
+STATIC filter
--- /dev/null
+++ b/modules/filter/ddtp.cpp
@@ -0,0 +1,137 @@
+/* Filter for DDTP-emails (Debian Description Translation Project).
+ *
+ * Copyright (C) 2007, Christer Andersson <klamm@comhem.se>
+ *
+ * This filter is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 2.0 of the License, or
+ * (at your option) any later version.
+ *
+ * This filter is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "settings.h"
+#include "indiv_filter.hpp"
+#include "key_info.hpp"
+
+using namespace acommon;
+
+namespace {
+  class DDTPFilter : public IndividualFilter
+  {
+  public:
+    DDTPFilter() : IndividualFilter() {}
+    virtual ~DDTPFilter() {}
+
+    virtual PosibErr<bool> setup(Config *);
+    virtual void reset();
+    virtual void process(FilterChar * & start, FilterChar * & stop);
+    
+  protected:
+    enum po_filter_state {
+      STATE_COMMENT,      // state: comment (don't check)
+      STATE_ORIGINAL,     // state: original text (don't check)
+      STATE_TRANSLATED    // state: translated text (do check)
+    } state;
+
+    // Set to true when the last character read is a line-break.
+    // States only change at the beginning of lines.
+    bool prev_char_newline;
+  };
+
+
+  PosibErr<bool> 
+  DDTPFilter::setup(Config *config)
+  {
+    name_ = "ddtp-filter";
+    order_num_ = 0.90;
+    reset();
+    return true;
+  }
+
+  void 
+  DDTPFilter::reset() 
+  {
+    prev_char_newline=true;
+    state = STATE_TRANSLATED;
+  }
+
+  void 
+  DDTPFilter::process(FilterChar * & start, FilterChar * & stop)
+  {
+    FilterChar *i = start;   // Current position in text
+    FilterChar *eol;         // Next end-of-line or end of text
+
+    // Identify end-of-line if the previous text chunk did not include one.
+    for ( eol = i ; eol != stop && *eol != '\n' ; eol++ );
+
+    while ( i != stop ) {
+      // Iterate over entire text chunk.
+
+      if ( prev_char_newline ) {
+        // Handle beginning of new lines.
+        prev_char_newline = false;
+
+        // Swallow leading whitespace. With the current formatting of
+        // DDTP-emails this isn't really necessary.
+        while ( i != stop 
+                && ( *i == ' ' || *i == '\t' || *i == '\r' 
+                     || *i == '\f' || *i == '\v' ) )
+          ++i;
+
+        // Determine end of this line.
+        for ( eol = i ; eol != stop && *eol != '\n' ; eol++ );
+
+        // Check for literals:
+        //  '#'                     Comments
+        //  'Description:'          Begin original message
+        //  'Description-LANG.ENC:' Begin translated message
+        if ( *i == '#' ) {
+          state = STATE_COMMENT;
+        }
+        else if ( eol-i >= 12 
+             && i[0] == 'D' && i[1] == 'e' && i[2] == 's' && i[3] == 'c'
+             && i[4] == 'r' && i[5] == 'i' && i[6] == 'p' && i[7] == 't' 
+             && i[8] == 'i' && i[9] == 'o' && i[10] == 'n' 
+             && (i[11] == ':' || i[11] == '-') ) {
+          if (i[11] == ':')
+            state = STATE_ORIGINAL;
+          else
+            state = STATE_TRANSLATED;
+
+          // Blank out keyword.
+          for ( ; i != eol && *i != ':' ; i++)
+            *i = ' ';
+          if ( i != eol ) 
+            *i = ' '; // Colon
+        }
+      }
+
+      // Process current line.
+      if (state == STATE_TRANSLATED) {
+        i = eol;
+      }
+      else {
+        for ( ; i != eol ; i++ )
+          *i = ' ';
+      }
+
+      if (eol != stop) {
+        // More text to process. Move to next line and continue.
+        i++;
+        prev_char_newline = true;
+      }
+    }
+  }
+}
+
+C_EXPORT 
+IndividualFilter* new_aspell_ddtp_filter() {
+  return new DDTPFilter;                       
+}
--- /dev/null
+++ b/modules/filter/modes/ddtp.amf
@@ -0,0 +1,8 @@
+MODE ddtp
+
+ASPELL >=0.60.5
+
+DESCRIPTION mode for Debian DDTP-emails
+
+FILTER ddtp
+FILTER url