1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_i18npool.hxx"
26 #include <stdio.h>
27 #include <string.h>
28 #include "LocaleNode.hxx"
29 //-----------------------------------------
30 // The document handler, which is needed for the saxparser
31 // The Documenthandler for reading sax
32 //-----------------------------------------
OFileWriter(const char * pcFile,const char * locale)33 OFileWriter::OFileWriter(const char *pcFile, const char *locale ) {
34 
35 	strncpy( m_pcFile , pcFile, sizeof(m_pcFile) );
36     m_pcFile[sizeof(m_pcFile)-1] = 0;
37 	printf("file generated=%s\n", m_pcFile);
38     m_f = fopen( m_pcFile , "w" );
39     strncpy( theLocale, locale, sizeof(theLocale) );
40     theLocale[sizeof(theLocale)-1] = 0;
41 }
42 
~OFileWriter()43 OFileWriter::~OFileWriter() {
44 	if(m_f)
45 		fclose( m_f );
46 }
47 
writeInt(sal_Int16 nb) const48 void OFileWriter::writeInt(sal_Int16 nb) const
49 {
50 	fprintf(m_f, "%d", nb);
51 }
52 
writeAsciiString(const char * str) const53 void OFileWriter::writeAsciiString(const char* str) const
54 {
55 	fprintf(m_f, "%s", str);
56 }
57 
writeStringCharacters(const::rtl::OUString & str) const58 void OFileWriter::writeStringCharacters(const ::rtl::OUString& str) const
59 {
60 	for(int i = 0; i < str.getLength(); i++)
61 	    fprintf(m_f, "0x%x, ", str[i]);
62 }
63 
writeFunction(const char * func,const char * count,const char * array) const64 void OFileWriter::writeFunction(const char *func, const char *count, const char *array) const
65 {
66 	fprintf(m_f, "sal_Unicode **  SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
67 	fprintf(m_f, "\tcount = %s;\n", count);
68 	fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
69 }
70 
writeRefFunction(const char * func,const::rtl::OUString & useLocale) const71 void OFileWriter::writeRefFunction(const char *func, const ::rtl::OUString& useLocale) const
72 {
73     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
74 	const char* locale = aRefLocale.getStr();
75 	fprintf(m_f, "extern sal_Unicode **  SAL_CALL %s%s(sal_Int16& count);\n", func, locale);
76 	fprintf(m_f, "sal_Unicode **  SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
77 	fprintf(m_f, "\treturn %s%s(count);\n}\n", func, locale);
78 }
79 
writeFunction(const char * func,const char * count,const char * array,const char * from,const char * to) const80 void OFileWriter::writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const
81 {
82 	fprintf(m_f, "sal_Unicode **  SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
83 	fprintf(m_f, "\tcount = %s;\n", count);
84 	fprintf(m_f, "\tfrom = %s;\n", from);
85 	fprintf(m_f, "\tto = %s;\n", to);
86 	fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
87 }
88 
writeRefFunction(const char * func,const::rtl::OUString & useLocale,const char * to) const89 void OFileWriter::writeRefFunction(const char *func, const ::rtl::OUString& useLocale, const char *to) const
90 {
91     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
92 	const char* locale = aRefLocale.getStr();
93 	fprintf(m_f, "extern sal_Unicode **  SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to);\n", func, locale);
94 	fprintf(m_f, "sal_Unicode **  SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
95 	fprintf(m_f, "\tto = %s;\n", to);
96 	fprintf(m_f, "\tconst sal_Unicode* tmp;\n");
97 	fprintf(m_f, "\treturn %s%s(count, from, tmp);\n}\n", func, locale);
98 }
99 
writeFunction2(const char * func,const char * style,const char * attr,const char * array) const100 void OFileWriter::writeFunction2(const char *func, const char *style, const char* attr, const char *array) const
101 {
102 	fprintf(m_f, "const sal_Unicode ***  SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nAttributes )\n{\n", func, theLocale);
103 	fprintf(m_f, "\tnStyles     = %s;\n", style);
104 	fprintf(m_f, "\tnAttributes = %s;\n", attr);
105 	fprintf(m_f, "\treturn %s;\n}\n", array);
106 }
107 
writeRefFunction2(const char * func,const::rtl::OUString & useLocale) const108 void OFileWriter::writeRefFunction2(const char *func, const ::rtl::OUString& useLocale) const
109 {
110     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
111 	const char* locale = aRefLocale.getStr();
112 	fprintf(m_f, "extern const sal_Unicode ***  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes);\n", func, locale);
113 	fprintf(m_f, "const sal_Unicode ***  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes)\n{\n", func, theLocale);
114 	fprintf(m_f, "\treturn %s%s(nStyles, nAttributes);\n}\n", func, locale);
115 }
116 
writeFunction3(const char * func,const char * style,const char * levels,const char * attr,const char * array) const117 void OFileWriter::writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const
118 {
119 	fprintf(m_f, "const sal_Unicode ****  SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes )\n{\n", func, theLocale);
120 	fprintf(m_f, "\tnStyles     = %s;\n", style);
121 	fprintf(m_f, "\tnLevels     = %s;\n", levels);
122 	fprintf(m_f, "\tnAttributes = %s;\n", attr);
123 	fprintf(m_f, "\treturn %s;\n}\n", array);
124 }
125 
writeRefFunction3(const char * func,const::rtl::OUString & useLocale) const126 void OFileWriter::writeRefFunction3(const char *func, const ::rtl::OUString& useLocale) const
127 {
128     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
129 	const char* locale = aRefLocale.getStr();
130 	fprintf(m_f, "extern const sal_Unicode ****  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes);\n", func, locale);
131 	fprintf(m_f, "const sal_Unicode ****  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes)\n{\n", func, theLocale);
132 	fprintf(m_f, "\treturn %s%s(nStyles, nLevels, nAttributes);\n}\n", func, locale);
133 }
134 
writeIntParameter(const sal_Char * pAsciiStr,const sal_Int16 count,sal_Int16 val) const135 void OFileWriter::writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const
136 {
137 	fprintf(m_f, "static const sal_Unicode %s%d[] = {%d};\n", pAsciiStr, count, val);
138 }
139 
writeDefaultParameter(const sal_Char * pAsciiStr,const::rtl::OUString & str,sal_Int16 count) const140 bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str, sal_Int16 count) const
141 {
142     bool bBool = (str.equalsAscii("true") ? 1 : 0);
143 	fprintf(m_f,"static const sal_Unicode default%s%d[] = {%d};\n", pAsciiStr, count, bBool);
144     return bBool;
145 }
146 
writeDefaultParameter(const sal_Char * pAsciiStr,const::rtl::OUString & str) const147 bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str) const
148 {
149     bool bBool = (str.equalsAscii("true") ? 1 : 0);
150 	fprintf(m_f,"static const sal_Unicode default%s[] = {%d};\n", pAsciiStr, bBool);
151     return bBool;
152 }
153 
writeParameter(const sal_Char * pAsciiStr,const::rtl::OUString & aChars) const154 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const
155 {
156 	fprintf(m_f, "static const sal_Unicode %s[] = {", pAsciiStr);
157 	writeStringCharacters(aChars);
158 	fprintf(m_f, "0x0};\n");
159 }
160 
writeParameter(const sal_Char * pAsciiStr,const::rtl::OUString & aChars,sal_Int16 count) const161 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count) const
162 {
163 	fprintf(m_f, "static const sal_Unicode %s%d[] = {", pAsciiStr, count);
164 	writeStringCharacters(aChars);
165 	fprintf(m_f, "0x0};\n");
166 }
167 
writeParameter(const sal_Char * pAsciiStr,const::rtl::OUString & aChars,sal_Int16 count0,sal_Int16 count1) const168 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
169 {
170 	fprintf(m_f, "static const sal_Unicode %s%d%d[] = {", pAsciiStr, count0, count1);
171 	writeStringCharacters(aChars);
172 	fprintf(m_f, "0x0};\n");
173 }
174 
writeParameter(const sal_Char * pTagStr,const sal_Char * pAsciiStr,const::rtl::OUString & aChars,const sal_Int16 count) const175 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, const sal_Int16 count) const
176 {
177 	fprintf(m_f, "static const sal_Unicode %s%s%d[] = {", pTagStr, pAsciiStr, count);
178 	writeStringCharacters(aChars);
179 	fprintf(m_f, "0x0};\n");
180 }
181 
writeParameter(const sal_Char * pTagStr,const sal_Char * pAsciiStr,const::rtl::OUString & aChars) const182 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const
183 {
184 	fprintf(m_f, "static const sal_Unicode %s%s[] = {", pTagStr, pAsciiStr);
185 	writeStringCharacters(aChars);
186 	fprintf(m_f, "0x0};\n");
187 }
188 
writeParameter(const sal_Char * pTagStr,const sal_Char * pAsciiStr,const::rtl::OUString & aChars,sal_Int16 count0,sal_Int16 count1) const189 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
190 {
191 	fprintf(m_f, "static const sal_Unicode %s%s%d%d[] = {", pTagStr, pAsciiStr, count0, count1);
192 	writeStringCharacters(aChars);
193 	fprintf(m_f, "0x0};\n");
194 }
195 
flush(void) const196 void OFileWriter::flush(void) const
197 {
198 	fflush( m_f );
199 }
200 
closeOutput(void) const201 void OFileWriter::closeOutput(void) const
202 {
203 	if(m_f)
204 	{
205 		fclose( m_f );
206 		const_cast< OFileWriter * > ( this )->m_f = 0;
207 	}
208 }
209 
210