Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / i18npool / source / localedata / filewriter.cxx
blob8ea5c70478a0652b00ba5c329028f21f4e53f2b5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <stdio.h>
21 #include <string.h>
22 #include "LocaleNode.hxx"
23 //-----------------------------------------
24 // The document handler, which is needed for the saxparser
25 // The Documenthandler for reading sax
26 //-----------------------------------------
27 OFileWriter::OFileWriter(const char *pcFile, const char *locale ) {
29 strncpy( m_pcFile , pcFile, sizeof(m_pcFile) );
30 m_pcFile[sizeof(m_pcFile)-1] = 0;
31 printf("file generated=%s\n", m_pcFile);
32 m_f = fopen( m_pcFile , "w" );
33 strncpy( theLocale, locale, sizeof(theLocale) );
34 theLocale[sizeof(theLocale)-1] = 0;
37 OFileWriter::~OFileWriter() {
38 if(m_f)
39 fclose( m_f );
42 void OFileWriter::writeInt(sal_Int16 nb) const
44 fprintf(m_f, "%d", nb);
47 void OFileWriter::writeAsciiString(const char* str) const
49 fprintf(m_f, "%s", str);
52 void OFileWriter::writeStringCharacters(const ::rtl::OUString& str) const
54 for(int i = 0; i < str.getLength(); i++)
55 fprintf(m_f, "0x%x, ", str[i]);
58 void OFileWriter::writeFunction(const char *func, const char *count, const char *array) const
60 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
61 fprintf(m_f, "\tcount = %s;\n", count);
62 fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
65 void OFileWriter::writeRefFunction(const char *func, const ::rtl::OUString& useLocale) const
67 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
68 const char* locale = aRefLocale.getStr();
69 fprintf(m_f, "extern sal_Unicode ** SAL_CALL %s%s(sal_Int16& count);\n", func, locale);
70 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
71 fprintf(m_f, "\treturn %s%s(count);\n}\n", func, locale);
74 void OFileWriter::writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const
76 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
77 fprintf(m_f, "\tcount = %s;\n", count);
78 fprintf(m_f, "\tfrom = %s;\n", from);
79 fprintf(m_f, "\tto = %s;\n", to);
80 fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
83 void OFileWriter::writeRefFunction(const char *func, const ::rtl::OUString& useLocale, const char *to) const
85 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
86 const char* locale = aRefLocale.getStr();
87 fprintf(m_f, "extern sal_Unicode ** SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to);\n", func, locale);
88 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
89 fprintf(m_f, "\tto = %s;\n", to);
90 fprintf(m_f, "\tconst sal_Unicode* tmp;\n");
91 fprintf(m_f, "\treturn %s%s(count, from, tmp);\n}\n", func, locale);
94 void OFileWriter::writeFunction2(const char *func, const char *style, const char* attr, const char *array) const
96 fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nAttributes )\n{\n", func, theLocale);
97 fprintf(m_f, "\tnStyles = %s;\n", style);
98 fprintf(m_f, "\tnAttributes = %s;\n", attr);
99 fprintf(m_f, "\treturn %s;\n}\n", array);
102 void OFileWriter::writeRefFunction2(const char *func, const ::rtl::OUString& useLocale) const
104 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
105 const char* locale = aRefLocale.getStr();
106 fprintf(m_f, "extern const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes);\n", func, locale);
107 fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes)\n{\n", func, theLocale);
108 fprintf(m_f, "\treturn %s%s(nStyles, nAttributes);\n}\n", func, locale);
111 void OFileWriter::writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const
113 fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes )\n{\n", func, theLocale);
114 fprintf(m_f, "\tnStyles = %s;\n", style);
115 fprintf(m_f, "\tnLevels = %s;\n", levels);
116 fprintf(m_f, "\tnAttributes = %s;\n", attr);
117 fprintf(m_f, "\treturn %s;\n}\n", array);
120 void OFileWriter::writeRefFunction3(const char *func, const ::rtl::OUString& useLocale) const
122 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
123 const char* locale = aRefLocale.getStr();
124 fprintf(m_f, "extern const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes);\n", func, locale);
125 fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes)\n{\n", func, theLocale);
126 fprintf(m_f, "\treturn %s%s(nStyles, nLevels, nAttributes);\n}\n", func, locale);
129 void OFileWriter::writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const
131 fprintf(m_f, "static const sal_Unicode %s%d[] = {%d};\n", pAsciiStr, count, val);
134 bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str, sal_Int16 count) const
136 bool bBool = (str == "true" ? 1 : 0);
137 fprintf(m_f,"static const sal_Unicode default%s%d[] = {%d};\n", pAsciiStr, count, bBool);
138 return bBool;
141 bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str) const
143 bool bBool = (str == "true" ? 1 : 0);
144 fprintf(m_f,"static const sal_Unicode default%s[] = {%d};\n", pAsciiStr, bBool);
145 return bBool;
148 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const
150 fprintf(m_f, "static const sal_Unicode %s[] = {", pAsciiStr);
151 writeStringCharacters(aChars);
152 fprintf(m_f, "0x0};\n");
155 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count) const
157 fprintf(m_f, "static const sal_Unicode %s%d[] = {", pAsciiStr, count);
158 writeStringCharacters(aChars);
159 fprintf(m_f, "0x0};\n");
162 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
164 fprintf(m_f, "static const sal_Unicode %s%d%d[] = {", pAsciiStr, count0, count1);
165 writeStringCharacters(aChars);
166 fprintf(m_f, "0x0};\n");
169 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, const sal_Int16 count) const
171 fprintf(m_f, "static const sal_Unicode %s%s%d[] = {", pTagStr, pAsciiStr, count);
172 writeStringCharacters(aChars);
173 fprintf(m_f, "0x0};\n");
176 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const
178 fprintf(m_f, "static const sal_Unicode %s%s[] = {", pTagStr, pAsciiStr);
179 writeStringCharacters(aChars);
180 fprintf(m_f, "0x0};\n");
183 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
185 fprintf(m_f, "static const sal_Unicode %s%s%d%d[] = {", pTagStr, pAsciiStr, count0, count1);
186 writeStringCharacters(aChars);
187 fprintf(m_f, "0x0};\n");
190 void OFileWriter::flush(void) const
192 fflush( m_f );
195 void OFileWriter::closeOutput(void) const
197 if(m_f)
199 fclose( m_f );
200 const_cast< OFileWriter * > ( this )->m_f = 0;
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */