Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / i18npool / source / localedata / filewriter.cxx
blob58a3e1ff81afb3b3476a8e93e0a022e1332bf641
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <stdio.h>
30 #include <string.h>
31 #include "LocaleNode.hxx"
32 //-----------------------------------------
33 // The document handler, which is needed for the saxparser
34 // The Documenthandler for reading sax
35 //-----------------------------------------
36 OFileWriter::OFileWriter(const char *pcFile, const char *locale ) {
38 strncpy( m_pcFile , pcFile, sizeof(m_pcFile) );
39 m_pcFile[sizeof(m_pcFile)-1] = 0;
40 printf("file generated=%s\n", m_pcFile);
41 m_f = fopen( m_pcFile , "w" );
42 strncpy( theLocale, locale, sizeof(theLocale) );
43 theLocale[sizeof(theLocale)-1] = 0;
46 OFileWriter::~OFileWriter() {
47 if(m_f)
48 fclose( m_f );
51 void OFileWriter::writeInt(sal_Int16 nb) const
53 fprintf(m_f, "%d", nb);
56 void OFileWriter::writeAsciiString(const char* str) const
58 fprintf(m_f, "%s", str);
61 void OFileWriter::writeStringCharacters(const ::rtl::OUString& str) const
63 for(int i = 0; i < str.getLength(); i++)
64 fprintf(m_f, "0x%x, ", str[i]);
67 void OFileWriter::writeFunction(const char *func, const char *count, const char *array) const
69 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
70 fprintf(m_f, "\tcount = %s;\n", count);
71 fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
74 void OFileWriter::writeRefFunction(const char *func, const ::rtl::OUString& useLocale) const
76 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
77 const char* locale = aRefLocale.getStr();
78 fprintf(m_f, "extern sal_Unicode ** SAL_CALL %s%s(sal_Int16& count);\n", func, locale);
79 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
80 fprintf(m_f, "\treturn %s%s(count);\n}\n", func, locale);
83 void OFileWriter::writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const
85 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
86 fprintf(m_f, "\tcount = %s;\n", count);
87 fprintf(m_f, "\tfrom = %s;\n", from);
88 fprintf(m_f, "\tto = %s;\n", to);
89 fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
92 void OFileWriter::writeRefFunction(const char *func, const ::rtl::OUString& useLocale, const char *to) const
94 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
95 const char* locale = aRefLocale.getStr();
96 fprintf(m_f, "extern sal_Unicode ** SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to);\n", func, locale);
97 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
98 fprintf(m_f, "\tto = %s;\n", to);
99 fprintf(m_f, "\tconst sal_Unicode* tmp;\n");
100 fprintf(m_f, "\treturn %s%s(count, from, tmp);\n}\n", func, locale);
103 void OFileWriter::writeFunction2(const char *func, const char *style, const char* attr, const char *array) const
105 fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nAttributes )\n{\n", func, theLocale);
106 fprintf(m_f, "\tnStyles = %s;\n", style);
107 fprintf(m_f, "\tnAttributes = %s;\n", attr);
108 fprintf(m_f, "\treturn %s;\n}\n", array);
111 void OFileWriter::writeRefFunction2(const char *func, const ::rtl::OUString& useLocale) const
113 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
114 const char* locale = aRefLocale.getStr();
115 fprintf(m_f, "extern const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes);\n", func, locale);
116 fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes)\n{\n", func, theLocale);
117 fprintf(m_f, "\treturn %s%s(nStyles, nAttributes);\n}\n", func, locale);
120 void OFileWriter::writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const
122 fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes )\n{\n", func, theLocale);
123 fprintf(m_f, "\tnStyles = %s;\n", style);
124 fprintf(m_f, "\tnLevels = %s;\n", levels);
125 fprintf(m_f, "\tnAttributes = %s;\n", attr);
126 fprintf(m_f, "\treturn %s;\n}\n", array);
129 void OFileWriter::writeRefFunction3(const char *func, const ::rtl::OUString& useLocale) const
131 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
132 const char* locale = aRefLocale.getStr();
133 fprintf(m_f, "extern const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes);\n", func, locale);
134 fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes)\n{\n", func, theLocale);
135 fprintf(m_f, "\treturn %s%s(nStyles, nLevels, nAttributes);\n}\n", func, locale);
138 void OFileWriter::writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const
140 fprintf(m_f, "static const sal_Unicode %s%d[] = {%d};\n", pAsciiStr, count, val);
143 bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str, sal_Int16 count) const
145 bool bBool = (str == "true" ? 1 : 0);
146 fprintf(m_f,"static const sal_Unicode default%s%d[] = {%d};\n", pAsciiStr, count, bBool);
147 return bBool;
150 bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str) const
152 bool bBool = (str == "true" ? 1 : 0);
153 fprintf(m_f,"static const sal_Unicode default%s[] = {%d};\n", pAsciiStr, bBool);
154 return bBool;
157 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const
159 fprintf(m_f, "static const sal_Unicode %s[] = {", pAsciiStr);
160 writeStringCharacters(aChars);
161 fprintf(m_f, "0x0};\n");
164 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count) const
166 fprintf(m_f, "static const sal_Unicode %s%d[] = {", pAsciiStr, count);
167 writeStringCharacters(aChars);
168 fprintf(m_f, "0x0};\n");
171 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
173 fprintf(m_f, "static const sal_Unicode %s%d%d[] = {", pAsciiStr, count0, count1);
174 writeStringCharacters(aChars);
175 fprintf(m_f, "0x0};\n");
178 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, const sal_Int16 count) const
180 fprintf(m_f, "static const sal_Unicode %s%s%d[] = {", pTagStr, pAsciiStr, count);
181 writeStringCharacters(aChars);
182 fprintf(m_f, "0x0};\n");
185 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const
187 fprintf(m_f, "static const sal_Unicode %s%s[] = {", pTagStr, pAsciiStr);
188 writeStringCharacters(aChars);
189 fprintf(m_f, "0x0};\n");
192 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
194 fprintf(m_f, "static const sal_Unicode %s%s%d%d[] = {", pTagStr, pAsciiStr, count0, count1);
195 writeStringCharacters(aChars);
196 fprintf(m_f, "0x0};\n");
199 void OFileWriter::flush(void) const
201 fflush( m_f );
204 void OFileWriter::closeOutput(void) const
206 if(m_f)
208 fclose( m_f );
209 const_cast< OFileWriter * > ( this )->m_f = 0;
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */