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