Line data Source code
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 <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 220 : OFileWriter::OFileWriter(const char *pcFile, const char *locale ) {
28 :
29 220 : strncpy( m_pcFile , pcFile, sizeof(m_pcFile) );
30 220 : m_pcFile[sizeof(m_pcFile)-1] = 0;
31 220 : printf("file generated=%s\n", m_pcFile);
32 220 : m_f = fopen( m_pcFile , "w" );
33 220 : strncpy( theLocale, locale, sizeof(theLocale) );
34 220 : theLocale[sizeof(theLocale)-1] = 0;
35 220 : }
36 :
37 220 : OFileWriter::~OFileWriter() {
38 220 : if(m_f)
39 0 : fclose( m_f );
40 220 : }
41 :
42 159679 : void OFileWriter::writeInt(sal_Int16 nb) const
43 : {
44 159679 : fprintf(m_f, "%d", nb);
45 159679 : }
46 :
47 370568 : void OFileWriter::writeAsciiString(const char* str) const
48 : {
49 370568 : fprintf(m_f, "%s", str);
50 370568 : }
51 :
52 95067 : void OFileWriter::writeStringCharacters(const ::rtl::OUString& str) const
53 : {
54 580994 : for(int i = 0; i < str.getLength(); i++)
55 485927 : fprintf(m_f, "0x%x, ", str[i]);
56 95067 : }
57 :
58 2168 : void OFileWriter::writeFunction(const char *func, const char *count, const char *array) const
59 : {
60 2168 : fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
61 2168 : fprintf(m_f, "\tcount = %s;\n", count);
62 2168 : fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
63 2168 : }
64 :
65 1132 : void OFileWriter::writeRefFunction(const char *func, const ::rtl::OUString& useLocale) const
66 : {
67 1132 : OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
68 1132 : const char* locale = aRefLocale.getStr();
69 1132 : fprintf(m_f, "extern sal_Unicode ** SAL_CALL %s%s(sal_Int16& count);\n", func, locale);
70 1132 : fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
71 1132 : fprintf(m_f, "\treturn %s%s(count);\n}\n", func, locale);
72 1132 : }
73 :
74 148 : void OFileWriter::writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const
75 : {
76 148 : 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 148 : fprintf(m_f, "\tcount = %s;\n", count);
78 148 : fprintf(m_f, "\tfrom = %s;\n", from);
79 148 : fprintf(m_f, "\tto = %s;\n", to);
80 148 : fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
81 148 : }
82 :
83 73 : void OFileWriter::writeRefFunction(const char *func, const ::rtl::OUString& useLocale, const char *to) const
84 : {
85 73 : OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
86 73 : const char* locale = aRefLocale.getStr();
87 73 : 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 73 : 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 73 : fprintf(m_f, "\tto = %s;\n", to);
90 73 : fprintf(m_f, "\tconst sal_Unicode* tmp;\n");
91 73 : fprintf(m_f, "\treturn %s%s(count, from, tmp);\n}\n", func, locale);
92 73 : }
93 :
94 67 : void OFileWriter::writeFunction2(const char *func, const char *style, const char* attr, const char *array) const
95 : {
96 67 : fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nAttributes )\n{\n", func, theLocale);
97 67 : fprintf(m_f, "\tnStyles = %s;\n", style);
98 67 : fprintf(m_f, "\tnAttributes = %s;\n", attr);
99 67 : fprintf(m_f, "\treturn %s;\n}\n", array);
100 67 : }
101 :
102 153 : void OFileWriter::writeRefFunction2(const char *func, const ::rtl::OUString& useLocale) const
103 : {
104 153 : OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
105 153 : const char* locale = aRefLocale.getStr();
106 153 : fprintf(m_f, "extern const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes);\n", func, locale);
107 153 : fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes)\n{\n", func, theLocale);
108 153 : fprintf(m_f, "\treturn %s%s(nStyles, nAttributes);\n}\n", func, locale);
109 153 : }
110 :
111 27 : void OFileWriter::writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const
112 : {
113 27 : fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes )\n{\n", func, theLocale);
114 27 : fprintf(m_f, "\tnStyles = %s;\n", style);
115 27 : fprintf(m_f, "\tnLevels = %s;\n", levels);
116 27 : fprintf(m_f, "\tnAttributes = %s;\n", attr);
117 27 : fprintf(m_f, "\treturn %s;\n}\n", array);
118 27 : }
119 :
120 193 : void OFileWriter::writeRefFunction3(const char *func, const ::rtl::OUString& useLocale) const
121 : {
122 193 : OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
123 193 : const char* locale = aRefLocale.getStr();
124 193 : fprintf(m_f, "extern const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes);\n", func, locale);
125 193 : fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes)\n{\n", func, theLocale);
126 193 : fprintf(m_f, "\treturn %s%s(nStyles, nLevels, nAttributes);\n}\n", func, locale);
127 193 : }
128 :
129 7477 : void OFileWriter::writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const
130 : {
131 7477 : fprintf(m_f, "static const sal_Unicode %s%d[] = {%d};\n", pAsciiStr, count, val);
132 7477 : }
133 :
134 8424 : bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str, sal_Int16 count) const
135 : {
136 8424 : bool bBool = (str == "true" ? 1 : 0);
137 8424 : fprintf(m_f,"static const sal_Unicode default%s%d[] = {%d};\n", pAsciiStr, count, bBool);
138 8424 : return bBool;
139 : }
140 :
141 0 : bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str) const
142 : {
143 0 : bool bBool = (str == "true" ? 1 : 0);
144 0 : fprintf(m_f,"static const sal_Unicode default%s[] = {%d};\n", pAsciiStr, bBool);
145 0 : return bBool;
146 : }
147 :
148 5572 : void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const
149 : {
150 5572 : fprintf(m_f, "static const sal_Unicode %s[] = {", pAsciiStr);
151 5572 : writeStringCharacters(aChars);
152 5572 : fprintf(m_f, "0x0};\n");
153 5572 : }
154 :
155 41154 : void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count) const
156 : {
157 41154 : fprintf(m_f, "static const sal_Unicode %s%d[] = {", pAsciiStr, count);
158 41154 : writeStringCharacters(aChars);
159 41154 : fprintf(m_f, "0x0};\n");
160 41154 : }
161 :
162 8417 : void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
163 : {
164 8417 : fprintf(m_f, "static const sal_Unicode %s%d%d[] = {", pAsciiStr, count0, count1);
165 8417 : writeStringCharacters(aChars);
166 8417 : fprintf(m_f, "0x0};\n");
167 8417 : }
168 :
169 2730 : void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, const sal_Int16 count) const
170 : {
171 2730 : fprintf(m_f, "static const sal_Unicode %s%s%d[] = {", pTagStr, pAsciiStr, count);
172 2730 : writeStringCharacters(aChars);
173 2730 : fprintf(m_f, "0x0};\n");
174 2730 : }
175 :
176 0 : void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const
177 : {
178 0 : fprintf(m_f, "static const sal_Unicode %s%s[] = {", pTagStr, pAsciiStr);
179 0 : writeStringCharacters(aChars);
180 0 : fprintf(m_f, "0x0};\n");
181 0 : }
182 :
183 37194 : void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
184 : {
185 37194 : fprintf(m_f, "static const sal_Unicode %s%s%d%d[] = {", pTagStr, pAsciiStr, count0, count1);
186 37194 : writeStringCharacters(aChars);
187 37194 : fprintf(m_f, "0x0};\n");
188 37194 : }
189 :
190 0 : void OFileWriter::flush(void) const
191 : {
192 0 : fflush( m_f );
193 0 : }
194 :
195 440 : void OFileWriter::closeOutput(void) const
196 : {
197 440 : if(m_f)
198 : {
199 220 : fclose( m_f );
200 220 : const_cast< OFileWriter * > ( this )->m_f = 0;
201 : }
202 440 : }
203 :
204 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|