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