Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / i18npool / source / localedata / filewriter.cxx
blob2026e55b5f721f1d422582522ad50b7b385b1392
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"
24 // The document handler, which is needed for the saxparser
25 // The Documenthandler for reading sax
27 OFileWriter::OFileWriter(const char *pcFile, const char *locale ) {
29 printf("file generated=%s\n", pcFile);
30 m_f = fopen(pcFile, "w");
31 strncpy( theLocale, locale, sizeof(theLocale) );
32 theLocale[sizeof(theLocale)-1] = 0;
35 OFileWriter::~OFileWriter() {
36 if(m_f)
37 fclose( m_f );
40 void OFileWriter::writeInt(sal_Int16 nb) const
42 fprintf(m_f, "%d", nb);
45 void OFileWriter::writeAsciiString(const char* str) const
47 fprintf(m_f, "%s", str);
50 void OFileWriter::writeStringCharacters(const OUString& str) const
52 for(int i = 0; i < str.getLength(); i++)
53 fprintf(m_f, "0x%x, ", str[i]);
56 void OFileWriter::writeFunction(const char *func, const char *count, const char *array) const
58 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
59 fprintf(m_f, "\tcount = %s;\n", count);
60 fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
63 void OFileWriter::writeRefFunction(const char *func, const OUString& useLocale) const
65 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
66 const char* locale = aRefLocale.getStr();
67 fprintf(m_f, "extern sal_Unicode ** SAL_CALL %s%s(sal_Int16& count);\n", func, locale);
68 fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
69 fprintf(m_f, "\treturn %s%s(count);\n}\n", func, locale);
72 void OFileWriter::writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const
74 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);
75 fprintf(m_f, "\tcount = %s;\n", count);
76 fprintf(m_f, "\tfrom = %s;\n", from);
77 fprintf(m_f, "\tto = %s;\n", to);
78 fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
81 void OFileWriter::writeRefFunction(const char *func, const OUString& useLocale, const char *to) const
83 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
84 const char* locale = aRefLocale.getStr();
85 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);
86 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);
87 fprintf(m_f, "\tto = %s;\n", to);
88 fprintf(m_f, "\tconst sal_Unicode* tmp;\n");
89 fprintf(m_f, "\treturn %s%s(count, from, tmp);\n}\n", func, locale);
92 void OFileWriter::writeFunction2(const char *func, const char *style, const char* attr, const char *array) const
94 fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nAttributes )\n{\n", func, theLocale);
95 fprintf(m_f, "\tnStyles = %s;\n", style);
96 fprintf(m_f, "\tnAttributes = %s;\n", attr);
97 fprintf(m_f, "\treturn %s;\n}\n", array);
100 void OFileWriter::writeRefFunction2(const char *func, const OUString& useLocale) const
102 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
103 const char* locale = aRefLocale.getStr();
104 fprintf(m_f, "extern const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes);\n", func, locale);
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, "\treturn %s%s(nStyles, nAttributes);\n}\n", func, locale);
109 void OFileWriter::writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const
111 fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes )\n{\n", func, theLocale);
112 fprintf(m_f, "\tnStyles = %s;\n", style);
113 fprintf(m_f, "\tnLevels = %s;\n", levels);
114 fprintf(m_f, "\tnAttributes = %s;\n", attr);
115 fprintf(m_f, "\treturn %s;\n}\n", array);
118 void OFileWriter::writeRefFunction3(const char *func, const OUString& useLocale) const
120 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
121 const char* locale = aRefLocale.getStr();
122 fprintf(m_f, "extern const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes);\n", func, locale);
123 fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes)\n{\n", func, theLocale);
124 fprintf(m_f, "\treturn %s%s(nStyles, nLevels, nAttributes);\n}\n", func, locale);
127 void OFileWriter::writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const
129 fprintf(m_f, "static const sal_Unicode %s%d[] = {%d};\n", pAsciiStr, count, val);
132 bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const OUString& str, sal_Int16 count) const
134 bool bBool = str == "true";
135 fprintf(m_f,"static const sal_Unicode default%s%d[] = {%d};\n", pAsciiStr, count, bBool);
136 return bBool;
139 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const OUString& aChars) const
141 fprintf(m_f, "static const sal_Unicode %s[] = {", pAsciiStr);
142 writeStringCharacters(aChars);
143 fprintf(m_f, "0x0};\n");
146 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count) const
148 fprintf(m_f, "static const sal_Unicode %s%d[] = {", pAsciiStr, count);
149 writeStringCharacters(aChars);
150 fprintf(m_f, "0x0};\n");
153 void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
155 fprintf(m_f, "static const sal_Unicode %s%d%d[] = {", pAsciiStr, count0, count1);
156 writeStringCharacters(aChars);
157 fprintf(m_f, "0x0};\n");
160 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars, const sal_Int16 count) const
162 fprintf(m_f, "static const sal_Unicode %s%s%d[] = {", pTagStr, pAsciiStr, count);
163 writeStringCharacters(aChars);
164 fprintf(m_f, "0x0};\n");
167 void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
169 fprintf(m_f, "static const sal_Unicode %s%s%d%d[] = {", pTagStr, pAsciiStr, count0, count1);
170 writeStringCharacters(aChars);
171 fprintf(m_f, "0x0};\n");
174 void OFileWriter::closeOutput() const
176 if(m_f)
178 fclose( m_f );
179 const_cast< OFileWriter * > ( this )->m_f = nullptr;
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */