Branch data 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 : : /****************** I N C L U D E S **************************************/
21 : :
22 : : // C and C++ Includes.
23 : : #include <stdlib.h>
24 : : #include <stdio.h>
25 : : #include <string.h>
26 : :
27 : : // Programmabh�ngige Includes.
28 : : #include <rscdb.hxx>
29 : : #include <rscstr.hxx>
30 : :
31 : : #include <rtl/textcvt.h>
32 : : #include <rtl/textenc.h>
33 : :
34 : : /****************** C O D E **********************************************/
35 : : /****************** R s c S t r i n g ************************************/
36 : : /*************************************************************************
37 : : |*
38 : : |* RscString::RscString()
39 : : |*
40 : : *************************************************************************/
41 : 2880 : RscString::RscString( Atom nId, sal_uInt32 nTypeId )
42 : 2880 : : RscTop( nId, nTypeId )
43 : : {
44 : 2880 : nSize = ALIGNED_SIZE( sizeof( RscStringInst ) );
45 : 2880 : pRefClass = NULL;
46 : 2880 : }
47 : :
48 : : /*************************************************************************
49 : : |*
50 : : |* RscString::GetClassType()
51 : : |*
52 : : *************************************************************************/
53 : 0 : RSCCLASS_TYPE RscString::GetClassType() const
54 : : {
55 : 0 : return RSCCLASS_STRING;
56 : : }
57 : :
58 : : /*************************************************************************
59 : : |*
60 : : |* RscString::SetNumber()
61 : : |*
62 : : *************************************************************************/
63 : 270084 : ERRTYPE RscString::SetString( const RSCINST & rInst, const char * pStr ){
64 : : char * pTmp;
65 : 270084 : ERRTYPE aError;
66 : :
67 [ + - ]: 270084 : if( aError.IsOk() ){
68 : 270084 : ((RscStringInst *)rInst.pData)->bDflt = sal_False;
69 : :
70 : 270084 : pTmp = ((RscStringInst *)rInst.pData)->pStr;
71 [ + + ]: 270084 : if( pTmp ){
72 : 42602 : rtl_freeMemory( pTmp );
73 : 42602 : pTmp = NULL;
74 : : }
75 : :
76 [ + + ]: 270084 : if( pStr ){
77 : 227436 : sal_uInt32 nLen = strlen( pStr ) +1;
78 : 227436 : pTmp = (char *)rtl_allocateMemory( nLen );
79 : 227436 : memcpy( pTmp, pStr, nLen );
80 : : };
81 : :
82 : 270084 : ((RscStringInst *)rInst.pData)->pStr = pTmp;
83 : : }
84 : :
85 : 270084 : return( aError );
86 : : }
87 : :
88 : : /*************************************************************************
89 : : |*
90 : : |* RscString::GetString()
91 : : |*
92 : : *************************************************************************/
93 : 1452 : ERRTYPE RscString::GetString( const RSCINST & rInst, char ** ppStr ){
94 : 1452 : *ppStr = ((RscStringInst *)rInst.pData)->pStr;
95 : 1452 : return( ERR_OK );
96 : : }
97 : :
98 : : /*************************************************************************
99 : : |*
100 : : |* RscString::GetRef()
101 : : |*
102 : : *************************************************************************/
103 : 6964 : ERRTYPE RscString::GetRef( const RSCINST & rInst, RscId * pRscId ){
104 : 6964 : *pRscId = ((RscStringInst *)rInst.pData)->aRefId;
105 : 6964 : return( ERR_OK );
106 : : }
107 : :
108 : : /*************************************************************************
109 : : |*
110 : : |* RscString::SetRef()
111 : : |*
112 : : *************************************************************************/
113 : 0 : ERRTYPE RscString::SetRef( const RSCINST & rInst, const RscId & rRefId ){
114 [ # # ]: 0 : if( pRefClass ){
115 : 0 : ((RscStringInst *)rInst.pData)->aRefId = rRefId;
116 : 0 : ((RscStringInst *)rInst.pData)->bDflt = sal_False;
117 : : }
118 : : else
119 : 0 : return( ERR_REFNOTALLOWED );
120 : :
121 : 0 : return ERR_OK;
122 : : }
123 : :
124 : : /*************************************************************************
125 : : |*
126 : : |* RscString::Create()
127 : : |*
128 : : *************************************************************************/
129 : 236874 : RSCINST RscString::Create( RSCINST * pInst, const RSCINST & rDflt,
130 : : sal_Bool bOwnClass )
131 : : {
132 : 236874 : RSCINST aInst;
133 : :
134 [ + + ]: 236874 : if( !pInst ){
135 : 140188 : aInst.pClass = this;
136 : : aInst.pData = (CLASS_DATA)
137 : 140188 : rtl_allocateMemory( sizeof( RscStringInst ) );
138 : : }
139 : : else
140 : 96686 : aInst = *pInst;
141 [ + + ][ + + ]: 236874 : if( !bOwnClass && rDflt.IsInst() )
[ + + ]
142 : 85480 : bOwnClass = rDflt.pClass->InHierarchy( this );
143 : :
144 : 236874 : ((RscStringInst *)aInst.pData)->aRefId.Create();
145 : 236874 : ((RscStringInst *)aInst.pData)->pStr = NULL;
146 : 236874 : ((RscStringInst *)aInst.pData)->bDflt = sal_True;
147 : :
148 [ + + ]: 236874 : if( bOwnClass ){
149 : : ((RscStringInst *)aInst.pData)->aRefId =
150 : 85714 : ((RscStringInst *)rDflt.pData)->aRefId;
151 : 85714 : SetString( aInst, ((RscStringInst *)rDflt.pData)->pStr );
152 : : ((RscStringInst *)aInst.pData)->bDflt =
153 : 85714 : ((RscStringInst *)rDflt.pData)->bDflt ;
154 : : }
155 : :
156 : 236874 : return( aInst );
157 : : }
158 : :
159 : : /*************************************************************************
160 : : |*
161 : : |* RscString::Destroy()
162 : : |*
163 : : *************************************************************************/
164 : 234666 : void RscString::Destroy( const RSCINST & rInst ){
165 [ + + ]: 234666 : if( ((RscStringInst *)rInst.pData)->pStr )
166 : 184834 : rtl_freeMemory( ((RscStringInst *)rInst.pData)->pStr );
167 : 234666 : ((RscStringInst *)rInst.pData)->aRefId.Destroy();
168 : 234666 : }
169 : :
170 : : /*************************************************************************
171 : : |*
172 : : |* RscString::IsValueDefault()
173 : : |*
174 : : *************************************************************************/
175 : 156232 : sal_Bool RscString::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ){
176 : 156232 : RscStringInst * pData = (RscStringInst*)rInst.pData;
177 : 156232 : RscStringInst * pDefData = (RscStringInst*)pDef;
178 : :
179 [ + - ]: 156232 : if( pDef ){
180 [ + - ][ - + ]: 156232 : if( pData->aRefId.IsId() || pDefData->aRefId.IsId() )
[ - + ]
181 : : {
182 [ # # # # ]: 0 : if( pData->aRefId.aExp.IsNumber()
[ # # ]
183 : 0 : && pDefData->aRefId.aExp.IsNumber() )
184 : : {
185 : : // Sind die Referenzidentifier gleich
186 [ # # ]: 0 : if( pData->aRefId.GetNumber() == pDefData->aRefId.GetNumber() )
187 : : {
188 : 0 : return sal_True;
189 : : }
190 : : }
191 : : }
192 : : else {
193 : 156232 : sal_Bool bStrEmpty = sal_False;
194 : 156232 : sal_Bool bDefStrEmpty = sal_False;
195 : :
196 [ + + ]: 156232 : if( pData->pStr ){
197 : 113688 : bStrEmpty = ('\0' == *pData->pStr);
198 : : }
199 : : else
200 : 42544 : bStrEmpty = sal_True;
201 : :
202 [ + + ]: 156232 : if( pDefData->pStr ){
203 : 2 : bDefStrEmpty = ('\0' == *pDefData->pStr);
204 : : }
205 : : else
206 : 156230 : bDefStrEmpty = sal_True;
207 : :
208 [ + + ][ - + ]: 156232 : if( !bStrEmpty || !bDefStrEmpty ){
209 : 113552 : return sal_False;
210 : : }
211 : 42680 : return sal_True;
212 : : }
213 : : }
214 : :
215 : 156232 : return sal_False;
216 : : }
217 : :
218 : : /*************************************************************************
219 : : |*
220 : : |* RscString::WriteSrc()
221 : : |*
222 : : *************************************************************************/
223 : 112846 : void RscString::WriteSrc( const RSCINST & rInst, FILE * fOutput,
224 : : RscTypCont *, sal_uInt32, const char * )
225 : : {
226 [ - + ]: 112846 : if ( ((RscStringInst *)rInst.pData)->aRefId.IsId() )
227 : : {
228 : : fprintf( fOutput, "%s",
229 [ # # ]: 0 : ((RscStringInst *)rInst.pData)->aRefId.GetName().getStr() );
230 : : }
231 : : else
232 : : {
233 : 112846 : RscStringInst * pStrI = ((RscStringInst *)rInst.pData);
234 [ + + ]: 112846 : if( pStrI->pStr ){
235 : : //char * pChangeTab = RscChar::GetChangeTab();
236 : 70376 : sal_uInt32 n = 0;
237 : : sal_uInt32 nPos, nSlashPos;
238 : :
239 [ + + ]: 72816 : do {
240 : 72816 : fputc( '\"', fOutput );
241 : 72816 : nSlashPos = nPos = 0;
242 [ + + ][ + + ]: 1607956 : while( pStrI->pStr[ n ]
[ + + ][ + + ]
243 : : && (nPos < 72 || nPos - nSlashPos <= 3) )
244 : : { // nach \ mindesten 3 Zeichen wegeb \xa7
245 : 1535140 : fputc( pStrI->pStr[ n ], fOutput );
246 [ + + ]: 1535140 : if( pStrI->pStr[ n ] == '\\' )
247 : 2022 : nSlashPos = nPos;
248 : 1535140 : n++;
249 : 1535140 : nPos++;
250 : : }
251 : :
252 : 72816 : fputc( '\"', fOutput );
253 [ + + ]: 72816 : if( pStrI->pStr[ n ] ) //nocht nicht zu ende
254 : 2440 : fputc( '\n', fOutput );
255 : 72816 : } while( pStrI->pStr[ n ] );
256 : : }
257 : : else
258 : 42470 : fprintf( fOutput, "\"\"" );
259 : : }
260 : 112846 : }
261 : :
262 : : /*************************************************************************
263 : : |*
264 : : |* RscString::WriteRc()
265 : : |*
266 : : *************************************************************************/
267 : 74620 : ERRTYPE RscString::WriteRc( const RSCINST & rInst, RscWriteRc & rMem,
268 : : RscTypCont * pTC, sal_uInt32 nDeep, sal_Bool bExtra )
269 : : {
270 : 74620 : ERRTYPE aError;
271 : 74620 : ObjNode * pObjNode = NULL;
272 : :
273 : :
274 [ - + ]: 74620 : if( ((RscStringInst *)rInst.pData)->aRefId.IsId() ){
275 [ # # ]: 0 : RscId aId( ((RscStringInst *)rInst.pData)->aRefId );
276 : 0 : RSCINST aTmpI;
277 : :
278 : 0 : aTmpI.pClass = pRefClass;
279 : :
280 [ # # ][ # # ]: 0 : while( aError.IsOk() && aId.IsId() ){
[ # # ]
281 : : //Erhoehen und abfragen um Endlosrekusion zu vermeiden
282 : 0 : nDeep++;
283 [ # # ]: 0 : if( nDeep > nRefDeep )
284 [ # # ]: 0 : aError = ERR_REFTODEEP;
285 : : else
286 : : {
287 [ # # ]: 0 : pObjNode = pRefClass->GetObjNode( aId );
288 [ # # ]: 0 : if( pObjNode )
289 : : {
290 : 0 : aTmpI.pData = pObjNode->GetRscObj();
291 [ # # ][ # # ]: 0 : aError = pRefClass->GetRef( aTmpI, &aId );
292 : : }
293 : : else
294 : : {
295 [ # # ]: 0 : if( pTC )
296 : : {
297 : : rtl::OStringBuffer aMsg(pHS->getString(
298 [ # # ][ # # ]: 0 : pRefClass->GetId()));
[ # # ]
299 [ # # ][ # # ]: 0 : aMsg.append(' ').append(aId.GetName());
[ # # ]
300 [ # # ]: 0 : aError = WRN_STR_REFNOTFOUND;
301 : : pTC->pEH->Error( aError, rInst.pClass,
302 [ # # ][ # # ]: 0 : RscId(), aMsg.getStr() );
303 : : }
304 : 0 : break;
305 : : }
306 : : }
307 [ # # ]: 0 : }
308 : : }
309 : :
310 [ + - ]: 74620 : if( aError.IsOk() )
311 : : {
312 [ - + ]: 74620 : if( pObjNode )
313 : : {
314 : 0 : RSCINST aRefI;
315 : :
316 : 0 : aRefI = RSCINST( pRefClass, pObjNode->GetRscObj() );
317 [ # # ][ # # ]: 0 : aError = aRefI.pClass->WriteRc( aRefI, rMem, pTC, nDeep, bExtra );
318 : : }
319 : : else
320 : : {
321 [ + + ][ + - ]: 74620 : if( ((RscStringInst *)rInst.pData)->pStr && pTC )
322 : : {
323 : : char * pStr = RscChar::MakeUTF8( ((RscStringInst *)rInst.pData)->pStr,
324 : 73494 : pTC->GetSourceCharSet() );
325 : 73494 : rMem.PutUTF8( pStr );
326 : 73494 : rtl_freeMemory( pStr );
327 : : }
328 : : else
329 : 74620 : rMem.PutUTF8( ((RscStringInst *)rInst.pData)->pStr );
330 : : };
331 : : };
332 : 74620 : return( aError );
333 : : }
334 : :
335 : : //==================================================================
336 : 0 : void RscString::WriteRcAccess
337 : : (
338 : : FILE * fOutput,
339 : : RscTypCont * /*pTC*/,
340 : : const char * pName
341 : : )
342 : : {
343 : 0 : fprintf( fOutput, "\t\tString aStr( (const char*)(pResData+nOffset) );\n" );
344 : 0 : fprintf( fOutput, "\t\tSet%s( aStr );\n", pName );
345 : 0 : fprintf( fOutput, "\t\tnOffset += GetStringSizeRes( aStr );\n" );
346 : 0 : }
347 : :
348 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|