LibreOffice Module i18npool (master)  1
filewriter.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <stdio.h>
21 #include "LocaleNode.hxx"
22 
23 // The document handler, which is needed for the saxparser
24 // The Documenthandler for reading sax
25 
26 OFileWriter::OFileWriter(const char *pcFile, const char *locale ): theLocale(locale) {
27 
28  printf("file generated=%s\n", pcFile);
29  m_f = fopen(pcFile, "w");
30 }
31 
33  if(m_f)
34  fclose( m_f );
35 }
36 
37 void OFileWriter::writeInt(sal_Int16 nb) const
38 {
39  fprintf(m_f, "%d", nb);
40 }
41 
42 void OFileWriter::writeAsciiString(const char* str) const
43 {
44  fprintf(m_f, "%s", str);
45 }
46 
47 void OFileWriter::writeStringCharacters(const OUString& str) const
48 {
49  for(int i = 0; i < str.getLength(); i++)
50  fprintf(m_f, "0x%x, ", str[i]);
51 }
52 
53 void OFileWriter::writeFunction(const char *func, const char *count, const char *array) const
54 {
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);
58 }
59 
60 void OFileWriter::writeRefFunction(const char *func, std::u16string_view useLocale) const
61 {
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);
67 }
68 
69 void OFileWriter::writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const
70 {
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);
76 }
77 
78 void OFileWriter::writeRefFunction(const char *func, std::u16string_view useLocale, const char *to) const
79 {
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);
87 }
88 
89 void OFileWriter::writeFunction2(const char *func, const char *style, const char* attr, const char *array) const
90 {
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);
95 }
96 
97 void OFileWriter::writeRefFunction2(const char *func, std::u16string_view useLocale) const
98 {
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);
104 }
105 
106 void OFileWriter::writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const
107 {
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);
113 }
114 
115 void OFileWriter::writeRefFunction3(const char *func, std::u16string_view useLocale) const
116 {
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);
122 }
123 
124 void OFileWriter::writeIntParameter(const char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const
125 {
126  fprintf(m_f, "static const sal_Unicode %s%d[] = {%d};\n", pAsciiStr, count, val);
127 }
128 
129 bool OFileWriter::writeDefaultParameter(const char* pAsciiStr, std::u16string_view str, sal_Int16 count) const
130 {
131  bool bBool = str == u"true";
132  fprintf(m_f,"static const sal_Unicode default%s%d[] = {%d};\n", pAsciiStr, count, bBool);
133  return bBool;
134 }
135 
136 void OFileWriter::writeParameter(const char* pAsciiStr, const OUString& aChars) const
137 {
138  fprintf(m_f, "static const sal_Unicode %s[] = {", pAsciiStr);
139  writeStringCharacters(aChars);
140  fprintf(m_f, "0x0};\n");
141 }
142 
143 void OFileWriter::writeParameter(const char* pAsciiStr, const OUString& aChars, sal_Int16 count) const
144 {
145  fprintf(m_f, "static const sal_Unicode %s%d[] = {", pAsciiStr, count);
146  writeStringCharacters(aChars);
147  fprintf(m_f, "0x0};\n");
148 }
149 
150 void OFileWriter::writeParameter(const char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
151 {
152  fprintf(m_f, "static const sal_Unicode %s%d%d[] = {", pAsciiStr, count0, count1);
153  writeStringCharacters(aChars);
154  fprintf(m_f, "0x0};\n");
155 }
156 
157 void OFileWriter::writeParameter(const char* pTagStr, const char* pAsciiStr, const OUString& aChars, const sal_Int16 count) const
158 {
159  fprintf(m_f, "static const sal_Unicode %s%s%d[] = {", pTagStr, pAsciiStr, count);
160  writeStringCharacters(aChars);
161  fprintf(m_f, "0x0};\n");
162 }
163 
164 void OFileWriter::writeParameter(const char* pTagStr, const char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
165 {
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");
169 }
170 
172 {
173  if(m_f)
174  {
175  fclose( m_f );
176  const_cast< OFileWriter * > ( this )->m_f = nullptr;
177  }
178 }
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OFileWriter(const char *pcFile, const char *locale)
Definition: filewriter.cxx:26
void writeIntParameter(const char *pAsciiStr, const sal_Int16 count, sal_Int16 val) const
Definition: filewriter.cxx:124
std::string theLocale
Definition: LocaleNode.hxx:62
void writeRefFunction3(const char *func, std::u16string_view useLocale) const
Definition: filewriter.cxx:115
UBlockCode from
UBlockCode to
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
int i
void writeParameter(const char *pAsciiStr, const OUString &aChars) const
Definition: filewriter.cxx:136
void writeAsciiString(const char *str) const
Definition: filewriter.cxx:42
float u
void writeRefFunction2(const char *func, std::u16string_view useLocale) const
Definition: filewriter.cxx:97
void writeFunction(const char *func, const char *count, const char *array) const
Definition: filewriter.cxx:53
FILE * m_f
Definition: LocaleNode.hxx:63
void writeInt(sal_Int16 nb) const
Definition: filewriter.cxx:37
void closeOutput() const
Definition: filewriter.cxx:171
void writeRefFunction(const char *func, std::u16string_view useLocale) const
Definition: filewriter.cxx:60
void writeStringCharacters(const OUString &str) const
Definition: filewriter.cxx:47
bool writeDefaultParameter(const char *pAsciiStr, std::u16string_view str, sal_Int16 count) const
Definition: filewriter.cxx:129
void writeFunction3(const char *func, const char *style, const char *levels, const char *attr, const char *array) const
Definition: filewriter.cxx:106
void writeFunction2(const char *func, const char *style, const char *attr, const char *array) const
Definition: filewriter.cxx:89