/usr/share/apertium/reformat.xsl is in apertium 3.4.0~r61013-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | <?xml version="1.0" encoding="ISO-8859-1"?> <!-- -*- nxml -*- -->
<!--
Copyright (C) 2005 Universitat d'Alacant / Universidad de Alicante
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="format">
%{
#ifndef GENFORMAT
#include "apertium_config.h"
#endif
#include <apertium/unlocked_cstdio.h>
#include <cstdlib>
#include <iostream>
#include <libgen.h>
#include <map>
#include <string>
#include <unistd.h>
#include <lttoolbox/lt_locale.h>
#include <lttoolbox/ltstr.h>
#include <wchar.h>
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif
using namespace std;
<xsl:for-each select="./rules/replacement-rule">
<xsl:variable name="varname"
select="concat(concat(string('S'),position()),string('_substitution'))"/>
<xsl:value-of select="string('map<wstring, wstring, Ltstr> S')"/>
<xsl:value-of select="position()"/>
<xsl:value-of select="string('_substitution;

void S')"/>
<xsl:value-of select="position()"/>
<xsl:value-of select="string('_init()
{')"/>
<xsl:for-each select="./replace">
<xsl:if test="./@prefer = string('yes')">
<xsl:value-of select="string('
 ')"/>
<xsl:value-of select="$varname"/>
<xsl:value-of select="string('[L"')"/>
<xsl:value-of select="./@target"/>
<xsl:value-of select="string('"] = L"')"/>
<xsl:value-of select="./@source"/>
<xsl:value-of select="string('";')"/>
</xsl:if>
</xsl:for-each>
<xsl:value-of select="string('
}
')"/>
</xsl:for-each>
string memconv;
wstring convertir(char const *multibyte, int const length)
{
memconv.append(multibyte, length);
int tam = memconv.size();
if (memconv == "")
return L"";
wchar_t *retval = new wchar_t[tam+1];
size_t l = mbstowcs(retval, memconv.c_str(), tam);
if(l == ((size_t) -1))
{
if(memconv.size() >= 4)
{
wcerr << L"Warning: wrong encoding" << endl;
}
if (retval != NULL)
delete[] retval;
return L"";
}
else
{
memconv = "";
retval[l] = 0;
wstring ret = retval;
if (retval != NULL)
delete[] retval;
return ret;
}
}
%}
%option nounput
%option noyywrap<xsl:if test="./options/case-sensitive/@value=string('no')">
%option caseless</xsl:if>
%%
"["|"]"	{
// do nothing
}
"[@"[^]]+"]"	{
string filename = yytext;
filename = filename.substr(2, filename.size()-3);
FILE *temp = fopen(filename.c_str(), "r");
wint_t mychar;
#ifdef _WIN32
_setmode(_fileno(temp), _O_U8TEXT);
#endif
if(!temp)
{
cerr << "ERROR: File '" << filename <<"' not found." << endl;
exit(EXIT_FAILURE);
}
while(static_cast<int>(mychar = fgetwc_unlocked(temp)) != EOF)
{
fputwc_unlocked(mychar, yyout);
}
fclose(temp);
unlink(filename.c_str());
}
"[\\@"	{
fputwc_unlocked(L'@', yyout);
}
".[]"	{
// do nothing
}
"\\"<xsl:value-of select="/format/options/escape-chars/@regexp"/>	{
fputws_unlocked(convertir(yytext+1, yyleng-1).c_str(), yyout);
}
.|\n	{
wstring yytext_conv = convertir(yytext, yyleng);
<xsl:for-each select="./rules/replacement-rule">
<xsl:variable name="varname"
select="concat(concat(string('S'),position()),string('_substitution'))"/>
<xsl:value-of select="string(' ')"/>
<xsl:if test="not(position()=1)">
<xsl:value-of select="string('else ')"/>
</xsl:if>
<xsl:value-of select="string('if(')"/>
<xsl:value-of select="$varname"/>
<xsl:value-of select="string('.find(yytext_conv) != ')"/>
<xsl:value-of select="$varname"/>
<xsl:value-of select="string('.end())
 {
')"/>
<xsl:value-of select="string(' fputws_unlocked(')"/>
<xsl:value-of select="$varname"/>
<xsl:value-of select="string('[yytext_conv].c_str(), yyout);')"/>
<xsl:value-of select="string('
 }
')"/>
</xsl:for-each>
<xsl:if test="not(count(./rules/replacement-rule)=0)">
<xsl:value-of select="string(' else
 {
 ')"/>
</xsl:if>
<xsl:value-of select="string(' fputws_unlocked(yytext_conv.c_str(), yyout);
')"/>
<xsl:if test="not(count(./rules/replacement-rule)=0)">
<xsl:value-of select="string(' }')"/>
</xsl:if>
}
<<EOF>>	{
return 0;
}
%%
void usage(string const &progname)
{
cerr << "USAGE: " << progname << " [input_file [output_file]" << ']' << endl;
cerr << "<xsl:value-of select="./@name"/> format processor " << endl;
exit(EXIT_SUCCESS);
}
int main(int argc, char *argv[])
{
LtLocale::tryToSetLocale();
if(argc > 3)
{
usage(argv[0]);
}
switch(argc)
{
case 3:
yyout = fopen(argv[2], "w");
if(!yyout)
{
usage(argv[0]);
}
case 2:
yyin = fopen(argv[1], "r");
if(!yyin)
{
usage(argv[0]);
}
break;
default:
break;
}
#ifdef _WIN32
_setmode(_fileno(yyin), _O_U8TEXT);
_setmode(_fileno(yyout), _O_U8TEXT);
#endif
<xsl:for-each select="./rules/replacement-rule">
<xsl:value-of select="string(' S')"/>
<xsl:value-of select="position()"/>
<xsl:value-of select="string('_init();
')"/>
</xsl:for-each>
yylex();
fclose(yyin);
fclose(yyout);
}
</xsl:template>
</xsl:stylesheet>
|