bump product version to 6.3.0.0.beta1
[LibreOffice.git] / i18npool / source / localedata / filewriter.cxx
blob02540996e3ea2be7f885b5aeb12bec169a086da2
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 "LocaleNode.hxx"
23 // The document handler, which is needed for the saxparser
24 // The Documenthandler for reading sax
26 OFileWriter::OFileWriter(const char *pcFile, const char *locale ): theLocale(locale) {
28 printf("file generated=%s\n", pcFile);
29 m_f = fopen(pcFile, "w");
32 OFileWriter::~OFileWriter() {
33 if(m_f)
34 fclose( m_f );
37 void OFileWriter::writeInt(sal_Int16 nb) const
39 fprintf(m_f, "%d", nb);
42 void OFileWriter::writeAsciiString(const char* str) const
44 fprintf(m_f, "%s", str);
47 void OFileWriter::writeStringCharacters(const OUString& str) const
49 for(int i = 0; i < str.getLength(); i++)
50 fprintf(m_f, "0x%x, ", str[i]);
53 void OFileWriter::writeFunction(const char *func, const char *count, const char *array) const
55 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale.c_str());
56 fprintf(m_f, "\tcount = %s;\n", count);
57 fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
60 void OFileWriter::writeRefFunction(const char *func, const OUString& useLocale) const
62 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
63 const char* locale = aRefLocale.getStr();
64 fprintf(m_f, "extern sal_Unicode ** SAL_CALL %s%s(sal_Int16& count);\n", func, locale);
65 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale.c_str());
66 fprintf(m_f, "\treturn %s%s(count);\n}\n", func, locale);
69 void OFileWriter::writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const
71 fprintf(m_f, "sal_Unicode const * const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale.c_str());
72 fprintf(m_f, "\tcount = %s;\n", count);
73 fprintf(m_f, "\tfrom = %s;\n", from);
74 fprintf(m_f, "\tto = %s;\n", to);
75 fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
78 void OFileWriter::writeRefFunction(const char *func, const OUString& useLocale, const char *to) const
80 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
81 const char* locale = aRefLocale.getStr();
82 fprintf(m_f, "extern sal_Unicode const * const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to);\n", func, locale);
83 fprintf(m_f, "sal_Unicode const * const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale.c_str());
84 fprintf(m_f, "\tto = %s;\n", to);
85 fprintf(m_f, "\tconst sal_Unicode* tmp;\n");
86 fprintf(m_f, "\treturn %s%s(count, from, tmp);\n}\n", func, locale);
89 void OFileWriter::writeFunction2(const char *func, const char *style, const char* attr, const char *array) const
91 fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nAttributes )\n{\n", func, theLocale.c_str());
92 fprintf(m_f, "\tnStyles = %s;\n", style);
93 fprintf(m_f, "\tnAttributes = %s;\n", attr);
94 fprintf(m_f, "\treturn %s;\n}\n", array);
97 void OFileWriter::writeRefFunction2(const char *func, const OUString& useLocale) const
99 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
100 const char* locale = aRefLocale.getStr();
101 fprintf(m_f, "extern const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes);\n", func, locale);
102 fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes)\n{\n", func, theLocale.c_str());
103 fprintf(m_f, "\treturn %s%s(nStyles, nAttributes);\n}\n", func, locale);
106 void OFileWriter::writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const
108 fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes )\n{\n", func, theLocale.c_str());
109 fprintf(m_f, "\tnStyles = %s;\n", style);
110 fprintf(m_f, "\tnLevels = %s;\n", levels);
111 fprintf(m_f, "\tnAttributes = %s;\n", attr);
112 fprintf(m_f, "\treturn %s;\n}\n", array);
115 void OFileWriter::writeRefFunction3(const char *func, const OUString& useLocale) const
117 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
118 const char* locale = aRefLocale.getStr();
119 fprintf(m_f, "extern const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes);\n", func, locale);
120 fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes)\n{\n", func, theLocale.c_str());
121 fprintf(m_f, "\treturn %s%s(nStyles, nLevels, nAttributes);\n}\n", func, locale);
124 void OFileWriter::writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const
126 fprintf(m_f, "static const sal_Unicode %s%d[] = {%d};\n", pAsciiStr, count, val);
129 bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const OUString& str, sal_Int16 count) const
131 bool bBool = str == "true";
132 fprintf(m_f,"static const sal_Unicode default%s%d[] = {%d};\n", pAsciiStr, count, bBool);
133 return bBool;
136 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const OUString& aChars) const
138 fprintf(m_f, "static const sal_Unicode %s[] = {", pAsciiStr);
139 writeStringCharacters(aChars);
140 fprintf(m_f, "0x0};\n");
143 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count) const
145 fprintf(m_f, "static const sal_Unicode %s%d[] = {", pAsciiStr, count);
146 writeStringCharacters(aChars);
147 fprintf(m_f, "0x0};\n");
150 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
152 fprintf(m_f, "static const sal_Unicode %s%d%d[] = {", pAsciiStr, count0, count1);
153 writeStringCharacters(aChars);
154 fprintf(m_f, "0x0};\n");
157 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars, const sal_Int16 count) const
159 fprintf(m_f, "static const sal_Unicode %s%s%d[] = {", pTagStr, pAsciiStr, count);
160 writeStringCharacters(aChars);
161 fprintf(m_f, "0x0};\n");
164 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
166 fprintf(m_f, "static const sal_Unicode %s%s%d%d[] = {", pTagStr, pAsciiStr, count0, count1);
167 writeStringCharacters(aChars);
168 fprintf(m_f, "0x0};\n");
171 void OFileWriter::closeOutput() const
173 if(m_f)
175 fclose( m_f );
176 const_cast< OFileWriter * > ( this )->m_f = nullptr;
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */