1*477794c1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*477794c1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*477794c1SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*477794c1SAndrew Rist * distributed with this work for additional information
6*477794c1SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*477794c1SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*477794c1SAndrew Rist * "License"); you may not use this file except in compliance
9*477794c1SAndrew Rist * with the License. You may obtain a copy of the License at
10*477794c1SAndrew Rist *
11*477794c1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*477794c1SAndrew Rist *
13*477794c1SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*477794c1SAndrew Rist * software distributed under the License is distributed on an
15*477794c1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*477794c1SAndrew Rist * KIND, either express or implied. See the License for the
17*477794c1SAndrew Rist * specific language governing permissions and limitations
18*477794c1SAndrew Rist * under the License.
19*477794c1SAndrew Rist *
20*477794c1SAndrew Rist *************************************************************/
21*477794c1SAndrew Rist
22*477794c1SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_rsc.hxx"
26cdf0e10cSrcweir /****************** I N C L U D E S **************************************/
27cdf0e10cSrcweir
28cdf0e10cSrcweir // C and C++ Includes.
29cdf0e10cSrcweir #include <stdlib.h>
30cdf0e10cSrcweir #include <stdio.h>
31cdf0e10cSrcweir #include <string.h>
32cdf0e10cSrcweir
33cdf0e10cSrcweir // Programmabh�ngige Includes.
34cdf0e10cSrcweir #include <rscdb.hxx>
35cdf0e10cSrcweir #include <rscstr.hxx>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include <rtl/textcvt.h>
38cdf0e10cSrcweir #include <rtl/textenc.h>
39cdf0e10cSrcweir
40cdf0e10cSrcweir /****************** C O D E **********************************************/
41cdf0e10cSrcweir /****************** R s c S t r i n g ************************************/
42cdf0e10cSrcweir /*************************************************************************
43cdf0e10cSrcweir |*
44cdf0e10cSrcweir |* RscString::RscString()
45cdf0e10cSrcweir |*
46cdf0e10cSrcweir |* Beschreibung
47cdf0e10cSrcweir |* Ersterstellung MM 25.04.91
48cdf0e10cSrcweir |* Letzte Aenderung MM 25.04.91
49cdf0e10cSrcweir |*
50cdf0e10cSrcweir *************************************************************************/
RscString(Atom nId,sal_uInt32 nTypeId)51cdf0e10cSrcweir RscString::RscString( Atom nId, sal_uInt32 nTypeId )
52cdf0e10cSrcweir : RscTop( nId, nTypeId )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir nSize = ALIGNED_SIZE( sizeof( RscStringInst ) );
55cdf0e10cSrcweir pRefClass = NULL;
56cdf0e10cSrcweir }
57cdf0e10cSrcweir
58cdf0e10cSrcweir /*************************************************************************
59cdf0e10cSrcweir |*
60cdf0e10cSrcweir |* RscString::GetClassType()
61cdf0e10cSrcweir |*
62cdf0e10cSrcweir |* Beschreibung
63cdf0e10cSrcweir |* Ersterstellung MM 25.04.91
64cdf0e10cSrcweir |* Letzte Aenderung MM 25.04.91
65cdf0e10cSrcweir |*
66cdf0e10cSrcweir *************************************************************************/
GetClassType() const67cdf0e10cSrcweir RSCCLASS_TYPE RscString::GetClassType() const
68cdf0e10cSrcweir {
69cdf0e10cSrcweir return RSCCLASS_STRING;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
72cdf0e10cSrcweir /*************************************************************************
73cdf0e10cSrcweir |*
74cdf0e10cSrcweir |* RscString::SetNumber()
75cdf0e10cSrcweir |*
76cdf0e10cSrcweir |* Beschreibung
77cdf0e10cSrcweir |* Ersterstellung MM 25.04.91
78cdf0e10cSrcweir |* Letzte Aenderung MM 25.04.91
79cdf0e10cSrcweir |*
80cdf0e10cSrcweir *************************************************************************/
SetString(const RSCINST & rInst,const char * pStr)81cdf0e10cSrcweir ERRTYPE RscString::SetString( const RSCINST & rInst, const char * pStr ){
82cdf0e10cSrcweir char * pTmp;
83cdf0e10cSrcweir ERRTYPE aError;
84cdf0e10cSrcweir
85cdf0e10cSrcweir if( aError.IsOk() ){
86cdf0e10cSrcweir ((RscStringInst *)rInst.pData)->bDflt = sal_False;
87cdf0e10cSrcweir
88cdf0e10cSrcweir pTmp = ((RscStringInst *)rInst.pData)->pStr;
89cdf0e10cSrcweir if( pTmp ){
90cdf0e10cSrcweir rtl_freeMemory( pTmp );
91cdf0e10cSrcweir pTmp = NULL;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir if( pStr ){
95cdf0e10cSrcweir sal_uInt32 nLen = strlen( pStr ) +1;
96cdf0e10cSrcweir pTmp = (char *)rtl_allocateMemory( nLen );
97cdf0e10cSrcweir memcpy( pTmp, pStr, nLen );
98cdf0e10cSrcweir };
99cdf0e10cSrcweir
100cdf0e10cSrcweir ((RscStringInst *)rInst.pData)->pStr = pTmp;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
103cdf0e10cSrcweir return( aError );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
106cdf0e10cSrcweir /*************************************************************************
107cdf0e10cSrcweir |*
108cdf0e10cSrcweir |* RscString::GetString()
109cdf0e10cSrcweir |*
110cdf0e10cSrcweir |* Beschreibung
111cdf0e10cSrcweir |* Ersterstellung MM 25.04.91
112cdf0e10cSrcweir |* Letzte Aenderung MM 25.04.91
113cdf0e10cSrcweir |*
114cdf0e10cSrcweir *************************************************************************/
GetString(const RSCINST & rInst,char ** ppStr)115cdf0e10cSrcweir ERRTYPE RscString::GetString( const RSCINST & rInst, char ** ppStr ){
116cdf0e10cSrcweir *ppStr = ((RscStringInst *)rInst.pData)->pStr;
117cdf0e10cSrcweir return( ERR_OK );
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir /*************************************************************************
121cdf0e10cSrcweir |*
122cdf0e10cSrcweir |* RscString::GetRef()
123cdf0e10cSrcweir |*
124cdf0e10cSrcweir |* Beschreibung
125cdf0e10cSrcweir |* Ersterstellung MM 22.07.91
126cdf0e10cSrcweir |* Letzte Aenderung MM 22.07.91
127cdf0e10cSrcweir |*
128cdf0e10cSrcweir *************************************************************************/
GetRef(const RSCINST & rInst,RscId * pRscId)129cdf0e10cSrcweir ERRTYPE RscString::GetRef( const RSCINST & rInst, RscId * pRscId ){
130cdf0e10cSrcweir *pRscId = ((RscStringInst *)rInst.pData)->aRefId;
131cdf0e10cSrcweir return( ERR_OK );
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir /*************************************************************************
135cdf0e10cSrcweir |*
136cdf0e10cSrcweir |* RscString::SetRef()
137cdf0e10cSrcweir |*
138cdf0e10cSrcweir |* Beschreibung
139cdf0e10cSrcweir |* Ersterstellung MM 15.05.91
140cdf0e10cSrcweir |* Letzte Aenderung MM 15.05.91
141cdf0e10cSrcweir |*
142cdf0e10cSrcweir *************************************************************************/
SetRef(const RSCINST & rInst,const RscId & rRefId)143cdf0e10cSrcweir ERRTYPE RscString::SetRef( const RSCINST & rInst, const RscId & rRefId ){
144cdf0e10cSrcweir if( pRefClass ){
145cdf0e10cSrcweir ((RscStringInst *)rInst.pData)->aRefId = rRefId;
146cdf0e10cSrcweir ((RscStringInst *)rInst.pData)->bDflt = sal_False;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir else
149cdf0e10cSrcweir return( ERR_REFNOTALLOWED );
150cdf0e10cSrcweir
151cdf0e10cSrcweir return ERR_OK;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
154cdf0e10cSrcweir /*************************************************************************
155cdf0e10cSrcweir |*
156cdf0e10cSrcweir |* RscString::Create()
157cdf0e10cSrcweir |*
158cdf0e10cSrcweir |* Beschreibung
159cdf0e10cSrcweir |* Ersterstellung MM 25.04.91
160cdf0e10cSrcweir |* Letzte Aenderung MM 25.04.91
161cdf0e10cSrcweir |*
162cdf0e10cSrcweir *************************************************************************/
Create(RSCINST * pInst,const RSCINST & rDflt,sal_Bool bOwnClass)163cdf0e10cSrcweir RSCINST RscString::Create( RSCINST * pInst, const RSCINST & rDflt,
164cdf0e10cSrcweir sal_Bool bOwnClass )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir RSCINST aInst;
167cdf0e10cSrcweir
168cdf0e10cSrcweir if( !pInst ){
169cdf0e10cSrcweir aInst.pClass = this;
170cdf0e10cSrcweir aInst.pData = (CLASS_DATA)
171cdf0e10cSrcweir rtl_allocateMemory( sizeof( RscStringInst ) );
172cdf0e10cSrcweir }
173cdf0e10cSrcweir else
174cdf0e10cSrcweir aInst = *pInst;
175cdf0e10cSrcweir if( !bOwnClass && rDflt.IsInst() )
176cdf0e10cSrcweir bOwnClass = rDflt.pClass->InHierarchy( this );
177cdf0e10cSrcweir
178cdf0e10cSrcweir ((RscStringInst *)aInst.pData)->aRefId.Create();
179cdf0e10cSrcweir ((RscStringInst *)aInst.pData)->pStr = NULL;
180cdf0e10cSrcweir ((RscStringInst *)aInst.pData)->bDflt = sal_True;
181cdf0e10cSrcweir
182cdf0e10cSrcweir if( bOwnClass ){
183cdf0e10cSrcweir ((RscStringInst *)aInst.pData)->aRefId =
184cdf0e10cSrcweir ((RscStringInst *)rDflt.pData)->aRefId;
185cdf0e10cSrcweir SetString( aInst, ((RscStringInst *)rDflt.pData)->pStr );
186cdf0e10cSrcweir ((RscStringInst *)aInst.pData)->bDflt =
187cdf0e10cSrcweir ((RscStringInst *)rDflt.pData)->bDflt ;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir
190cdf0e10cSrcweir return( aInst );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
193cdf0e10cSrcweir /*************************************************************************
194cdf0e10cSrcweir |*
195cdf0e10cSrcweir |* RscString::Destroy()
196cdf0e10cSrcweir |*
197cdf0e10cSrcweir |* Beschreibung
198cdf0e10cSrcweir |* Ersterstellung MM 15.05.91
199cdf0e10cSrcweir |* Letzte Aenderung MM 15.05.91
200cdf0e10cSrcweir |*
201cdf0e10cSrcweir *************************************************************************/
Destroy(const RSCINST & rInst)202cdf0e10cSrcweir void RscString::Destroy( const RSCINST & rInst ){
203cdf0e10cSrcweir if( ((RscStringInst *)rInst.pData)->pStr )
204cdf0e10cSrcweir rtl_freeMemory( ((RscStringInst *)rInst.pData)->pStr );
205cdf0e10cSrcweir ((RscStringInst *)rInst.pData)->aRefId.Destroy();
206cdf0e10cSrcweir }
207cdf0e10cSrcweir
208cdf0e10cSrcweir /*************************************************************************
209cdf0e10cSrcweir |*
210cdf0e10cSrcweir |* RscString::IsValueDefault()
211cdf0e10cSrcweir |*
212cdf0e10cSrcweir |* Beschreibung
213cdf0e10cSrcweir |* Ersterstellung MM 15.01.92
214cdf0e10cSrcweir |* Letzte Aenderung MM 15.01.92
215cdf0e10cSrcweir |*
216cdf0e10cSrcweir *************************************************************************/
IsValueDefault(const RSCINST & rInst,CLASS_DATA pDef)217cdf0e10cSrcweir sal_Bool RscString::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ){
218cdf0e10cSrcweir RscStringInst * pData = (RscStringInst*)rInst.pData;
219cdf0e10cSrcweir RscStringInst * pDefData = (RscStringInst*)pDef;
220cdf0e10cSrcweir
221cdf0e10cSrcweir if( pDef ){
222cdf0e10cSrcweir if( pData->aRefId.IsId() || pDefData->aRefId.IsId() )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir if( pData->aRefId.aExp.IsNumber()
225cdf0e10cSrcweir && pDefData->aRefId.aExp.IsNumber() )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir // Sind die Referenzidentifier gleich
228cdf0e10cSrcweir if( pData->aRefId.GetNumber() == pDefData->aRefId.GetNumber() )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir return sal_True;
231cdf0e10cSrcweir }
232cdf0e10cSrcweir }
233cdf0e10cSrcweir }
234cdf0e10cSrcweir else {
235cdf0e10cSrcweir sal_Bool bStrEmpty = sal_False;
236cdf0e10cSrcweir sal_Bool bDefStrEmpty = sal_False;
237cdf0e10cSrcweir
238cdf0e10cSrcweir if( pData->pStr ){
239cdf0e10cSrcweir bStrEmpty = ('\0' == *pData->pStr);
240cdf0e10cSrcweir }
241cdf0e10cSrcweir else
242cdf0e10cSrcweir bStrEmpty = sal_True;
243cdf0e10cSrcweir
244cdf0e10cSrcweir if( pDefData->pStr ){
245cdf0e10cSrcweir bDefStrEmpty = ('\0' == *pDefData->pStr);
246cdf0e10cSrcweir }
247cdf0e10cSrcweir else
248cdf0e10cSrcweir bDefStrEmpty = sal_True;
249cdf0e10cSrcweir
250cdf0e10cSrcweir if( !bStrEmpty || !bDefStrEmpty ){
251cdf0e10cSrcweir return sal_False;
252cdf0e10cSrcweir }
253cdf0e10cSrcweir return sal_True;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir }
256cdf0e10cSrcweir
257cdf0e10cSrcweir return sal_False;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir /*************************************************************************
261cdf0e10cSrcweir |*
262cdf0e10cSrcweir |* RscString::WriteSrc()
263cdf0e10cSrcweir |*
264cdf0e10cSrcweir |* Beschreibung
265cdf0e10cSrcweir |* Ersterstellung MM 25.04.91
266cdf0e10cSrcweir |* Letzte Aenderung MM 25.04.91
267cdf0e10cSrcweir |*
268cdf0e10cSrcweir *************************************************************************/
WriteSrc(const RSCINST & rInst,FILE * fOutput,RscTypCont *,sal_uInt32,const char *)269cdf0e10cSrcweir void RscString::WriteSrc( const RSCINST & rInst, FILE * fOutput,
270cdf0e10cSrcweir RscTypCont *, sal_uInt32, const char * )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir if ( ((RscStringInst *)rInst.pData)->aRefId.IsId() )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir fprintf( fOutput, "%s",
275cdf0e10cSrcweir ((RscStringInst *)rInst.pData)->aRefId.GetName().GetBuffer() );
276cdf0e10cSrcweir }
277cdf0e10cSrcweir else
278cdf0e10cSrcweir {
279cdf0e10cSrcweir RscStringInst * pStrI = ((RscStringInst *)rInst.pData);
280cdf0e10cSrcweir if( pStrI->pStr ){
281cdf0e10cSrcweir //char * pChangeTab = RscChar::GetChangeTab();
282cdf0e10cSrcweir sal_uInt32 n = 0;
283cdf0e10cSrcweir sal_uInt32 nPos, nSlashPos;
284cdf0e10cSrcweir
285cdf0e10cSrcweir do {
286cdf0e10cSrcweir fputc( '\"', fOutput );
287cdf0e10cSrcweir nSlashPos = nPos = 0;
288cdf0e10cSrcweir while( pStrI->pStr[ n ]
289cdf0e10cSrcweir && (nPos < 72 || nPos - nSlashPos <= 3) )
290cdf0e10cSrcweir { // nach \ mindesten 3 Zeichen wegeb \xa7
291cdf0e10cSrcweir fputc( pStrI->pStr[ n ], fOutput );
292cdf0e10cSrcweir if( pStrI->pStr[ n ] == '\\' )
293cdf0e10cSrcweir nSlashPos = nPos;
294cdf0e10cSrcweir n++;
295cdf0e10cSrcweir nPos++;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir
298cdf0e10cSrcweir fputc( '\"', fOutput );
299cdf0e10cSrcweir if( pStrI->pStr[ n ] ) //nocht nicht zu ende
300cdf0e10cSrcweir fputc( '\n', fOutput );
301cdf0e10cSrcweir } while( pStrI->pStr[ n ] );
302cdf0e10cSrcweir }
303cdf0e10cSrcweir else
304cdf0e10cSrcweir fprintf( fOutput, "\"\"" );
305cdf0e10cSrcweir }
306cdf0e10cSrcweir }
307cdf0e10cSrcweir
308cdf0e10cSrcweir /*************************************************************************
309cdf0e10cSrcweir |*
310cdf0e10cSrcweir |* RscString::WriteRc()
311cdf0e10cSrcweir |*
312cdf0e10cSrcweir |* Beschreibung
313cdf0e10cSrcweir |* Ersterstellung MM 15.04.91
314cdf0e10cSrcweir |* Letzte Aenderung MM 15.04.91
315cdf0e10cSrcweir |*
316cdf0e10cSrcweir *************************************************************************/
WriteRc(const RSCINST & rInst,RscWriteRc & rMem,RscTypCont * pTC,sal_uInt32 nDeep,sal_Bool bExtra)317cdf0e10cSrcweir ERRTYPE RscString::WriteRc( const RSCINST & rInst, RscWriteRc & rMem,
318cdf0e10cSrcweir RscTypCont * pTC, sal_uInt32 nDeep, sal_Bool bExtra )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir ERRTYPE aError;
321cdf0e10cSrcweir ObjNode * pObjNode = NULL;
322cdf0e10cSrcweir
323cdf0e10cSrcweir
324cdf0e10cSrcweir if( ((RscStringInst *)rInst.pData)->aRefId.IsId() ){
325cdf0e10cSrcweir RscId aId( ((RscStringInst *)rInst.pData)->aRefId );
326cdf0e10cSrcweir RSCINST aTmpI;
327cdf0e10cSrcweir
328cdf0e10cSrcweir aTmpI.pClass = pRefClass;
329cdf0e10cSrcweir
330cdf0e10cSrcweir while( aError.IsOk() && aId.IsId() ){
331cdf0e10cSrcweir //Erhoehen und abfragen um Endlosrekusion zu vermeiden
332cdf0e10cSrcweir nDeep++;
333cdf0e10cSrcweir if( nDeep > nRefDeep )
334cdf0e10cSrcweir aError = ERR_REFTODEEP;
335cdf0e10cSrcweir else
336cdf0e10cSrcweir {
337cdf0e10cSrcweir pObjNode = pRefClass->GetObjNode( aId );
338cdf0e10cSrcweir if( pObjNode )
339cdf0e10cSrcweir {
340cdf0e10cSrcweir aTmpI.pData = pObjNode->GetRscObj();
341cdf0e10cSrcweir aError = pRefClass->GetRef( aTmpI, &aId );
342cdf0e10cSrcweir }
343cdf0e10cSrcweir else
344cdf0e10cSrcweir {
345cdf0e10cSrcweir if( pTC )
346cdf0e10cSrcweir {
347cdf0e10cSrcweir ByteString aMsg( pHS->getString( pRefClass->GetId() ).getStr() );
348cdf0e10cSrcweir aMsg += ' ';
349cdf0e10cSrcweir aMsg += aId.GetName();
350cdf0e10cSrcweir aError = WRN_STR_REFNOTFOUND;
351cdf0e10cSrcweir pTC->pEH->Error( aError, rInst.pClass,
352cdf0e10cSrcweir RscId(), aMsg.GetBuffer() );
353cdf0e10cSrcweir }
354cdf0e10cSrcweir break;
355cdf0e10cSrcweir }
356cdf0e10cSrcweir }
357cdf0e10cSrcweir }
358cdf0e10cSrcweir }
359cdf0e10cSrcweir
360cdf0e10cSrcweir if( aError.IsOk() )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir if( pObjNode )
363cdf0e10cSrcweir {
364cdf0e10cSrcweir RSCINST aRefI;
365cdf0e10cSrcweir
366cdf0e10cSrcweir aRefI = RSCINST( pRefClass, pObjNode->GetRscObj() );
367cdf0e10cSrcweir aError = aRefI.pClass->WriteRc( aRefI, rMem, pTC, nDeep, bExtra );
368cdf0e10cSrcweir }
369cdf0e10cSrcweir else
370cdf0e10cSrcweir {
371cdf0e10cSrcweir if( ((RscStringInst *)rInst.pData)->pStr && pTC )
372cdf0e10cSrcweir {
373cdf0e10cSrcweir char * pStr = RscChar::MakeUTF8( ((RscStringInst *)rInst.pData)->pStr,
374cdf0e10cSrcweir pTC->GetSourceCharSet() );
375cdf0e10cSrcweir rMem.PutUTF8( pStr );
376cdf0e10cSrcweir rtl_freeMemory( pStr );
377cdf0e10cSrcweir }
378cdf0e10cSrcweir else
379cdf0e10cSrcweir rMem.PutUTF8( ((RscStringInst *)rInst.pData)->pStr );
380cdf0e10cSrcweir };
381cdf0e10cSrcweir };
382cdf0e10cSrcweir return( aError );
383cdf0e10cSrcweir }
384cdf0e10cSrcweir
385cdf0e10cSrcweir //==================================================================
WriteRcAccess(FILE * fOutput,RscTypCont *,const char * pName)386cdf0e10cSrcweir void RscString::WriteRcAccess
387cdf0e10cSrcweir (
388cdf0e10cSrcweir FILE * fOutput,
389cdf0e10cSrcweir RscTypCont * /*pTC*/,
390cdf0e10cSrcweir const char * pName
391cdf0e10cSrcweir )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir fprintf( fOutput, "\t\tString aStr( (const char*)(pResData+nOffset) );\n" );
394cdf0e10cSrcweir fprintf( fOutput, "\t\tSet%s( aStr );\n", pName );
395cdf0e10cSrcweir fprintf( fOutput, "\t\tnOffset += GetStringSizeRes( aStr );\n" );
396cdf0e10cSrcweir }
397cdf0e10cSrcweir
398