1 <?xml version=
"1.0" encoding=
"ISO-8859-1"?> <!-- -*- nxml -*- -->
3 Copyright (C) 2005 Universitat d'Alacant / Universidad de Alicante
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 <xsl:stylesheet version=
"1.0"
21 xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform">
22 <xsl:output method=
"text" encoding=
"ISO-8859-1"/>
24 <xsl:template match=
"format">
28 #include
<apertium/ApertiumConfig.H
>
30 #if !HAVE_DECL_FPUTS_UNLOCKED
31 #define fputs_unlocked fputs
34 #if !HAVE_DECL_FPUTC_UNLOCKED
35 #define fputc_unlocked fputc
38 #include
<cstdlib
>
39 #include
<iostream
>
40 #include
<libgen.h
>
42 #include
<string
>
43 #include
<unistd.h
>
48 <xsl:for-each select=
"./rules/replacement-rule">
49 <xsl:variable name=
"varname"
50 select=
"concat(concat(string('S'),position()),string('_substitution'))"/>
51 <xsl:value-of select=
"string('map<string, string> S')"/>
52 <xsl:value-of select=
"position()"/>
53 <xsl:value-of select=
"string('_substitution;

void S')"/>
54 <xsl:value-of select=
"position()"/>
55 <xsl:value-of select=
"string('_init()
{')"/>
57 <xsl:for-each select=
"./replace">
58 <xsl:if test=
"./@prefer = string('yes')">
59 <xsl:value-of select=
"string('
 ')"/>
60 <xsl:value-of select=
"$varname"/>
61 <xsl:value-of select=
"string('["')"/>
62 <xsl:value-of select=
"./@target"/>
63 <xsl:value-of select=
"string('"] = "')"/>
64 <xsl:value-of select=
"./@source"/>
65 <xsl:value-of select=
"string('";')"/>
69 <xsl:value-of select=
"string('
}
')"/>
75 %option noyywrap
<xsl:if test=
"./options/case-sensitive/@value=string('no')">
76 %option caseless
</xsl:if>
85 string filename = yytext;
86 filename = filename.substr(
2, filename.size()-
3);
87 FILE *temp = fopen(filename.c_str(),
"r");
92 cerr
<< "ERROR: File '" << filename
<<"' not found." << endl;
95 while((mychar = fgetc_unlocked(temp)) != EOF)
97 fputc_unlocked(mychar, yyout);
100 unlink(filename.c_str());
104 fputc_unlocked('@', yyout);
111 "\\"<xsl:value-of select=
"/format/options/escape-chars/@regexp"/>	{
112 fputc_unlocked(yytext[
1], yyout);
118 <xsl:for-each select=
"./rules/replacement-rule">
119 <xsl:variable name=
"varname"
120 select=
"concat(concat(string('S'),position()),string('_substitution'))"/>
122 <xsl:value-of select=
"string(' ')"/>
123 <xsl:if test=
"not(position()=1)">
124 <xsl:value-of select=
"string('else ')"/>
126 <xsl:value-of select=
"string('if(')"/>
127 <xsl:value-of select=
"$varname"/>
128 <xsl:value-of select=
"string('.find(yytext) != ')"/>
129 <xsl:value-of select=
"$varname"/>
130 <xsl:value-of select=
"string('.end())
 {
')"/>
131 <xsl:value-of select=
"string(' fputs_unlocked(')"/>
132 <xsl:value-of select=
"$varname"/>
133 <xsl:value-of select=
"string('[yytext].c_str(), yyout);')"/>
134 <xsl:value-of select=
"string('
 }
')"/>
137 <xsl:if test=
"not(count(./rules/replacement-rule)=0)">
138 <xsl:value-of select=
"string(' else
 {
 ')"/>
140 <xsl:value-of select=
"string(' fputc_unlocked(yytext[0], yyout);
')"/>
141 <xsl:if test=
"not(count(./rules/replacement-rule)=0)">
142 <xsl:value-of select=
"string(' }')"/>
147 <<EOF
>>	{
153 void usage(string const
&progname)
155 cerr
<< "USAGE: " << progname
<< " [input_file [output_file]" << ']'
<< endl;
156 cerr
<< "<xsl:value-of select="./@name
"/> format processor " << endl;
160 int main(int argc, char *argv[])
170 yyout = fopen(argv[
2],
"w");
176 yyin = fopen(argv[
1],
"r");
186 <xsl:for-each select=
"./rules/replacement-rule">
187 <xsl:value-of select=
"string(' S')"/>
188 <xsl:value-of select=
"position()"/>
189 <xsl:value-of select=
"string('_init();
')"/>