diff options
Diffstat (limited to 'rsc')
63 files changed, 0 insertions, 16491 deletions
diff --git a/rsc/Executable_rsc.mk b/rsc/Executable_rsc.mk deleted file mode 100644 index 06b119805d10..000000000000 --- a/rsc/Executable_rsc.mk +++ /dev/null @@ -1,86 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_Executable_Executable,rsc)) - -$(eval $(call gb_Executable_use_external,rsc,boost_headers)) - -$(eval $(call gb_Executable_set_include,rsc,\ - $$(INCLUDE) \ - -I$(SRCDIR)/rsc/inc \ -)) - -$(eval $(call gb_Executable_use_sdk_api,rsc)) - -$(eval $(call gb_Executable_add_defs,rsc,\ - -DSOLAR \ -)) - -$(eval $(call gb_Executable_use_libraries,rsc,\ - comphelper \ - $(if $(filter TRUE,$(DISABLE_DYNLOADING)),cppu) \ - i18nlangtag \ - tl \ - sal \ -)) - -$(eval $(call gb_Executable_use_externals,rsc,\ - $(if $(filter TRUE,$(DISABLE_DYNLOADING)),liblangtag) \ - $(if $(filter TRUE,$(DISABLE_DYNLOADING)),libxml2) \ -)) - -$(eval $(call gb_Executable_add_grammars,rsc,\ - rsc/source/parser/rscyacc \ -)) - -$(eval $(call gb_Executable_add_exception_objects,rsc,\ - rsc/source/parser/erscerr \ - rsc/source/parser/rscdb \ - rsc/source/parser/rscibas \ - rsc/source/parser/rscicpx \ - rsc/source/parser/rscinit \ - rsc/source/parser/rsckey \ - rsc/source/parser/rsclex \ - rsc/source/parser/rscpar \ - rsc/source/prj/gui \ - rsc/source/prj/start \ - rsc/source/res/rscall \ - rsc/source/res/rscarray \ - rsc/source/res/rscclass \ - rsc/source/res/rscclobj \ - rsc/source/res/rscconst \ - rsc/source/res/rsccont \ - rsc/source/res/rscmgr \ - rsc/source/res/rscrange \ - rsc/source/res/rscstr \ - rsc/source/res/rsctop \ - rsc/source/rsc/rsc \ - rsc/source/tools/rscchar \ - rsc/source/tools/rscdef \ - rsc/source/tools/rschash \ - rsc/source/tools/rsctools \ - rsc/source/tools/rsctree \ -)) - -$(eval $(call gb_Executable_add_cobjects,rsc,\ - rsc/source/rscpp/cpp1 \ - rsc/source/rscpp/cpp2 \ - rsc/source/rscpp/cpp3 \ - rsc/source/rscpp/cpp4 \ - rsc/source/rscpp/cpp5 \ - rsc/source/rscpp/cpp6 \ -)) - -ifneq ($(OS),WNT) -$(eval $(call gb_Executable_add_defs,rsc,\ - -Dunix \ -)) -endif - -# vim: set noet sw=4 ts=4: diff --git a/rsc/Makefile b/rsc/Makefile deleted file mode 100644 index ccb1c85a04da..000000000000 --- a/rsc/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- - -module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) - -include $(module_directory)/../solenv/gbuild/partial_build.mk - -# vim: set noet sw=4 ts=4: diff --git a/rsc/Module_rsc.mk b/rsc/Module_rsc.mk deleted file mode 100644 index 40e7f03fbc28..000000000000 --- a/rsc/Module_rsc.mk +++ /dev/null @@ -1,16 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_Module_Module,rsc)) - -$(eval $(call gb_Module_add_targets_for_build,rsc,\ - Executable_rsc \ -)) - -# vim: set noet sw=4 ts=4: diff --git a/rsc/README b/rsc/README deleted file mode 100644 index ed940f727fb0..000000000000 --- a/rsc/README +++ /dev/null @@ -1,32 +0,0 @@ -Resource Compiler. - -This compiler converts .src files and .hrc equivalents into binary -.res files. The basic idea is that this provides a map between -integer identifiers and the resources: string, pixmap (only the -file-name), and VCL control properties. - -In more detail: - -Typically we would have a .hrc file with entries like this: - -#define SID_STR_FOO 1234 - -And then a .src file with some entries like this: - -String SID_STR_FOO -{ - Text [ en-US ] = "Foo !" ; -}; - -This is compiled into a binary resource file, we have many of these -which live in program/resource/ and then tends to get used in the code -thus: - -String aStr( ResId( SID_STR_FOO ) ); - -It is important to note that any appearance of hierarchical structure -in the .src files is in fact a mirage. The file is compiled at root -into a plain map<integer,resource>. - -There is some German documentation about it in a subdirectory called -[git:rsc/doku]. Seems to be very old (January 1992). diff --git a/rsc/documentation/rsc.odt b/rsc/documentation/rsc.odt Binary files differdeleted file mode 100644 index 3b93057a6256..000000000000 --- a/rsc/documentation/rsc.odt +++ /dev/null diff --git a/rsc/documentation/rscerror.odt b/rsc/documentation/rscerror.odt Binary files differdeleted file mode 100644 index effe74db93fb..000000000000 --- a/rsc/documentation/rscerror.odt +++ /dev/null diff --git a/rsc/documentation/rscinst.odt b/rsc/documentation/rscinst.odt Binary files differdeleted file mode 100644 index 8880557ac3b8..000000000000 --- a/rsc/documentation/rscinst.odt +++ /dev/null diff --git a/rsc/inc/rscall.h b/rsc/inc/rscall.h deleted file mode 100644 index e141b50340f4..000000000000 --- a/rsc/inc/rscall.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCALL_H -#define INCLUDED_RSC_INC_RSCALL_H - -#include <rsctools.hxx> -#include <rscerror.h> -#include <rscdef.hxx> -#include <rschash.hxx> -#include <rtl/alloc.h> -#include <o3tl/typed_flags_set.hxx> - -/******************* T y p e s *******************************************/ -typedef char * CLASS_DATA; // Pointer to the data of a class - -/******************* C l a s s e s F o r w a r d s *********************/ -class RscCompiler; -class RscTop; -class RscTypCont; - -/******************* G l o b a l V a r i a b l e s *********************/ -extern OString* pStdParType; -extern OString* pStdPar1; -extern OString* pStdPar2; -extern sal_uInt32 nRefDeep; -extern sal_uInt32 nRsc_DELTALANG; -extern sal_uInt32 nRsc_DELTASYSTEM; -extern AtomContainer* pHS; - -/******************* D e f i n e s ***************************************/ - -enum class CommandFlags { - NONE = 0x0000, - Help = 0x0001, // show help - NoPrePro = 0x0002, // no preprocessor - NoSyntax = 0x0004, // no parsing - NoLink = 0x0008, // no linking - NoResFile = 0x0010, // do not create .res file - Define = 0x0020, // definitions stated - Include = 0x0040, // include path extended - Preload = 0x0200, // preload all resources - SrsDefault = 0x1000, // always wrote the default - NoSysResTest = 0x2000 // do not check the correctness of (bmp, ico, cur) -}; -namespace o3tl { - template<> struct typed_flags<CommandFlags> : is_typed_flags<CommandFlags, 0x327f> {}; -} - -/******************* S t r u c t s ***************************************/ -struct RSCINST -{ - RscTop * pClass; - CLASS_DATA pData; - - RSCINST(){ pClass = nullptr; pData = nullptr; } - RSCINST( RscTop * pCl, CLASS_DATA pClassData ) - { - pClass = pCl; - pData = pClassData; - } - bool IsInst() const { return( pData != nullptr ); } -}; - -/********************** S U B I N F O S T R U C T ************************/ -struct SUBINFO_STRUCT -{ - RscId aId; // resource identifier -}; - -/******************* F u n c t i o n *************************************/ -void InitRscCompiler(); - -#endif // INCLUDED_RSC_INC_RSCALL_H - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscarray.hxx b/rsc/inc/rscarray.hxx deleted file mode 100644 index 01a5ddf8795e..000000000000 --- a/rsc/inc/rscarray.hxx +++ /dev/null @@ -1,102 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_RSC_INC_RSCARRAY_HXX -#define INCLUDED_RSC_INC_RSCARRAY_HXX - -#include <rscall.h> -#include <rscerror.h> -#include <rsctop.hxx> - -class RscEnum; - -class RscInstNode : public IdNode -{ - sal_uInt32 nTypeId; -protected: - using NameNode::Search; -public: - RSCINST aInst; - RscInstNode( sal_uInt32 nId ); - virtual ~RscInstNode() override; - virtual sal_uInt32 GetId() const override; - RscInstNode * Left() const { return static_cast<RscInstNode *>(pLeft); }; - RscInstNode * Right() const{ return static_cast<RscInstNode *>(pRight); }; - RscInstNode * Search( sal_uInt32 nId ) const - { - return static_cast<RscInstNode *>(IdNode::Search( nId )); - } -}; - -struct RscArrayInst -{ - RscInstNode * pNode; -}; - -/* The tree is sorted against its enum value, not against its HashId */ -class RscArray : public RscTop -{ -protected: - RscEnum * pTypeClass; // type of entries - const sal_uInt32 nOffInstData;// Offset of self instance data - const sal_uInt32 nSize; // size of this class instance data with super class - void WriteSrcArray( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * ); -public: - RscArray( Atom nId, RESOURCE_TYPE nTypId, - RscTop * pSuper, RscEnum * pTypeClass ); - virtual ~RscArray() override; - - virtual RscTop * GetTypeClass() const override; - RSCINST Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass = false ) override; - void Destroy( const RSCINST & rInst ) override; - virtual ERRTYPE GetValueEle( const RSCINST & rInst, sal_Int32 lValue, - RscTop * pCreateClass, - RSCINST * pGetInst ) override; - virtual ERRTYPE GetArrayEle( const RSCINST & rInst, Atom nId, - RscTop * pCreateClass, - RSCINST * pGetInst ) override; - - // gives the size of the class in bytes - sal_uInt32 Size() const override { return nSize; } - - bool IsConsistent( const RSCINST & rInst ) override; - virtual void SetToDefault( const RSCINST & rInst ) override; - bool IsDefault( const RSCINST & rInst ) override; - bool IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) override; - - virtual void WriteSrcHeader( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const RscId & aId, const char * ) override; - void WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * ) override; - ERRTYPE WriteRc( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont * pTC, sal_uInt32 ) override; -}; - -class RscLangArray : public RscArray -{ -public: - RscLangArray( Atom nId, RESOURCE_TYPE nTypId, - RscTop * pSuper, RscEnum * pTypeClass ); -}; - -#endif // INCLUDED_RSC_INC_RSCARRAY_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscclass.hxx b/rsc/inc/rscclass.hxx deleted file mode 100644 index 382006c39c5d..000000000000 --- a/rsc/inc/rscclass.hxx +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCCLASS_HXX -#define INCLUDED_RSC_INC_RSCCLASS_HXX - -#include <rscall.h> -#include <rscerror.h> -#include <rschash.hxx> -#include <rsctop.hxx> - -class RscClass : public RscTop -{ -protected: - struct RscClassInst - { - sal_uLong nVarDflt; - }; - struct VARTYPE_STRUCT - { - Atom nVarName; // variable name - RSCVAR nVarType; // variable type - sal_uInt32 nMask; // bit mask - sal_uInt32 nOffset; // start of instance data - RscTop * pClass; // class - CLASS_DATA pDefault; // pointer to default data - Atom nDataBaseName;//name of foreign data area - }; - sal_uInt32 nSuperSize; // size of super class instance data - sal_uInt32 nSize; // size of this class instance data - // with super class - sal_uInt32 nEntries; // entries in pVarTypeList - VARTYPE_STRUCT * pVarTypeList; // variable list - RSCINST GetInstData( CLASS_DATA pData, sal_uInt32 nEle, - bool bGetCopy = false ); - CLASS_DATA GetDfltData( sal_uInt32 nEle ); - bool IsDflt( CLASS_DATA pData, sal_uInt32 nEle ); - bool IsValueDflt( CLASS_DATA pData, sal_uInt32 nEle ); - void SetVarDflt( CLASS_DATA pData, sal_uInt32 nEle, - bool bSet ); -public: - RscClass( Atom nId, RESOURCE_TYPE nTypId, RscTop * pSuperCl ); - virtual ~RscClass() override; - - void Pre_dtor() override; - ERRTYPE SetVariable( Atom nVarName, RscTop * pClass, - RSCINST * pDflt = nullptr, - RSCVAR nVarType = RSCVAR::NONE, sal_uInt32 nMask = 0, - Atom nDataBaseName = InvalidAtom ) override; - RSCINST GetVariable( const RSCINST & rInst, Atom nVarName, - const RSCINST & rInitInst, - bool bInitDflt = false, - RscTop * pCreateClass = nullptr ) override; - RSCINST GetCopyVar( const RSCINST & rInst, Atom nVarName ) override; - - // gives the class size in bytes - sal_uInt32 Size() const override { return nSize; } - - bool IsConsistent( const RSCINST & rInst ) override; - void SetToDefault( const RSCINST & rInst ) override; - bool IsDefault( const RSCINST & rInst ) override; - bool IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) override; - void SetDefault( const RSCINST & rData, Atom nVarId ) override; - using RscTop::GetDefault; - RSCINST GetDefault( Atom nVarId ) override; - - RSCINST Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass = false ) override; - void Destroy( const RSCINST & rInst ) override; - void WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * ) override; - ERRTYPE WriteInstRc( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont * pTC, sal_uInt32 ); - ERRTYPE WriteRc( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont * pTC, sal_uInt32 ) override; -}; - -class RscTupel : public RscClass -{ -public: - RscTupel( Atom nId, RESOURCE_TYPE nTypId ); - RSCINST GetTupelVar( const RSCINST & rInst, sal_uInt32 nPos, - const RSCINST & rInitInst ) override; - void WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * ) override; -}; - -#endif // INCLUDED_RSC_INC_RSCCLASS_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscclobj.hxx b/rsc/inc/rscclobj.hxx deleted file mode 100644 index 61e350773d7d..000000000000 --- a/rsc/inc/rscclobj.hxx +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCCLOBJ_HXX -#define INCLUDED_RSC_INC_RSCCLOBJ_HXX - -#include <rsctree.hxx> -#include <rscdef.hxx> -#include <rscall.h> - -/******************* O b j N o d e ***************************************/ -class ObjNode : public IdNode -{ - RscId aRscId; // resource ID - CLASS_DATA pRscObj; // pointer to a resourceobject - RscFileTab::Index lFileKey; -protected: - using NameNode::Search; - -public: - using NameNode::Insert; - - ObjNode( const RscId & rId, CLASS_DATA pData, RscFileTab::Index lKey ); - ObjNode * DelObjNode( RscTop * pClass, RscFileTab::Index lFileKey ); - sal_uInt32 GetId() const override; - const RscId& GetRscId() const { return aRscId; } - RscFileTab::Index GetFileKey() const { return lFileKey; }; - ObjNode* Search( const RscId &rName ) const //< search the index in the b-tree - { - return static_cast<ObjNode *>(IdNode::Search( rName.GetNumber() )); - } - bool Insert( ObjNode* pTN ) //< insert a new node in the b-tree - - { - return IdNode::Insert( static_cast<IdNode *>(pTN) ); - } - CLASS_DATA GetRscObj() const//< get the Object from this Node - - { - return pRscObj; - } - bool IsConsistent(); -}; - -/******************* R e f N o d e ***************************************/ -class RefNode : public IdNode -{ - Atom nTypNameId; // index of a Name in a hashtabel -protected: - using NameNode::Search; - -public: - using NameNode::Insert; - - ObjNode* pObjBiTree; // pointer to object tree - RefNode( Atom nTyp ); - sal_uInt32 GetId() const override; - void Insert( RefNode* pTN ) //< insert a new node in the b-tree - { - IdNode::Insert( static_cast<IdNode *>(pTN) ); - } - bool PutObjNode( ObjNode * pPutObject ); - - // insert new node in b-tree pObjBiTree - ObjNode * GetObjNode( const RscId &rRscId ); - - ObjNode * GetObjNode() const - { - return pObjBiTree; - } -}; - -#endif // INCLUDED_RSC_INC_RSCCLOBJ_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscconst.hxx b/rsc/inc/rscconst.hxx deleted file mode 100644 index a9ce5040a168..000000000000 --- a/rsc/inc/rscconst.hxx +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCCONST_HXX -#define INCLUDED_RSC_INC_RSCCONST_HXX - -#include <rscall.h> -#include <rscerror.h> -#include <rschash.hxx> -#include <rsctop.hxx> -#include <tools/resid.hxx> - -class RscEnum : public RscTop -{ - struct RscEnumInst - { - sal_uInt32 nValue; // constant position in the array - bool bDflt; // is default - }; - struct VarEle - { - Atom nId; // constant name - sal_Int32 lValue; // constant value - }; - VarEle * pVarArray; // pointer to the field with constant - sal_uInt32 nEntries; // number of entries in field -public: - RscEnum( Atom nId, RESOURCE_TYPE nTypId ); - virtual ~RscEnum() override; - // sets the allowed values - void SetConstant( Atom nVarName, sal_Int32 lValue ); - bool GetConstValue( Atom nConstId, sal_Int32 * pVal ) const; - bool GetValueConst( sal_Int32 nValue, Atom * pConstId ) const; - sal_uInt32 GetConstPos( Atom nConstId ); - - RSCINST Create( RSCINST * pInst, const RSCINST & rDfltInst, bool bOwnClass = false ) override; - sal_uInt32 Size() const override { return ALIGNED_SIZE(sizeof(RscEnumInst)); } - - virtual void SetToDefault( const RSCINST & rInst ) override - { - reinterpret_cast<RscEnumInst*>(rInst.pData)->bDflt = true; - } - bool IsDefault( const RSCINST & rInst ) override - { - return reinterpret_cast<RscEnumInst*>(rInst.pData)->bDflt; - }; - // sets as default - bool IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) override; - - ERRTYPE SetConst( const RSCINST & rInst, Atom nValueId, - sal_Int32 nValue ) override; - ERRTYPE SetNumber( const RSCINST & rInst, sal_Int32 nValue ) override; - ERRTYPE GetConst( const RSCINST & rInst, Atom * ) override; - ERRTYPE GetNumber( const RSCINST & rInst, sal_Int32 * nValue ) override; - void WriteSrc( const RSCINST &rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * ) override; - ERRTYPE WriteRc( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont * pTC, sal_uInt32 ) override; -}; - -class RscNameTable; - -sal_uInt32 GetLangId( const OString& rLang); - -class RscLangEnum : public RscEnum -{ - long mnLangId; -public: - RscLangEnum(); - - void Init( RscNameTable& rNames ); - - Atom AddLanguage( const char* pLang, RscNameTable& rNames ); -}; - -#endif // INCLUDED_RSC_INC_RSCCONST_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rsccont.hxx b/rsc/inc/rsccont.hxx deleted file mode 100644 index c1cf83700a11..000000000000 --- a/rsc/inc/rsccont.hxx +++ /dev/null @@ -1,120 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCCONT_HXX -#define INCLUDED_RSC_INC_RSCCONT_HXX - -#include <rscall.h> -#include <rscerror.h> -#include <rsctop.hxx> - -struct ENTRY_STRUCT -{ - RscId aName; - RSCINST aInst; - void Create(){ aName.Create(); aInst = RSCINST(); } - void Destroy(); -}; -struct RscBaseContInst -{ - sal_uInt32 nEntries; - ENTRY_STRUCT * pEntries; - bool bDflt; -}; - -class RscBaseCont : public RscTop -{ -protected: - RscTop * pTypeClass; // type of entries - bool bNoId; // whether there is no identifier - const sal_uInt32 nOffInstData;// offset of own instance data - const sal_uInt32 nSize; // size of this class and super classes instance data - static void DestroyElements( RscBaseContInst * pClassData ); - RSCINST SearchElePos( const RSCINST & rInst, const RscId & rEleName, - RscTop * pClass, sal_uInt32 nPos ); -protected: - void ContWriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * ); - ERRTYPE ContWriteRc( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont * pTC, sal_uInt32 ); -public: - RscBaseCont( Atom nId, RESOURCE_TYPE nTypId, - bool bNoId ); - virtual ~RscBaseCont() override; - void SetTypeClass( RscTop * pClass ) - { - pTypeClass = pClass; - } - RSCINST Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass = false ) override; - void Destroy( const RSCINST & rInst ) override; - ERRTYPE GetElement( const RSCINST & rInst, const RscId & rEleName, - RscTop * pCreateClass, const RSCINST & rCreateInst, - RSCINST * pGetInst ) override; - RSCINST SearchEle( const RSCINST & rInst, const RscId & rEleName, - RscTop * pClass ) override; - sal_uInt32 GetCount( const RSCINST & rInst ) override; - RSCINST GetPosEle( const RSCINST & rInst, sal_uInt32 nPos ) override; - ERRTYPE MovePosEle( const RSCINST & rInst, sal_uInt32 nDestPos, - sal_uInt32 nSourcePos ) override; - virtual ERRTYPE SetPosRscId( const RSCINST & rInst, sal_uInt32 nPos, - const RscId & rRscId) override; - SUBINFO_STRUCT GetInfoEle( const RSCINST & rInst, sal_uInt32 nPos ) override; - ERRTYPE SetString( const RSCINST &, const char * pStr ) override; - ERRTYPE SetNumber( const RSCINST &, sal_Int32 lValue ) override; - ERRTYPE SetBool( const RSCINST & rInst, bool bValue ) override; - ERRTYPE SetConst( const RSCINST & rInst, Atom nValueId, - sal_Int32 nValue ) override; - ERRTYPE SetRef( const RSCINST & rInst, const RscId & rRefId ) override; - - // returns the class size in bytes - sal_uInt32 Size() const override { return nSize; } - - bool IsConsistent( const RSCINST & rInst ) override; - void SetToDefault( const RSCINST & rInst ) override; - bool IsDefault( const RSCINST & rInst ) override; - bool IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) override; - - void Delete( const RSCINST & rInst, RscTop * pClass, - const RscId & rId ) override; - void DeletePos( const RSCINST & rInst, sal_uInt32 nPos ) override; - - void WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * ) override; - ERRTYPE WriteRc( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont * pTC, sal_uInt32 ) override; -}; - -class RscContWriteSrc : public RscBaseCont -{ -public: - RscContWriteSrc( Atom nId, RESOURCE_TYPE nTypId ); - void WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * ) override; -}; - -class RscCont : public RscContWriteSrc -{ -public: - RscCont( Atom nId, RESOURCE_TYPE nTypId ); - ERRTYPE WriteRc( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont * pTC, sal_uInt32 ) override; -}; - -#endif // INCLUDED_RSC_INC_RSCCONT_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscdb.hxx b/rsc/inc/rscdb.hxx deleted file mode 100644 index da235e8bc0e3..000000000000 --- a/rsc/inc/rscdb.hxx +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_RSC_INC_RSCDB_HXX -#define INCLUDED_RSC_INC_RSCDB_HXX - -#include <rscall.h> -#include <rsckey.hxx> -#include <rscconst.hxx> -#include <rscrange.hxx> -#include <rscstr.hxx> -#include <rscarray.hxx> -#include <rscdef.hxx> - -#include <vector> -#include <map> - -class RscError; -class RscTupel; -class RscCont; -class RscCmdLine; -enum class MenuItemBits : sal_Int16; -enum class MapUnit; - -struct WriteRcContext -{ - FILE * fOutput; - OString aOutputRc; - OString aOutputSysList; - RscCmdLine* pCmdLine; -}; - -class RscTypCont -{ - rtl_TextEncoding nSourceCharSet; - RSCBYTEORDER_TYPE nByteOrder; // Intel or - OString aLanguage; // output language - std::vector< sal_uInt32 > aLangFallbacks; // language fallback list (entry 0 is language itself) - sal_uLong nFilePos; // position in file (MTF) - sal_uInt32 nPMId; // unique id for PR-resource file - // must be greater that RSC_VERSIONCONTROL_ID - RscTop * pRoot; // pointer to the root of type tree - RSCINST aVersion; // version control instance - - ::std::vector< RscTop* > - aBaseLst; // list of simple resource class - - void Init(); // initializes classes and tables - void SETCONST( RscEnum *, const char *, sal_uInt32 ); - RscEnum * InitFieldUnitsType(); - RscTupel * InitStringLongTupel(); - static RscCont * InitStringLongTupelList( RscTupel * pStringLongTupel ); - RscArray * InitLangStringLongTupelList( RscCont * pStrLongTupelLst ); - - RscTop * InitClassMgr(); - RscTop * InitClassString( RscTop * pSuper ); - -public: - RscLongEnumRange aEnumLong; - RscString aString; - RscLangEnum aLangType; - RscLangArray aLangString; - - RscError* pEH; // error handler - RscNameTable aNmTb; // name table - RscFileTab aFileTab; // file name table - CommandFlags nFlags; - std::map<sal_uInt64, sal_uLong> aIdTranslator; // map resources types and ids to an id (under PM9 or to a file position (MTF) - - RscTypCont( RscError *, RSCBYTEORDER_TYPE, CommandFlags nFlags ); - ~RscTypCont(); - - Atom AddLanguage( const char* ); - bool IsSrsDefault() const - { return bool(nFlags & CommandFlags::SrsDefault); } - OString ChangeLanguage(const OString & rNewLang); - const std::vector< sal_uInt32 >& GetFallbacks() const - { return aLangFallbacks; } - - RSCBYTEORDER_TYPE GetByteOrder() const { return nByteOrder; } - rtl_TextEncoding GetSourceCharSet() const { return nSourceCharSet; } - void SetSourceCharSet( rtl_TextEncoding aCharSet ) - { - nSourceCharSet = aCharSet; - } - // deletes all resource objects of this file - void Delete( RscFileTab::Index lFileKey ); - ERRTYPE WriteRc( WriteRcContext& rContext ); - void WriteSrc( FILE * fOutput, RscFileTab::Index nFileIndex ); - void PutTranslatorKey( sal_uInt64 nKey ); - void IncFilePos( sal_uLong nOffset ){ nFilePos += nOffset; } -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscdef.hxx b/rsc/inc/rscdef.hxx deleted file mode 100644 index 9ca0c8483fab..000000000000 --- a/rsc/inc/rscdef.hxx +++ /dev/null @@ -1,282 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCDEF_HXX -#define INCLUDED_RSC_INC_RSCDEF_HXX - -#include <sal/config.h> - -#include <tools/solar.h> -#include <tools/unqidx.hxx> -#include <rsctree.hxx> -#include <rtl/strbuf.hxx> -#include <vector> - -/****************** C L A S S E S ****************************************/ -class RscExpression; -class RscFileTab; -class RscDefine; - -/*********** R s c E x p r e s s i o n ***********************************/ -#define RSCEXP_LONG 0 -#define RSCEXP_EXP 1 -#define RSCEXP_DEF 2 -#define RSCEXP_NOTHING 3 - -class RscExpType -{ -public: - union - { - RscExpression * pExp; - RscDefine * pDef; - struct - { - short nHi; - unsigned short nLo; - } aLong; - } aExp; - char cType; - bool cUnused; - bool IsNumber() const { return( RSCEXP_LONG == cType ); } - bool IsExpression()const { return( RSCEXP_EXP == cType ); } - bool IsDefinition()const { return( RSCEXP_DEF == cType ); } - bool IsNothing() const { return( RSCEXP_NOTHING == cType ); } - void SetLong( sal_Int32 lValue ) - { - aExp.aLong.nHi = (short)(lValue >> 16); - aExp.aLong.nLo = (unsigned short)lValue; - cType = RSCEXP_LONG; - } - sal_Int32 GetLong() const - { - return aExp.aLong.nLo | ((sal_uInt32)aExp.aLong.nHi << 16); - } - bool Evaluate( sal_Int32 * pValue ) const; - void AppendMacro( OStringBuffer & ) const; -}; - -/*********** R s c I d ***************************************************/ -class RscId -{ - static bool bNames;// if false, only count name operation -public: - RscExpType aExp; // number, define or expression - sal_Int32 GetNumber() const; - void Create( const RscExpType & rExpType ); - void Create(){ aExp.cType = RSCEXP_NOTHING; } - - RscId() { Create(); } - - RscId( RscDefine * pEle ); - RscId( sal_Int32 lNumber ) - { - aExp.cUnused = false; - aExp.SetLong( lNumber ); - } - - RscId( const RscExpType & rExpType ) - { Create( rExpType ); } - - void Destroy(); - - ~RscId() { Destroy(); } - - RscId( const RscId& rRscId ); - - RscId& operator = ( const RscId& rRscId ); - - static void SetNames( bool bSet = true ); - OString GetName() const; // returns the define - bool operator < ( const RscId& rRscId ) const; - bool operator > ( const RscId& rRscId ) const; - bool operator == ( const RscId& rRscId ) const; - bool operator <= ( const RscId& rRscId ) const - { return !(operator > ( rRscId )); } - bool operator >= ( const RscId& rRscId ) const - { return !(operator < ( rRscId )); } - bool IsId() const { return !aExp.IsNothing(); } -}; - -typedef ::std::vector< RscDefine* > RscSubDefList; - -/*********** R s c E x p r e s s i o n ***********************************/ -class RscExpression -{ -friend class RscFileTab; - char cOperation; - RscExpType aLeftExp; - RscExpType aRightExp; -public: - RscExpression( RscExpType aLE, char cOp, - RscExpType aRE ); - ~RscExpression(); - bool Evaluate( sal_Int32 * pValue ); - OString GetMacro(); -}; - -/********************** R S C F I L E ************************************/ -class RscDepend; - -typedef ::std::vector< RscDepend* > RscDependList; - -class RscDefTree -{ - RscDefine * pDefRoot; -public: - static bool Evaluate( RscDefine * pDef ); - RscDefTree(){ pDefRoot = nullptr; } - ~RscDefTree(); - void Remove(); - RscDefine * Search( const char * pName ); - void Insert( RscDefine * pDef ); - void Remove( RscDefine * pDef ); -}; - -class RscFile; - -class RscFileTab : public UniqueIndex<RscFile> -{ -public: - using UniqueIndex<RscFile>::Index; - using UniqueIndex<RscFile>::IndexNotFound; - -private: - RscDefTree aDefTree; - Index Find(const OString& rName); -public: - RscFileTab(); - ~RscFileTab(); - - RscDefine * FindDef( const char * ); - RscDefine * FindDef(const OString& rStr) - { - return FindDef(rStr.getStr()); - } - - bool Depend( Index lDepend, Index lFree ); - bool TestDef( Index lFileKey, size_t lPos, - const RscDefine * pDefDec ); - bool TestDef( Index lFileKey, size_t lPos, - const RscExpression * pExpDec ); - - RscDefine * NewDef( Index lKey, const OString& rDefName, - sal_Int32 lId ); - RscDefine * NewDef( Index lKey, const OString& rDefName, - RscExpression * ); - - // deletes all defines defined in this file - void DeleteFileContext( Index lKey ); - Index NewCodeFile(const OString& rName); - Index NewIncFile(const OString& rName, const OString& rPath); - RscFile * GetFile( Index lFileKey ){ return Get( lFileKey ); } -}; - -class RscDepend -{ - RscFileTab::Index lKey; -public: - RscDepend( RscFileTab::Index lIncKey ){ lKey = lIncKey; }; - RscFileTab::Index GetFileKey(){ return lKey; } -}; - -class RscDefineList -{ -friend class RscFile; -friend class RscFileTab; -private: - RscSubDefList maList; - // pExpression always belongs to the list - RscDefine * New( RscFileTab::Index lFileKey, const OString& rDefName, - sal_Int32 lDefId, size_t lPos ); - RscDefine * New( RscFileTab::Index lFileKey, const OString& rDefName, - RscExpression * pExpression, size_t lPos ); - bool Remove(); - size_t GetPos( RscDefine* item ) - { - for ( size_t i = 0, n = maList.size(); i < n; ++i ) - if ( maList[ i ] == item ) - return i; - return size_t(-1); - } -}; - -// table containing all file names -class RscFile -{ -friend class RscFileTab; - bool bIncFile; // whether it is an include file -public: - bool bLoaded; // whether the file is loaded - bool bScanned; // whether the file searches for include - OString aFileName; // file name - OString aPathName; // file path and name - RscDefineList aDefLst; // list of defines - RscDependList aDepLst; // list of depend - - RscFile(); - ~RscFile(); - void InsertDependFile( RscFileTab::Index lDepFile ); - bool Depend( RscFileTab::Index lDepend, RscFileTab::Index lFree ); - void SetIncFlag(){ bIncFile = true; }; - bool IsIncFile(){ return bIncFile; }; -}; - -/*********** R s c D e f i n e *******************************************/ -class RscDefine : public NameNode -{ -friend class RscFileTab; -friend class RscDefineList; -friend class RscDefTree; -friend class RscExpression; -friend class RscId; - - RscFileTab::Index lFileKey; // file the define belongs to - sal_uInt32 nRefCount; // reference count to this object - sal_Int32 lId; // identifier - RscExpression * pExp; // expression - OString m_aName; - - virtual COMPARE Compare( const NameNode * ) const override; - virtual COMPARE Compare( const void * ) const override; - -public: - RscDefine( RscFileTab::Index lFileKey, const OString& rDefName, - sal_Int32 lDefId ); - virtual ~RscDefine() override; - -protected: - RscDefine( RscFileTab::Index lFileKey, const OString& rDefName, - RscExpression * pExpression ); - - void IncRef() { nRefCount++; } - void DecRef(); - void DefineToNumber(); - -public: - RscFileTab::Index GetFileKey() const { return lFileKey; } - void Evaluate(); - sal_Int32 GetNumber() const { return lId; } - RscDefine* Search( const char * ) const; - const OString& GetName() const { return m_aName; } -}; - - -#endif // INCLUDED_RSC_INC_RSCDEF_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscerror.h b/rsc/inc/rscerror.h deleted file mode 100644 index 11a498e96756..000000000000 --- a/rsc/inc/rscerror.h +++ /dev/null @@ -1,149 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <sal/types.h> - -#ifndef INCLUDED_RSC_INC_RSCERROR_H -#define INCLUDED_RSC_INC_RSCERROR_H - -// Return errors -#define ERR_OK 0xFFFFFFFF - -#define ERR_ERROR 0x0100 -#define ERR_UNKNOWN_METHOD 0x0101 // Return -#define ERR_OPENFILE 0x0102 // Return -#define ERR_NOCHAR 0x0103 // Return -#define ERR_NORSCINST 0x0104 // Return -#define ERR_USAGE 0x0105 -#define ERR_NOINPUT 0x0106 // Return -#define ERR_UNKNOWNSW 0x0107 -#define ERR_REFTODEEP 0x0108 // Return -#define ERR_FILEFORMAT 0x0109 // Return -#define ERR_FILESIZE 0x010A // Return -#define ERR_RENAMEFILE 0x010B // Return -#define ERR_NOIMAGE 0x010C // Return - -#define ERR_RSCRANGE 0x0200 // Return -#define ERR_RSCRANGE_OUTDEFSET (ERR_RSCRANGE +1 ) - -#define ERR_RSCENUM 0x0210 // Return -#define ERR_RSCFLAG 0x0220 // Return -#define ERR_RSCCONT 0x0240 // Return -#define ERR_CONT_INVALIDPOS (ERR_RSCCONT +1 ) // Return -#define ERR_CONT_INVALIDTYPE (ERR_RSCCONT +2 ) // Return - -#define ERR_RSCINST 0x0260 -#define ERR_RSCINST_NOVARNAME (ERR_RSCINST +1 ) // Return -#define ERR_RSCINST_RESERVEDNAME (ERR_RSCINST +2 ) // Return - -#define ERR_YACC 0x0280 -#define ERR_DOUBLEID (ERR_YACC +1 ) -#define ERR_FALSETYPE (ERR_YACC +2 ) -#define ERR_NOVARIABLENAME (ERR_YACC +3 ) -#define ERR_USHORTRANGE (ERR_YACC +4 ) -#define ERR_IDRANGE (ERR_YACC +5 ) -#define ERR_NOCOPYOBJ (ERR_YACC +6 ) -#define ERR_REFNOTALLOWED (ERR_YACC +7 ) // Return -#define ERR_DOUBLEDEFINE (ERR_YACC +8 ) -#define ERR_COPYNOTALLOWED (ERR_YACC +9 ) -#define ERR_IDEXPECTED (ERR_YACC +10) -#define ERR_ZERODIVISION (ERR_YACC +11) -#define ERR_PRAGMA (ERR_YACC +12) -#define ERR_DECLAREDEFINE (ERR_YACC +13) -#define ERR_NOTUPELNAME (ERR_YACC +14) -#define ERR_NOTYPE (ERR_YACC +15) - -#define ERR_RSCARRAY 0x02A0 // Return -#define ERR_ARRAY_INVALIDINDEX (ERR_RSCARRAY +1 ) // Return - -#define ERR_ERROREND 0x1000 - -#define ERR_WARNINGSTART 0x1001 -#define WRN_LOCALID (ERR_WARNINGSTART +1 ) -#define WRN_GLOBALID (ERR_WARNINGSTART +2 ) -#define WRN_SUBINMEMBER (ERR_WARNINGSTART +3 ) -#define WRN_CONT_NOID (ERR_WARNINGSTART +4 ) -#define WRN_STR_REFNOTFOUND (ERR_WARNINGSTART +5 ) -#define WRN_MGR_REFNOTFOUND (ERR_WARNINGSTART +6 ) -#define WRN_CONT_DOUBLEID (ERR_WARNINGSTART +7 ) - -#define ERR_WARNINGEND 0x2000 - -class ERRTYPE -{ - sal_uInt32 nError; -public: - ERRTYPE() { nError = ERR_OK; } - ERRTYPE( sal_uInt32 nErr ) { nError = nErr; } - ERRTYPE( const ERRTYPE & ) = default; - ERRTYPE& operator = ( const ERRTYPE & rError ); - sal_uInt32 GetError() const { return nError; } - bool IsError() const { return nError <= ERR_ERROREND; } - bool IsOk() const { return !IsError(); } - bool IsWarning() const { return nError >= ERR_WARNINGSTART && nError <= ERR_WARNINGEND;} - void Clear() { nError = ERR_OK; } -}; - -// Rsc Error -class RscId; -class RscTop; - -enum RscVerbosity -{ - RscVerbositySilent = 0, - RscVerbosityNormal = 1, - RscVerbosityVerbose = 2 -}; - -class RscError final -{ - FILE * fListing; - RscVerbosity m_verbosity; - - void WriteError( const ERRTYPE& rError, const char * pMessage ); - void StdLstOut( const char * pStr ); - void StdLstErr( const char * pStr ); - void ErrorFormat( const ERRTYPE& rError, RscTop * pClass, - const RscId & aId ); -public: - - sal_uInt32 nErrors; // Number of errors - RscError( RscVerbosity _verbosity ) - { - fListing = nullptr; - nErrors = 0; - m_verbosity = _verbosity; - } - void SetListFile( FILE * fList ){ fListing = fList; } - FILE * GetListFile(){ return fListing; } - RscVerbosity GetVerbosity() const { return m_verbosity; } - void StdOut( const char *, const RscVerbosity _verbosityLevel = RscVerbosityNormal ); - static void StdErr( const char * ); - void LstOut( const char * ); - void Error( const ERRTYPE& rError, RscTop* pClass, const RscId &aId, - const char * pMessage = nullptr ); - // The error should only happen in compile mode, - // the program will terminated with exit() - void FatalError( const ERRTYPE& rError, const RscId &aId, - const char * pMessage = nullptr ); -}; - -#endif // INCLUDED_RSC_INC_RSCERROR_H - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rschash.hxx b/rsc/inc/rschash.hxx deleted file mode 100644 index 898969e7c14c..000000000000 --- a/rsc/inc/rschash.hxx +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCHASH_HXX -#define INCLUDED_RSC_INC_RSCHASH_HXX - -#include <sal/types.h> -#include <rtl/string.hxx> -#include <unordered_map> - -typedef sal_uInt32 Atom; - -#define InvalidAtom Atom( ~0 ) - -class AtomContainer -{ - Atom m_nNextID; - std::unordered_map< OString, Atom, OStringHash > m_aStringToID; - std::unordered_map< Atom, OString > m_aIDToString; - - public: - AtomContainer(); - ~AtomContainer(); - - Atom getID( const OString& rStr, bool bOnlyIfExists = false ); - const OString& getString( Atom nAtom ); - -}; - -#endif // INCLUDED_RSC_INC_RSCHASH_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rsckey.hxx b/rsc/inc/rsckey.hxx deleted file mode 100644 index 4ca2812ff69d..000000000000 --- a/rsc/inc/rsckey.hxx +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCKEY_HXX -#define INCLUDED_RSC_INC_RSCKEY_HXX - -// class forwards -class RscTop; - -#include <rscall.h> - -typedef struct -{ - Atom nName; - sal_uInt32 nTyp; - sal_IntPtr yylval; -} KEY_STRUCT; - -class RscNameTable -{ - bool bSort; // whether it must be sorted for each insertion - sal_uInt32 nEntries; // number of entries - KEY_STRUCT * pTable; -public: - RscNameTable(); - ~RscNameTable(); - void SetSort( bool bSorted = true ); - Atom Put( Atom nName, sal_uInt32 nTyp, sal_IntPtr nValue ); - Atom Put( const char * pName, sal_uInt32 nTyp, sal_IntPtr nValue ); - Atom Put( const char * pName, sal_uInt32 nTyp ); - void Put( Atom nName, sal_uInt32 nTyp, RscTop * pClass ); - - // if true, it was found - bool Get( Atom nName, KEY_STRUCT * pEle ); -}; - -#endif // INCLUDED_RSC_INC_RSCKEY_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rsclex.hxx b/rsc/inc/rsclex.hxx deleted file mode 100644 index 307e6bc8ea7f..000000000000 --- a/rsc/inc/rsclex.hxx +++ /dev/null @@ -1,115 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_RSC_INC_RSCLEX_HXX -#define INCLUDED_RSC_INC_RSCLEX_HXX - -#include <rtl/strbuf.hxx> -#include <rtl/string.hxx> -#include <unordered_set> - -// a buffer for unique strings -class StringContainer -{ - std::unordered_set< OString, OStringHash > m_aStrings; -public: - StringContainer() {} - - const char* putString( const char* pString ); -}; - - -enum MODE_ENUM { MODE_MODELESS, MODE_APPLICATIONMODAL, MODE_SYSTEMMODAL }; - -enum JUSTIFY_ENUM { JUST_CENTER, JUST_RIGHT, JUST_LEFT }; - -enum SHOW_ENUM { SHOW_NORMAL, SHOW_MINIMIZED, SHOW_MAXIMIZED }; - -enum ENUMHEADER { HEADER_NAME, HEADER_NUMBER }; - -enum REF_ENUM { TYPE_NOTHING, TYPE_REF, TYPE_COPY }; - -struct RSCHEADER { - RscTop * pClass; - RscExpType nName1; - REF_ENUM nTyp; - RscTop * pRefClass; - RscExpType nName2; -}; - -/************** O b j e c t s t a c k ************************************/ -struct Node -{ - Node* pPrev; - RSCINST aInst; - Node() { pPrev = nullptr; } -}; - -class ObjectStack -{ - private: - Node* pRoot; - public: - - ObjectStack () { pRoot = nullptr; } - - const RSCINST & Top () { return pRoot->aInst; } - bool IsEmpty() { return( pRoot == nullptr ); } - void Push( RSCINST aInst ) - { - Node* pTmp; - - pTmp = pRoot; - pRoot = new Node; - pRoot->aInst = aInst; - pRoot->pPrev = pTmp; - } - void Pop() - { - Node* pTmp; - - pTmp = pRoot; - pRoot = pTmp->pPrev; - delete pTmp; - } -}; - -/****************** F o r w a r d s **************************************/ -#if defined(__sun) -extern "C" int yyparse(); // forward declaration for created function -extern "C" void yyerror( const char * ); -extern "C" int yylex(); -#else -int yyparse(); // forward declaration for created function -void yyerror( char * ); -int yylex(); -#endif - -class RscTypCont; -class RscFileInst; - -extern RscTypCont* pTC; -extern RscFileInst * pFI; -extern RscExpression * pExp; -extern ObjectStack S; -extern StringContainer* pStringContainer; - -#endif // INCLUDED_RSC_INC_RSCLEX_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscmgr.hxx b/rsc/inc/rscmgr.hxx deleted file mode 100644 index 3bd159a901ec..000000000000 --- a/rsc/inc/rscmgr.hxx +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCMGR_HXX -#define INCLUDED_RSC_INC_RSCMGR_HXX - -#include <rscall.h> -#include <rscerror.h> -#include <rschash.hxx> -#include <rsctop.hxx> -#include <rscclass.hxx> - -/******************* R s c M g r *****************************************/ -class RscMgr : public RscClass -{ - struct RscMgrInst - { - RscId aRefId; // nRefId = Referenz Identifier - bool bDflt; // default - void Create(){ aRefId.Create(); bDflt = true; } - void Destroy(){ aRefId.Destroy(); } - }; - ERRTYPE IsToDeep( const RSCINST & rInst ); -public: - RscMgr( Atom nId, RESOURCE_TYPE nTypId, RscTop * pSuperCl ); - - void SetToDefault( const RSCINST & rInst ) override; - bool IsDefault( const RSCINST & rInst ) override; - bool IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) override; - - RSCINST Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass = false ) override; - void Destroy( const RSCINST & rInst ) override; - sal_uInt32 Size() const override; - void WriteSrcHeader( const RSCINST & aInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const RscId & rId, const char * ) override; - - void WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * ) override; - ERRTYPE WriteRcHeader( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont * pTC, const RscId & rId, - sal_uInt32 ) override; - ERRTYPE WriteRc( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont * pTC, sal_uInt32 ) override; - bool IsConsistent( const RSCINST & rInst ) override; - ERRTYPE GetRef( const RSCINST & rInst, RscId * ) override; - ERRTYPE SetRef( const RSCINST & rInst, const RscId & rRefId ) override; -}; - -#endif // INCLUDED_RSC_INC_RSCMGR_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscpar.hxx b/rsc/inc/rscpar.hxx deleted file mode 100644 index aea9a8740c35..000000000000 --- a/rsc/inc/rscpar.hxx +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCPAR_HXX -#define INCLUDED_RSC_INC_RSCPAR_HXX - -#include <rsctools.hxx> -#include <rscerror.h> -#include <rscdef.hxx> -#include <tools/solar.h> - -class RscTypCont; - -#define READBUFFER_MAX 256 - -class RscFileInst -{ - ERRTYPE aFirstError; - sal_uInt32 nLineNo; // line in input file - RscFileTab::Index lFileIndex; // index input file - RscFileTab::Index lSrcIndex; // index base file - FILE * fInputFile; - char * pInput; // read buffer - static const sal_uInt32 nInputBufLen = READBUFFER_MAX; - sal_uInt32 nInputPos; - sal_uInt32 nInputEndPos; - char * pLine; - sal_uInt32 nLineBufLen; - sal_uInt32 nScanPos; // line position - int cLastChar; - bool bEof; - -public: - RscTypCont * pTypCont; - void Init(); // init ctor - RscFileInst( RscTypCont * pTC, RscFileTab::Index lIndexSrc, - RscFileTab::Index lFileIndex, FILE * fFile ); - ~RscFileInst(); - bool IsEof() const { return bEof; } - void SetFileIndex( RscFileTab::Index lFIndex ) { lFileIndex = lFIndex; } - RscFileTab::Index GetFileIndex() { return lFileIndex; } - void SetLineNo( sal_uInt32 nLine ) { nLineNo = nLine; } - sal_uInt32 GetLineNo() { return nLineNo; } - sal_uInt32 GetScanPos() { return nScanPos; } - char * GetLine() { return pLine; } - char GetChar(); - char GetFastChar() - { - return pLine[ nScanPos ] ? - pLine[ nScanPos++ ] : GetChar(); - } - void GetNewLine(); - // error handling - void SetError( ERRTYPE aError ); -}; - -void IncludeParser( RscFileInst * pFileInst ); -ERRTYPE parser( RscFileInst * pFileInst ); - -#endif // INCLUDED_RSC_INC_RSCPAR_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscrange.hxx b/rsc/inc/rscrange.hxx deleted file mode 100644 index 202b86f98e08..000000000000 --- a/rsc/inc/rscrange.hxx +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCRANGE_HXX -#define INCLUDED_RSC_INC_RSCRANGE_HXX - -#include <rscall.h> -#include <rscerror.h> -#include <rschash.hxx> -#include <rsctop.hxx> - -class RscLongRange : public RscTop -{ -protected: - struct RscLongRangeInst - { - sal_Int32 nValue; // nValue = output value - nMin - bool bDflt; // is default - }; - sal_Int32 nMin; // range minimum value - sal_Int32 nMax; // range maximum value -public: - RscLongRange( Atom nId, RESOURCE_TYPE nTypId ); - RSCINST Create( RSCINST * pInst, const RSCINST & rDfltInst, bool bOwnClass = false ) override; - // sets the allowed range - void SetRange( sal_Int32 nMinimum, sal_Int32 nMaximum ); - // returns the class size in bytes - sal_uInt32 Size() const override { return ALIGNED_SIZE(sizeof(RscLongRangeInst)); } - // an assignment to a variable - virtual void SetToDefault( const RSCINST & rInst ) override - { - reinterpret_cast<RscLongRangeInst*>(rInst.pData)->bDflt = true; - } - bool IsDefault( const RSCINST & rInst) override - { - return reinterpret_cast<RscLongRangeInst*>(rInst.pData)->bDflt; - }; - // sets as default - bool IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) override; - ERRTYPE SetNumber( const RSCINST &, sal_Int32 ) override; - ERRTYPE GetNumber( const RSCINST &, sal_Int32 * ) override; - void WriteSrc( const RSCINST &, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * ) override; - ERRTYPE WriteRc( const RSCINST &, RscWriteRc & aMem, - RscTypCont * pTC, sal_uInt32 ) override; - -}; - -class RscLongEnumRange : public RscLongRange -{ -public: - RscLongEnumRange( Atom nId, RESOURCE_TYPE nTypId ); - - ERRTYPE SetConst( const RSCINST & rInst, Atom nValueId, - sal_Int32 nValue ) override; -}; - -#endif // INCLUDED_RSC_INC_RSCRANGE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscrsc.hxx b/rsc/inc/rscrsc.hxx deleted file mode 100644 index f09b42d6004d..000000000000 --- a/rsc/inc/rscrsc.hxx +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCRSC_HXX -#define INCLUDED_RSC_INC_RSCRSC_HXX - -#include <rscall.h> -#include <rscerror.h> -#include <rsctools.hxx> - -#include <list> - -class RscTypCont; - - -/****************** R s c C m d L i n e **********************************/ -class RscCmdLine -{ - void Init(); - -public: - - RscStrList aInputList; // source file list - OString aPath; // path list - RSCBYTEORDER_TYPE nByteOrder; - CommandFlags nCommands; // command bits - OString aOutputSrs; // Srs output file name - - struct OutputFile - { - OString aLangName; // language name - OString aOutputRc; // target file - OString aLangSearchPath; // language specific search path - ::std::list< OString > aSysSearchDirs; // paths to search for images - - OutputFile() {} - }; - - std::list<OutputFile> m_aOutputFiles; - std::list< std::pair< OString, OString > > m_aReplacements; - - RscCmdLine( int argc, char ** argv, RscError * pEH ); - ~RscCmdLine(); - - OString substitutePaths( const OString& rIn ); -}; -/****************** R s c ************************************************/ - -struct WriteRcContext; - -class RscCompiler -{ -private: - static bool GetImageFilePath( const RscCmdLine::OutputFile& rOutputFile, - const WriteRcContext& rContext, - const OString& rBaseFileName, - OString& rImagePath, - FILE* pSysListFile ); - void PreprocessSrsFile( const RscCmdLine::OutputFile& rOutputFile, - const WriteRcContext& rContext, - const OUString& rSrsInPath, - const OUString& rSrsOutPath ); - -public: - RscTypCont* pTC; // string and id manager - RscCmdLine* pCL; // command line - FILE * fExitFile; // when deconstructed, this file must be deleted - - RscCompiler( RscCmdLine *, RscTypCont * ); - ~RscCompiler(); - - ERRTYPE Start(); - - // read include statements - ERRTYPE IncludeParser( RscFileTab::Index lFileKey ); - ERRTYPE ParseOneFile( RscFileTab::Index lFileKey, const RscCmdLine::OutputFile* pOutputFile, const WriteRcContext* pContext ); - ERRTYPE Link(); - void EndCompile(); -}; - -#endif // INCLUDED_RSC_INC_RSCRSC_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rscstr.hxx b/rsc/inc/rscstr.hxx deleted file mode 100644 index 5ae1d17aa92d..000000000000 --- a/rsc/inc/rscstr.hxx +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCSTR_HXX -#define INCLUDED_RSC_INC_RSCSTR_HXX - -#include <rscall.h> -#include <rscerror.h> -#include <rschash.hxx> -#include <rsctop.hxx> - -class RscString : public RscTop -{ - RscTop * pRefClass; - struct RscStringInst - { - char * pStr; // pointer to string - bool bDflt; // is default - RscId aRefId; // reference name - }; -public: - RscString( Atom nId, RESOURCE_TYPE nTypId ); - - void SetRefClass( RscTop * pClass ) { pRefClass = pClass; } - RSCINST Create( RSCINST * pInst, const RSCINST & rDfltInst, bool bOwnClass = false ) override; - // sets the allowed range - void Destroy( const RSCINST & rInst ) override; - sal_uInt32 Size() const override { return ALIGNED_SIZE(sizeof(RscStringInst)); } - void SetToDefault( const RSCINST & rInst ) override - { - reinterpret_cast<RscStringInst*>(rInst.pData)->bDflt = true; - } - bool IsDefault( const RSCINST & rInst) override - { - return reinterpret_cast<RscStringInst*>(rInst.pData)->bDflt; - } - // sets as default - bool IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) override; - ERRTYPE SetString( const RSCINST &, const char * pStr ) override; - ERRTYPE GetString( const RSCINST &, char ** ppStr ) override; - ERRTYPE GetRef( const RSCINST & rInst, RscId * ) override; - ERRTYPE SetRef( const RSCINST & rInst, const RscId & rRefId ) override; - void WriteSrc( const RSCINST &, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * ) override; - ERRTYPE WriteRc( const RSCINST &, RscWriteRc & aMem, - RscTypCont * pTC, sal_uInt32 ) override; -}; - -#endif // INCLUDED_RSC_INC_RSCSTR_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rsctools.hxx b/rsc/inc/rsctools.hxx deleted file mode 100644 index dcfade4adaf7..000000000000 --- a/rsc/inc/rsctools.hxx +++ /dev/null @@ -1,185 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -struct RSHEADER_TYPE; -class RscPtrPtr; - -#ifndef INCLUDED_RSC_INC_RSCTOOLS_HXX -#define INCLUDED_RSC_INC_RSCTOOLS_HXX - -#ifdef UNX -#include <stdlib.h> -#endif -#include <stdio.h> -#include <vector> -#include <rtl/ustring.hxx> -#include <osl/endian.h> - -// character set -enum COMPARE { LESS = -1, EQUAL = 0, GREATER = 1 }; - -enum RSCBYTEORDER_TYPE { RSC_BIGENDIAN, RSC_LITTLEENDIAN, RSC_SYSTEMENDIAN }; - -#define ALIGNED_SIZE( nSize ) \ - (nSize + sizeof( void * ) -1) / sizeof( void * ) * sizeof( void * ) - -// Function Forwards -OString GetTmpFileName(); - -OString OutputFile(const OString &rInput, const char * ext); - -char * ResponseFile( RscPtrPtr * ppCmd, char ** ppArgv, - sal_uInt32 nArgc ); - -void RscExit( sal_uInt32 nExit ); - -int rsc_strnicmp( const char *string1, const char *string2, size_t count ); -int rsc_stricmp( const char *string1, const char *string2 ); -char* rsc_strdup( const char* ); - -typedef ::std::vector< OString* > RscStrList; - -class RscChar -{ -public: - static char * MakeUTF8( char * pStr, sal_uInt16 nTextEncoding ); -}; - -class RscPtrPtr -{ - sal_uInt32 nCount; - void ** pMem; -public: - RscPtrPtr(); - ~RscPtrPtr(); - void Reset(); - sal_uInt32 Append( void * ); - sal_uInt32 Append( char * pStr ) { return Append( static_cast<void *>(pStr) ); } - sal_uInt32 GetCount() { return nCount; } - void * GetEntry( sal_uInt32 nEle ); - void ** GetBlock() { return pMem; } -}; - -class RscWriteRc -{ - sal_uInt32 nLen; - bool bSwap; - char * pMem; - char * GetPointer( sal_uInt32 nSize ); -public: - RscWriteRc( RSCBYTEORDER_TYPE nOrder = RSC_SYSTEMENDIAN ); - ~RscWriteRc(); - sal_uInt32 IncSize( sal_uInt32 nSize ); // gives the previous size - void * GetBuffer() - { - return GetPointer( 0 ); - } - sal_uInt32 GetLong( sal_uInt32 nPos ) - { - sal_uInt32 nVal = 0; - char* pFrom = GetPointer(nPos); - char* pTo = reinterpret_cast<char*>(&nVal); - *pTo++ = *pFrom++; - *pTo++ = *pFrom++; - *pTo++ = *pFrom++; - *pTo++ = *pFrom++; - return bSwap ? OSL_SWAPDWORD( nVal ) : nVal; - } - sal_uInt32 Size(){ return nLen; } - void Put( sal_uInt64 lVal ) - { - union - { - sal_uInt64 lVal64; - sal_uInt32 aVal32[2]; - }; - lVal64 = lVal; - if( bSwap ) - { - Put( aVal32[1] ); - Put( aVal32[0] ); - } - else - { - Put( aVal32[0] ); - Put( aVal32[1] ); - } - } - void Put( sal_Int32 lVal ) - { - union - { - sal_uInt32 lVal32; - sal_uInt16 aVal16[2]; - }; - lVal32 = lVal; - - if( bSwap ) - { - Put( aVal16[1] ); - Put( aVal16[0] ); - } - else - { - Put( aVal16[0] ); - Put( aVal16[1] ); - } - } - void Put( sal_uInt32 nValue ) - { Put( (sal_Int32)nValue ); } - void Put( sal_uInt16 nValue ); - void PutUTF8( char * pData ); - - void PutAt( sal_uInt32 nPos, sal_Int32 lVal ) - { - union - { - sal_uInt32 lVal32; - sal_uInt16 aVal16[2]; - }; - lVal32 = lVal; - - if( bSwap ) - { - PutAt( nPos, aVal16[1] ); - PutAt( nPos + 2, aVal16[0] ); - } - else - { - PutAt( nPos, aVal16[0] ); - PutAt( nPos + 2, aVal16[1] ); - } - } - void PutAt( sal_uInt32 nPos, sal_uInt32 lVal ) - { - PutAt( nPos, (sal_Int32)lVal); - } - void PutAt( sal_uInt32 nPos, sal_uInt16 nVal ) - { - if( bSwap ) - nVal = OSL_SWAPWORD( nVal ); - char* pTo = GetPointer( nPos ); - char* pFrom = reinterpret_cast<char*>(&nVal); - *pTo++ = *pFrom++; - *pTo++ = *pFrom++; - } -}; - -#endif // INCLUDED_RSC_INC_RSCTOOLS_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rsctop.hxx b/rsc/inc/rsctop.hxx deleted file mode 100644 index 76c96844cb73..000000000000 --- a/rsc/inc/rsctop.hxx +++ /dev/null @@ -1,210 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCTOP_HXX -#define INCLUDED_RSC_INC_RSCTOP_HXX - -#include <rscerror.h> -#include <rsctools.hxx> -#include <rschash.hxx> -#include <rscclobj.hxx> -#include <rsc/rscsfx.hxx> -#include <o3tl/typed_flags_set.hxx> -#include <tools/resid.hxx> - -enum class RSCVAR { - NONE = 0x0000, - Pointer = 0x0001, - Hidden = 0x0002, - NoDataInst = 0x0004, - NoRc = 0x0008, - SvDynamic = 0x0010, - NoEnum = 0x0020 -}; -namespace o3tl { - template<> struct typed_flags<RSCVAR> : is_typed_flags<RSCVAR, 0x007f> {}; -} - -class RscTop : public RefNode -{ - RscTop * pSuperClass; - RSCINST aDfltInst; - RESOURCE_TYPE nTypId; - RscTop * pRefClass; - -protected: - RscTop( Atom nId, RESOURCE_TYPE nTypIdent, - RscTop * pSuperCl = nullptr ); - -public: - OString aCallPar1; // class call without types until ResId - OString aCallPar2; // class call without types staring at ResId - OString aCallParType; // class call with types - - RscTop* GetSuperClass() const - { return pSuperClass; } - // returns the type identifier - RESOURCE_TYPE GetTypId() const - { return nTypId; }; - // returns the super class - bool InHierarchy( RscTop * pClass ); - void SetCallPar( const OString& rPar1, const OString& rPar2, - const OString& rParType ); - RscTop* GetRefClass() const { return pRefClass; } - RSCINST const & GetDefault(); - - // preparation fro the destructor call - // given that classes can have mutual dependencies, - // we cannot assume in destructor that all class pointer - // are still valid - virtual void Pre_dtor(); - - virtual RscTop* GetTypeClass() const; - - // returns the class size in bytes - virtual sal_uInt32 Size() const; - - // returns the reference - virtual ERRTYPE GetRef( const RSCINST & rInst, RscId * ); - - // sets the reference - virtual ERRTYPE SetRef( const RSCINST & rInst, const RscId & rRefId ); - - // sets the variable - virtual ERRTYPE SetVariable( Atom nVarName, RscTop * pClass, - RSCINST * pDflt = nullptr, - RSCVAR nVarType = RSCVAR::NONE, sal_uInt32 nMask = 0, - Atom nDataBaseName = InvalidAtom ); - - // returns variable instance - // returned pData, pClass may be NULL - virtual RSCINST GetVariable( const RSCINST & rInst, Atom nVarName, - const RSCINST & rInitInst, - bool bInitDflt = false, - RscTop * pCreateClass = nullptr ); - virtual RSCINST GetCopyVar( const RSCINST & rInst, Atom nVarName ); - - virtual RSCINST GetTupelVar( const RSCINST & rInst, sal_uInt32 nPos, - const RSCINST & rInitInst ); - - // returns instance from a field - // returned pGetInst may be NULL - virtual ERRTYPE GetElement( const RSCINST & rInst, const RscId & rEleName, - RscTop *pCreateClass, const RSCINST & rCreateInst, - RSCINST * pGetInst ); - - // returns instance from a value - // returned pGetInst may be NULL - virtual ERRTYPE GetValueEle( const RSCINST & rInst, sal_Int32 lValue, - RscTop * pCreateClass, - RSCINST * pGetInst ); - - // returns instance from an array - // returned pGetInst may be NULL - virtual ERRTYPE GetArrayEle( const RSCINST & rInst, Atom nId, - RscTop * pCreateClass, - RSCINST * pGetInst ); - - virtual RSCINST SearchEle( const RSCINST & rInst, const RscId & rEleName, - RscTop * pClass ); - - // returns instance at the position - virtual RSCINST GetPosEle( const RSCINST & rInst, sal_uInt32 nPos ); - - // move an instance - virtual ERRTYPE MovePosEle( const RSCINST & rInst, sal_uInt32 nDestPos, - sal_uInt32 nSourcePos ); - - // changes RscId at position - virtual ERRTYPE SetPosRscId( const RSCINST & rInst, sal_uInt32 nPos, - const RscId & rRscId); - - // returns instance information at position - virtual SUBINFO_STRUCT GetInfoEle( const RSCINST & rInst, sal_uInt32 nPos ); - - // number of entries - virtual sal_uInt32 GetCount( const RSCINST & rInst ); - - // an assignment to a variable - virtual ERRTYPE SetNumber( const RSCINST & rInst, sal_Int32 lValue ); - - // an assignment to a variable - virtual ERRTYPE SetBool( const RSCINST & rInst, bool bValue ); - - // an assignment to a variable - virtual ERRTYPE SetConst( const RSCINST & rInst, Atom nValueId, - sal_Int32 nValue ); - - // an assignment to a variable - ERRTYPE SetNotConst( const RSCINST & rInst, Atom nId ); - - virtual ERRTYPE SetString( const RSCINST & rInst, const char * pStr ); - - virtual ERRTYPE GetNumber( const RSCINST & rInst, sal_Int32 * pN ); - - ERRTYPE GetBool( const RSCINST & rInst, bool * pB ); - - virtual ERRTYPE GetConst( const RSCINST & rInst, Atom * pH ); - - virtual ERRTYPE GetString( const RSCINST & rInst, char ** ppStr ); - - virtual RSCINST Create( RSCINST * pInst, - const RSCINST & rDefInst, bool bOwnClass = false ); - - // destroys instance - virtual void Destroy( const RSCINST & rInst ); - - // checks consistency - virtual bool IsConsistent( const RSCINST & rInst ); - - // sets all default values - virtual void SetToDefault( const RSCINST & rInst ); - - // whether input is equal to default - virtual bool IsDefault( const RSCINST & rInst ); - - // sets value to default - virtual bool IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ); - - // sets intance to default - virtual void SetDefault( const RSCINST & rInst, Atom nVarId ); - - // returns a variable default - virtual RSCINST GetDefault( Atom nVarId ); - - virtual void Delete( const RSCINST & rInst, RscTop * pClass, - const RscId & rId ); - - virtual void DeletePos( const RSCINST & rInst, sal_uInt32 nPos ); - - // writes header and footer of a resource script file - virtual void WriteSrcHeader( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const RscId & aId, const char * ); - virtual void WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab,const char * ); - virtual ERRTYPE WriteRcHeader( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont * pTC, const RscId & aId, - sal_uInt32 nDeep ); - virtual ERRTYPE WriteRc( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont * pTC, sal_uInt32 nDeep ); -}; - -#endif // INCLUDED_RSC_INC_RSCTOP_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/inc/rsctree.hxx b/rsc/inc/rsctree.hxx deleted file mode 100644 index 47dffeb66a5a..000000000000 --- a/rsc/inc/rsctree.hxx +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_RSC_INC_RSCTREE_HXX -#define INCLUDED_RSC_INC_RSCTREE_HXX - -#include <tools/link.hxx> -#include <rsctools.hxx> - -class NameNode -{ - void SubOrderTree( NameNode * pOrderNode ); - -protected: - NameNode* pLeft; // left subtree - NameNode* pRight; // right subtree - - // pCmp is pointer to names - NameNode* Search( const void * pCmp ) const; - - // convert a double linked list into a binary tree - NameNode* ChangeDLListBTree( NameNode * pList ); - - NameNode(); - virtual ~NameNode(); - - // convert a binary tree in a double linked list - NameNode* ChangeBTreeDLList(); - -public: - void EnumNodes( Link<const NameNode&,void> aLink ) const; - NameNode* Left() const { return pLeft; } - NameNode* Right() const{ return pRight; } - NameNode* Search( const NameNode * pName ) const; - // insert a new node in the b-tree - bool Insert( NameNode * pTN, sal_uInt32 * nDepth ); - bool Insert( NameNode* pTN ); - virtual COMPARE Compare( const NameNode * ) const; - virtual COMPARE Compare( const void * ) const; - NameNode* SearchParent( const NameNode * ) const; - // returns the new root - NameNode* Remove( NameNode * ); - void OrderTree(); -}; - -class IdNode : public NameNode -{ - virtual COMPARE Compare( const NameNode * ) const override; - virtual COMPARE Compare( const void * ) const override; -protected: - using NameNode::Search; - -public: - - IdNode* Search( sal_uInt32 nTypName ) const; - virtual sal_uInt32 GetId() const; -}; - -#endif // INCLUDED_RSC_INC_RSCTREE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/parser/erscerr.cxx b/rsc/source/parser/erscerr.cxx deleted file mode 100644 index a6dcb46cf227..000000000000 --- a/rsc/source/parser/erscerr.cxx +++ /dev/null @@ -1,403 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <stdlib.h> -#include <stdio.h> - -#include <tools/rcid.h> -#include <rschash.hxx> -#include <rscerror.h> -#include <rscall.h> -#include <rscdb.hxx> -#include <rscpar.hxx> - -#include "rsclex.hxx" - -ERRTYPE& ERRTYPE::operator = ( const ERRTYPE & rError ) -{ - if( !IsError() ){ - if( rError.IsError() || !IsWarning() ) - nError = rError.nError; - } - return *this; -} - -void RscError::StdOut( const char * pStr, const RscVerbosity _verbosityLevel ) -{ - if ( m_verbosity >= _verbosityLevel ) - { - if( pStr ){ - printf( "%s", pStr ); - fflush( stdout ); - } - } -} - -void RscError::StdErr( const char * pStr ) -{ - if( pStr ) - fprintf( stderr, "%s", pStr ); -} - -void RscError::LstOut( const char * pStr ){ - if( fListing && pStr ) - fprintf( fListing, "%s", pStr ); -} - -void RscError::StdLstOut( const char * pStr ){ - StdOut( pStr ); - LstOut( pStr ); -} - -void RscError::StdLstErr( const char * pStr ){ - StdErr( pStr ); - LstOut( pStr ); -} - -void RscError::WriteError( const ERRTYPE& rError, const char * pMessage ) -{ - switch( rError.GetError() ) - { - case ERR_ERROR: { - StdLstErr( "!! " ); - if( 1 == nErrors ) - StdLstErr(OString::number(nErrors).getStr()); - else - StdLstErr(OString::number(nErrors -1).getStr()); - StdLstErr( " Error" ); - StdLstErr( " found!!" ); - } - break; - - case ERR_UNKNOWN_METHOD: - StdLstErr( "The used type is not allowed." ); - break; - - case ERR_OPENFILE: - StdLstErr( "This file <" ); - StdLstErr( pMessage ); - StdLstErr( "> cannot be opened." ); - break; - - case ERR_RENAMEFILE: - StdLstErr( "rename <" ); - StdLstErr( pMessage ); - StdLstErr( "> s not possible." ); - break; - - case ERR_FILESIZE: - StdLstErr( "Wrong file <" ); - StdLstErr( pMessage ); - StdLstErr( "> length." ); - break; - - case ERR_FILEFORMAT: - StdLstErr( "Wrong file type <" ); - StdLstErr( pMessage ); - StdLstErr( ">." ); - break; - - case ERR_NOCHAR: - StdLstErr( "Character: '\\xxx'; The value xxx is greater than 255."); - break; - - case ERR_NORSCINST: - StdLstErr( "Internal error, instance invalid."); - break; - - - case ERR_NOINPUT: - StdLstErr( "Input file was not specified.\n"); - SAL_FALLTHROUGH; - case ERR_USAGE: - StdLstOut( "Copyright (C) 2000 - 2012 LibreOffice contributors.\n" ); - { - char buf[40]; - - StdLstOut( "DataVersion: " ); - sprintf( buf, "%d.%d\n\n", - RSCVERSION_ID / 100, RSCVERSION_ID % 100 ); - StdLstOut( buf ); - } - - StdLstOut( "Command line: rsc [Switches] <Source File(s)>\n" ); - StdLstOut( "Command line: rsc @<Command File>\n" ); - StdLstOut( "-h shows this help.\n" ); - StdLstOut( "-p No preprocessor.\n" ); - StdLstOut( "-s Syntax analysis, creates .srs file\n"); - StdLstOut( "-l Linker, links files created with rsc -s,\n" ); - StdLstOut( " creates .rc file and .res file.\n" ); - StdLstOut( "-r Prevents .res file.\n" ); - StdLstOut( "-d Symbol definitions for the Preprocessor.\n" ); - StdLstOut( "-i Include directives for the Preprocessor.\n" ); - StdLstOut( "-presponse Use response file for Preprocessor.\n" ); - StdLstOut( "-lg<language> Use a different language.\n" ); - StdLstOut( "-fs=<filename> Name of the .res file.\n" ); - StdLstOut( "-lip=<path> additional search path for system dependent files\n" ); - StdLstOut( "-fp=<filename> Renaming of the .srs file.\n" ); - StdLstOut( "-sub<ENV>=<path> replace <path> by <ENV> in image list files\n" ); - StdLstOut( "-BIGENDIAN Format of number values.\n" ); - StdLstOut( "-LITTLEENDIAN Format of number values.\n" ); - StdLstOut( "-SrsDefault Only write one language to srs file.\n" ); - StdLstOut( "\nwhen creating multiple .res files in one pass, please give these\n" ); - StdLstOut( "options in consecutive blocks:\n" ); - StdLstOut( "-lg<language> -fs<filename> [-lip<path> [-lip<path>] ]\n" ); - StdLstOut( "a new block begins when either -lg or -fs is used again.\n" ); - break; - - case ERR_UNKNOWNSW: - StdLstErr( "Unknown switch <" ); - StdLstErr( pMessage ); - StdLstErr( ">." ); - break; - - case ERR_REFTODEEP: - StdLstErr( "Too many reference levels have been used (see Switch -RefDeep)." ); - break; - - case ERR_CONT_INVALIDPOS: - StdLstErr( "Internal error, Container class: invalid position." ); - break; - - case ERR_CONT_INVALIDTYPE: - StdLstErr( "Invalid type <" ); - StdLstErr( pMessage ); - StdLstErr( ">." ); - break; - - case ERR_ARRAY_INVALIDINDEX: - StdLstErr( "Internal error, Array class: invalid index." ); - break; - - case ERR_RSCINST_NOVARNAME: - StdLstErr( "Internal error, invalid name of variable." ); - break; - - case ERR_YACC: - StdLstErr( pMessage ); - break; - - case ERR_DOUBLEID: - StdLstErr( "Two global resources have the same identifier." ); - break; - - case ERR_FALSETYPE: - StdLstErr( "Wrong type <" ); - StdLstErr( pMessage ); - StdLstErr( ">." ); - break; - - case ERR_NOVARIABLENAME: - StdLstErr( "The variable <" ); - StdLstErr( pMessage ); - StdLstErr( "> must not be used here." ); - break; - - case ERR_RSCRANGE_OUTDEFSET: - StdLstErr( "The used value is not in the expected domain." ); - break; - - case ERR_USHORTRANGE: - StdLstErr( "Value is <" ); - StdLstErr( pMessage ); - StdLstErr( "> the allowed domain is from 0 up to 65535." ); - break; - - case ERR_IDRANGE: - StdLstErr( "Value is <" ); - StdLstErr( pMessage ); - StdLstErr( "> the allowed domain is from 1 up to 32767." ); - break; - - case ERR_NOCOPYOBJ: - StdLstErr( "Default resource <" ); - StdLstErr( pMessage ); - StdLstErr( "> not found." ); - break; - - case ERR_REFNOTALLOWED: - StdLstErr( "The use of a reference is not allowed." ); - break; - - case ERR_COPYNOTALLOWED: - StdLstErr( "The use of a default resource is not allowed." ); - break; - - case ERR_IDEXPECTED: - StdLstErr( "An identifier needs to be specified." ); - break; - - case ERR_DOUBLEDEFINE: - StdLstErr( "The symbol <" ); - StdLstErr( pMessage ); - StdLstErr( "> is defined twice." ); - break; - - case ERR_RSCINST_RESERVEDNAME: - StdLstErr( "The symbol <" ); - StdLstErr( pMessage ); - StdLstErr( "> is a reserved name." ); - break; - - case ERR_ZERODIVISION: - StdLstErr( "Attempt to divide by zero." ); - break; - - case ERR_PRAGMA: - StdLstErr( "Error in a #pragma statement." ); - break; - - case ERR_DECLAREDEFINE: - StdLstErr( "Error in the declaration part of the macro." ); - break; - - case ERR_NOTYPE: - StdLstErr( "type expected." ); - break; - - case ERR_NOIMAGE: - StdLstErr( "The image(s) <" ); - StdLstErr( pMessage ); - StdLstErr( "> could not be found." ); - break; - - case WRN_LOCALID: - StdLstErr( "Sub resources should have an identifier < 256." ); - break; - - case WRN_GLOBALID: - StdLstErr( "Global resources should have an identifier >= 256." ); - break; - - case WRN_SUBINMEMBER: - StdLstErr( "Sub resources are ignored." ); - break; - - case WRN_CONT_NOID: - StdLstErr( "Resources without name are ignored." ); - break; - - case WRN_CONT_DOUBLEID: - StdLstErr( "Two local resources have the same identifier." ); - break; - - case WRN_STR_REFNOTFOUND: - StdLstErr( "String reference <" ); - StdLstErr( pMessage ); - StdLstErr( " > could not be resolved." ); - break; - - case WRN_MGR_REFNOTFOUND: - StdLstErr( "Reference <" ); - StdLstErr( pMessage ); - StdLstErr( " > could not be resolved." ); - break; - - default: - if( pMessage ){ - StdLstErr( "\nMessage: " ); - StdLstErr( pMessage ); - }; - break; - } -} - -void RscError::ErrorFormat( const ERRTYPE& rError, RscTop * pClass, - const RscId & aId ){ - char buf[ 10 ]; - sal_uInt32 i; - - if( pFI ) - { - pFI->SetError( rError ); - StdErr( "\n" ); - StdErr( pFI->GetLine() ); - StdErr( "\n" ); - // Show location of error - for( i = 0; (i +1) < pFI->GetScanPos(); i++ ) - StdLstErr( " " ); - LstOut( " ^" ); // for the linenumber - StdErr( "^" ); - StdLstErr( "\n" ); - } - StdLstErr( "f" ); - sprintf( buf, "%u", (unsigned int)rError.GetError() ); - StdLstErr( buf ); - - if( pFI && pTC ){ - StdLstErr( ": \"" ); - StdLstErr( pTC->aFileTab.Get( pFI->GetFileIndex() )->aFileName.getStr() ); - StdLstErr( "\", line " ); - sprintf( buf, "%u", (unsigned int)pFI->GetLineNo() ); - StdLstErr( buf ); - } - - if( rError.IsError() ) - StdLstErr( ": Error" ); - else - StdLstErr( ": Warning" ); - - if( pClass || aId.IsId() ) - { - StdLstErr( " in the object (" ); - if( pClass ) - { - StdLstErr( "Type: " ); - StdLstErr( pHS->getString( pClass->GetId() ).getStr() ); - if( aId.IsId() ) - StdLstErr( ", " ); - } - if( aId.IsId() ) - StdLstErr( aId.GetName().getStr() ); - StdLstErr( "):\n" ); - } - else - StdLstErr( ": " ); -} - -void RscError::Error( const ERRTYPE& rError, RscTop * pClass, - const RscId & aId, const char * pMessage ) -{ - if( WRN_LOCALID == rError.GetError() ) // ignore warnings - return; - if( rError.IsError() ) - nErrors++; - if( rError.IsError() || rError.IsWarning() ){ - ErrorFormat( rError, pClass, aId ); - WriteError( rError, pMessage ); - StdLstErr( "\n" ); - } -} - -void RscError::FatalError( const ERRTYPE& rError, const RscId &aId, - const char * pMessage ) -{ - if( ERR_USAGE != rError.GetError() ){ - nErrors++; - ErrorFormat( rError, nullptr, aId ); - WriteError( rError, pMessage ); - StdLstErr( "\nTerminating compiler\n" ); - } - else - WriteError( rError, pMessage ); - - exit( 1 ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/parser/rscdb.cxx b/rsc/source/parser/rscdb.cxx deleted file mode 100644 index cf6f73bbaba8..000000000000 --- a/rsc/source/parser/rscdb.cxx +++ /dev/null @@ -1,456 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <i18nlangtag/languagetag.hxx> -#include <rtl/strbuf.hxx> -#include <sal/log.hxx> -#include <sal/macros.h> -#include <tools/rcid.h> - -#include <rsctree.hxx> -#include <rsctop.hxx> -#include <rscmgr.hxx> -#include <rscdb.hxx> -#include <rscrsc.hxx> - - -RscTypCont::RscTypCont( RscError * pErrHdl, - RSCBYTEORDER_TYPE nOrder, - CommandFlags nFlagsP ) - : nSourceCharSet( RTL_TEXTENCODING_UTF8 ) - , nByteOrder( nOrder ) - , nFilePos( 0 ) - , nPMId(RSC_VERSIONCONTROL + RESOURCE_TYPE(1)) // at least one more - , aEnumLong( pHS->getID( "enum_long" ), RSC_NOTYPE ) - , aString( pHS->getID( "Chars" ), RSC_NOTYPE ) - , aLangType() - , aLangString( pHS->getID( "Lang_Chars" ), RSC_NOTYPE, &aString, &aLangType ) - , pEH(pErrHdl) - , nFlags( nFlagsP ) -{ - Init(); -} - -OString RscTypCont::ChangeLanguage(const OString& rNewLang) -{ - OString aRet = aLanguage; - aLanguage = rNewLang; - - ::std::vector< OUString > aFallbacks; - - if (rNewLang.isEmpty()) - aFallbacks.push_back( "" ); // do not resolve to SYSTEM (en-US) - else - aFallbacks = LanguageTag( OStringToOUString( rNewLang, RTL_TEXTENCODING_ASCII_US)).getFallbackStrings( true); - - bool bAppendEnUsFallback = ! (rNewLang.equalsIgnoreAsciiCase( "en-US" ) || - rNewLang.equalsIgnoreAsciiCase( "x-no-translate" ) ); - if (bAppendEnUsFallback) - aFallbacks.push_back( "en-US"); - -#if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, "RscTypCont::ChangeLanguage: " ); -#endif - - aLangFallbacks.clear(); - - for (OUString& rItem : aFallbacks) - { - OString aLang(OUStringToOString(rItem, RTL_TEXTENCODING_ASCII_US)); - sal_uInt32 nID = GetLangId( aLang ); - bool bAdd = (nID == 0); - if ( bAdd ) - { - AddLanguage( aLang.getStr() ); - nID = GetLangId( aLang ); - } -#if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, " '%s' (0x%hx) (%s)", aLang.getStr(), (int)nID, (bAdd ? "added" : "exists") ); -#endif - aLangFallbacks.push_back( nID); - } - -#if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, "\n" ); -#endif - - return aRet; -} - -Atom RscTypCont::AddLanguage( const char* pLang ) -{ - return aLangType.AddLanguage( pLang, aNmTb ); -} - - -void DestroyNode( RscTop * pRscTop, ObjNode * pObjNode ) -{ - if( pObjNode ) - { - DestroyNode( pRscTop, static_cast<ObjNode*>(pObjNode->Left()) ); - DestroyNode( pRscTop, static_cast<ObjNode*>(pObjNode->Right()) ); - - if( pObjNode->GetRscObj() ) - { - pRscTop->Destroy( RSCINST( pRscTop, pObjNode->GetRscObj() ) ); - rtl_freeMemory( pObjNode->GetRscObj() ); - } - delete pObjNode; - } -} - -void DestroySubTrees( RscTop * pRscTop ) -{ - if( pRscTop ) - { - DestroySubTrees( static_cast<RscTop*>(pRscTop->Left()) ); - DestroyNode( pRscTop, pRscTop->GetObjNode() ); - DestroySubTrees( static_cast<RscTop*>(pRscTop->Right()) ); - } -} - -void DestroyTree( RscTop * pRscTop ) -{ - if( pRscTop ) - { - DestroyTree( static_cast<RscTop*>(pRscTop->Left()) ); - DestroyTree( static_cast<RscTop*>(pRscTop->Right()) ); - - delete pRscTop; - } -} - -void Pre_dtorTree( RscTop * pRscTop ) -{ - if( pRscTop ) - { - Pre_dtorTree( static_cast<RscTop*>(pRscTop->Left()) ); - Pre_dtorTree( static_cast<RscTop*>(pRscTop->Right()) ); - - pRscTop->Pre_dtor(); - } -} - -RscTypCont::~RscTypCont() -{ - // delete all subtrees - aVersion.pClass->Destroy( aVersion ); - rtl_freeMemory( aVersion.pData ); - DestroySubTrees( pRoot ); - - // all classes are still valid, destroy each instance - // of base types - for (RscTop* pItem : aBaseLst) - pItem->Pre_dtor(); - - aString.Pre_dtor(); - aVersion.pClass->Pre_dtor(); - // sub-types - Pre_dtorTree( pRoot ); - - // destroy classes - delete aVersion.pClass; - DestroyTree( pRoot ); - - for (RscTop* pItem : aBaseLst) - delete pItem; -} - -class RscEnumerateObj -{ -friend class RscEnumerateRef; -private: - ERRTYPE aError; // contains the first field - RscTypCont* pTypCont; - FILE * fOutput; // output file - RscFileTab::Index lFileKey; // what source file - RscTop * pClass; - - RscEnumerateObj(RscTypCont* pTC, FILE* pOutputFile) - :pTypCont(pTC) - ,fOutput(pOutputFile) - ,lFileKey(0) - ,pClass(nullptr) - { - } - - DECL_LINK( CallBackWriteRc, const NameNode&, void ); - DECL_LINK( CallBackWriteSrc, const NameNode&, void ); - - void WriteRc( RscTop * pCl, ObjNode * pRoot ) - { - pClass = pCl; - if( pRoot ) - pRoot->EnumNodes( LINK( this, RscEnumerateObj, CallBackWriteRc ) ); - } - void WriteSrc( RscTop * pCl, ObjNode * pRoot ){ - pClass = pCl; - if( pRoot ) - pRoot->EnumNodes( LINK( this, RscEnumerateObj, CallBackWriteSrc ) ); - } -public: - void WriteRcFile( RscWriteRc & rMem, FILE * fOutput ); -}; - -IMPL_LINK( RscEnumerateObj, CallBackWriteRc, const NameNode&, rNode, void ) -{ - const ObjNode& rObjNode = static_cast<const ObjNode&>(rNode); - RscWriteRc aMem( pTypCont->GetByteOrder() ); - - aError = pClass->WriteRcHeader( RSCINST( pClass, rObjNode.GetRscObj() ), - aMem, pTypCont, - rObjNode.GetRscId(), 0 ); - if( aError.IsError() || aError.IsWarning() ) - pTypCont->pEH->Error( aError, pClass, rObjNode.GetRscId() ); - - WriteRcFile( aMem, fOutput ); -} - -IMPL_LINK( RscEnumerateObj, CallBackWriteSrc, const NameNode&, rNode, void ) -{ - const ObjNode& rObjNode = static_cast<const ObjNode&>(rNode); - if( rObjNode.GetFileKey() == lFileKey ) - { - pClass->WriteSrcHeader( RSCINST( pClass, rObjNode.GetRscObj() ), - fOutput, pTypCont, 0, - rObjNode.GetRscId(), "" ); - fprintf( fOutput, ";\n" ); - } -} - -void RscEnumerateObj::WriteRcFile( RscWriteRc & rMem, FILE * fOut ) -{ - // structure definition from which the resource is built - /* - struct RSHEADER_TYPE{ - sal_uInt32 nId; // resource identifier - RESOURCE_TYPE nRT; // resource type - sal_uInt32 nGlobOff; // global offset - sal_uInt32 nLocalOff; // local offset - } aHeader; - */ - - sal_uInt32 nId = rMem.GetLong( 0 ); - RESOURCE_TYPE nRT(rMem.GetLong( 4 )); - - // table is filled with nId and nRT - pTypCont->PutTranslatorKey( (sal_uInt64(sal_uInt32(nRT)) << 32) + sal_uInt64(nId) ); - - if( nRT == RSC_VERSIONCONTROL ) - { // always comes last - sal_Int32 nCount = pTypCont->aIdTranslator.size(); - // table size - sal_uInt32 nSize = (nCount * (sizeof(sal_uInt64)+sizeof(sal_Int32))) + sizeof(sal_Int32); - - rMem.Put( nCount ); // save the count - for (auto& rItem : pTypCont->aIdTranslator) - { - // save the key - rMem.Put( rItem.first ); - // save the object id or position - rMem.Put( static_cast<sal_Int32>(rItem.second) ); - } - rMem.Put( nSize ); // save the size next - } - - // reset the file offset - pTypCont->IncFilePos( rMem.Size() ); - - - // position was written previously in the table - bool bSuccess = (1 == fwrite( rMem.GetBuffer(), rMem.Size(), 1, fOut )); - SAL_WARN_IF(!bSuccess, "rsc", "short write"); -}; - -class RscEnumerateRef -{ -private: - RscTop * pRoot; - - DECL_LINK( CallBackWriteRc, const NameNode&, void ); - DECL_LINK( CallBackWriteSrc, const NameNode&, void ); -public: - RscEnumerateObj aEnumObj; - - RscEnumerateRef(RscTypCont* pTC, RscTop* pR, FILE* fOutput) - : pRoot(pR), aEnumObj(pTC, fOutput) - { - } - ERRTYPE const & WriteRc() - { - aEnumObj.aError.Clear(); - pRoot->EnumNodes( LINK( this, RscEnumerateRef, CallBackWriteRc ) ); - return aEnumObj.aError; - } - ERRTYPE const & WriteSrc( RscFileTab::Index lFileKey ) - { - aEnumObj.lFileKey = lFileKey; - - aEnumObj.aError.Clear(); - pRoot->EnumNodes( LINK( this, RscEnumerateRef, CallBackWriteSrc ) ); - return aEnumObj.aError; - } -}; - -IMPL_LINK( RscEnumerateRef, CallBackWriteRc, const NameNode&, rNode, void ) -{ - const RscTop& rRef = static_cast<const RscTop&>(rNode); - aEnumObj.WriteRc( const_cast<RscTop*>(&rRef), rRef.GetObjNode() ); -} - -IMPL_LINK( RscEnumerateRef, CallBackWriteSrc, const NameNode&, rNode, void ) -{ - const RscTop& rRef = static_cast<const RscTop&>(rNode); - aEnumObj.WriteSrc( const_cast<RscTop*>(&rRef), rRef.GetObjNode() ); -} - -ERRTYPE RscTypCont::WriteRc( WriteRcContext& rContext ) -{ - ERRTYPE aError; - RscEnumerateRef aEnumRef( this, pRoot, rContext.fOutput ); - - aIdTranslator.clear(); - nFilePos = 0; - nPMId = RSCVERSION_ID +1; // at least one more - - aError = aEnumRef.WriteRc(); - - // version control - RscWriteRc aMem( nByteOrder ); - aVersion.pClass->WriteRcHeader( aVersion, aMem, this, RscId( RSCVERSION_ID ), 0 ); - aEnumRef.aEnumObj.WriteRcFile( aMem, rContext.fOutput ); - - return aError; -} - -void RscTypCont::WriteSrc( FILE * fOutput, RscFileTab::Index nFileKey ) -{ - RscEnumerateRef aEnumRef( this, pRoot, fOutput ); - - unsigned char aUTF8BOM[3] = { 0xef, 0xbb, 0xbf }; - size_t nItems = SAL_N_ELEMENTS(aUTF8BOM); - bool bSuccess = (nItems == fwrite(aUTF8BOM, 1, nItems, fOutput)); - SAL_WARN_IF(!bSuccess, "rsc", "short write"); - RscId::SetNames( false ); - if( nFileKey == RscFileTab::IndexNotFound ) - { - RscFileTab::Index aIndex = aFileTab.FirstIndex(); - while( aIndex != RscFileTab::IndexNotFound ) - { - aEnumRef.WriteSrc( aIndex ); - aIndex = aFileTab.NextIndex( aIndex ); - }; - } - else - aEnumRef.WriteSrc( nFileKey ); - RscId::SetNames(); -} - -class RscDel -{ - RscFileTab::Index lFileKey; - DECL_LINK( Delete, const NameNode&, void ); -public: - RscDel( RscTop * pRoot, RscFileTab::Index lKey ); -}; - - -inline RscDel::RscDel( RscTop * pRoot, RscFileTab::Index lKey ) - : lFileKey(lKey) -{ - pRoot->EnumNodes( LINK( this, RscDel, Delete ) ); -} - -IMPL_LINK( RscDel, Delete, const NameNode&, r, void ) -{ - RscTop* pNode = const_cast<RscTop*>(static_cast<const RscTop*>(&r)); - if( pNode->GetObjNode() ) - pNode->pObjBiTree = pNode->GetObjNode()->DelObjNode( pNode, lFileKey ); -} - -void RscTypCont::Delete( RscFileTab::Index lFileKey ) -{ - // delete resource instance - RscDel aDel( pRoot, lFileKey ); - // delete defines - aFileTab.DeleteFileContext( lFileKey ); -} - -bool IsInstConsistent( ObjNode * pObjNode, RscTop * pRscTop ) -{ - bool bRet = true; - - if( pObjNode ) - { - RSCINST aTmpI; - - if( ! IsInstConsistent( static_cast<ObjNode*>(pObjNode->Left()), pRscTop ) ) - bRet = false; - - aTmpI.pClass = pRscTop; - aTmpI.pData = pObjNode->GetRscObj(); - if( ! aTmpI.pClass->IsConsistent( aTmpI ) ) - bRet = false; - - if( ! IsInstConsistent( static_cast<ObjNode*>(pObjNode->Right()), pRscTop ) ) - bRet = false; - } - - return bRet; -} - -bool MakeConsistent( RscTop * pRscTop ) -{ - bool bRet = true; - - if( pRscTop ) - { - if( ! ::MakeConsistent( static_cast<RscTop*>(pRscTop->Left()) ) ) - bRet = false; - - if( pRscTop->GetObjNode() ) - { - if( ! pRscTop->GetObjNode()->IsConsistent() ) - { - pRscTop->GetObjNode()->OrderTree(); - if( ! pRscTop->GetObjNode()->IsConsistent() ) - bRet = false; - } - if( ! IsInstConsistent( pRscTop->GetObjNode(), pRscTop ) ) - bRet = false; - } - - if( ! ::MakeConsistent( static_cast<RscTop*>(pRscTop->Right()) ) ) - bRet = false; - } - - return bRet; -} - -void RscTypCont::PutTranslatorKey( sal_uInt64 nKey ) -{ - aIdTranslator[ nKey ] = nFilePos; - nPMId++; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/parser/rscibas.cxx b/rsc/source/parser/rscibas.cxx deleted file mode 100644 index 556563b76512..000000000000 --- a/rsc/source/parser/rscibas.cxx +++ /dev/null @@ -1,216 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <comphelper/string.hxx> -#include <i18nlangtag/mslangid.hxx> -#include <i18nlangtag/languagetag.hxx> -#include <tools/color.hxx> -#include <tools/fldunit.hxx> -#include <tools/gen.hxx> -#include <tools/mapunit.hxx> -#include <tools/wintypes.hxx> -#include <rsc/rsc-vcl-shared-types.hxx> - -#include <com/sun/star/awt/Key.hpp> - -#include <rscconst.hxx> -#include <rscarray.hxx> -#include <rscclass.hxx> -#include <rsccont.hxx> -#include <rscdb.hxx> -#include <rsclex.hxx> -#include <rscyacc.hxx> - -#include <unordered_map> - -void RscTypCont::SETCONST( RscEnum * pClass, const char * szString, sal_uInt32 nVal ) -{ -#if OSL_DEBUG_LEVEL > 2 - fprintf( stderr, "setconst : %s\n", szString ); -#endif - pClass->SetConstant( aNmTb.Put( szString, - CONSTNAME, nVal ), nVal ); -} - -typedef std::unordered_map< OString, sal_uInt32, OStringHash > langmap; -static langmap ULong_Iso_map; - -sal_uInt32 GetLangId(const OString &rLang) -{ - langmap::iterator pIter = ULong_Iso_map.find( rLang ); - if ( pIter != ULong_Iso_map.end()) - return pIter->second; - return 0; -} - -void RscLangEnum::Init( RscNameTable& rNames ) -{ - SetConstant( rNames.Put( "SYSTEM", CONSTNAME, (sal_uInt16)LANGUAGE_SYSTEM ), (sal_uInt16)LANGUAGE_SYSTEM ); - SetConstant( rNames.Put( "DONTKNOW", CONSTNAME, (sal_uInt16)LANGUAGE_DONTKNOW ), (sal_uInt16)LANGUAGE_DONTKNOW ); - - sal_Int32 nIndex = 0; - mnLangId = 0x400; // stay away from selfdefined... - - const ::std::vector< MsLangId::LanguagetagMapping > aList( MsLangId::getDefinedLanguagetags()); - for (::std::vector< MsLangId::LanguagetagMapping >::const_iterator iTag( aList.begin()); iTag != aList.end(); ++iTag) - { -#if OSL_DEBUG_LEVEL > 2 - fprintf( stderr, "ISO Language in : %d, 0x%04x, %s\n", - (int)nIndex, - (unsigned)(*iTag).mnLang, - OUStringToOString( (*iTag).maBcp47, RTL_TEXTENCODING_ASCII_US).getStr()); - fprintf( stderr, "ISO Language out:"); -#endif - LanguageTag aLanguageTag( (*iTag).maBcp47); - ::std::vector< OUString > aFallbacks( aLanguageTag.getFallbackStrings( true)); - for (::std::vector< OUString >::const_iterator it( aFallbacks.begin()); it != aFallbacks.end(); ++it) - { - OString aLang( OUStringToOString( *it, RTL_TEXTENCODING_ASCII_US)); - SetConstant( rNames.Put( aLang.getStr(), CONSTNAME, mnLangId ), mnLangId ); - bool bAdd = (GetLangId( aLang ) == 0); - if ( bAdd ) - ULong_Iso_map[ aLang ] = mnLangId; -#if OSL_DEBUG_LEVEL > 2 - fprintf( stderr, " %s 0x%lx (%s)", aLang.getStr(), mnLangId, (bAdd ? "added" : "exists") ); -#endif - mnLangId++; - } -#if OSL_DEBUG_LEVEL > 2 - fprintf( stderr, "\n"); -#endif - nIndex++; - } - // hack - survive "x-no-translate" - /* XXX: that ^^^ was the original comment, but we're adding "x-comment" - * here? Which is good anyway. */ - SetConstant( rNames.Put( "x-comment", CONSTNAME, mnLangId ), mnLangId ); - mnLangId++; - - OString aEnvIsoTokens = getenv( "RSC_LANG_ISO" ); - if ( !aEnvIsoTokens.isEmpty() ) - { - OString aIsoToken; - sal_uInt16 nTokenCounter = 0; - bool bOneMore = true; - while ( bOneMore ) - { - aIsoToken = aEnvIsoTokens.getToken(nTokenCounter, ' '); - if ( !aIsoToken.isEmpty() ) - { - SetConstant( rNames.Put( aIsoToken.getStr(), CONSTNAME, mnLangId ), mnLangId ); - bool bAdd = (GetLangId( aIsoToken ) == 0); - if ( bAdd ) - ULong_Iso_map[ aIsoToken ] = mnLangId; -#if OSL_DEBUG_LEVEL > 2 - fprintf( stderr, "Env ISO Language out: %s 0x%lx (%s)\n", - aIsoToken.getStr(), mnLangId, (bAdd ? "added" : "exists") ); -#endif - mnLangId++; - } - else - bOneMore = false; - - nTokenCounter++; - } - } -} - -Atom RscLangEnum::AddLanguage( const char* pLang, RscNameTable& rNames ) -{ - Atom nResult = 0; - KEY_STRUCT aStruct; - if( ! rNames.Get( nResult = pHS->getID( pLang ), &aStruct ) ) - { - SetConstant( nResult = rNames.Put( pLang, CONSTNAME, mnLangId ), mnLangId ); - // insert new lang to ULong_Iso_map - OString aLang( pLang ); - bool bAdd = (GetLangId( aLang ) == 0); - if ( bAdd ) - ULong_Iso_map[ aLang ] = mnLangId; - // increase id counter - mnLangId++; - } - return nResult; -} - -RscEnum * RscTypCont::InitFieldUnitsType() -{ - RscEnum * pFieldUnits; - pFieldUnits = new RscEnum( pHS->getID( "EnumFieldUnit" ), RSC_NOTYPE ); - - SETCONST( pFieldUnits, "FUNIT_NONE", FUNIT_NONE ); - SETCONST( pFieldUnits, "FUNIT_MM", FUNIT_MM ); - SETCONST( pFieldUnits, "FUNIT_CM", FUNIT_CM ); - SETCONST( pFieldUnits, "FUNIT_M", FUNIT_M ); - SETCONST( pFieldUnits, "FUNIT_KM", FUNIT_KM ); - SETCONST( pFieldUnits, "FUNIT_TWIP", FUNIT_TWIP ); - SETCONST( pFieldUnits, "FUNIT_POINT", FUNIT_POINT ); - SETCONST( pFieldUnits, "FUNIT_PICA", FUNIT_PICA ); - SETCONST( pFieldUnits, "FUNIT_INCH", FUNIT_INCH ); - SETCONST( pFieldUnits, "FUNIT_FOOT", FUNIT_FOOT ); - SETCONST( pFieldUnits, "FUNIT_MILE", FUNIT_MILE ); - SETCONST( pFieldUnits, "FUNIT_CUSTOM", FUNIT_CUSTOM ); - SETCONST( pFieldUnits, "FUNIT_CHAR", FUNIT_CHAR ); - SETCONST( pFieldUnits, "FUNIT_LINE", FUNIT_LINE ); - SETCONST( pFieldUnits, "FUNIT_PERCENT", FUNIT_PERCENT ); - SETCONST( pFieldUnits, "FUNIT_DEGREE", FUNIT_DEGREE); - SETCONST( pFieldUnits, "FUNIT_SECOND", FUNIT_SECOND); - SETCONST( pFieldUnits, "FUNIT_MILLISECOND", FUNIT_MILLISECOND); - SETCONST( pFieldUnits, "FUNIT_PIXEL", FUNIT_PIXEL ); - - return pFieldUnits; -} - -RscTupel * RscTypCont::InitStringLongTupel() -{ - RscTop * pTupel; - Atom nId; - - // insert client variables - pTupel = new RscTupel( pHS->getID( "CharsLongTupel" ), RSC_NOTYPE ); - nId = aNmTb.Put( "ItemText", VARNAME ); - pTupel->SetVariable( nId, &aString ); - nId = aNmTb.Put( "ItemId", VARNAME ); - pTupel->SetVariable( nId, &aEnumLong ); - - return static_cast<RscTupel *>(pTupel); -} - -RscCont * RscTypCont::InitStringLongTupelList( RscTupel * pStringLong ) -{ - RscCont * pCont; - - pCont = new RscCont( pHS->getID( "CharsLongTupel[]" ), RSC_NOTYPE ); - pCont->SetTypeClass( pStringLong ); - - return pCont; -} - -RscArray * RscTypCont::InitLangStringLongTupelList( RscCont * pStrLongTupelLst ) -{ - return new RscArray( pHS->getID( "Lang_CharsLongTupelList" ), - RSC_NOTYPE, pStrLongTupelLst, &aLangType ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/parser/rscicpx.cxx b/rsc/source/parser/rscicpx.cxx deleted file mode 100644 index 46ab34a0fd97..000000000000 --- a/rsc/source/parser/rscicpx.cxx +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> - -#include <tools/rcid.h> -#include <tools/wintypes.hxx> -#include <rsc/rsc-vcl-shared-types.hxx> - -#include <rscmgr.hxx> -#include <rscclass.hxx> -#include <rsccont.hxx> -#include <rscdb.hxx> -#include <rsc/rscsfx.hxx> -#include <rsclex.hxx> -#include <rscyacc.hxx> - -RscTop * RscTypCont::InitClassMgr() -{ - RscTop * pClassMgr; - RscBaseCont * pClass; - Atom nId; - - aBaseLst.push_back( pClass = new RscBaseCont( InvalidAtom, RSC_NOTYPE, false ) ); - - nId = pHS->getID( "Resource" ); - pClassMgr = new RscMgr( nId, RSC_RESOURCE, pClass ); - aNmTb.Put( nId, CLASSNAME, pClassMgr ); - pClassMgr->SetCallPar( *pStdPar1, *pStdPar2, *pStdParType ); - - // initialize variables - nId = aNmTb.Put( "Comment", VARNAME ); - pClassMgr->SetVariable( nId, &aString, nullptr, RSCVAR::NoRc ); - - pClass->SetTypeClass( pClassMgr ); - - return pClassMgr; -} - -RscTop * RscTypCont::InitClassString( RscTop * pSuper ) -{ - Atom nId; - RscTop * pClassString; - - nId = pHS->getID( "String" ); - pClassString = new RscClass( nId, RSC_STRING, pSuper ); - aNmTb.Put( nId, CLASSNAME, pClassString ); - pClassString->SetCallPar( *pStdPar1, *pStdPar2, *pStdParType ); - - // initialize variables - nId = aNmTb.Put( "Text", VARNAME ); - pClassString->SetVariable( nId, &aLangString ); - return pClassString; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/parser/rscinit.cxx b/rsc/source/parser/rscinit.cxx deleted file mode 100644 index 282b9cad33bf..000000000000 --- a/rsc/source/parser/rscinit.cxx +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> - -#include <tools/rcid.h> -#include <tools/wintypes.hxx> - -#include <rsctree.hxx> -#include <rsctop.hxx> -#include <rscrange.hxx> -#include <rscconst.hxx> -#include <rscstr.hxx> -#include <rsccont.hxx> -#include <rscmgr.hxx> -#include <rscclass.hxx> -#include <rsckey.hxx> -#include <rscdb.hxx> -#include <rsclex.hxx> -#include <rscyacc.hxx> - -void RscTypCont::Init() -{ - RscTupel * pStringLongTupel; - RscCont * pStringLongTupelList; - RscArray * pLangStringLongTupelList; - - RscTop * pClassMgr; - RscTop * pClassString; - RscTop * pClassStringArray; - - Atom nId; - - aNmTb.SetSort( false ); -{ - aNmTb.Put( "LINE", LINE, (sal_IntPtr)0 ); - aNmTb.Put( "NOT", NOT, (sal_IntPtr)0 ); - aNmTb.Put( "DEFINE", DEFINE, (sal_IntPtr)0 ); - aNmTb.Put( "INCLUDE", INCLUDE, (sal_IntPtr)0 ); - aNmTb.Put( "DEFAULT", DEFAULT, (sal_IntPtr)0 ); - aNmTb.Put( "class", CLASS, (sal_IntPtr)0 ); - aNmTb.Put( "extendable", EXTENDABLE, (sal_IntPtr)0 ); - aNmTb.Put( "writeifset", WRITEIFSET, (sal_IntPtr)0 ); - -/* values for integer types */ - aNmTb.Put( "TRUE", BOOLEAN, (sal_IntPtr)true ); - aNmTb.Put( "FALSE", BOOLEAN, (sal_IntPtr)false ); -} -{ - aEnumLong.SetRange( SAL_MIN_INT32, SAL_MAX_INT32 ); -} -{ - aLangType.Init( aNmTb ); - aBaseLst.push_back( InitFieldUnitsType() ); - - aBaseLst.push_back( pStringLongTupel = InitStringLongTupel() ); - aBaseLst.push_back( pStringLongTupelList = InitStringLongTupelList( pStringLongTupel ) ); - aBaseLst.push_back( pLangStringLongTupelList = InitLangStringLongTupelList( pStringLongTupelList ) ); -} -{ - pRoot = pClassMgr = InitClassMgr(); - - aVersion.pClass = new RscClass( pHS->getID( "VersionControl" ), - RSC_VERSIONCONTROL, pClassMgr ); - aVersion = aVersion.pClass->Create( nullptr, RSCINST() ); - - pClassString = InitClassString( pClassMgr ); - pRoot->Insert( pClassString ); - - // set String as reference class of the base strings - aString.SetRefClass( pClassString ); - - // initialize class - nId = pHS->getID( "StringArray" ); - pClassStringArray = new RscClass( nId, RSC_STRINGARRAY, pClassMgr ); - pClassStringArray->SetCallPar( *pStdPar1, *pStdPar2, *pStdParType ); - aNmTb.Put( nId, CLASSNAME, pClassStringArray ); - pRoot->Insert( pClassStringArray ); - - // initialize variables - nId = aNmTb.Put( "ItemList", VARNAME ); - pClassStringArray->SetVariable( nId, pLangStringLongTupelList ); -} - - aNmTb.SetSort(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/parser/rsckey.cxx b/rsc/source/parser/rsckey.cxx deleted file mode 100644 index 843470f793b8..000000000000 --- a/rsc/source/parser/rsckey.cxx +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <rscall.h> -#include <rsctools.hxx> -#include <rschash.hxx> -#include <rsckey.hxx> - -extern "C" { - int SAL_CALL KeyCompare( const void * pFirst, const void * pSecond ); -} - -int SAL_CALL KeyCompare( const void * pFirst, const void * pSecond ) -{ - if( static_cast<KEY_STRUCT const *>(pFirst)->nName > static_cast<KEY_STRUCT const *>(pSecond)->nName ) - return 1; - else if( static_cast<KEY_STRUCT const *>(pFirst)->nName < static_cast<KEY_STRUCT const *>(pSecond)->nName ) - return -1; - else - return 0; -} - -RscNameTable::RscNameTable() -{ - bSort = true; - nEntries = 0; - pTable = nullptr; -}; - -RscNameTable::~RscNameTable() -{ - if( pTable ) - rtl_freeMemory( pTable ); -}; - - -void RscNameTable::SetSort( bool bSorted ) -{ - bSort = bSorted; - if( bSort && pTable) - { - // sort keyword field - qsort( static_cast<void *>(pTable), nEntries, - sizeof( KEY_STRUCT ), KeyCompare ); - } -}; - -Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, sal_IntPtr nValue ) -{ - if( pTable ) - pTable = static_cast<KEY_STRUCT *>( - rtl_reallocateMemory( static_cast<void *>(pTable), - ((nEntries +1) * sizeof( KEY_STRUCT )) )); - else - pTable = static_cast<KEY_STRUCT *>( - rtl_allocateMemory( (nEntries + 1) * sizeof( KEY_STRUCT ) ) ); - - pTable[ nEntries ].nName = nName; - pTable[ nEntries ].nTyp = nTyp; - pTable[ nEntries ].yylval = nValue; - nEntries++; - if( bSort ) - SetSort(); - - return nName; -}; - -Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp, sal_IntPtr nValue ) -{ - return Put( pHS->getID( pName ), nTyp, nValue ); -}; - -Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp ) -{ - Atom nId; - - nId = pHS->getID( pName ); - return Put( nId, nTyp, (sal_IntPtr)nId ); -}; - -void RscNameTable::Put( Atom nName, sal_uInt32 nTyp, RscTop * pClass ) -{ - Put( nName, nTyp, reinterpret_cast<sal_IntPtr>(pClass) ); -}; - -bool RscNameTable::Get( Atom nName, KEY_STRUCT * pEle ) -{ - KEY_STRUCT * pKey = nullptr; - KEY_STRUCT aSearchName; - sal_uInt32 i; - - if( bSort ) - { - // search for the keyword - aSearchName.nName = nName; - pKey = static_cast<KEY_STRUCT *>(bsearch( - &aSearchName, pTable, - nEntries, sizeof( KEY_STRUCT ), KeyCompare )); - } - else - { - i = 0; - while( i < nEntries && !pKey ) - { - if( pTable[ i ].nName == nName ) - pKey = &pTable[ i ]; - i++; - } - } - - if( pKey ) - { - *pEle = *pKey; - return true; - } - return false; -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/parser/rsclex.cxx b/rsc/source/parser/rsclex.cxx deleted file mode 100644 index c85ef55c96cc..000000000000 --- a/rsc/source/parser/rsclex.cxx +++ /dev/null @@ -1,432 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include <limits.h> - -#include <rscerror.h> -#include <rschash.hxx> -#include <rscdb.hxx> -#include <rsctop.hxx> -#include <rsckey.hxx> -#include <rscpar.hxx> -#include <rscdef.hxx> - -#include <rsclex.hxx> -#include <rscyacc.hxx> - -#include <rtl/character.hxx> -#include <rtl/textcvt.h> -#include <rtl/textenc.h> - - -const char* StringContainer::putString( const char* pString ) -{ - OString aString( pString ); - std::pair< - std::unordered_set< OString, OStringHash >::iterator, - bool > aInsert = - m_aStrings.insert( aString ); - - return aInsert.first->getStr(); -} - -static char c; -static bool bLastInclude;// true, if last symbol was INCLUDE -RscFileInst* pFI; -RscTypCont* pTC; -RscExpression * pExp; -struct KeyVal -{ - int nKeyWord; - YYSTYPE aYYSType; -}; -static KeyVal aKeyVal[ 1 ]; -static bool bTargetDefined; - -StringContainer* pStringContainer = nullptr; - -static RscDefine RSC_GLOBAL_DEFINE(RscFileTab::Index(0), OString("__RSC"), 1); - -sal_uInt32 GetNumber() -{ - sal_uInt32 l = 0; - sal_uInt32 nLog = 10; - - if( '0' == c ) - { - c = pFI->GetFastChar(); - if( 'x' == c ) - { - nLog = 16; - c = pFI->GetFastChar(); - } - } - - if( nLog == 16 ) - { - while( rtl::isAsciiHexDigit( static_cast<unsigned char>(c) ) ) - { - if( rtl::isAsciiDigit( static_cast<unsigned char>(c) ) ) - l = l * nLog + (c - '0'); - else - l = l * nLog + (rtl::toAsciiUpperCase( static_cast<sal_uInt32>(c) ) - 'A' + 10 ); - - c = pFI->GetFastChar(); - } - } - else - { - while( rtl::isAsciiDigit( static_cast<unsigned char>(c) ) || 'x' == c ) - { - l = l * nLog + (c - '0'); - c = pFI->GetFastChar(); - } - } - - while( c=='U' || c=='u' || c=='l' || c=='L' ) // because of unsigned longs - c = pFI->GetFastChar(); - - if( l > 0x7fffffff ) // drop the most significant bit if needed; - l &= 0x7fffffff; - - return l; -} - -int MakeToken( YYSTYPE * pTokenVal ) -{ - int c1; - - while( true ) // ignore comments and space characters - { - while( rtl::isAsciiWhiteSpace( static_cast<unsigned char>(c) ) ) - c = pFI->GetFastChar(); - - if( '/' == c ) - { - c1 = c; - c = pFI->GetFastChar(); - if( '/' == c ) - { - while( '\n' != c && !pFI->IsEof() ) - c = pFI->GetFastChar(); - - c = pFI->GetFastChar(); - } - else if( '*' == c ) - { - c = pFI->GetFastChar(); - do - { - while( '*' != c && !pFI->IsEof() ) - c = pFI->GetFastChar(); - - c = pFI->GetFastChar(); - } - while( '/' != c && !pFI->IsEof() ); - c = pFI->GetFastChar(); - } - else - return c1; - } - else - break; - } - - // FIXME: wtf is this supposed to do? - if( (c != 0) == pFI->IsEof() ) - { - return 0; - } - - if( bLastInclude ) - { - bLastInclude = false; // reset - if( '<' == c ) - { - OStringBuffer aBuf( 256 ); - c = pFI->GetFastChar(); - while( '>' != c && !pFI->IsEof() ) - { - aBuf.append( c ); - c = pFI->GetFastChar(); - } - c = pFI->GetFastChar(); - pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() )); - return INCLUDE_STRING; - } - } - - if( c == '"' ) - { - OStringBuffer aBuf( 256 ); - bool bDone = false; - while( !bDone && !pFI->IsEof() && c ) - { - c = pFI->GetFastChar(); - if( c == '"' ) - { - do - { - c = pFI->GetFastChar(); - } - while( c == ' ' || c == '\t' ); - - if( c == '"' ) - { - // this is a continued string - // note: multiline string continuations are handled by the parser - // see rscyacc.y - } - else - bDone = true; - } - else if( c == '\\' ) - { - aBuf.append( '\\' ); - c = pFI->GetFastChar(); - if( c ) - aBuf.append( c ); - } - else - aBuf.append( c ); - } - pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() )); - return STRING; - } - if (rtl::isAsciiDigit (static_cast<unsigned char>(c))) - { - pTokenVal->value = GetNumber(); - return NUMBER; - } - - if( rtl::isAsciiAlpha (static_cast<unsigned char>(c)) || (c == '_') ) - { - Atom nHashId; - OStringBuffer aBuf( 256 ); - - while( rtl::isAsciiAlphanumeric (static_cast<unsigned char>(c)) - || (c == '_') || (c == '-') || (c == ':')) - { - aBuf.append( c ); - c = pFI->GetFastChar(); - } - - nHashId = pHS->getID( aBuf.getStr(), true ); - if( InvalidAtom != nHashId ) - { - KEY_STRUCT aKey; - - // search for keyword - if( pTC->aNmTb.Get( nHashId, &aKey ) ) - { - - // keyword found - switch( aKey.nTyp ) - { - case CLASSNAME: - pTokenVal->pClass = reinterpret_cast<RscTop *>(aKey.yylval); - break; - case VARNAME: - pTokenVal->varid = aKey.nName; - break; - case CONSTNAME: - pTokenVal->constname.hashid = aKey.nName; - pTokenVal->constname.nValue = aKey.yylval; - break; - case BOOLEAN: - pTokenVal->svbool = (bool)aKey.yylval; - break; - case INCLUDE: - bLastInclude = true; - SAL_FALLTHROUGH; - default: - pTokenVal->value = aKey.yylval; - } - - return aKey.nTyp; - } - else - { - pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() )); - return SYMBOL; - } - } - else - { - // Symbol - RscDefine * pDef; - - // this #define symbol is used to indicate to various code that it is being processed with the RSC compiler - if (strcmp(aBuf.getStr(), "__RSC") == 0) - pDef = &RSC_GLOBAL_DEFINE; - else - pDef = pTC->aFileTab.FindDef( aBuf.getStr() ); - if( pDef ) - { - pTokenVal->defineele = pDef; - - return RSCDEFINE; - } - - pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() )); - return SYMBOL; - } - } - - if( c=='<' ) - { - c = pFI->GetFastChar(); - if( c=='<' ) - { - c = pFI->GetFastChar(); - return LEFTSHIFT; - } - else - return '<'; - } - - if( c=='>' ) - { - c = pFI->GetFastChar(); - if( c=='>' ) - { - c = pFI->GetFastChar(); - return RIGHTSHIFT; - } - else - return '>'; - } - - c1 = c; - c = pFI->GetFastChar(); - return c1; -} - -int yylex() -{ - if( bTargetDefined ) - bTargetDefined = false; - else - aKeyVal[ 0 ].nKeyWord = MakeToken( &aKeyVal[ 0 ].aYYSType ); - - yylval = aKeyVal[ 0 ].aYYSType; - return aKeyVal[ 0 ].nKeyWord; -} - -#if defined __sun -extern "C" void yyerror( const char* pMessage ) -#else -void yyerror( char* pMessage ) -#endif -{ - pTC->pEH->Error( ERR_YACC, nullptr, RscId(), pMessage ); -} - -void InitParser( RscFileInst * pFileInst ) -{ - pTC = pFileInst->pTypCont; // set file container - pFI = pFileInst; - pStringContainer = new StringContainer(); - pExp = nullptr; // for macro parser - bTargetDefined = false; - - // initialize first character - bLastInclude = false; - c = pFI->GetFastChar(); -} - -void EndParser() -{ - // empty stack - while( ! S.IsEmpty() ) - S.Pop(); - - // free string container - delete pStringContainer; - pStringContainer = nullptr; - - delete pExp; - pTC = nullptr; - pFI = nullptr; - pExp = nullptr; - -} - -void IncludeParser( RscFileInst * pFileInst ) -{ - int nToken; // token value - YYSTYPE aYYSType; // token data - RscFile * pFName; // file structure - RscFileTab::Index lKey; // file key - RscTypCont * pTypCon = pFileInst->pTypCont; - - pFName = pTypCon->aFileTab.Get( pFileInst->GetFileIndex() ); - InitParser( pFileInst ); - - nToken = MakeToken( &aYYSType ); - while( 0 != nToken && CLASSNAME != nToken ) - { - if( '#' == nToken ) - { - if( INCLUDE == (nToken = MakeToken( &aYYSType )) ) - { - if( STRING == (nToken = MakeToken( &aYYSType )) ) - { - lKey = pTypCon->aFileTab.NewIncFile( aYYSType.string, - aYYSType.string ); - pFName->InsertDependFile( lKey ); - } - else if( INCLUDE_STRING == nToken ) - { - lKey = pTypCon->aFileTab.NewIncFile( aYYSType.string, - OString() ); - pFName->InsertDependFile( lKey ); - } - } - } - nToken = MakeToken( &aYYSType ); - } - - EndParser(); -} - -ERRTYPE parser( RscFileInst * pFileInst ) -{ - ERRTYPE aError; - - InitParser( pFileInst ); - - aError = yyparse(); - - EndParser(); - - // yyparser returns 0 on success - if( 0 == aError.GetError() ) - aError.Clear(); - if( pFileInst->pTypCont->pEH->nErrors ) - aError = ERR_ERROR; - pFileInst->SetError( aError ); - return aError; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/parser/rscpar.cxx b/rsc/source/parser/rscpar.cxx deleted file mode 100644 index de4780aee143..000000000000 --- a/rsc/source/parser/rscpar.cxx +++ /dev/null @@ -1,160 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <string.h> -#include <rscpar.hxx> -#include <rscdb.hxx> - -void RscFileInst::Init() -{ - nLineNo = 0; - nLineBufLen = 256; - pLine = static_cast<char *>(rtl_allocateMemory( nLineBufLen )); - *pLine = '\0'; - nScanPos = 0; - cLastChar = '\0'; - bEof = false; -} - -RscFileInst::RscFileInst( RscTypCont * pTC, RscFileTab::Index lIndexSrc, - RscFileTab::Index lFIndex, FILE * fFile ) -{ - pTypCont = pTC; - Init(); - - lFileIndex = lFIndex; - lSrcIndex = lIndexSrc; - fInputFile = fFile; - - // state: pointer at the end of the input buffer - nInputPos = nInputEndPos = READBUFFER_MAX; - pInput = static_cast<char *>(rtl_allocateMemory( nInputBufLen )); -} - -RscFileInst::~RscFileInst() -{ - if( pInput ) - rtl_freeMemory( pInput ); - if( pLine ) - rtl_freeMemory( pLine ); -} - -char RscFileInst::GetChar() -{ - if( pLine[ nScanPos ] ) - return pLine[ nScanPos++ ]; - else if( nInputPos >= nInputEndPos && nInputEndPos != nInputBufLen ) - { - // end of file - bEof = true; - return 0; - } - else - { - GetNewLine(); - return '\n'; - } -} - -void RscFileInst::GetNewLine() -{ - nLineNo++; - nScanPos = 0; - - // run until end of file - sal_uInt32 nLen = 0; - while( (nInputPos < nInputEndPos) || (nInputEndPos == nInputBufLen) ) - { - if( (nInputPos >= nInputEndPos) && fInputFile ) - { - nInputEndPos = fread( pInput, 1, nInputBufLen, fInputFile ); - nInputPos = 0; - } - - while( nInputPos < nInputEndPos ) - { - // always read one line - if( nLen >= nLineBufLen ) - { - nLineBufLen += 256; - // one more for '\0' - pLine = static_cast<char*>(rtl_reallocateMemory( pLine, nLineBufLen +1 )); - } - - // cr lf, lf cr, lf or cr become '\0' - if( pInput[ nInputPos ] == '\n' ) - { - nInputPos++; - if( cLastChar != '\r' ) - { - cLastChar = '\n'; - pLine[ nLen++ ] = '\0'; - goto END; - } - } - else if( pInput[ nInputPos ] == '\r' ) - { - nInputPos++; - if( cLastChar != '\n' ) - { - cLastChar = '\r'; - pLine[ nLen++ ] = '\0'; - goto END; - } - } - else - { - pLine[ nLen++ ] = pInput[ nInputPos++ ]; - if( nLen > 2 ) - { - if( (unsigned char)pLine[nLen-3] == 0xef && - (unsigned char)pLine[nLen-2] == 0xbb && - (unsigned char)pLine[nLen-1] == 0xbf ) - { - nLen -= 3; - } - } - } - } - } - - // stop on reaching EOF - pLine[ nLen ] = '\0'; - -END: - if( pTypCont->pEH->GetListFile() ) - { - char buf[ 10 ]; - - sprintf( buf, "%5d ", (int)GetLineNo() ); - pTypCont->pEH->LstOut( buf ); - pTypCont->pEH->LstOut( GetLine() ); - pTypCont->pEH->LstOut( "\n" ); - } -} - -void RscFileInst::SetError( ERRTYPE aError ) -{ - if( aError.IsOk() ) - { - aFirstError = aError; - } -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/parser/rscyacc.y b/rsc/source/parser/rscyacc.y deleted file mode 100644 index 45efad4891d7..000000000000 --- a/rsc/source/parser/rscyacc.y +++ /dev/null @@ -1,1153 +0,0 @@ -%{ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include "sal/config.h" - -#include <limits.h> -#include <stdio.h> -#include <string.h> - -#include <rtl/strbuf.hxx> -#include <rscerror.h> -#include <rsctools.hxx> -#include <rscclass.hxx> -#include <rsccont.hxx> -#include <rsctree.hxx> -#include <rscdb.hxx> -#include <rscdef.hxx> -#include <rscpar.hxx> - -#include <rsclex.hxx> - -ObjectStack S; - -RSCINST GetVarInst( const RSCINST & rInst, const char * pVarName ) -{ - RSCINST aInst; - - aInst = rInst.pClass->GetVariable( rInst, pHS->getID( pVarName ), - RSCINST() ); - - if( !aInst.pData ) - pTC->pEH->Error( ERR_NOVARIABLENAME, rInst.pClass, RscId() ); - - return aInst; -} - -void SetString( const RSCINST & rInst, const char * pVarName, const char * pStr ) -{ - RSCINST aInst; - - aInst = GetVarInst( rInst, pVarName ); - if( aInst.pData ){ - ERRTYPE aError; - aError = aInst.pClass->SetString( aInst, pStr ); - - if( aError.IsError() ) - pTC->pEH->Error( aError, aInst.pClass, RscId() ); - } -} - -RscId MakeRscId( RscExpType aExpType ) -{ - if( !aExpType.IsNothing() ) - { - sal_Int32 lValue(0); - - if( !aExpType.Evaluate( &lValue ) ) - pTC->pEH->Error( ERR_ZERODIVISION, nullptr, RscId() ); - if( lValue < 1 || lValue > (sal_Int32)0x7FFF ) - { - pTC->pEH->Error( ERR_IDRANGE, nullptr, RscId(), - rtl::OString::number(lValue).getStr() ); - } - - if( aExpType.IsDefinition() ) - return RscId( aExpType.aExp.pDef ); - else - return RscId( lValue ); - } - return RscId(); -} - -bool DoClassHeader( RSCHEADER * pHeader, bool bMember ) -{ - RSCINST aCopyInst; - RscId aName1 = MakeRscId( pHeader->nName1 ); - RscId aName2 = MakeRscId( pHeader->nName2 ); - - if( pHeader->pRefClass ) - aCopyInst.pClass = pHeader->pRefClass; - else - aCopyInst.pClass = pHeader->pClass; - - if( pHeader->nTyp == TYPE_COPY ) - { - ObjNode * pCopyObj = aCopyInst.pClass->GetObjNode( aName2 ); - - if( !pCopyObj ) - { - rtl::OStringBuffer aMsg( pHS->getString( aCopyInst.pClass->GetId() ) ); - aMsg.append(' '); - aMsg.append(aName2.GetName()); - pTC->pEH->Error( ERR_NOCOPYOBJ, pHeader->pClass, aName1, - aMsg.getStr() ); - } - else - aCopyInst.pData = pCopyObj->GetRscObj(); - } - - if( bMember ) - { - // specification of superclasses or derived classes is now allowed - if( S.Top().pClass->InHierarchy( pHeader->pClass ) || - pHeader->pClass->InHierarchy( S.Top().pClass) ) - { - if( aCopyInst.IsInst() ) - { - RSCINST aTmpI( S.Top() ); - aTmpI.pClass->Destroy( aTmpI ); - aTmpI.pClass->Create( &aTmpI, aCopyInst ); - } - } - else - pTC->pEH->Error( ERR_FALSETYPE, S.Top().pClass, aName1, - pHS->getString( pHeader->pClass->GetId() ).getStr() ); - } - else - { - if( S.IsEmpty() ) - { - if( aName1.GetNumber() < 256 ) - pTC->pEH->Error( WRN_GLOBALID, pHeader->pClass, aName1 ); - - if( aCopyInst.IsInst() ) - S.Push( pHeader->pClass->Create( nullptr, aCopyInst ) ); - else - S.Push( pHeader->pClass->Create( nullptr, RSCINST() ) ); - - pTC->pEH->StdOut( ".", RscVerbosityVerbose ); - - if( !aName1.IsId() ) - pTC->pEH->Error( ERR_IDEXPECTED, pHeader->pClass, aName1 ); - else - { - ObjNode * pNode = new ObjNode( aName1, S.Top().pData, - pFI->GetFileIndex() ); - if( !pHeader->pClass->PutObjNode( pNode ) ) - pTC->pEH->Error( ERR_DOUBLEID, pHeader->pClass, aName1 ); - } - } - else - { - RSCINST aTmpI; - ERRTYPE aError; - - if( aName1.GetNumber() >= 256 && aName1.IsId() ) - pTC->pEH->Error( WRN_LOCALID, pHeader->pClass, aName1 ); - - aError = S.Top().pClass->GetElement( S.Top(), aName1, - pHeader->pClass, aCopyInst, &aTmpI ); - - if( aError.IsWarning() ) - { - pTC->pEH->Error( aError, pHeader->pClass, aName1 ); - } - else if( aError.IsError() ) - { - if( aError.GetError() == ERR_CONT_INVALIDTYPE ) - pTC->pEH->Error( aError, S.Top().pClass, aName1, - pHS->getString( pHeader->pClass->GetId() ).getStr() ); - else - pTC->pEH->Error( aError, S.Top().pClass, aName1 ); - - S.Top().pClass->GetElement( S.Top(), RscId(), - pHeader->pClass, RSCINST(), &aTmpI ); - - if( !aTmpI.IsInst() ) - return false; - } - S.Push( aTmpI ); - } - } - if( pHeader->nTyp == TYPE_REF ) - { - ERRTYPE aError; - - aError = S.Top().pClass->SetRef( S.Top(), aName2 ); - pTC->pEH->Error( aError, S.Top().pClass, aName1 ); - } - - return true ; -} - -RSCINST GetFirstTupelEle( const RSCINST & rTop ) -{ // upward compatible, test Tupel - RSCINST aInst; - ERRTYPE aErr; - - aErr = rTop.pClass->GetElement( rTop, RscId(), nullptr, RSCINST(), &aInst ); - if( !aErr.IsError() ) - aInst = aInst.pClass->GetTupelVar( aInst, 0, RSCINST() ); - return aInst; -} - -//#define YYDEBUG 1 - -#ifdef UNX -#define YYMAXDEPTH 2000 -#else -#define YYMAXDEPTH 800 -#endif - -#if defined _MSC_VER -#pragma warning(push, 1) -#pragma warning(disable:4129 4273 4701 4702) -#endif -#ifdef __GNUC__ -#pragma GCC diagnostic ignored "-Wwrite-strings" -#endif -%} - -/* Compilerstack */ - -%union { - Atom varid; - struct { - Atom hashid; - sal_Int32 nValue; - } constname; - RscTop * pClass; - RSCHEADER header; - struct { - CLASS_DATA pData; - RscTop * pClass; - } instance; - sal_Int32 value; - sal_uInt16 ushort; - short exp_short; - char * string; - bool svbool; - REF_ENUM copyref; - RscDefine * defineele; - rtl_TextEncoding charset; - RscExpType macrostruct; -} - -/* Token */ -%token <value> NUMBER -%token <string> SYMBOL -%token <defineele> RSCDEFINE -%token <string> STRING -%token <string> INCLUDE_STRING -%token <character> CHARACTER -%token <svbool> BOOLEAN - -%token LINE -%token AUTO_ID -%token NOT -%token DEFINE -%token INCLUDE -%token MACROTARGET -%token DEFAULT - - -%token <pClass> CLASSNAME -%token <varid> VARNAME -%token <constname> CONSTNAME -%token CLASS -%token EXTENDABLE -%token WRITEIFSET - - -%type <macrostruct> macro_expression -%type <macrostruct> id_expression -%type <string> string_multiline - -%type <header> class_header_body -%type <header> class_header -%type <header> var_header_class -%type <copyref> copy_ref - - -%left '|' -%left '&' -%left LEFTSHIFT RIGHTSHIFT -%left '+' '-' -%left '*' '/' -%left UNARYMINUS -%left UNARYPLUS -%left ',' -%left '(' ')' - - -/* Grammatik */ - -%start resource_definitions - -%% - -resource_definitions - : - | resource_definitions resource_definition - | MACROTARGET macro_expression - { - RscExpType aExpType; - sal_Int32 lValue; - - aExpType.cUnused = false; - aExpType.cType = RSCEXP_NOTHING; - pExp = new RscExpression( aExpType, '+', $2 ); - if( !pExp->Evaluate( &lValue ) ) - { - pTC->pEH->Error( ERR_ZERODIVISION, nullptr, RscId() ); - } - delete pExp; - } -; - -resource_definition - : line_number - | '#' DEFINE SYMBOL macro_expression - { - bool bError = false; - - if( $4.IsNumber() ) - { - if( !pTC->aFileTab.NewDef( pFI->GetFileIndex(), - rtl::OString( $3 ), - $4.GetLong() ) ) - bError = true; - } - else if( $4.IsDefinition() ) - { - RscExpType aExpType; - RscExpression * pExpr; - - aExpType.cUnused = false; - aExpType.cType = RSCEXP_NOTHING; - aExpType.SetLong( 0 ); - aExpType.cType = RSCEXP_LONG; - pExpr = new RscExpression( aExpType, '+', $4 ); - - if( !pTC->aFileTab.NewDef( pFI->GetFileIndex(), - rtl::OString( $3 ), pExpr ) ) - { - bError =true; - } - } - else if( $4.IsExpression() ) - { - if( !pTC->aFileTab.NewDef( pFI->GetFileIndex(), - rtl::OString( $3 ), $4.aExp.pExp ) ) - { - bError = true; - } - } - - if( bError ) - { - pTC->pEH->Error( ERR_DECLAREDEFINE, nullptr, RscId(), $3 ); - } - } - | '#' DEFINE RSCDEFINE macro_expression - { - pTC->pEH->Error( - ERR_DOUBLEDEFINE, nullptr, RscId(), $3->GetName().getStr() ); - } - | '#' INCLUDE STRING - { - } - | '#' INCLUDE INCLUDE_STRING - { - } - | class_definition ';' - { -#ifdef D40 - void * pMem; - pMem = rtl_allocateMemory( 20000 ); - rtl_freeMemory( pMem ); -#endif - } - ; - -class_definition - : class_header class_body - { - if( $1.nTyp == TYPE_REF ) - { - pTC->pEH->Error( ERR_REFNOTALLOWED, S.Top().pClass, - RscId( $1.nName1 ) ); - } - S.Pop(); - } - | class_header - { - ERRTYPE aError; - RscId aRscId( $1.nName1 ); - - if( $1.nTyp == TYPE_NOTHING && aRscId.IsId() ) - aError = S.Top().pClass->SetRef( S.Top(), aRscId ); - else if( $1.nTyp == TYPE_COPY ) - aError = ERR_COPYNOTALLOWED; - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, aRscId ); - S.Pop(); - } - ; - -class_header - : class_header_body - { - if( !DoClassHeader( &$1, false ) ) - return ERR_ERROR; - $$ = $1; - } - ; - -copy_ref - : '<' - { - $$ = TYPE_COPY; - } - | ',' - { - $$ = TYPE_REF; - } -; - -class_header_body - : CLASSNAME id_expression copy_ref CLASSNAME id_expression - { - $$.pClass = $1; - $$.nName1 = $2; - $$.nTyp = $3; - $$.pRefClass = $4; - $$.nName2 = $5; - } - | CLASSNAME id_expression copy_ref id_expression - { - $$.pClass = $1; - $$.nName1 = $2; - $$.nTyp = $3; - $$.pRefClass = nullptr; - $$.nName2 = $4; - } - | CLASSNAME id_expression - { - $$.pClass = $1; - $$.nName1 = $2; - $$.nTyp = TYPE_NOTHING; - $$.pRefClass = nullptr; - $$.nName2.cType = RSCEXP_NOTHING; - } - | CLASSNAME copy_ref id_expression - { - $$.pClass = $1; - $$.nName1.cType = RSCEXP_NOTHING; - $$.nTyp = $2; - $$.pRefClass = nullptr; - $$.nName2 = $3; - } - | CLASSNAME copy_ref CLASSNAME id_expression - { - $$.pClass = $1; - $$.nName1.cType = RSCEXP_NOTHING; - $$.nTyp = $2; - $$.pRefClass = $3; - $$.nName2 = $4; - } - | CLASSNAME - { - $$.pClass = $1; - $$.nName1.cType = RSCEXP_NOTHING; - $$.nTyp = TYPE_NOTHING; - $$.nName2.cType = RSCEXP_NOTHING; - } -; - -class_body - : '{' var_definitions '}' - | '{' '}' - | string_multiline - { - SetString( S.Top(), "TEXT", $1 ); - } -; - -var_definitions - : var_definition - | var_definitions var_definition - ; - -var_definition - : line_number - | var_header var_body ';' - { - S.Pop(); - } - | class_definition ';' - | var_header_class class_body ';' - { - if( $1.nTyp == TYPE_REF ) - pTC->pEH->Error( ERR_REFNOTALLOWED, S.Top().pClass, - RscId( $1.nName1 ) ); - - if( S.Top().pClass->GetCount( S.Top() ) ) - pTC->pEH->Error( WRN_SUBINMEMBER, S.Top().pClass, - RscId( $1.nName1 ) ); - - S.Pop(); - } - | var_header_class ';' - { - ERRTYPE aError; - RscId aRscId( $1.nName1 ); - - if( $1.nTyp == TYPE_NOTHING && aRscId.IsId() ) - aError = S.Top().pClass->SetRef( S.Top(), aRscId ); - else if( $1.nTyp == TYPE_COPY ) - aError = ERR_COPYNOTALLOWED; - if( S.Top().pClass->GetCount( S.Top() ) ) - aError = WRN_SUBINMEMBER; - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, aRscId ); - - S.Pop(); - } -; - -var_header_class - : VARNAME '=' class_header_body - { - RSCINST aInst; - - aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST(), false, $3.pClass ); - - if( aInst.pData ) - S.Push( aInst ); - else - { - pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(), - pHS->getString( $1 ).getStr() ); - return ERR_ERROR; - } - - if( !DoClassHeader( &$3, true ) ) - return ERR_ERROR; - $$ = $3; - } - | VARNAME '[' CONSTNAME ']' '=' class_header_body - { - RSCINST aInst; - - aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() ); - - if( aInst.pData ) - { - ERRTYPE aError; - RSCINST aIdxInst; - - aError = aInst.pClass->GetArrayEle( - aInst, $3.hashid, nullptr, &aIdxInst ); - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, RscId() ); - if( aError.IsError() ) - return ERR_ERROR; - S.Push( aIdxInst ); - } - else - { - pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(), - pHS->getString( $1 ).getStr() ); - return ERR_ERROR; - } - if( !DoClassHeader( &$6, true ) ) - return ERR_ERROR; - $$ = $6; - } - | VARNAME '[' SYMBOL ']' '=' class_header_body - { - RSCINST aInst; - - aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() ); - - if( aInst.pData ) - { - long nNewLang = pTC->AddLanguage( $3 ); - ERRTYPE aError; - RSCINST aIdxInst; - - aError = aInst.pClass->GetArrayEle( - aInst, nNewLang, nullptr, &aIdxInst ); - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, RscId() ); - if( aError.IsError() ) - return ERR_ERROR; - S.Push( aIdxInst ); - } - else - { - pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(), - pHS->getString( $1 ).getStr() ); - return ERR_ERROR; - } - if( !DoClassHeader( &$6, true ) ) - return ERR_ERROR; - $$ = $6; - } -; - -var_header - : VARNAME '=' - { - RSCINST aInst; - - aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() ); - - if( aInst.pData ) - S.Push( aInst ); - else - { - pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(), - pHS->getString( $1 ).getStr() ); - return ERR_ERROR; - } - } - | VARNAME '[' CONSTNAME ']' '=' - { - RSCINST aInst; - - aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() ); - - if( aInst.pData ) - { - ERRTYPE aError; - RSCINST aIdxInst; - - aError = aInst.pClass->GetArrayEle( - aInst, $3.hashid, nullptr, &aIdxInst ); - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, RscId() ); - if( aError.IsError() ) - return ERR_ERROR; - S.Push( aIdxInst ); - } - else - { - pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(), - pHS->getString( $1 ).getStr() ); - return ERR_ERROR; - } - } - | VARNAME '[' SYMBOL ']' '=' - { - RSCINST aInst; - - aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() ); - - if( aInst.pData ) - { - long nNewLang = pTC->AddLanguage( $3 ); - ERRTYPE aError; - RSCINST aIdxInst; - - aError = aInst.pClass->GetArrayEle( - aInst, nNewLang, nullptr, &aIdxInst ); - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, RscId() ); - if( aError.IsError() ) - return ERR_ERROR; - S.Push( aIdxInst ); - } - else - { - pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(), - pHS->getString( $1 ).getStr() ); - return ERR_ERROR; - } - } -; - -tupel_header0 - : - { - RSCINST aInst; - - aInst = S.Top().pClass->GetTupelVar( S.Top(), 0, RSCINST() ); - if( aInst.pData ) - S.Push( aInst ); - else - { - pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() ); - return ERR_ERROR; - } - } -; - -tupel_header1 - : - { - RSCINST aInst; - - aInst = S.Top().pClass->GetTupelVar( S.Top(), 1, RSCINST() ); - if( aInst.pData ) - S.Push( aInst ); - else - { - pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() ); - return ERR_ERROR; - } - } -; - -tupel_header2 - : - { - RSCINST aInst; - - aInst = S.Top().pClass->GetTupelVar( S.Top(), 2, RSCINST() ); - if( aInst.pData ) - S.Push( aInst ); - else - { - pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() ); - return ERR_ERROR; - } - } -; - -tupel_header3 - : - { - RSCINST aInst; - - aInst = S.Top().pClass->GetTupelVar( S.Top(), 3, RSCINST() ); - if( !aInst.pData ) - { - pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() ); - return ERR_ERROR; - } - S.Push( aInst ); - } -; - -tupel_body - : var_body - { - S.Pop(); - } -; - -var_list_header - : - { - ERRTYPE aError; - RSCINST aInst; - - aError = S.Top().pClass->GetElement( S.Top(), RscId(), - nullptr, RSCINST(), &aInst ); - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, RscId() ); - if( aError.IsError() ) - { // implicit to get instance on the stack - aInst = S.Top().pClass->Create( nullptr, RSCINST() ); - } - S.Push( aInst ); - } -; - -list_body - : var_bodycomplex - { - S.Pop(); - } -; - -list_header - : - { - sal_uInt32 nCount = S.Top().pClass->GetCount( S.Top() ); - sal_uInt32 i; - - for( i = nCount; i > 0; i-- ) - S.Top().pClass->DeletePos( S.Top(), i -1 ); - } -; - -list - : list var_list_header list_body ';' - | list var_bodysimple ';' - | list class_definition ';' - | list line_number - | - ; - -var_bodysimple - : macro_expression - { - sal_Int32 l; - ERRTYPE aError; - - if( !$1.Evaluate( &l ) ) - pTC->pEH->Error( ERR_ZERODIVISION, nullptr, RscId() ); - else - { - aError = S.Top().pClass->SetRef( S.Top(), RscId( $1 ) ); - if( aError.IsError() ) - { - aError.Clear(); - aError = S.Top().pClass->SetNumber( S.Top(), l ); - } - if( aError.IsError() ) - { // upward compatible, test Tupel - RSCINST aInst = GetFirstTupelEle( S.Top() ); - if( aInst.pData ) - { - aError.Clear(); // reset error - aError = aInst.pClass->SetRef( aInst, RscId( $1 ) ); - if( aError.IsError() ) - { - aError.Clear(); - aError = aInst.pClass->SetNumber( aInst, l ); - } - } - } - } - - if( $1.IsExpression() ) - delete $1.aExp.pExp; - - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, RscId() ); - } - | CONSTNAME - { - ERRTYPE aError; - aError = S.Top().pClass->SetConst( S.Top(), $1.hashid, $1.nValue ); - if( aError.IsError() ) - { // upward compatible, test Tupel - RSCINST aInst = GetFirstTupelEle( S.Top() ); - if( aInst.pData ) - { - aError.Clear(); // reset error - aError = aInst.pClass->SetConst( aInst, $1.hashid, $1.nValue ); - } - } - - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, RscId() ); - } - | NOT CONSTNAME - { - ERRTYPE aError; - aError = S.Top().pClass->SetNotConst( S.Top(), $2.hashid ); - if( aError.IsError() ) - { // upward compatible, test Tupel - RSCINST aInst = GetFirstTupelEle( S.Top() ); - if( aInst.pData ) - { - aError.Clear(); // reset error - aError = aInst.pClass->SetNotConst( aInst, $2.hashid ); - } - } - - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, RscId() ); - } - | BOOLEAN - { - ERRTYPE aError; - aError = S.Top().pClass->SetBool( S.Top(), $1 ); - if( aError.IsError() ) - { // upward compatible, test Tupel - RSCINST aInst = GetFirstTupelEle( S.Top() ); - if( aInst.pData ) - { - aError.Clear(); // reset error - aError = aInst.pClass->SetBool( aInst, $1 ); - } - } - - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, RscId() ); - } - | string_multiline - { - ERRTYPE aError; - aError = S.Top().pClass->SetString( S.Top(), $1 ); - if( aError.IsError() ) - { // upward compatible, test Tupel - RSCINST aInst = GetFirstTupelEle( S.Top() ); - if( aInst.pData ) - { - aError.Clear(); // reset error - aError = aInst.pClass->SetString( aInst, $1 ); - } - } - - if( aError.IsError() || aError.IsWarning() ) - pTC->pEH->Error( aError, S.Top().pClass, RscId() ); - } - | DEFAULT - ; - -var_bodycomplex - : '{' list_header list '}' - | '<' tupel_header0 tupel_body ';' '>' - | '<' tupel_header0 tupel_body ';' tupel_header1 tupel_body ';' '>' - | '<' tupel_header0 tupel_body ';' tupel_header1 tupel_body ';' - tupel_header2 tupel_body ';' '>' - | '<' tupel_header0 tupel_body ';' tupel_header1 tupel_body ';' - tupel_header2 tupel_body ';' tupel_header3 tupel_body ';' '>' - ; - -var_body - : var_bodysimple - | var_bodycomplex - ; - -string_multiline - : STRING - { - $$ = $1; - } - | string_multiline STRING - { - rtl::OStringBuffer aBuf( 256 ); - aBuf.append( $1 ); - aBuf.append( $2 ); - $$ = const_cast<char*>(pStringContainer->putString( aBuf.getStr() )); - } -; - -macro_expression - : RSCDEFINE - { - $$.cType = RSCEXP_DEF; - $$.aExp.pDef = $1; - } - | NUMBER - { - $$.cType = RSCEXP_LONG; - $$.SetLong( $1 ); - } - | '-' macro_expression %prec UNARYMINUS - { - if( $2.IsNumber() ){ - $$.cType = $2.cType; - $$.SetLong( - $2.GetLong() ); - } - else - { - RscExpType aLeftExp; - - aLeftExp.cType = RSCEXP_NOTHING; - $$.cType = RSCEXP_EXP; - $$.aExp.pExp = new RscExpression( aLeftExp, '-', $2 ); - } - } - | '+' macro_expression %prec UNARYPLUS - { - $$ = $2; - } - | macro_expression '+' macro_expression - { - if( $1.IsNumber() && $3.IsNumber() ) - { - $$.cType = RSCEXP_LONG; - $$.SetLong( $1.GetLong() + $3.GetLong() ); - } - else - { - $$.cType = RSCEXP_EXP; - $$.aExp.pExp = new RscExpression( $1, '+', $3 ); - } - } - | macro_expression '-' macro_expression - { - if( $1.IsNumber() && $3.IsNumber() ) - { - $$.cType = RSCEXP_LONG; - $$.SetLong( $1.GetLong() - $3.GetLong() ); - } - else - { - $$.cType = RSCEXP_EXP; - $$.aExp.pExp = new RscExpression( $1, '-', $3 ); - } - } - | macro_expression '*' macro_expression - { - if( $1.IsNumber() && $3.IsNumber() ) - { - $$.cType = RSCEXP_LONG; - $$.SetLong( $1.GetLong() * $3.GetLong() ); - } - else - { - $$.cType = RSCEXP_EXP; - $$.aExp.pExp = new RscExpression( $1, '*', $3 ); - } - } - | macro_expression '/' macro_expression - { - if( $1.IsNumber() && $3.IsNumber() ) - { - if( $3.GetLong() == 0 ) - { - $$.cType = RSCEXP_EXP; - $$.aExp.pExp = new RscExpression( $1, '/', $3 ); - } - else - { - $$.cType = RSCEXP_LONG; - $$.SetLong( $1.GetLong() / $3.GetLong() ); - } - } - else - { - $$.cType = RSCEXP_EXP; - $$.aExp.pExp = new RscExpression( $1, '/', $3 ); - } - } - | macro_expression '&' macro_expression - { - if( $1.IsNumber() && $3.IsNumber() ) - { - $$.cType = RSCEXP_LONG; - $$.SetLong( $1.GetLong() & $3.GetLong() ); - } - else - { - $$.cType = RSCEXP_EXP; - $$.aExp.pExp = new RscExpression( $1, '&', $3 ); - } - } - | macro_expression '|' macro_expression - { - if( $1.IsNumber() && $3.IsNumber() ) - { - $$.cType = RSCEXP_LONG; - $$.SetLong( $1.GetLong() | $3.GetLong() ); - } - else - { - $$.cType = RSCEXP_EXP; - $$.aExp.pExp = new RscExpression( $1, '|', $3 ); - } - } - | '(' macro_expression ')' - { - $$ = $2; - } - | macro_expression LEFTSHIFT macro_expression - { - if( $1.IsNumber() && $3.IsNumber() ) - { - $$.cType = RSCEXP_LONG; - $$.SetLong( $1.GetLong() << $3.GetLong() ); - } - else - { - $$.cType = RSCEXP_EXP; - $$.aExp.pExp = new RscExpression( $1, 'l', $3 ); - } - } - | macro_expression RIGHTSHIFT macro_expression - { - if( $1.IsNumber() && $3.IsNumber() ) - { - $$.cType = RSCEXP_LONG; - $$.SetLong( $1.GetLong() >> $3.GetLong() ); - } - else - { - $$.cType = RSCEXP_EXP; - $$.aExp.pExp = new RscExpression( $1, 'r', $3 ); - } - } -; - -id_expression - : id_expression line_number - | macro_expression - { // evaluate pExpession and delete it - if( $1.cType == RSCEXP_EXP ) - { - sal_Int32 lValue; - - if( !$1.Evaluate( &lValue ) ) - pTC->pEH->Error( ERR_ZERODIVISION, nullptr, RscId() ); - delete $1.aExp.pExp; - $$.cType = RSCEXP_LONG; - $$.SetLong( lValue ); - } - else - { - $$ = $1; - } - } -; - -DUMMY_NUMBER - : NUMBER - { - } - | - { - } - ; - -line_number - : '#' LINE NUMBER STRING - { - RscFile * pFName; - - pFI->SetLineNo( $3 ); - pFI->SetFileIndex( pTC->aFileTab.NewCodeFile( rtl::OString( $4 ) ) ); - pFName = pTC->aFileTab.Get( pFI->GetFileIndex() ); - pFName->bLoaded = true; - pFName->bScanned = true; - } - | '#' NUMBER STRING DUMMY_NUMBER - { - RscFile * pFName; - - pFI->SetLineNo( $2 ); - pFI->SetFileIndex( pTC->aFileTab.NewCodeFile( rtl::OString( $3 ) ) ); - pFName = pTC->aFileTab.Get( pFI->GetFileIndex() ); - pFName->bLoaded = true; - pFName->bScanned = true; - } - | '#' NUMBER - { - pFI->SetLineNo( $2 ); - } -; - -%% -#if defined _MSC_VER -#pragma warning(pop) -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ - - diff --git a/rsc/source/prj/gui.cxx b/rsc/source/prj/gui.cxx deleted file mode 100644 index 323bc5728cc0..000000000000 --- a/rsc/source/prj/gui.cxx +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <memory> - -#include <gui.hxx> -#include <rscrsc.hxx> -#include <rscdb.hxx> - -static RscVerbosity lcl_determineVerbosity( int argc, char ** argv ) -{ - for ( int i = 0; i < argc; ++i ) - { - if ( argv[i] == nullptr ) - continue; - if ( rsc_stricmp( argv[i], "-verbose" ) == 0 ) - return RscVerbosityVerbose; - if ( rsc_stricmp( argv[i], "-quiet" ) == 0 ) - return RscVerbositySilent; - } - return RscVerbosityNormal; -} - -int rsc2_main( int argc, char **argv ) -{ -#if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, "debugging %s\n", argv[0] ); -#endif - - ERRTYPE aError; - - InitRscCompiler(); - std::unique_ptr<RscError> pErrHdl(new RscError( lcl_determineVerbosity( argc, argv ) )); - std::unique_ptr<RscCmdLine> pCmdLine(new RscCmdLine( argc, argv, pErrHdl.get() )); - std::unique_ptr<RscTypCont> pTypCont(new RscTypCont( pErrHdl.get(), - pCmdLine->nByteOrder, - pCmdLine->nCommands )); - - if( pErrHdl->nErrors ) - aError = ERR_ERROR; - else{ - std::unique_ptr<RscCompiler> pCompiler(new RscCompiler( pCmdLine.get(), pTypCont.get() )); - - aError = pCompiler->Start(); - } - - delete pHS; // is generated by InitRscCompiler - - if( aError.IsOk() ) - return 0; - else - return 1; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/prj/gui.hxx b/rsc/source/prj/gui.hxx deleted file mode 100644 index 7deab5b3b88e..000000000000 --- a/rsc/source/prj/gui.hxx +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_RSC_SOURCE_PRJ_GUI_HXX -#define INCLUDED_RSC_SOURCE_PRJ_GUI_HXX - -#include <sal/config.h> - -int rsc2_main(int, char**); - -// Entry point declaration for modules rscpp and rsc2 -extern "C" int rscpp_main(int, char**); - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/prj/start.cxx b/rsc/source/prj/start.cxx deleted file mode 100644 index c4ed4bf21f5a..000000000000 --- a/rsc/source/prj/start.cxx +++ /dev/null @@ -1,350 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <fcntl.h> -#include <string.h> - -#ifdef UNX -#include <unistd.h> -#include <sys/wait.h> -#else // UNX - -#include <io.h> -#include <process.h> -#include <dos.h> - -#endif // UNX - -#include <gui.hxx> -#include <rsctools.hxx> -#include <rscerror.h> -#include <sal/main.h> -#include <rtl/strbuf.hxx> - - -static bool CallPrePro( const OString& rInput, - const OString& rOutput, RscPtrPtr * pCmdLine, - bool bResponse ) -{ - RscPtrPtr aNewCmdL; - RscPtrPtr aRespCmdL; - RscPtrPtr * pCmdL = &aNewCmdL; - int i, nRet; - FILE* fRspFile = nullptr; - OString aRspFileName; - - if( bResponse ) - { - aRspFileName = ::GetTmpFileName(); - fRspFile = fopen( aRspFileName.getStr(), "w" ); - } - - if( !fRspFile ) - aNewCmdL.Append( rsc_strdup( "rscpp" ) ); - - bool bVerbose = false; - for( i = 1; i < int(pCmdLine->GetCount() -1); i++ ) - { - if ( 0 == rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-verbose" ) ) - { - bVerbose = true; - continue; - } - if (strcmp(static_cast<char *>(pCmdLine->GetEntry(i)), "-isystem") == 0) - { - // ignore "-isystem" and following arg - if (i < int(pCmdLine->GetCount()) - 1) - { - ++i; - } - continue; - } - if (strncmp( - static_cast<char *>(pCmdLine->GetEntry(i)), "-isystem", - strlen("-isystem")) - == 0) - { - // ignore args starting with "-isystem" - continue; - } - if ( !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-u", 2 ) || - !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-i", 2 ) || - !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-d", 2 )) - { - aNewCmdL.Append( rsc_strdup( static_cast<char *>(pCmdLine->GetEntry( i )) ) ); - } - } - - aNewCmdL.Append( rsc_strdup( rInput.getStr() ) ); - aNewCmdL.Append( rsc_strdup( rOutput.getStr() ) ); - aNewCmdL.Append( static_cast<void *>(nullptr) ); - - if ( bVerbose ) - { - printf( "Preprocessor commandline: " ); - for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ ) - { - printf( " " ); - printf( "%s", static_cast<const char *>(pCmdL->GetEntry( i )) ); - } - printf( "\n" ); - } - - if( fRspFile ) - { - aRespCmdL.Append( rsc_strdup( "rscpp" ) ); - OStringBuffer aTmpStr; - aTmpStr.append('@').append(aRspFileName); - aRespCmdL.Append( rsc_strdup( aTmpStr.getStr() ) ); - aRespCmdL.Append( static_cast<void *>(nullptr) ); - - pCmdL = &aRespCmdL; - for( i = 0; i < (int)(aNewCmdL.GetCount() -1); i++ ) - { - fprintf( fRspFile, "%s ", static_cast<const char *>(aNewCmdL.GetEntry( i )) ); - } - fclose( fRspFile ); - - if ( bVerbose ) - { - printf( "Preprocessor startline: " ); - for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ ) - { - printf( " " ); - printf( "%s", static_cast<const char *>(pCmdL->GetEntry( i )) ); - } - printf( "\n" ); - } - } - - nRet = rscpp_main( pCmdL->GetCount()-1, reinterpret_cast<char**>(pCmdL->GetBlock()) ); - - if ( fRspFile ) - { - #if OSL_DEBUG_LEVEL > 5 - fprintf( stderr, "leaving response file %s\n", aRspFileName.getStr() ); - #else - unlink( aRspFileName.getStr() ); - #endif - } - if ( nRet ) - return false; - - return true; -} - - -static bool CallRsc2( RscStrList * pInputList, - const OString &rSrsName, RscPtrPtr * pCmdLine ) -{ - int nRet; - RscVerbosity eVerbosity = RscVerbosityNormal; - - RscPtrPtr aNewCmdL; - aNewCmdL.Append( rsc_strdup( "rsc2" ) ); - - for (int i = 1; i < (int)(pCmdLine->GetCount() -1); ++i) - { - if ( !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-verbose" ) ) - { - eVerbosity = RscVerbosityVerbose; - continue; - } - if ( !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-quiet" ) ) - { - eVerbosity = RscVerbositySilent; - continue; - } - if( !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-fp=", 4 ) || - !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-fo=", 4 ) || - !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-presponse", 10 ) || - !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-rc", 3 ) || - !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-+" ) || - !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-br" ) || - !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-bz" ) || - !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-r" ) || - ( '-' != *static_cast<char *>(pCmdLine->GetEntry( i )) ) ) - { - } - else - { - aNewCmdL.Append( rsc_strdup( static_cast<char *>(pCmdLine->GetEntry( i )) ) ); - } - } - - aNewCmdL.Append( rsc_strdup( rSrsName.getStr() ) ); - - for ( size_t i = 0, n = pInputList->size(); i < n; ++i ) - { - OString* pString = (*pInputList)[ i ]; - aNewCmdL.Append( rsc_strdup( pString->getStr() ) ); - } - - if ( eVerbosity >= RscVerbosityVerbose ) - { - printf( "Rsc2 commandline: " ); - for( size_t i = 0; i < (unsigned int)(aNewCmdL.GetCount() -1); i++ ) - { - printf( " %s", static_cast<const char *>(aNewCmdL.GetEntry( i )) ); - } - printf( "\n" ); - } - - nRet = rsc2_main( aNewCmdL.GetCount(), reinterpret_cast<char**>(aNewCmdL.GetBlock()) ); - - if( nRet ) - return false; - return true; -} - -SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) -{ - bool bPrePro = true; - bool bHelp = false; - bool bError = false; - bool bResponse = false; - OString aSrsName; - OString aResName; - RscStrList aInputList; - RscStrList aTmpList; - char * pStr; - char ** ppStr; - RscPtrPtr aCmdLine; - sal_uInt32 i; - - pStr = ::ResponseFile( &aCmdLine, argv, argc ); - if( pStr ) - { - printf( "Cannot open response file <%s>\n", pStr ); - return 1; - }; - - ppStr = reinterpret_cast<char **>(aCmdLine.GetBlock()); - ppStr++; - i = 1; - bool bSetSrs = false; - while( ppStr && i < (aCmdLine.GetCount() -1) ) - { - if (strcmp(*ppStr, "-isystem") == 0) - { - // ignore "-isystem" and following arg - if (i < aCmdLine.GetCount() - 1) - { - ++ppStr; - ++i; - } - } - else if (strncmp(*ppStr, "-isystem", strlen("-isystem")) == 0) - { - // ignore args starting with "-isystem" - } - else if( '-' == **ppStr ) - { - if( !rsc_stricmp( (*ppStr) + 1, "p" ) - || !rsc_stricmp( (*ppStr) + 1, "l" ) ) - { // no pre-processor - bPrePro = false; - } - else if( !rsc_stricmp( (*ppStr) + 1, "h" ) ) - { // print help - bHelp = true; - } - else if( !rsc_strnicmp( (*ppStr) + 1, "presponse", 9 ) ) - { // whether to use response file when parameterising preprocessor - bResponse = true; - } - else if( !rsc_strnicmp( (*ppStr) + 1, "fo=", 3 ) ) - { // another Name for .res-file - aResName = (*ppStr) + 4; - } - else if( !rsc_strnicmp( (*ppStr) + 1, "fp=", 3 ) ) - { // another Name for .srs-file - bSetSrs = true; - aSrsName = (*ppStr); - } - } - else - { - aInputList.push_back( new OString(*ppStr) ); - } - ppStr++; - i++; - } - - if( !aInputList.empty() ) - { - // build the output file names - if (!aResName.getLength()) - aResName = OutputFile( *aInputList[ 0 ], "res" ); - if( ! bSetSrs ) - { - aSrsName = OString("-fp=") + OutputFile(*aInputList[0], "srs"); - } - }; - - if( bHelp ) - bPrePro = false; - - if( bPrePro && !aInputList.empty() ) - { - OString aTmpName; - - for ( size_t k = 0, n = aInputList.size(); k < n; ++k ) - { - OString* pString = aInputList[ k ]; - aTmpName = ::GetTmpFileName(); - if( !CallPrePro( *pString, aTmpName, &aCmdLine, bResponse ) ) - { - printf( "Error starting preprocessor\n" ); - bError = true; - break; - } - aTmpList.push_back( new OString(aTmpName) ); - }; - }; - - if( !bError ) - { - if( !CallRsc2( bPrePro ? &aTmpList : &aInputList, aSrsName, &aCmdLine ) ) - { - if( !bHelp ) - { - printf( "Error starting rsc2 compiler\n" ); - bError = true; - } - }; - }; - - for ( size_t k = 0, n = aTmpList.size(); k < n; ++k ) - unlink( aTmpList[ k ]->getStr() ); - - return bError ? EXIT_FAILURE : EXIT_SUCCESS; -} - -void RscExit( sal_uInt32 nExit ) -{ - if( nExit ) - printf( "Program exit is %d\n", (int)nExit ); - exit( nExit ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/res/rscall.cxx b/rsc/source/res/rscall.cxx deleted file mode 100644 index 84829c7e0ced..000000000000 --- a/rsc/source/res/rscall.cxx +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> - -#include <rscall.h> -#include <rsckey.hxx> - -Atom nRsc_DELTALANG = InvalidAtom; -Atom nRsc_DELTASYSTEM = InvalidAtom; - -void InitRscCompiler() -{ - pStdParType = new OString("( const ResId & rResId, sal_Bool"); - pStdPar1 = new OString('('); - pStdPar2 = new OString('('); - - nRefDeep = 10; - pHS = new AtomContainer(); -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/res/rscarray.cxx b/rsc/source/res/rscarray.cxx deleted file mode 100644 index ba5f8fe16cbc..000000000000 --- a/rsc/source/res/rscarray.cxx +++ /dev/null @@ -1,426 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <rscconst.hxx> -#include <rscarray.hxx> -#include <rscdb.hxx> - -RscInstNode::RscInstNode(sal_uInt32 nId) : nTypeId(nId) -{ -} - -RscInstNode::~RscInstNode() -{ - if( aInst.IsInst() ) - { - aInst.pClass->Destroy( aInst ); - rtl_freeMemory( aInst.pData ); - } -} - -sal_uInt32 RscInstNode::GetId() const -{ - return nTypeId; -} - -RscArray::RscArray( Atom nId, RESOURCE_TYPE nTypeId, RscTop * pSuper, RscEnum * pTypeCl ) - : RscTop( nId, nTypeId, pSuper ) - , pTypeClass(pTypeCl) - , nOffInstData(RscTop::Size()) - , nSize(nOffInstData + ALIGNED_SIZE(sizeof(RscArrayInst))) -{ -} - -RscArray::~RscArray() -{ -} - -RscTop * RscArray::GetTypeClass() const -{ - return pTypeClass; -} - -static RscInstNode * Create( RscInstNode * pNode ) -{ - RscInstNode * pRetNode = nullptr; - - if( pNode ) - { - pRetNode = new RscInstNode( pNode->GetId() ); - pRetNode->aInst = pNode->aInst.pClass->Create( nullptr, pNode->aInst ); - RscInstNode * pTmpNode = Create(pNode->Left()); - if (pTmpNode) - pRetNode->Insert( pTmpNode ); - if( (pTmpNode = Create( pNode->Right() )) != nullptr ) - pRetNode->Insert( pTmpNode ); - } - - return pRetNode; -} - -RSCINST RscArray::Create( RSCINST * pInst, const RSCINST & rDflt, - bool bOwnClass ) -{ - RSCINST aInst; - RscArrayInst * pClassData; - - if( !pInst ) - { - aInst.pClass = this; - aInst.pData = static_cast<CLASS_DATA>(rtl_allocateMemory( Size() )); - } - else - aInst = *pInst; - - if( !bOwnClass && rDflt.IsInst() ) - bOwnClass = rDflt.pClass->InHierarchy( this ); - - RscTop::Create( &aInst, rDflt, bOwnClass ); - - pClassData = reinterpret_cast<RscArrayInst *>(aInst.pData + nOffInstData); - pClassData->pNode = nullptr; - if( bOwnClass ) - { - RscArrayInst * pDfltClassData; - - pDfltClassData = reinterpret_cast<RscArrayInst *>(rDflt.pData + nOffInstData); - - pClassData->pNode = ::Create( pDfltClassData->pNode ); - } - return aInst; -} - -static void Destroy( RscInstNode * pNode ) -{ - if( pNode ) - { - Destroy( pNode->Left() ); - Destroy( pNode->Right() ); - delete pNode; - } -} - -void RscArray::Destroy( const RSCINST & rInst ) -{ - RscArrayInst * pClassData; - - RscTop::Destroy( rInst ); - - pClassData = reinterpret_cast<RscArrayInst *>(rInst.pData + nOffInstData); - - // delete the tree recursively - ::Destroy( pClassData->pNode ); -} - -ERRTYPE RscArray::GetValueEle( const RSCINST & rInst, - sal_Int32 lValue, - RscTop * pCreateClass, - RSCINST * pGetInst) -{ - RscArrayInst * pClassData; - RscInstNode * pNode; - - pClassData = reinterpret_cast<RscArrayInst *>(rInst.pData + nOffInstData); - - ERRTYPE aError; - - Atom nId; - if( !pTypeClass->GetValueConst( sal_uInt32(lValue), &nId ) ) - { // not found - return ERR_ARRAY_INVALIDINDEX; - } - - if( pClassData->pNode ) - pNode = pClassData->pNode->Search( sal_uInt32(lValue) ); - else - pNode = nullptr; - - if( !pNode ) - { - pNode = new RscInstNode( sal_uInt32(lValue) ); - if( pCreateClass && GetSuperClass()->InHierarchy( pCreateClass ) ) - pNode->aInst = pCreateClass->Create( nullptr, rInst ); - else - pNode->aInst = GetSuperClass()->Create( nullptr, rInst ); - - pNode->aInst.pClass->SetToDefault( pNode->aInst ); - if( pClassData->pNode ) - pClassData->pNode->Insert( pNode ); - else - pClassData->pNode = pNode; - } - - *pGetInst = pNode->aInst; - return aError; -} - -ERRTYPE RscArray::GetArrayEle( const RSCINST & rInst, - Atom nId, - RscTop * pCreateClass, - RSCINST * pGetInst) -{ - sal_Int32 lValue; - if( !pTypeClass->GetConstValue( nId, &lValue ) ) - { // not found - return ERR_ARRAY_INVALIDINDEX; - } - - return GetValueEle( rInst, lValue, pCreateClass, pGetInst ); -} - -static bool IsConsistent( RscInstNode * pNode ) -{ - bool bRet = true; - - if( pNode ) - { - bRet = pNode->aInst.pClass->IsConsistent( pNode->aInst ); - if( !IsConsistent( pNode->Left() ) ) - bRet = false; - if( !IsConsistent( pNode->Right() ) ) - bRet = false; - } - return bRet; -} - -bool RscArray::IsConsistent( const RSCINST & rInst ) -{ - RscArrayInst * pClassData; - bool bRet; - - bRet = RscTop::IsConsistent( rInst ); - - pClassData = reinterpret_cast<RscArrayInst *>(rInst.pData + nOffInstData); - if( !::IsConsistent( pClassData->pNode ) ) - bRet = false; - - return bRet; -} - -static void SetToDefault( RscInstNode * pNode ) -{ - if( pNode ) - { - pNode->aInst.pClass->SetToDefault( pNode->aInst ); - SetToDefault( pNode->Left() ); - SetToDefault( pNode->Right() ); - } -} - -void RscArray::SetToDefault( const RSCINST & rInst ) -{ - RscArrayInst * pClassData; - - pClassData = reinterpret_cast<RscArrayInst *>(rInst.pData + nOffInstData); - - ::SetToDefault( pClassData->pNode ); - - RscTop::SetToDefault( rInst ); -} - -static bool IsDefault( RscInstNode * pNode ) -{ - bool bRet = true; - - if( pNode ) - { - bRet = pNode->aInst.pClass->IsDefault( pNode->aInst ); - if( bRet ) - bRet = IsDefault( pNode->Left() ); - if( bRet ) - bRet = IsDefault( pNode->Right() ); - } - return bRet; -} - -bool RscArray::IsDefault( const RSCINST & rInst ) -{ - RscArrayInst * pClassData; - - pClassData = reinterpret_cast<RscArrayInst *>(rInst.pData + nOffInstData); - - bool bRet = ::IsDefault( pClassData->pNode ); - - if( bRet ) - bRet = RscTop::IsDefault( rInst ); - return bRet; -} - -static bool IsValueDefault( RscInstNode * pNode, CLASS_DATA pDef ) -{ - bool bRet = true; - - if( pNode ) - { - bRet = pNode->aInst.pClass->IsValueDefault( pNode->aInst, pDef ); - if( bRet ) - bRet = IsValueDefault( pNode->Left(), pDef ); - if( bRet ) - bRet = IsValueDefault( pNode->Right(), pDef ); - } - return bRet; -} - -bool RscArray::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) -{ - bool bRet = RscTop::IsValueDefault( rInst, pDef ); - - if( bRet ) - { - RscArrayInst * pClassData = reinterpret_cast<RscArrayInst *>(rInst.pData + nOffInstData); - - bRet = ::IsValueDefault( pClassData->pNode, pDef ); - } - return bRet; -} - -void RscArray::WriteSrcHeader( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const RscId & aId, const char * pVarName ) -{ - RscArrayInst * pClassData; - - pClassData = reinterpret_cast<RscArrayInst *>(rInst.pData + nOffInstData); - - if( pTC->IsSrsDefault() ) - { // only write one value - RscInstNode * pNode = nullptr; - if( pClassData->pNode ) - { - std::vector< sal_uInt32 >::const_iterator it; - for( it = pTC->GetFallbacks().begin(); !pNode && it != pTC->GetFallbacks().end(); ++it ) - pNode = pClassData->pNode->Search( *it ); - } - - if( pNode ) - { - if( pNode->aInst.pClass->IsDefault( pNode->aInst ) ) - fprintf( fOutput, "Default" ); - else - pNode->aInst.pClass->WriteSrcHeader( - pNode->aInst, fOutput, - pTC, nTab, aId, pVarName ); - return; - } - } - - if( IsDefault( rInst ) ) - fprintf( fOutput, "Default" ); - else - { - RSCINST aSuper( GetSuperClass(), rInst.pData ); - aSuper.pClass->WriteSrcHeader( aSuper, fOutput, pTC, - nTab, aId, pVarName ); - } - if( !pTC->IsSrsDefault() ) - WriteSrc( rInst, fOutput, pTC, nTab, pVarName ); -} - -static void WriteSrc( RscInstNode * pNode, FILE * fOutput, RscTypCont * pTC, - sal_uInt32 nTab, const char * pVarName, - CLASS_DATA pDfltData, RscEnum * pTypeClass ) -{ - if( pNode ) - { - WriteSrc( pNode->Left(), fOutput, pTC, nTab, pVarName, - pDfltData, pTypeClass ); - if( !pNode->aInst.pClass->IsValueDefault( pNode->aInst, pDfltData ) ) - { - fprintf( fOutput, ";\n" ); - for( sal_uInt32 n = 0; n < nTab; n++ ) - fputc( '\t', fOutput ); - - Atom nIdxId; - pTypeClass->GetValueConst( pNode->GetId(), &nIdxId ); - fprintf( fOutput, "%s[ %s ] = ", pVarName, pHS->getString( nIdxId ).getStr() ); - pNode->aInst.pClass->WriteSrcHeader( pNode->aInst, fOutput, pTC, - nTab, RscId(), pVarName ); - } - WriteSrc( pNode->Right(), fOutput, pTC, nTab, pVarName, - pDfltData, pTypeClass ); - } -} - -void RscArray::WriteSrcArray( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const char * pVarName ) -{ - RscArrayInst * pClassData; - - pClassData = reinterpret_cast<RscArrayInst *>(rInst.pData + nOffInstData); - - ::WriteSrc( pClassData->pNode, fOutput, pTC, nTab, pVarName, - rInst.pData, pTypeClass ); -}; - -void RscArray::WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const char * pVarName ) -{ - WriteSrcArray( rInst, fOutput, pTC, nTab, pVarName ); -} - -ERRTYPE RscArray::WriteRc( const RSCINST & rInst, RscWriteRc & rMem, - RscTypCont * pTC, sal_uInt32 nDeep ) -{ - ERRTYPE aError; - RscArrayInst * pClassData; - RscInstNode * pNode = nullptr; - - pClassData = reinterpret_cast<RscArrayInst *>(rInst.pData + nOffInstData); - - if( pClassData->pNode ) - { -#if OSL_DEBUG_LEVEL > 2 - fprintf( stderr, "RscArray::WriteRc: Fallback " ); -#endif - std::vector< sal_uInt32 >::const_iterator it; - for( it = pTC->GetFallbacks().begin(); !pNode && it != pTC->GetFallbacks().end(); ++it ) - { - pNode = pClassData->pNode->Search( *it ); -#if OSL_DEBUG_LEVEL > 2 - fprintf( stderr, " 0x%hx", *it ); -#endif - } -#if OSL_DEBUG_LEVEL > 2 - fprintf( stderr, "\n" ); -#endif - } - - if( pNode ) - aError = pNode->aInst.pClass->WriteRc( pNode->aInst, rMem, pTC, - nDeep ); - else - aError = RscTop::WriteRc( rInst, rMem, pTC, nDeep ); - - return aError; -} - -RscLangArray::RscLangArray( Atom nId, RESOURCE_TYPE nTypeId, RscTop * pSuper, - RscEnum * pTypeCl ) - : RscArray( nId, nTypeId, pSuper, pTypeCl ) -{ -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/res/rscclass.cxx b/rsc/source/res/rscclass.cxx deleted file mode 100644 index 386b34a2229a..000000000000 --- a/rsc/source/res/rscclass.cxx +++ /dev/null @@ -1,672 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <rscdb.hxx> -#include <rscclass.hxx> - -#include <tools/rcid.h> - -RscClass::RscClass( Atom nId, RESOURCE_TYPE nTypeId, RscTop * pSuperCl ) - : RscTop( nId, nTypeId, pSuperCl ) - , nSuperSize(RscTop::Size()) - , nSize(nSuperSize + ALIGNED_SIZE(sizeof(RscClassInst ))) - , nEntries(0), pVarTypeList(nullptr) -{ -} - -void RscClass::Pre_dtor() -{ - sal_uInt32 i; - - RscTop::Pre_dtor(); - - for( i = 0; i < nEntries; i++ ) - { - if( pVarTypeList[ i ].pDefault ) - { - pVarTypeList[ i ].pClass->Destroy( - RSCINST( pVarTypeList[ i ].pClass, - pVarTypeList[ i ].pDefault ) ); - rtl_freeMemory( pVarTypeList[ i ].pDefault ); - pVarTypeList[ i ].pDefault = nullptr; - } - } -} - -RscClass::~RscClass() -{ - if( pVarTypeList ) - rtl_freeMemory( static_cast<void *>(pVarTypeList) ); -} - -RSCINST RscClass::GetInstData -( - CLASS_DATA pData, - sal_uInt32 nEle, - bool bGetCopy -) -{ - RSCINST aInst; - - aInst.pClass = pVarTypeList[ nEle ].pClass; - if( pData ) - { - if( RSCVAR::NoDataInst & pVarTypeList[ nEle ].nVarType ) - { - RSCINST aTmpI; - - aTmpI.pClass = this; - aTmpI.pData = pData; - if( bGetCopy ) - aInst.pData = GetCopyVar( - aTmpI, - pVarTypeList[ nEle ].nDataBaseName - ).pData; - else - aInst.pData = GetVariable( - aTmpI, - pVarTypeList[ nEle ].nDataBaseName, - RSCINST() - ).pData; - } - else if( RSCVAR::Pointer & pVarTypeList[ nEle ].nVarType ) - { - aInst.pData = *reinterpret_cast<CLASS_DATA *>(pData + pVarTypeList[ nEle ].nOffset); - } - else - aInst.pData = pData + pVarTypeList[ nEle ].nOffset; - } - return aInst; -} - -CLASS_DATA RscClass::GetDfltData( sal_uInt32 nEle ) -{ - if( pVarTypeList[ nEle ].pDefault ) - return pVarTypeList[ nEle ].pDefault; - - return pVarTypeList[ nEle ].pClass->GetDefault().pData; -} - -void RscClass::SetVarDflt( CLASS_DATA pData, sal_uInt32 nEle, bool bSet ) -{ - RscClassInst * pClass; - - pClass = reinterpret_cast<RscClassInst *>(pData + nSuperSize ); - if( bSet ) - pClass->nVarDflt |= ((sal_uLong)1 << nEle); - else - pClass->nVarDflt &= ~((sal_uLong)1 << nEle); -} - -bool RscClass::IsDflt( CLASS_DATA pData, sal_uInt32 nEle ) -{ - RscClassInst * pClass; - - pClass = reinterpret_cast<RscClassInst *>(pData + nSuperSize ); - return pClass->nVarDflt & ((sal_uLong)1 << nEle); -} - -RSCINST RscClass::Create( RSCINST * pInst, - const RSCINST & rDflt, - bool bOwnClass) -{ - sal_uInt32 i; - RSCINST aInst; - RSCINST aMemInst, aDfltI; - - if( !pInst ) - { - aInst.pClass = this; - aInst.pData = static_cast<CLASS_DATA>(rtl_allocateMemory( Size() )); - } - else - aInst = *pInst; - - if( !bOwnClass && rDflt.IsInst() ) - bOwnClass = rDflt.pClass->InHierarchy( this ); - - RscTop::Create( &aInst, rDflt, bOwnClass ); - - if( bOwnClass ) - reinterpret_cast<RscClassInst *>(aInst.pData + nSuperSize)->nVarDflt = - reinterpret_cast<RscClassInst *>(rDflt.pData + nSuperSize)->nVarDflt; - else - reinterpret_cast<RscClassInst *>(aInst.pData + nSuperSize)->nVarDflt = ~((sal_uLong)0); - - for( i = 0; i < nEntries; i++ ) - { - aDfltI = GetInstData( bOwnClass ? rDflt.pData : nullptr, i, true ); - - if( (RSCVAR::Pointer & pVarTypeList[ i ].nVarType) && - !(RSCVAR::NoDataInst & pVarTypeList[ i ].nVarType) ) - { - CLASS_DATA * ppData = reinterpret_cast<CLASS_DATA*>(aInst.pData + pVarTypeList[ i ].nOffset ); - *ppData = nullptr; - if( aDfltI.IsInst() ) - { - aMemInst = pVarTypeList[ i ].pClass->Create( nullptr, aDfltI ); - *ppData = aMemInst.pData; - } - } - else - { - aMemInst = GetInstData( aInst.pData, i, true ); - aMemInst = aMemInst.pClass->Create( &aMemInst, aDfltI ); - } - } - - return aInst; -} - -void RscClass::Destroy( const RSCINST & rInst ) -{ - sal_uInt32 i; - - RscTop::Destroy( rInst ); - - for( i = 0; i < nEntries; i++ ) - { - if( !(pVarTypeList[ i ].nVarType & RSCVAR::NoDataInst) ) - { - RSCINST aTmpI; - - aTmpI = GetInstData( rInst.pData, i, true ); - if( aTmpI.IsInst() ) - { - // destroy object - aTmpI.pClass->Destroy( aTmpI ); - if( pVarTypeList[ i ].nVarType & RSCVAR::Pointer ) - { - // free memory - rtl_freeMemory( aTmpI.pData ); - } - } - } - } -} - -ERRTYPE RscClass::SetVariable( Atom nVarName, - RscTop * pClass, - RSCINST * pDflt, - RSCVAR nVarType, - sal_uInt32 nMask, - Atom nDataBaseName) -{ - if( pVarTypeList ) - { - pVarTypeList = static_cast<VARTYPE_STRUCT *>(rtl_reallocateMemory( static_cast<void *>(pVarTypeList), - ((nEntries +1) * sizeof( VARTYPE_STRUCT )) )); - } - else - { - pVarTypeList = static_cast<VARTYPE_STRUCT *>(rtl_allocateMemory( (nEntries + 1) - * sizeof( VARTYPE_STRUCT ) )); - } - pVarTypeList[ nEntries ].nVarName = nVarName; - pVarTypeList[ nEntries ].nMask = nMask; - pVarTypeList[ nEntries ].pClass = pClass; - pVarTypeList[ nEntries ].nOffset = nSize; - pVarTypeList[ nEntries ].nDataBaseName = nDataBaseName; - if( pDflt ) - pVarTypeList[ nEntries ].pDefault = pDflt->pData; - else - pVarTypeList[ nEntries ].pDefault = nullptr; - - pVarTypeList[ nEntries ].nVarType = ~RSCVAR::Pointer & nVarType; - if( pClass->Size() > 10 ) - pVarTypeList[ nEntries ].nVarType |= RSCVAR::Pointer; - - if( !(pVarTypeList[ nEntries ].nVarType & RSCVAR::NoDataInst) ) - { - if( pVarTypeList[ nEntries ].nVarType & RSCVAR::Pointer ) - { - nSize += sizeof( CLASS_DATA ); - } - else - nSize += pClass->Size(); - } - - nEntries++; - if( nEntries > (sizeof( sal_uLong ) * 8) ) - { - // range for default is too small - RscExit( 16 ); - } - return ERR_OK; -} - -RSCINST RscClass::GetVariable( const RSCINST & rInst, - Atom nVarName, - const RSCINST & rInitInst, - bool bInitDflt, - RscTop * pCreateClass) -{ - sal_uInt32 i = 0; - RSCINST aTmpI; - - while( i < nEntries && pVarTypeList[ i ].nVarName != nVarName ) - i++; - - if( i < nEntries ) - { - if( RSCVAR::NoDataInst & pVarTypeList[ i ].nVarType ) - { - aTmpI = GetVariable( rInst, - pVarTypeList[ i ].nDataBaseName, - RSCINST() ); - aTmpI.pClass = pVarTypeList[ i ].pClass; - } - else - { - // generate default instance - RSCINST aDefInst = rInitInst; - if( !aDefInst.IsInst() && bInitDflt ) - { - // set to default variables - aDefInst.pData = pVarTypeList[ i ].pDefault; - aDefInst.pClass = pVarTypeList[ i ].pClass; - } - - aTmpI = GetInstData( rInst.pData, i ); - if( aTmpI.IsInst() ) - { - if( aDefInst.IsInst() ) - { - aTmpI.pClass->Destroy( aTmpI ); - aTmpI.pClass->Create( &aTmpI, aDefInst ); - } - } - else - { // is provided via pointer - CLASS_DATA * ppData - = reinterpret_cast<CLASS_DATA *>(rInst.pData + pVarTypeList[ i ].nOffset); - aTmpI = aTmpI.pClass->Create( nullptr, aDefInst ); - *ppData = aTmpI.pData; - } - } - // set as non default - SetVarDflt( rInst.pData, i, false ); - return aTmpI; - } - - return RscTop::GetVariable( rInst, nVarName, rInitInst, - bInitDflt, pCreateClass ); -} - -RSCINST RscClass::GetCopyVar( const RSCINST & rInst, Atom nVarName) -{ - sal_uInt32 i = 0; - RSCINST aVarI; - - while( i < nEntries && pVarTypeList[ i ].nVarName != nVarName ) - i++; - - if( i < nEntries ) - { - if( RSCVAR::NoDataInst & pVarTypeList[ i ].nVarType ) - { - aVarI = GetCopyVar( rInst, pVarTypeList[ i ].nDataBaseName ); - aVarI.pClass = pVarTypeList[ i ].pClass; - } - else - { - if( IsDflt( rInst.pData, i ) ) - { - // initialize with default variables - aVarI = GetVariable( rInst, nVarName, RSCINST(), true ); - SetVarDflt( rInst.pData, i, true ); - } - else - aVarI = GetInstData( rInst.pData, i, true ); - - } - return aVarI ; - } - - return RscTop::GetCopyVar( rInst, nVarName ); -} - -bool RscClass::IsConsistent( const RSCINST & rInst ) -{ - sal_uInt32 i = 0; - RSCINST aTmpI; - bool bRet; - - bRet = RscTop::IsConsistent( rInst ); - - for( i = 0; i < nEntries; i++ ) - { - if( !(RSCVAR::NoDataInst & pVarTypeList[ i ].nVarType) ) - { - aTmpI = GetInstData( rInst.pData, i, true ); - - if( aTmpI.IsInst() ) - if( ! aTmpI.pClass->IsConsistent( aTmpI ) ) - bRet = false; - } - } - - return bRet; -} - -void RscClass::SetToDefault( const RSCINST & rInst ) -{ - sal_uInt32 i; - RSCINST aTmpI; - RscClassInst * pClass; - - pClass = reinterpret_cast<RscClassInst *>(rInst.pData + nSuperSize ); - - for( i = 0; i < nEntries; i++ ) - { - // variables without own memory are set from "data server" to default - if( !(RSCVAR::NoDataInst & pVarTypeList[ i ].nVarType) ) - { - aTmpI = GetInstData( rInst.pData, i, true ); - if( aTmpI.IsInst() ) - aTmpI.pClass->SetToDefault( aTmpI ); - } - } - pClass->nVarDflt = ~((sal_uLong)0); // set everything to default - - RscTop::SetToDefault( rInst ); -} - -bool RscClass::IsDefault( const RSCINST & rInst ) -{ - sal_uInt32 i; - RSCINST aTmpI; - - for( i = 0; i < nEntries; i++ ) - { - // variables without own memory are looked for default in "data server" - if( !(RSCVAR::NoDataInst & pVarTypeList[ i ].nVarType) ) - if( !IsDflt( rInst.pData, i ) ) - return false; - } - - return RscTop::IsDefault( rInst ); -} - -RSCINST RscClass::GetDefault( Atom nVarId ) -{ - sal_uInt32 i; - - i = 0; - while( i < nEntries && pVarTypeList[ i ].nVarName != nVarId ) - i++; - - if( i < nEntries ) - { - RSCINST aTmpI; - - aTmpI.pClass = pVarTypeList[ i ].pClass; - aTmpI.pData = GetDfltData( i ); - return aTmpI; - } - - return RscTop::GetDefault( nVarId ); -} - -bool RscClass::IsValueDflt( CLASS_DATA pData, sal_uInt32 nEle ) -{ - RSCINST aTmpI; - - aTmpI = GetInstData( pData, nEle, true ); - - if( aTmpI.IsInst() ) - { - if( RSCVAR::SvDynamic & pVarTypeList[ nEle ].nVarType ) - return false; - - if( aTmpI.pClass == pVarTypeList[ nEle ].pClass ) - // they also have the same class - return aTmpI.pClass->IsValueDefault( aTmpI, GetDfltData( nEle ) ); - else - return false; - } - return true; -} - -bool RscClass::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) -{ - RSCINST aTmpI; - RSCINST aDfltI; - - if( !RscTop::IsValueDefault( rInst, pDef ) ) - return false; - - if( pDef ) - { - for( sal_uInt32 i = 0; i < nEntries; i++ ) - { - aTmpI = GetInstData( rInst.pData, i, true ); - if( aTmpI.IsInst() ) - { - if( aTmpI.pClass != pVarTypeList[ i ].pClass ) - // they don't have the same class - return false; - - aDfltI = GetInstData( pDef, i, true ); - if( !aDfltI.IsInst() ) - aDfltI.pData = GetDfltData( i ); - - if( !aTmpI.pClass->IsValueDefault( aTmpI, aDfltI.pData ) ) - return false; - } - } - } - else - return false; - - return true; -} - -void RscClass::SetDefault( const RSCINST & rInst, Atom nVarName ) -{ - sal_uInt32 i = 0; - RSCINST aTmpI; - - while( i < nEntries && pVarTypeList[ i ].nVarName != nVarName ) - i++; - - if( i < nEntries ) - { - aTmpI = GetInstData( rInst.pData, i, true ); - if( aTmpI.IsInst() ) - { - aTmpI.pClass->Destroy( aTmpI ); - aTmpI.pClass->Create( &aTmpI, RSCINST() ); - SetVarDflt( rInst.pData, i, true ); - } - } - else // look for variable in super class - RscTop::SetDefault( rInst, nVarName ); - -} - - -void RscClass::WriteSrc( const RSCINST & rInst, - FILE * fOutput, - RscTypCont * pTC, - sal_uInt32 nTab, - const char * pVarName) -{ - sal_uInt32 i = 0, n = 0; - RSCINST aTmpI; - - RscTop::WriteSrc( rInst, fOutput, pTC, nTab, pVarName ); - - for( i = 0; i < nEntries; i++ ) - { - if( !(RSCVAR::Hidden & pVarTypeList[ i ].nVarType) ) - { - if( !IsDflt( rInst.pData, i ) && !IsValueDflt( rInst.pData, i ) ) - { - aTmpI = GetInstData( rInst.pData, i, true ); - - if( aTmpI.IsInst() ) - { - const char * pName = pHS->getString( pVarTypeList[ i ].nVarName ).getStr(); - - for( n = 0; n < nTab; n++ ) - fputc( '\t', fOutput ); - - fprintf( fOutput, "%s", pName ); - fprintf( fOutput, " = " ); - aTmpI.pClass->WriteSrcHeader( - aTmpI, fOutput, pTC, nTab, RscId(), pName ); - fprintf( fOutput, ";\n" ); - } - } - } - } - - return; -} - -ERRTYPE RscClass::WriteInstRc( const RSCINST & rInst, - RscWriteRc & rMem, - RscTypCont * pTC, - sal_uInt32 nDeep ) -{ - sal_uInt32 i = 0; - ERRTYPE aError; - RSCINST aTmpI; - sal_uInt32 nMaskOff = 0;// offset to address mask field - - // when a variable is masked, then mask field - for( i = 0; i < nEntries; i++ ) - { - if( pVarTypeList[ i ].nMask ) - { - nMaskOff = rMem.Size(); - rMem.Put( sal_uInt32(0) ); - break; - } - } - - for( i = 0; i < nEntries && aError.IsOk(); i++ ) - { - if( !((RSCVAR::NoDataInst | RSCVAR::NoRc) & pVarTypeList[ i ].nVarType )) - { - if( pVarTypeList[ i ].nMask ) - { - if( !IsDflt( rInst.pData, i ) ) - { - aTmpI = GetInstData( rInst.pData, i, true ); - aError = aTmpI.pClass-> - WriteRcHeader(aTmpI, rMem, pTC, - RscId(), nDeep); - sal_uInt32 nMask = rMem.GetLong( nMaskOff ); - nMask |= pVarTypeList[ i ].nMask; - rMem.PutAt( nMaskOff, nMask ); - } - } - else - { - if( IsDflt( rInst.pData, i ) ) - { - aTmpI.pClass = pVarTypeList[ i ].pClass; - aTmpI.pData = GetDfltData( i ); - } - else - aTmpI = GetInstData( rInst.pData, i, true ); - - aError = aTmpI.pClass-> - WriteRcHeader( aTmpI, rMem, pTC, - RscId(), nDeep ); - } - } - } - - return aError; -} - -ERRTYPE RscClass::WriteRc( const RSCINST & rInst, - RscWriteRc & rMem, - RscTypCont * pTC, - sal_uInt32 nDeep ) -{ - ERRTYPE aError; - - aError = RscTop::WriteRc(rInst, rMem, pTC, nDeep); - if( aError.IsOk() ) - aError = WriteInstRc(rInst, rMem, pTC, nDeep); - - return aError; -} - -RscTupel::RscTupel( Atom nId, RESOURCE_TYPE nTypeId ) - : RscClass( nId, nTypeId, nullptr ) -{ -} - -RSCINST RscTupel::GetTupelVar( const RSCINST & rInst, sal_uInt32 nPos, - const RSCINST & rInitInst ) -{ - if( nPos >= nEntries ) - { - return RSCINST(); - } - else - return GetVariable( rInst, pVarTypeList[ nPos ].nVarName, rInitInst ); -} - -void RscTupel::WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const char * pVarName ) -{ - sal_uInt32 i = 0; - RSCINST aTmpI; - - RscTop::WriteSrc( rInst, fOutput, pTC, nTab, pVarName ); - - fprintf( fOutput, "< " ); - for( i = 0; i < nEntries; i++ ) - { - if( !(RSCVAR::Hidden & pVarTypeList[ i ].nVarType) ) - { - if( !IsDflt( rInst.pData, i ) - && !IsValueDflt( rInst.pData, i ) ) - { - aTmpI = GetInstData( rInst.pData, i, true ); - - if( aTmpI.IsInst() ) - aTmpI.pClass->WriteSrcHeader( - aTmpI, fOutput, pTC, nTab, RscId(), pVarName ); - else - fprintf( fOutput, "Default" ); - } - else - fprintf( fOutput, "Default" ); - fprintf( fOutput, "; " ); - } - } - fprintf( fOutput, ">" ); - - return; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/res/rscclobj.cxx b/rsc/source/res/rscclobj.cxx deleted file mode 100644 index 29184286cd8d..000000000000 --- a/rsc/source/res/rscclobj.cxx +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <rscclobj.hxx> -#include <rsctop.hxx> - - -RefNode::RefNode( Atom nTyp ) - : nTypNameId(nTyp), pObjBiTree(nullptr) -{ -} - -sal_uInt32 RefNode::GetId() const -{ - return nTypNameId; -} - -// insert a node in the b-tree pObjBiTree -// if the node with the same name is in pObjBiTree, -// return sal_False and no insert, - -bool RefNode::PutObjNode( ObjNode * pPutObject ) -{ - if( pObjBiTree ) - return pObjBiTree->Insert( pPutObject ); - - pObjBiTree = pPutObject; - return true; -} - -// insert a node in the b-tree pObjBiTree -// if the node with the same name is in pObjBiTree, -// return NULL and no insert, -// if not return the pointer to the Object -ObjNode * RefNode::GetObjNode( const RscId & rRscId ) -{ - if( pObjBiTree ) - return pObjBiTree->Search( rRscId ); - return nullptr; -} - -ObjNode::ObjNode( const RscId & rId, CLASS_DATA pData, RscFileTab::Index lKey ) - : aRscId(rId) - , pRscObj(pData) - , lFileKey(lKey) -{ -} - -ObjNode * ObjNode::DelObjNode( RscTop * pClass, RscFileTab::Index nFileKey ) -{ - ObjNode * pRetNode = this; - - if( Right() ) - pRight = static_cast<ObjNode *>(Right())->DelObjNode( pClass, nFileKey ); - if( Left() ) - pLeft = static_cast<ObjNode *>(Left())->DelObjNode( pClass, nFileKey ); - - if( GetFileKey() == nFileKey ) - { - if( GetRscObj() ) - { - pClass->Destroy( RSCINST( pClass, GetRscObj() ) ); - rtl_freeMemory( GetRscObj() ); - } - pRetNode = static_cast<ObjNode *>(Right()); - if( pRetNode ) - { - if( Left() ) - pRetNode->Insert( static_cast<ObjNode *>(Left()) ); - } - else - pRetNode = static_cast<ObjNode *>(Left()); - - delete this; - } - return pRetNode; -} - -sal_uInt32 ObjNode::GetId() const -{ - return aRscId.GetNumber(); -} - -bool ObjNode::IsConsistent() -{ - bool bRet = true; - - if( aRscId.GetNumber() > 0x7FFF || aRscId.GetNumber() < 1 ) - { - bRet = false; - } - else - { - if( Left() ) - { - if( !static_cast<ObjNode *>(Left())->IsConsistent() ) - { - bRet = false; - } - if( static_cast<ObjNode *>(Left())->aRscId >= aRscId ) - { - bRet = false; - } - } - if( Right() ) - { - if( static_cast<ObjNode *>(Right())->aRscId <= aRscId ) - { - bRet = false; - } - if( !static_cast<ObjNode *>(Right())->IsConsistent() ) - { - bRet = false; - } - } - } - - return bRet; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/res/rscconst.cxx b/rsc/source/res/rscconst.cxx deleted file mode 100644 index c0161106dbea..000000000000 --- a/rsc/source/res/rscconst.cxx +++ /dev/null @@ -1,186 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <cstdlib> -#include <cstdio> -#include <cstring> - -#include <rscconst.hxx> -#include <rscall.h> -#include <rschash.hxx> -#include <tools/resid.hxx> - -RscEnum::RscEnum( Atom nId, RESOURCE_TYPE nTypeId ) - : RscTop( nId, nTypeId ) - , pVarArray(nullptr), nEntries(0) -{ -} - -RscEnum::~RscEnum() -{ - if( pVarArray ) - rtl_freeMemory( static_cast<void *>(pVarArray) ); -} - -void RscEnum::SetConstant( Atom nVarName, sal_Int32 lValue ) -{ - if( pVarArray ) - pVarArray = static_cast<VarEle *>(rtl_reallocateMemory( static_cast<void *>(pVarArray), - ((nEntries +1) * sizeof( VarEle )) )); - else - pVarArray = static_cast<VarEle *>(rtl_allocateMemory( (nEntries +1) * sizeof( VarEle ) )); - pVarArray[ nEntries ].nId = nVarName; - pVarArray[ nEntries ].lValue = lValue; - nEntries++; -} - -bool RscEnum::GetConstValue( Atom nConst, sal_Int32 * pValue ) const -{ - sal_uInt32 i = 0; - - for( i = 0; i < nEntries; i++ ) - { - if( pVarArray[ i ].nId == nConst ) - { - *pValue = pVarArray[ i ].lValue; - return true; - } - } - return false; -} - -bool RscEnum::GetValueConst( sal_Int32 lValue, Atom * pConst ) const -{ - sal_uInt32 i = 0; - - for( i = 0; i < nEntries; i++ ) - { - if( pVarArray[ i ].lValue == lValue ) - { - *pConst = pVarArray[ i ].nId; - return true; - } - } - return false; -} - -sal_uInt32 RscEnum::GetConstPos( Atom nConst ) -{ - sal_uInt32 i = 0; - - for( i = 0; i < nEntries; i++ ) - { - if( pVarArray[ i ].nId == nConst ) - return i; - } - - return nEntries; -} - -ERRTYPE RscEnum::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ ) -{ - sal_uInt32 i = 0; - - if( nEntries != (i = GetConstPos( nConst )) ) - { - reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue = i; - reinterpret_cast<RscEnumInst *>(rInst.pData)->bDflt = false; - return ERR_OK; - } - - return ERR_RSCENUM; -} - -ERRTYPE RscEnum::SetNumber( const RSCINST & rInst, sal_Int32 lValue ) -{ - sal_uInt32 i = 0; - - for( i = 0; i < nEntries; i++ ) - { - if( pVarArray[ i ].lValue == lValue ) - return SetConst( rInst, pVarArray[ i ].nId, lValue ); - } - - return ERR_RSCENUM; -} - -ERRTYPE RscEnum::GetConst( const RSCINST & rInst, Atom * pH ) -{ - *pH = pVarArray[ reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue ].nId; - return ERR_OK; -} - -ERRTYPE RscEnum::GetNumber( const RSCINST & rInst, sal_Int32 * pNumber ){ - *pNumber = pVarArray[ reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue ].lValue; - return ERR_OK; -} - -RSCINST RscEnum::Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass ) -{ - RSCINST aInst; - - if( !pInst ) - { - aInst.pClass = this; - aInst.pData = static_cast<CLASS_DATA>( - rtl_allocateMemory( sizeof( RscEnumInst ) )); - } - else - aInst = *pInst; - - if( !bOwnClass && rDflt.IsInst() ) - bOwnClass = rDflt.pClass->InHierarchy( this ); - - if( bOwnClass ) - memmove( aInst.pData, rDflt.pData, Size() ); - else - { - reinterpret_cast<RscEnumInst *>(aInst.pData)->nValue = 0; - reinterpret_cast<RscEnumInst *>(aInst.pData)->bDflt = true; - } - - return aInst; -} - -bool RscEnum::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) -{ - return pDef && (reinterpret_cast<RscEnumInst*>(rInst.pData)->nValue == reinterpret_cast<RscEnumInst*>(pDef)->nValue ); -} - -void RscEnum::WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont *, sal_uInt32, const char * ) -{ - fprintf( fOutput, "%s", - pHS->getString( pVarArray[ reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue ].nId ).getStr() ); -} - -ERRTYPE RscEnum::WriteRc( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont *, sal_uInt32 ) -{ - aMem.Put( pVarArray[ reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue ].lValue ); - return ERR_OK; -} - -RscLangEnum::RscLangEnum() - : RscEnum( pHS->getID( "LangEnum" ), RSC_NOTYPE ), - mnLangId( 0x400 ) -{ -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/res/rsccont.cxx b/rsc/source/res/rsccont.cxx deleted file mode 100644 index 60e7064efe49..000000000000 --- a/rsc/source/res/rsccont.cxx +++ /dev/null @@ -1,755 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <rsccont.hxx> - -#include <tools/rcid.h> - -void ENTRY_STRUCT::Destroy() -{ - aName.Destroy(); - if( aInst.IsInst() ) - { - aInst.pClass->Destroy( aInst ); - rtl_freeMemory( aInst.pData ); - } -} - -RscBaseCont::RscBaseCont( Atom nId, RESOURCE_TYPE nTypeId, - bool bNoIdent ) - : RscTop(nId, nTypeId, nullptr) - , pTypeClass(nullptr) - , bNoId(bNoIdent), nOffInstData(RscTop::Size()) - , nSize(nOffInstData + ALIGNED_SIZE(sizeof(RscBaseContInst))) - -{ -} - -RscBaseCont::~RscBaseCont() -{ -} - -void RscBaseCont::DestroyElements( RscBaseContInst * pClassData ) -{ - if( pClassData->nEntries ) - { - for (sal_uInt32 i = 0; i < pClassData->nEntries; i++ ) - { - pClassData->pEntries[ i ].Destroy(); - } - rtl_freeMemory( pClassData->pEntries ); - pClassData->pEntries = nullptr; - pClassData->nEntries = 0; - } -} - -RSCINST RscBaseCont::Create( RSCINST * pInst, const RSCINST & rDflt, - bool bOwnClass ) -{ - RSCINST aInst; - RscBaseContInst * pClassData; - - if( !pInst ) - { - aInst.pClass = this; - aInst.pData = static_cast<CLASS_DATA>(rtl_allocateMemory( Size() )); - } - else - aInst = *pInst; - - if( !bOwnClass && rDflt.IsInst() ) - bOwnClass = rDflt.pClass->InHierarchy( this ); - - RscTop::Create( &aInst, rDflt, bOwnClass ); - - pClassData = reinterpret_cast<RscBaseContInst *>(aInst.pData + nOffInstData); - pClassData->nEntries = 0; - pClassData->pEntries = nullptr; - pClassData->bDflt = true; - - if( bOwnClass ) - { - RscBaseContInst * pDfltClassData; - RSCINST aDfltI; - - pDfltClassData = reinterpret_cast<RscBaseContInst *>(rDflt.pData + nOffInstData); - - if( 0 != pDfltClassData->nEntries ) - { - *pClassData = *pDfltClassData; - pClassData->pEntries = - static_cast<ENTRY_STRUCT *>(rtl_allocateMemory( sizeof( ENTRY_STRUCT ) - * pClassData->nEntries )); - for (sal_uInt32 i = 0; i < pClassData->nEntries; i++ ) - { - pClassData->pEntries[ i ].Create(); - pClassData->pEntries[ i ].aName = - pDfltClassData->pEntries[ i ].aName; - aDfltI = pDfltClassData->pEntries[ i ].aInst; - pClassData->pEntries[ i ].aInst = - aDfltI.pClass->Create( nullptr, aDfltI ); - } - } - } - - return aInst; -} - -void RscBaseCont::Destroy( const RSCINST & rInst ) -{ - RscBaseContInst * pClassData; - - RscTop::Destroy( rInst); - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - DestroyElements( pClassData ); -} - -RSCINST RscBaseCont::SearchElePos( const RSCINST & rInst, const RscId & rEleName, - RscTop * pClass, sal_uInt32 nPos ) -{ - RscBaseContInst * pClassData; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - if( !pClass ) - pClass = pTypeClass; - - if( rEleName.IsId() ) - { - for (sal_uInt32 i = nPos; i < pClassData->nEntries; i++ ) - { - if( pClassData->pEntries[ i ].aName == rEleName && - pClassData->pEntries[ i ].aInst.pClass == pClass ) - { - return pClassData->pEntries[ i ].aInst; - } - } - } - return RSCINST(); -} - -RSCINST RscBaseCont::SearchEle( const RSCINST & rInst, const RscId & rEleName, - RscTop * pClass ) -{ - return SearchElePos( rInst, rEleName, pClass, 0 ); -} - -ERRTYPE RscBaseCont::GetElement( const RSCINST & rInst, const RscId & rEleName, - RscTop * pCreateClass, - const RSCINST & rCreateInst, RSCINST * pGetInst ) -{ - RscBaseContInst * pClassData; - RSCINST aTmpI; - ERRTYPE aError; - - if( !bNoId && !rEleName.IsId() ) - aError = WRN_CONT_NOID; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - if( pCreateClass ) - { - if( !pCreateClass->InHierarchy( pTypeClass ) ) - { - return ERR_CONT_INVALIDTYPE; - } - } - else - pCreateClass = pTypeClass; - - pClassData->bDflt = false; - - if( !bNoId ) - aTmpI = SearchEle( rInst, rEleName, pCreateClass ); - // entry found - if( aTmpI.IsInst() ) - { - aError = WRN_CONT_DOUBLEID; - if( rCreateInst.IsInst() ) - { - aTmpI.pClass->Destroy( aTmpI ); - aTmpI.pClass->Create( &aTmpI, rCreateInst ); - } - } - else - { - if( pClassData->pEntries ) - { - pClassData->pEntries = - static_cast<ENTRY_STRUCT *>(rtl_reallocateMemory( pClassData->pEntries, - sizeof( ENTRY_STRUCT ) * (pClassData->nEntries +1) )); - } - else - { - pClassData->pEntries = - static_cast<ENTRY_STRUCT *>(rtl_allocateMemory( sizeof( ENTRY_STRUCT ) - * (pClassData->nEntries +1) )); - } - - pClassData->pEntries[ pClassData->nEntries ].Create(); - pClassData->pEntries[ pClassData->nEntries ].aName = rEleName; - - if( rCreateInst.IsInst() ) - { - // initialize instance with CreateInst data - pClassData->pEntries[ pClassData->nEntries ].aInst = - pCreateClass->Create( nullptr, rCreateInst ); - } - else - { - pClassData->pEntries[ pClassData->nEntries ].aInst = - pCreateClass->Create( nullptr, RSCINST() ); - } - - pClassData->nEntries++; - aTmpI = pClassData->pEntries[ pClassData->nEntries -1 ].aInst; - } - - *pGetInst = aTmpI; - return aError; -} - -sal_uInt32 RscBaseCont::GetCount( const RSCINST & rInst ) -{ - RscBaseContInst * pClassData; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - return pClassData->nEntries; -} - -RSCINST RscBaseCont::GetPosEle( const RSCINST & rInst, sal_uInt32 nPos ) -{ - RscBaseContInst * pClassData; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - if( nPos < pClassData->nEntries ) - return pClassData->pEntries[ nPos ].aInst; - return RSCINST(); -} - -ERRTYPE RscBaseCont::MovePosEle( const RSCINST & rInst, sal_uInt32 nDestPos, - sal_uInt32 nSourcePos ) -{ - ERRTYPE aError; - RscBaseContInst * pClassData; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - if( (nDestPos < pClassData->nEntries) && (nSourcePos < pClassData->nEntries) ) - { - ENTRY_STRUCT aEntry; - int nInc = 1; - sal_uInt32 i = 0; - - // mark source - aEntry = pClassData->pEntries[ nSourcePos ]; - // guess direction of the for-loop - if( nDestPos < nSourcePos ) - nInc = -1; - - for( i = nSourcePos; i != nDestPos; i += nInc ) - pClassData->pEntries[ i ] = pClassData->pEntries[ i + nInc ]; - - // assign source to target - pClassData->pEntries[ nDestPos ] = aEntry; - } - else - aError = ERR_RSCCONT; - - return aError; -} - -ERRTYPE RscBaseCont::SetPosRscId( const RSCINST & rInst, sal_uInt32 nPos, - const RscId & rId ) -{ - RscBaseContInst * pClassData; - RSCINST aTmpI; - ERRTYPE aError; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - if( nPos < pClassData->nEntries ) - { - if( ! (rId == pClassData->pEntries[ nPos ].aName) ) - aTmpI = SearchEle( rInst, rId, - pClassData->pEntries[ nPos ].aInst.pClass ); - if( !aTmpI.IsInst() ) - pClassData->pEntries[ nPos ].aName = rId; - else - aError = ERR_RSCCONT; - } - else - aError = ERR_RSCCONT; - - return aError; -} - -SUBINFO_STRUCT RscBaseCont::GetInfoEle( const RSCINST & rInst, sal_uInt32 nPos ) -{ - RscBaseContInst * pClassData; - SUBINFO_STRUCT aInfo; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - if( nPos < pClassData->nEntries ) - { - aInfo.aId = pClassData->pEntries[ nPos ].aName; - } - return aInfo; -} - -ERRTYPE RscBaseCont::SetString( const RSCINST & rInst, const char * pStr ) -{ - RscBaseContInst * pClassData; - RSCINST aTmpI; - ERRTYPE aError; - char *pTmpStr; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - // otherwise infinite recursion is possible - if( RSC_NOTYPE == pTypeClass->GetTypId() ) - { - aError = GetElement( rInst, RscId(), pTypeClass, RSCINST(), &aTmpI ); - aError = aTmpI.pClass->GetString( aTmpI, &pTmpStr ); - - if( aError.IsOk() ) - aError = aTmpI.pClass->SetString( aTmpI, pStr ); - else - { - aError.Clear(); - DeletePos( rInst, pClassData->nEntries -1 ); - aError = GetElement( rInst, RscId(), nullptr, RSCINST(), &aTmpI ); - aError = aTmpI.pClass->GetString( aTmpI, &pTmpStr ); - if( aError.IsOk() ) - aError = aTmpI.pClass->SetString( aTmpI, pStr ); - } - - if( aError.IsError() ) - DeletePos( rInst, pClassData->nEntries -1 ); - } - else - aError = ERR_UNKNOWN_METHOD; - - return aError; -} - -ERRTYPE RscBaseCont::SetNumber( const RSCINST & rInst, sal_Int32 lValue ) -{ - RscBaseContInst * pClassData; - RSCINST aTmpI; - ERRTYPE aError; - sal_Int32 lNumber; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - // otherwise infinite recursion is possible - if( RSC_NOTYPE == pTypeClass->GetTypId() ) - { - aError = GetElement( rInst, RscId(), pTypeClass, RSCINST(), &aTmpI ); - aError = aTmpI.pClass->GetNumber( aTmpI, &lNumber ); - - if( aError.IsOk() ) - aError = aTmpI.pClass->SetNumber( aTmpI, lValue ); - else - { - aError.Clear(); - DeletePos( rInst, pClassData->nEntries -1 ); - aError = GetElement( rInst, RscId(), nullptr, RSCINST(), &aTmpI ); - aError = aTmpI.pClass->GetNumber( aTmpI, &lNumber ); - if( aError.IsOk() ) - aError = aTmpI.pClass->SetNumber( aTmpI, lValue ); - } - if( aError.IsError() ) - DeletePos( rInst, pClassData->nEntries -1 ); - } - else - aError = ERR_UNKNOWN_METHOD; - - return aError; -} - -ERRTYPE RscBaseCont::SetBool( const RSCINST & rInst, - bool bValue) -{ - RscBaseContInst * pClassData; - RSCINST aTmpI; - ERRTYPE aError; - bool bBool; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - // otherwise infinite recursion is possible - if( RSC_NOTYPE == pTypeClass->GetTypId() ) - { - aError = GetElement( rInst, RscId(), pTypeClass, RSCINST(), &aTmpI ); - aError = aTmpI.pClass->GetBool( aTmpI, &bBool ); - - if( aError.IsOk() ) - aError = aTmpI.pClass->SetBool( aTmpI, bValue ); - else - { - aError.Clear(); - DeletePos( rInst, pClassData->nEntries -1 ); - aError = GetElement( rInst, RscId(), nullptr, RSCINST(), &aTmpI ); - aError = aTmpI.pClass->GetBool( aTmpI, &bBool ); - if( aError.IsOk() ) - aError = aTmpI.pClass->SetBool( aTmpI, bValue ); - } - - if( aError.IsError() ) - DeletePos( rInst, pClassData->nEntries -1 ); - } - else - aError = ERR_UNKNOWN_METHOD; - - return aError; -} - -ERRTYPE RscBaseCont::SetConst( const RSCINST & rInst, - Atom nValueId, - sal_Int32 lValue) -{ - RscBaseContInst * pClassData; - RSCINST aTmpI; - ERRTYPE aError; - Atom nConst; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - // otherwise infinite recursion is possible - if( RSC_NOTYPE == pTypeClass->GetTypId() ) - { - aError = GetElement( rInst, RscId(), pTypeClass, RSCINST(), &aTmpI ); - aError = aTmpI.pClass->GetConst( aTmpI, &nConst ); - - if( aError.IsOk() ) - aError = aTmpI.pClass->SetConst( aTmpI, nValueId, lValue ); - else - { - aError.Clear(); - DeletePos( rInst, pClassData->nEntries -1 ); - aError = GetElement( rInst, RscId(), nullptr, RSCINST(), &aTmpI ); - aError = aTmpI.pClass->GetConst( aTmpI, &nConst ); - if( aError.IsOk() ) - aError = aTmpI.pClass->SetConst( aTmpI, nValueId, lValue ); - } - - if( aError.IsError() ) - DeletePos( rInst, pClassData->nEntries -1 ); - } - else - aError = ERR_UNKNOWN_METHOD; - - return aError; -} - -ERRTYPE RscBaseCont::SetRef( const RSCINST & rInst, const RscId & rRefId ) -{ - RscBaseContInst * pClassData; - RSCINST aTmpI; - ERRTYPE aError; - RscId aId; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - // otherwise infinite recursion is possible - if( RSC_NOTYPE == pTypeClass->GetTypId() ) - { - aError = GetElement( rInst, RscId(), pTypeClass, RSCINST(), &aTmpI ); - aError = aTmpI.pClass->GetRef( aTmpI, &aId ); - - if( aError.IsOk() ) - aError = aTmpI.pClass->SetRef( aTmpI, rRefId ); - else - { - aError.Clear(); - DeletePos( rInst, pClassData->nEntries -1 ); - aError = GetElement( rInst, RscId(), nullptr, RSCINST(), &aTmpI ); - aError = aTmpI.pClass->GetRef( aTmpI, &aId ); - if( aError.IsOk() ) - aError = aTmpI.pClass->SetNumber( aTmpI, rRefId.GetNumber() ); - } - - if( aError.IsError() ) - DeletePos( rInst, pClassData->nEntries -1 ); - } - else - aError = ERR_UNKNOWN_METHOD; - - return aError; -} - -bool RscBaseCont::IsConsistent( const RSCINST & rInst ) -{ - sal_uInt32 i = 0; - RscBaseContInst * pClassData; - bool bRet; - - bRet = RscTop::IsConsistent( rInst ); - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - // check for duplicate Id and keep order - // complexity = n^2 / 2 - for( i = 0; i < pClassData->nEntries; i++ ) - { - if( !bNoId ) - { - if( pClassData->pEntries[ i ].aName.GetNumber() > 0x7FFF || - pClassData->pEntries[ i ].aName.GetNumber() < 1 ) - { - bRet = false; - } - else if( SearchElePos( rInst, pClassData->pEntries[ i ].aName, - pClassData->pEntries[ i ].aInst.pClass, i +1 ).IsInst() ) - { - bRet = false; - } - } - if( ! pClassData->pEntries[ i ].aInst.pClass-> - IsConsistent( pClassData->pEntries[ i ].aInst ) ) - { - bRet = false; - } - } - - return bRet; -} - -void RscBaseCont::SetToDefault( const RSCINST & rInst ) -{ - sal_uInt32 i = 0; - RscBaseContInst * pClassData; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - for( i = 0; i < pClassData->nEntries; i++ ) - { - pClassData->pEntries[ i ].aInst.pClass-> - SetToDefault( pClassData->pEntries[ i ].aInst ); - } - - RscTop::SetToDefault( rInst ); -} - -bool RscBaseCont::IsDefault( const RSCINST & rInst ) -{ - sal_uInt32 i = 0; - RscBaseContInst * pClassData; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - if( !pClassData->bDflt ) - return false; - - for( i = 0; i < pClassData->nEntries; i++ ) - { - if( ! pClassData->pEntries[ i ].aInst.pClass-> - IsDefault( pClassData->pEntries[ i ].aInst ) ) - { - return false; - } - } - - return RscTop::IsDefault( rInst ); -} - -bool RscBaseCont::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) -{ - RscBaseContInst * pClassData; - - if( !RscTop::IsValueDefault( rInst, pDef ) ) - return false; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - if( pClassData->nEntries ) - return false; - else - return true; -} - -void RscBaseCont::Delete( const RSCINST & rInst, RscTop * pClass, - const RscId & rId ) -{ - sal_uInt32 i = 0; - RscBaseContInst * pClassData; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - if( !pClass ) - pClass = pTypeClass; - - for( i = 0; i < pClassData->nEntries; i++ ) - { - if( pClassData->pEntries[ i ].aName == rId ) - { - if( pClassData->pEntries[ i ].aInst.pClass == pClass || !pClass ) - { - DeletePos( rInst, i ); - return; - } - } - } - -} - -void RscBaseCont::DeletePos( const RSCINST & rInst, sal_uInt32 nPos ) -{ - RscBaseContInst * pClassData; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - if( nPos < pClassData->nEntries ) - { - if( 1 == pClassData->nEntries ) - DestroyElements( pClassData ); - else - { - pClassData->pEntries[ nPos ].Destroy(); - pClassData->nEntries--; - - for (sal_uInt32 i = nPos; i < pClassData->nEntries; i++ ) - pClassData->pEntries[ i ] = pClassData->pEntries[ i + 1 ]; - - } - } -} - -void RscBaseCont::ContWriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const char * pVarName ) -{ - sal_uInt32 i = 0, t = 0; - RscBaseContInst * pClassData; - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - for( i = 0; i < pClassData->nEntries; i++ ) - { - for( t = 0; t < nTab; t++ ) - fputc( '\t', fOutput ); - - pClassData->pEntries[ i ].aInst.pClass-> - WriteSrcHeader( pClassData->pEntries[ i ].aInst, - fOutput, pTC, nTab, - pClassData->pEntries[ i ].aName, pVarName ); - fprintf( fOutput, ";\n" ); - } -} - -ERRTYPE RscBaseCont::ContWriteRc( const RSCINST & rInst, RscWriteRc & rMem, - RscTypCont * pTC, sal_uInt32 nDeep ) -{ - RscBaseContInst * pClassData; - ERRTYPE aError; - - if( bNoId ) - { - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - for (sal_uInt32 i = 0; i < pClassData->nEntries && aError.IsOk(); i++ ) - { - aError = pClassData->pEntries[ i ].aInst.pClass-> - WriteRcHeader( pClassData->pEntries[ i ].aInst, - rMem, pTC, - pClassData->pEntries[ i ].aName, - nDeep ); - } - } - - return aError ; -} - -void RscBaseCont::WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const char * pVarName ) -{ - RscTop::WriteSrc( rInst, fOutput, pTC, nTab, pVarName ); - ContWriteSrc( rInst, fOutput, pTC, nTab, pVarName ); -} - -ERRTYPE RscBaseCont::WriteRc( const RSCINST & rInst, RscWriteRc & rMem, - RscTypCont * pTC, sal_uInt32 nDeep ) -{ - ERRTYPE aError; - - aError = RscTop::WriteRc( rInst, rMem, pTC, nDeep ); - if( aError.IsOk() ) - aError = ContWriteRc( rInst, rMem, pTC, nDeep ); - - return aError; -} - -RscContWriteSrc::RscContWriteSrc( Atom nId, RESOURCE_TYPE nTypeId ) - : RscBaseCont( nId, nTypeId, true ) -{ -} - -void RscContWriteSrc::WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const char * pVarName ) -{ - sal_uInt32 i; - - RscTop::WriteSrc( rInst, fOutput, pTC, nTab, pVarName ); - - fprintf( fOutput, "\n" ); - for( i = 0; i < nTab; i++ ) - fputc( '\t', fOutput ); - - fprintf( fOutput, "{\n" ); - - ContWriteSrc( rInst, fOutput, pTC, nTab +1, pVarName ); - - for( i = 0; i < nTab; i++ ) - fputc( '\t', fOutput ); - - fprintf( fOutput, "}" ); -} - -RscCont::RscCont( Atom nId, RESOURCE_TYPE nTypeId ) - : RscContWriteSrc( nId, nTypeId ) -{ -} - -ERRTYPE RscCont::WriteRc( const RSCINST & rInst, RscWriteRc & rMem, - RscTypCont * pTC, sal_uInt32 nDeep ) -{ - RscBaseContInst * pClassData; - ERRTYPE aError; - - aError = RscTop::WriteRc( rInst, rMem, pTC, nDeep ); - - pClassData = reinterpret_cast<RscBaseContInst *>(rInst.pData + nOffInstData); - - rMem.Put( pClassData->nEntries ); - - if( aError.IsOk() ) - aError = ContWriteRc( rInst, rMem, pTC, nDeep ); - - return aError; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/res/rscmgr.cxx b/rsc/source/res/rscmgr.cxx deleted file mode 100644 index 6c0b1441d042..000000000000 --- a/rsc/source/res/rscmgr.cxx +++ /dev/null @@ -1,346 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <rscmgr.hxx> -#include <rscdb.hxx> - -RscMgr::RscMgr( Atom nId, RESOURCE_TYPE nTypeId, RscTop * pSuperCl ) - : RscClass( nId, nTypeId, pSuperCl ) -{ -} - -sal_uInt32 RscMgr::Size() const -{ - return RscClass::Size() + ALIGNED_SIZE( sizeof( RscMgrInst ) ); -} - -RSCINST RscMgr::Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass ) -{ - RSCINST aInst; - RscMgrInst * pClassData; - - if( !pInst ) - { - aInst.pClass = this; - aInst.pData = static_cast<CLASS_DATA>(rtl_allocateMemory( Size() )); - } - else - aInst = *pInst; - - if( !bOwnClass && rDflt.IsInst() ) - bOwnClass = rDflt.pClass->InHierarchy( this ); - - RscClass::Create( &aInst, rDflt, bOwnClass ); - - pClassData = reinterpret_cast<RscMgrInst *>(aInst.pData + RscClass::Size() ); - pClassData->Create(); - - if( bOwnClass ) - { - RscMgrInst * pDfltData = reinterpret_cast<RscMgrInst *>(rDflt.pData + RscClass::Size()); - *pClassData = *pDfltData; - } - - return aInst; -} - -void RscMgr::Destroy( const RSCINST & rInst ) -{ - RscMgrInst * pClassData; - - RscClass::Destroy( rInst ); - - pClassData = reinterpret_cast<RscMgrInst *>(rInst.pData + RscClass::Size()); - pClassData->Destroy(); -} - -void RscMgr::SetToDefault( const RSCINST & rInst ) -{ - RscMgrInst * pClassData; - - pClassData = reinterpret_cast<RscMgrInst *>(rInst.pData + RscClass::Size()); - pClassData->bDflt = true; - - RscClass::SetToDefault( rInst ); -} - -bool RscMgr::IsDefault( const RSCINST & rInst ) -{ - RscMgrInst * pClassData; - - pClassData = reinterpret_cast<RscMgrInst *>(rInst.pData + RscClass::Size()); - if( !pClassData->bDflt ) - return false; - - return RscClass::IsDefault( rInst ); -} - -bool RscMgr::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) -{ - if( !RscClass::IsValueDefault( rInst, pDef ) ) - return false; - - if( pDef ) - { - RscMgrInst * pClassData = reinterpret_cast<RscMgrInst *>(rInst.pData + RscClass::Size()); - RscMgrInst * pDfltData = reinterpret_cast<RscMgrInst *>(pDef + RscClass::Size()); - - if( !pClassData->aRefId.IsId() && !pDfltData->aRefId.IsId() ) - { - return true; - } - } - - return false; -} - - -void RscMgr::WriteSrcHeader( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const RscId & rId, const char * pVarName ) -{ - RscMgrInst * pClassData; - sal_uInt32 i; - - pClassData = reinterpret_cast<RscMgrInst *>(rInst.pData + RscClass::Size()); - - fprintf( fOutput, "%s %s", - pHS->getString( rInst.pClass->GetId() ).getStr(), - (rId.GetName()).getStr() ); - - if( pClassData->aRefId.IsId() ) - fprintf( fOutput, ",%s", pClassData->aRefId.GetName().getStr() ); - else - { - fprintf( fOutput, "\n" ); - for( i = 0; i < nTab; i++ ) - fputc( '\t', fOutput ); - - fprintf( fOutput, "{\n" ); - - rInst.pClass->WriteSrc( rInst, fOutput, pTC, nTab +1, pVarName ); - - RscClass::WriteSrc( rInst, fOutput, pTC, nTab +1, pVarName); - - for( i = 0; i < nTab; i++ ) - fputc( '\t', fOutput ); - - fprintf( fOutput, "}" ); - } -} - -void RscMgr::WriteSrc( const RSCINST &, FILE *, RscTypCont *, sal_uInt32, - const char * ) -{ -} - -ERRTYPE RscMgr::WriteRcHeader( const RSCINST & rInst, RscWriteRc & rMem, - RscTypCont * pTC, const RscId &rId, - sal_uInt32 nDeep ) -{ - RscMgrInst * pClassData; - ERRTYPE aError; - ObjNode * pObjNode = nullptr; - - pClassData = reinterpret_cast<RscMgrInst *>(rInst.pData + RscClass::Size()); - - if( pClassData->aRefId.IsId() ) - { - // increment and test to avoid endless recursion - nDeep++; - if( nDeep > nRefDeep ) - aError = ERR_REFTODEEP; - else - pObjNode = rInst.pClass->GetRefClass()-> - GetObjNode( pClassData->aRefId ); - - if( !pObjNode && pTC ) - { - OStringBuffer aMsg(pHS->getString(rInst.pClass->GetId())); - aMsg.append(' ').append(pClassData->aRefId.GetName()); - aError = WRN_MGR_REFNOTFOUND; - pTC->pEH->Error(aError, rInst.pClass, rId, aMsg.getStr()); - } - } - - if( aError.IsOk() ) - { - if( pObjNode ) - { - RSCINST aRefI; - RscTop * pTmpRefClass = rInst.pClass->GetRefClass(); - - aRefI = RSCINST( rInst.pClass, pObjNode->GetRscObj() ); - if( pTmpRefClass == rInst.pClass ) - { - aError = aRefI.pClass->WriteRcHeader( aRefI, rMem, pTC, - rId, nDeep ); - } - else - { - RSCINST aRefInst = rInst.pClass->Create( nullptr, aRefI ); - aError = aRefI.pClass->WriteRcHeader( aRefInst, rMem, pTC, - rId, nDeep ); - pTmpRefClass->Destroy( aRefInst ); - } - } - else - { - sal_uInt32 nOldSize; - sal_uInt32 nLocalSize; - - nOldSize = rMem.IncSize( 16 /*sizeof( RSHEADER_TYPE )*/ ); - - aError = rInst.pClass->WriteRc( rInst, rMem, pTC, nDeep ); - if( aError.IsOk() ) - aError = WriteInstRc( rInst, rMem, pTC, nDeep ); - nLocalSize = rMem.Size(); - - if( aError.IsOk() ) - { - // RscClass is skipped - aError = RscTop::WriteRc( rInst, rMem, pTC, nDeep ); - } - - /* - // structure definition from which the resource is built - struct RSHEADER_TYPE{ - RESOURCE_TYPE nRT; // resource type - sal_uInt32 nRT; // resource type - sal_uInt32 nGlobOff; // global offset - sal_uInt32 nLocalOff; // local offset - }; - */ - sal_uInt32 nID = rId.GetNumber(); - rMem.PutAt( nOldSize, nID ); - rMem.PutAt( nOldSize +4, (sal_uInt32)rInst.pClass->GetTypId() ); - rMem.PutAt( nOldSize +8, (sal_uInt32)(rMem.Size() - nOldSize) ); - rMem.PutAt( nOldSize +12, (sal_uInt32)(nLocalSize - nOldSize) ); - } - } - - return aError; -} - -ERRTYPE RscMgr::WriteRc( const RSCINST &, RscWriteRc &, - RscTypCont *, sal_uInt32 ) - -{ - return ERR_OK; -} - -bool RscMgr::IsConsistent( const RSCINST & rInst ) -{ - bool bRet; - RscMgrInst * pClassData; - - bRet = RscClass::IsConsistent( rInst ); - - pClassData = reinterpret_cast<RscMgrInst *>(rInst.pData + RscClass::Size()); - if( pClassData->aRefId.IsId() && - ((pClassData->aRefId.GetNumber() < 1) || - (pClassData->aRefId.GetNumber() > 0x7FFF) || - IsToDeep( rInst ).IsError()) ) - { - bRet = false; - } - - return bRet; -} - -ERRTYPE RscMgr::GetRef( const RSCINST & rInst, RscId * pRscId ) -{ - RscMgrInst * pClassData; - - pClassData = reinterpret_cast<RscMgrInst *>(rInst.pData + RscClass::Size()); - *pRscId = pClassData->aRefId; - return ERR_OK; -} - -ERRTYPE RscMgr::IsToDeep( const RSCINST & rInst ) -{ - RscMgrInst * pClassData; - RscId aOldId, aId; - ERRTYPE aError; - RSCINST aTmpI = rInst; - ObjNode * pObjNode; - sal_uInt32 nDeep = 0; - - pClassData = reinterpret_cast<RscMgrInst *>(rInst.pData + RscClass::Size()); - - while( aTmpI.IsInst() && (nDeep < nRefDeep) && aError.IsOk() ) - { - // retrieve reference - aTmpI.pClass->GetRef( aTmpI, &aId ); - // retrieve referenced object - pObjNode = aTmpI.pClass->GetObjNode( aId ); - // was the referenced object found? - if( pObjNode ) - { - aTmpI.pData = pObjNode->GetRscObj(); - nDeep++; - } - else //aTmpI.IsInst() becomes false, end loop - aTmpI.pData = nullptr; - } - - if( nDeep >= nRefDeep ) - { - pClassData->aRefId = aOldId; - aError = ERR_REFTODEEP; - } - - return aError; -} - -ERRTYPE RscMgr::SetRef( const RSCINST & rInst, const RscId & rRefId ) -{ - RscMgrInst * pClassData; - RscId aOldId, aId; - ERRTYPE aError; - - if( rRefId.IsId() && - ((rRefId.GetNumber() < 1) || - (rRefId.GetNumber() > 0x7FFF)) ) - { - aError = ERR_IDRANGE; - } - else - { - pClassData = reinterpret_cast<RscMgrInst *>(rInst.pData + RscClass::Size()); - aOldId = pClassData->aRefId;// mark old value - pClassData->aRefId = rRefId;// previous entry to avoid failure when recursing - - - aError = IsToDeep( rInst ); - if( aError.IsOk() ) - pClassData->bDflt = false; - else - pClassData->aRefId = aOldId; - } - - return aError; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/res/rscrange.cxx b/rsc/source/res/rscrange.cxx deleted file mode 100644 index db7957d07644..000000000000 --- a/rsc/source/res/rscrange.cxx +++ /dev/null @@ -1,139 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <rscrange.hxx> - -RscLongRange::RscLongRange( Atom nId, RESOURCE_TYPE nTypeId ) - : RscTop( nId, nTypeId ) - , nMin(0), nMax(0) -{ -} - -void RscLongRange::SetRange( sal_Int32 nMinimum, sal_Int32 nMaximum ) -{ - if( nMinimum > nMaximum ) - { - nMin = nMaximum; - nMax = nMinimum; - } - else - { - nMax = nMaximum; - nMin = nMinimum; - } -} - -bool RscLongRange::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) -{ - if( pDef ) - return 0 == memcmp( &reinterpret_cast<RscLongRangeInst*>(rInst.pData)->nValue, - &reinterpret_cast<RscLongRangeInst*>(pDef)->nValue, - sizeof( sal_Int32 ) ); - - return false; -} - -ERRTYPE RscLongRange::SetNumber( const RSCINST & rInst, sal_Int32 nValue ) -{ - if( nMax < nValue || nMin > nValue ) - return ERR_RSCRANGE_OUTDEFSET; - - void * pData = &reinterpret_cast<RscLongRangeInst*>(rInst.pData)->nValue; - memcpy( pData, &nValue, sizeof( sal_Int32 ) ); - reinterpret_cast<RscLongRangeInst *>(rInst.pData)->bDflt = false; - return ERR_OK; -} - -ERRTYPE RscLongRange::GetNumber( const RSCINST & rInst, sal_Int32 * pN ) -{ - memmove( pN, &reinterpret_cast<RscLongRangeInst*>(rInst.pData)->nValue, - sizeof( sal_Int32 ) ); - return ERR_OK; -} - -RSCINST RscLongRange::Create( RSCINST * pInst, const RSCINST & rDflt, - bool bOwnClass ) -{ - RSCINST aInst; - - if( !pInst ) - { - aInst.pClass = this; - aInst.pData = static_cast<CLASS_DATA>(rtl_allocateMemory( sizeof( RscLongRangeInst ) )); - } - else - aInst = *pInst; - - if( !bOwnClass && rDflt.IsInst() ) - bOwnClass = rDflt.pClass->InHierarchy( this ); - - if( bOwnClass ) - memmove( aInst.pData, rDflt.pData, sizeof( RscLongRangeInst ) ); - else - { - sal_Int32 lDflt; - if( 0 >= nMin && 0 <= nMax ) - lDflt = 0; - else - lDflt = nMin; - - void * pData = &reinterpret_cast<RscLongRangeInst*>(aInst.pData)->nValue; - memcpy( pData, &lDflt, sizeof( sal_Int32 ) ); - reinterpret_cast<RscLongRangeInst *>(aInst.pData)->bDflt = true; - } - - return aInst; -} - -void RscLongRange::WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont *, sal_uInt32, const char * ) -{ - sal_Int32 lVal; - GetNumber( rInst, &lVal ); - fprintf( fOutput, "%d", static_cast<int>(lVal) ); -} - -ERRTYPE RscLongRange::WriteRc( const RSCINST & rInst, RscWriteRc & aMem, - RscTypCont *, sal_uInt32 ) -{ - sal_Int32 lVal; - - GetNumber( rInst, &lVal ); - aMem.Put( lVal ); - - return ERR_OK; -} - -RscLongEnumRange::RscLongEnumRange( Atom nId, RESOURCE_TYPE nTypeId ) - : RscLongRange( nId, nTypeId ) -{ -} - -ERRTYPE RscLongEnumRange::SetConst( const RSCINST & rInst, Atom /*nConst*/, - sal_Int32 nValue ) -{ - return SetNumber( rInst, nValue ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/res/rscstr.cxx b/rsc/source/res/rscstr.cxx deleted file mode 100644 index 918fb5ab1afb..000000000000 --- a/rsc/source/res/rscstr.cxx +++ /dev/null @@ -1,293 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <rscdb.hxx> -#include <rscstr.hxx> - -#include <rtl/textcvt.h> -#include <rtl/textenc.h> - -RscString::RscString( Atom nId, RESOURCE_TYPE nTypeId ) - : RscTop( nId, nTypeId ) - , pRefClass(nullptr) -{ -} - -ERRTYPE RscString::SetString( const RSCINST & rInst, const char * pStr ) -{ - char * pTmp; - ERRTYPE aError; - - if( aError.IsOk() ) - { - reinterpret_cast<RscStringInst *>(rInst.pData)->bDflt = false; - - pTmp = reinterpret_cast<RscStringInst *>(rInst.pData)->pStr; - if( pTmp ) - { - rtl_freeMemory( pTmp ); - pTmp = nullptr; - } - - if( pStr ) - { - sal_uInt32 nLen = strlen( pStr ) +1; - pTmp = static_cast<char *>(rtl_allocateMemory( nLen )); - memcpy( pTmp, pStr, nLen ); - } - - reinterpret_cast<RscStringInst *>(rInst.pData)->pStr = pTmp; - } - - return aError; -} - -ERRTYPE RscString::GetString( const RSCINST & rInst, char ** ppStr ) -{ - *ppStr = reinterpret_cast<RscStringInst *>(rInst.pData)->pStr; - return ERR_OK; -} - -ERRTYPE RscString::GetRef( const RSCINST & rInst, RscId * pRscId ) -{ - *pRscId = reinterpret_cast<RscStringInst *>(rInst.pData)->aRefId; - return ERR_OK; -} - -ERRTYPE RscString::SetRef( const RSCINST & rInst, const RscId & rRefId ) -{ - if( pRefClass ) - { - reinterpret_cast<RscStringInst *>(rInst.pData)->aRefId = rRefId; - reinterpret_cast<RscStringInst *>(rInst.pData)->bDflt = false; - } - else - return ERR_REFNOTALLOWED; - - return ERR_OK; -} - -RSCINST RscString::Create( RSCINST * pInst, const RSCINST & rDflt, - bool bOwnClass ) -{ - RSCINST aInst; - - if( !pInst ) - { - aInst.pClass = this; - aInst.pData = static_cast<CLASS_DATA>( - rtl_allocateMemory( sizeof( RscStringInst ) )); - } - else - aInst = *pInst; - - if( !bOwnClass && rDflt.IsInst() ) - bOwnClass = rDflt.pClass->InHierarchy( this ); - - reinterpret_cast<RscStringInst *>(aInst.pData)->aRefId.Create(); - reinterpret_cast<RscStringInst *>(aInst.pData)->pStr = nullptr; - reinterpret_cast<RscStringInst *>(aInst.pData)->bDflt = true; - - if( bOwnClass ) - { - reinterpret_cast<RscStringInst *>(aInst.pData)->aRefId = - reinterpret_cast<RscStringInst *>(rDflt.pData)->aRefId; - SetString( aInst, reinterpret_cast<RscStringInst *>(rDflt.pData)->pStr ); - reinterpret_cast<RscStringInst *>(aInst.pData)->bDflt = - reinterpret_cast<RscStringInst *>(rDflt.pData)->bDflt; - } - - return aInst; -} - -void RscString::Destroy( const RSCINST & rInst ) -{ - if( reinterpret_cast<RscStringInst *>(rInst.pData)->pStr ) - rtl_freeMemory( reinterpret_cast<RscStringInst *>(rInst.pData)->pStr ); - reinterpret_cast<RscStringInst *>(rInst.pData)->aRefId.Destroy(); -} - -bool RscString::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) -{ - RscStringInst * pData = reinterpret_cast<RscStringInst*>(rInst.pData); - RscStringInst * pDefData = reinterpret_cast<RscStringInst*>(pDef); - - if( pDef ) - { - if( pData->aRefId.IsId() || pDefData->aRefId.IsId() ) - { - if( pData->aRefId.aExp.IsNumber() && - pDefData->aRefId.aExp.IsNumber() ) - { - // check whether reference identifiers are equal - if( pData->aRefId.GetNumber() == pDefData->aRefId.GetNumber() ) - { - return true; - } - } - } - else - { - bool bStrEmpty = false; - bool bDefStrEmpty = false; - - if( pData->pStr ) - { - bStrEmpty = ('\0' == *pData->pStr); - } - else - bStrEmpty = true; - - if( pDefData->pStr ) - { - bDefStrEmpty = ('\0' == *pDefData->pStr); - } - else - bDefStrEmpty = true; - - if( !bStrEmpty || !bDefStrEmpty ) - { - return false; - } - return true; - } - } - - return false; -} - -void RscString::WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont *, sal_uInt32, const char * ) -{ - if ( reinterpret_cast<RscStringInst *>(rInst.pData)->aRefId.IsId() ) - { - fprintf( fOutput, "%s", - reinterpret_cast<RscStringInst *>(rInst.pData)->aRefId.GetName().getStr() ); - } - else - { - RscStringInst * pStrI = reinterpret_cast<RscStringInst *>(rInst.pData); - if( pStrI->pStr ){ - //char * pChangeTab = RscChar::GetChangeTab(); - sal_uInt32 n = 0; - sal_uInt32 nPos, nSlashPos; - - do - { - fputc( '\"', fOutput ); - nSlashPos = nPos = 0; - - while( pStrI->pStr[ n ] && (nPos < 72 || nPos - nSlashPos <= 3) ) - { // after \ drop at least 3 characters \xa7 - fputc( pStrI->pStr[ n ], fOutput ); - if( pStrI->pStr[ n ] == '\\' ) - nSlashPos = nPos; - n++; - nPos++; - } - - fputc( '\"', fOutput ); - if( pStrI->pStr[ n ] ) // end not reached yet - { - fputc( '\n', fOutput ); - } - } - while( pStrI->pStr[ n ] ); - } - else - fprintf( fOutput, "\"\"" ); - } -} - -ERRTYPE RscString::WriteRc( const RSCINST & rInst, RscWriteRc & rMem, - RscTypCont * pTC, sal_uInt32 nDeep ) -{ - ERRTYPE aError; - ObjNode * pObjNode = nullptr; - - - if( reinterpret_cast<RscStringInst *>(rInst.pData)->aRefId.IsId() ) - { - RscId aId( reinterpret_cast<RscStringInst *>(rInst.pData)->aRefId ); - RSCINST aTmpI; - - aTmpI.pClass = pRefClass; - - while( aError.IsOk() && aId.IsId() ) - { - // increment and test to avoid endless recursion - nDeep++; - if( nDeep > nRefDeep ) - aError = ERR_REFTODEEP; - else - { - pObjNode = pRefClass->GetObjNode( aId ); - if( pObjNode ) - { - aTmpI.pData = pObjNode->GetRscObj(); - aError = pRefClass->GetRef( aTmpI, &aId ); - } - else - { - if( pTC ) - { - OStringBuffer aMsg(pHS->getString( - pRefClass->GetId())); - aMsg.append(' ').append(aId.GetName()); - aError = WRN_STR_REFNOTFOUND; - pTC->pEH->Error( aError, rInst.pClass, - RscId(), aMsg.getStr() ); - } - break; - } - } - } - } - - if( aError.IsOk() ) - { - if( pObjNode ) - { - RSCINST aRefI; - - aRefI = RSCINST( pRefClass, pObjNode->GetRscObj() ); - aError = aRefI.pClass->WriteRc( aRefI, rMem, pTC, nDeep ); - } - else - { - if( reinterpret_cast<RscStringInst *>(rInst.pData)->pStr && pTC ) - { - char * pStr = RscChar::MakeUTF8( reinterpret_cast<RscStringInst *>(rInst.pData)->pStr, - pTC->GetSourceCharSet() ); - rMem.PutUTF8( pStr ); - rtl_freeMemory( pStr ); - } - else - rMem.PutUTF8( reinterpret_cast<RscStringInst *>(rInst.pData)->pStr ); - } - } - return aError; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/res/rsctop.cxx b/rsc/source/res/rsctop.cxx deleted file mode 100644 index adc61de5a086..000000000000 --- a/rsc/source/res/rsctop.cxx +++ /dev/null @@ -1,410 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdio.h> -#include <string.h> -#include <rsctop.hxx> - -RscTop::RscTop( Atom nId, RESOURCE_TYPE nTypIdent, RscTop * pSuperCl ) - : RefNode( nId ) - , pSuperClass( pSuperCl ) - , nTypId( nTypIdent ) -{ - pRefClass = this; - if( pSuperClass ) - SetCallPar( pSuperClass->aCallPar1, pSuperClass->aCallPar2, - pSuperClass->aCallParType ); -} - -void RscTop::SetCallPar(const OString& rPar1, const OString& rPar2, - const OString& rParType) -{ - aCallPar1 = rPar1; - aCallPar2 = rPar2; - aCallParType = rParType; -} - -RSCINST const & RscTop::GetDefault() -{ - if( !aDfltInst.IsInst() ) - aDfltInst = this->Create( nullptr, RSCINST() ); - return aDfltInst; -} - -void RscTop::Pre_dtor() -{ - if( aDfltInst.IsInst() ) - { - aDfltInst.pClass->Destroy( aDfltInst ); - rtl_freeMemory( aDfltInst.pData ); - aDfltInst = RSCINST(); - }; -} - -RscTop * RscTop::GetTypeClass() const -{ - if( pSuperClass ) - return pSuperClass->GetTypeClass(); - else - return nullptr; -} - -sal_uInt32 RscTop::Size() const -{ - if( pSuperClass ) - return pSuperClass->Size(); - else - return 0; -} - -ERRTYPE RscTop::GetRef( const RSCINST & rInst, RscId * pRscId ) -{ - if( pSuperClass ) - return pSuperClass->GetRef( rInst, pRscId ); - else - return ERR_UNKNOWN_METHOD; -} - -bool RscTop::InHierarchy( RscTop * pClass ) -{ - if( this == pClass ) - return true; - if( pSuperClass ) - return pSuperClass->InHierarchy( pClass ); - return false; -} - -ERRTYPE RscTop::SetVariable( Atom nVarName, RscTop * pClass, - RSCINST * pDflt, RSCVAR nVarType, sal_uInt32 nMask, - Atom nDataBaseName ) -{ - if( pSuperClass ) - return pSuperClass->SetVariable( nVarName, pClass, pDflt, - nVarType, nMask, nDataBaseName ); - else - return ERR_UNKNOWN_METHOD; -} - -RSCINST RscTop::GetVariable( const RSCINST & rInst, - Atom nVarName, - const RSCINST & rInitInst, - bool bInitDflt, - RscTop * pCreateClass) -{ - if( pSuperClass ) - return pSuperClass->GetVariable( rInst, nVarName, rInitInst, bInitDflt, pCreateClass ); - else - return RSCINST(); -} - -RSCINST RscTop::GetCopyVar( const RSCINST & rInst, Atom nVarName ) -{ - if( pSuperClass ) - return pSuperClass->GetCopyVar( rInst, nVarName ); - else - return RSCINST(); -} - -RSCINST RscTop::GetTupelVar( const RSCINST & rInst, sal_uInt32 nPos, - const RSCINST & rInitInst ) -{ - if( pSuperClass ) - return pSuperClass->GetTupelVar( rInst, nPos, rInitInst ); - else - return RSCINST(); -} - -ERRTYPE RscTop::GetElement( const RSCINST & rInst, const RscId & rEleName, - RscTop *pCreateClass, const RSCINST & rCreateInst, - RSCINST * pGetInst ) -{ - if( pSuperClass ) - return pSuperClass-> GetElement( rInst, rEleName, - pCreateClass, rCreateInst, - pGetInst ); - else - return ERR_UNKNOWN_METHOD; -} - -ERRTYPE RscTop::GetArrayEle( const RSCINST & rInst, - Atom nId, - RscTop * pCreateClass, - RSCINST * pGetInst) -{ - if( pSuperClass ) - return pSuperClass->GetArrayEle( rInst, nId, pCreateClass, pGetInst ); - else - return ERR_UNKNOWN_METHOD; -} - -ERRTYPE RscTop::GetValueEle( const RSCINST & rInst, - sal_Int32 lValue, - RscTop * pCreateClass, - RSCINST * pGetInst) -{ - if( pSuperClass ) - return pSuperClass->GetValueEle( rInst, lValue, pCreateClass, pGetInst ); - else - return ERR_UNKNOWN_METHOD; -} - -RSCINST RscTop::SearchEle( const RSCINST & rInst, const RscId & rEleName, - RscTop * pClass ) -{ - if( pSuperClass ) - return pSuperClass->SearchEle( rInst, rEleName, pClass ); - else - return RSCINST(); -} - -RSCINST RscTop::GetPosEle( const RSCINST & rInst, sal_uInt32 nPos ) -{ - if( pSuperClass ) - return pSuperClass->GetPosEle( rInst, nPos ); - else - return RSCINST(); -} - -ERRTYPE RscTop::MovePosEle( const RSCINST & rInst, sal_uInt32 nDestPos, - sal_uInt32 nSourcePos ) -{ - if( pSuperClass ) - return pSuperClass->MovePosEle( rInst, nDestPos, nSourcePos ); - else - return ERR_UNKNOWN_METHOD; -} - -ERRTYPE RscTop::SetPosRscId( const RSCINST & rInst, sal_uInt32 nPos, - const RscId & rRscId ) -{ - if( pSuperClass ) - return pSuperClass->SetPosRscId( rInst, nPos, rRscId ); - else - return ERR_UNKNOWN_METHOD; -} - -SUBINFO_STRUCT RscTop::GetInfoEle( const RSCINST & rInst, sal_uInt32 nPos ) -{ - if( pSuperClass ) - return pSuperClass->GetInfoEle( rInst, nPos ); - else - return SUBINFO_STRUCT(); -} - -sal_uInt32 RscTop::GetCount( const RSCINST & rInst ) -{ - if( pSuperClass ) - return pSuperClass->GetCount( rInst ); - else - return 0; -} - -ERRTYPE RscTop::SetNumber( const RSCINST & rInst, sal_Int32 lValue ) -{ - if( pSuperClass ) - return pSuperClass->SetNumber( rInst, lValue ); - else - return ERR_UNKNOWN_METHOD; -} - -ERRTYPE RscTop::SetBool( const RSCINST & rInst, bool bValue ) -{ - if( pSuperClass ) - return pSuperClass->SetBool( rInst, bValue ); - else - return ERR_UNKNOWN_METHOD; -} - -ERRTYPE RscTop::SetConst( const RSCINST & rInst, Atom nId, sal_Int32 nVal ) -{ - if( pSuperClass ) - return pSuperClass->SetConst( rInst, nId, nVal ); - else - return ERR_UNKNOWN_METHOD; -} - -ERRTYPE RscTop::SetNotConst( const RSCINST & rInst, Atom nId ) -{ - if( pSuperClass ) - return pSuperClass->SetNotConst( rInst, nId ); - else - return ERR_UNKNOWN_METHOD; -} - -ERRTYPE RscTop::SetString( const RSCINST & rInst, const char * pStr ) -{ - if( pSuperClass ) - return pSuperClass->SetString( rInst, pStr ); - else - return ERR_UNKNOWN_METHOD; -} - -ERRTYPE RscTop::GetNumber( const RSCINST & rInst, sal_Int32 * pN ) -{ - if( pSuperClass ) - return pSuperClass->GetNumber( rInst, pN ); - else - return ERR_UNKNOWN_METHOD; -} - -ERRTYPE RscTop::GetBool( const RSCINST & rInst, bool * pB ) -{ - if( pSuperClass ) - return pSuperClass->GetBool( rInst, pB ); - else - return ERR_UNKNOWN_METHOD; -} - -ERRTYPE RscTop::GetConst( const RSCINST & rInst, Atom * pH ) -{ - if( pSuperClass ) - return pSuperClass->GetConst( rInst, pH ); - else - return ERR_UNKNOWN_METHOD; -} - -ERRTYPE RscTop::GetString( const RSCINST & rInst, char ** ppStr ) -{ - if( pSuperClass ) - return pSuperClass->GetString( rInst, ppStr ); - else - return ERR_UNKNOWN_METHOD; -} - -RSCINST RscTop::Create( RSCINST * pInst, const RSCINST & rDefInst, bool bOwnRange ) -{ - if( pSuperClass ) - return pSuperClass->Create( pInst, rDefInst, bOwnRange ); - else - { - if( pInst ) - return *pInst; - return RSCINST(); - } -} - -void RscTop::Destroy( const RSCINST & rInst ) -{ - if( pSuperClass ) - pSuperClass->Destroy( rInst ); -} - -bool RscTop::IsConsistent( const RSCINST & rInst ) -{ - if( pSuperClass ) - return pSuperClass->IsConsistent( rInst ); - else - return true; -} - -void RscTop::SetToDefault( const RSCINST & rInst ) -{ - if( pSuperClass ) - pSuperClass->SetToDefault( rInst ); -} - -bool RscTop::IsDefault( const RSCINST & rInst ) -{ - if( pSuperClass ) - return pSuperClass->IsDefault( rInst ); - else - return true; -} - -bool RscTop::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) -{ - if( pSuperClass ) - return pSuperClass->IsValueDefault( rInst, pDef ); - else - return true; -} - -void RscTop::SetDefault( const RSCINST & rInst, Atom nVarId ) -{ - if( pSuperClass ) - pSuperClass->SetDefault( rInst, nVarId ); -} - -RSCINST RscTop::GetDefault( Atom nVarId ) -{ - if( pSuperClass ) - return pSuperClass->GetDefault( nVarId ); - else - return RSCINST(); -} - -void RscTop::Delete( const RSCINST & rInst, RscTop * pClass, - const RscId & rId ) -{ - if( pSuperClass ) - pSuperClass->Delete( rInst, pClass, rId ); -} - -void RscTop::DeletePos( const RSCINST & rInst, sal_uInt32 nPos ) -{ - if( pSuperClass ) - pSuperClass->DeletePos( rInst, nPos ); -} - -ERRTYPE RscTop::SetRef( const RSCINST & rInst, const RscId & rRefId ) -{ - if( pSuperClass ) - return pSuperClass->SetRef( rInst, rRefId ); - else - return ERR_UNKNOWN_METHOD; -} - -void RscTop::WriteSrcHeader( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, - const RscId & rId, const char * pVarName ) -{ - if( pSuperClass ) - pSuperClass->WriteSrcHeader( rInst, fOutput, pTC, nTab, rId, pVarName ); - else - rInst.pClass->WriteSrc( rInst, fOutput, pTC, nTab, pVarName ); -} - -void RscTop::WriteSrc( const RSCINST & rInst, FILE * fOutput, - RscTypCont * pTC, sal_uInt32 nTab, const char * pVarName ) -{ - if( pSuperClass ) - pSuperClass->WriteSrc( rInst, fOutput, pTC, nTab, pVarName ); -} - -ERRTYPE RscTop::WriteRcHeader( const RSCINST & rInst, RscWriteRc & rMem, - RscTypCont * pTC, const RscId & rId, - sal_uInt32 nDeep ) -{ - if( pSuperClass ) - return pSuperClass->WriteRcHeader( rInst, rMem, pTC, rId, nDeep ); - else - return rInst.pClass->WriteRc( rInst, rMem, pTC, nDeep ); -} - -ERRTYPE RscTop::WriteRc( const RSCINST & rInst, RscWriteRc & rMem, - RscTypCont * pTC, sal_uInt32 nDeep ) -{ - if( pSuperClass ) - return pSuperClass->WriteRc( rInst, rMem, pTC, nDeep ); - else - return ERR_OK; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/rsc/rsc.cxx b/rsc/source/rsc/rsc.cxx deleted file mode 100644 index 187a0b1a1e1c..000000000000 --- a/rsc/source/rsc/rsc.cxx +++ /dev/null @@ -1,843 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <stdlib.h> -#include <stdio.h> -#include <fcntl.h> - -#ifdef UNX -#include <unistd.h> -#include <sys/wait.h> -#include <sys/stat.h> -#else -#include <io.h> -#include <process.h> -#include <direct.h> -#endif - -#include <string.h> -#include <errno.h> - -#include <tools/stream.hxx> -#include <rscerror.h> -#include <rsctop.hxx> -#include <rscdb.hxx> -#include <rscpar.hxx> -#include <rscrsc.hxx> -#include <rschash.hxx> - -#include <osl/file.h> -#include <osl/file.hxx> -#include <osl/process.h> -#include <rtl/strbuf.hxx> -#include <rtl/tencinfo.h> -#include <rtl/textenc.h> -#include <comphelper/string.hxx> - -#include <vector> -#include <algorithm> - -using comphelper::string::getTokenCount; - -OString* pStdParType = nullptr; -OString* pStdPar1 = nullptr; -OString* pStdPar2 = nullptr; -sal_uInt32 nRefDeep = 10; -AtomContainer* pHS = nullptr; - - -void RscCmdLine::Init() -{ - nCommands = CommandFlags::NONE; - nByteOrder = RSC_BIGENDIAN; - - aPath = OString("."); - m_aOutputFiles.clear(); - m_aOutputFiles.push_back( OutputFile() ); -} - -RscCmdLine::RscCmdLine( int argc, char ** argv, RscError * pEH ) -{ - char * pStr; - char ** ppStr; - RscPtrPtr aCmdLine; - sal_uInt32 i; - bool bOutputSrsIsSet = false; - - Init(); - - pStr = ::ResponseFile( &aCmdLine, argv, argc ); - if( pStr ) - pEH->FatalError( ERR_OPENFILE, RscId(), pStr ); - - /* check the inputted switches */ - ppStr = reinterpret_cast<char **>(aCmdLine.GetBlock()); - ppStr++; - i = 1; - while( ppStr && i < (aCmdLine.GetCount() -1) ) - { -#if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, "CmdLineArg: \"%s\"\n", *ppStr ); -#endif - if (strcmp(*ppStr, "-isystem") == 0) - { - // ignore "-isystem" and following arg - if (i < aCmdLine.GetCount() - 1) - { - ++ppStr; - ++i; - } - } - else if (strncmp(*ppStr, "-isystem", strlen("-isystem")) == 0) - { - // ignore args starting with "-isystem" - } - else if( '-' == **ppStr ) - { - if( !rsc_stricmp( (*ppStr) + 1, "h" ) - || !strcmp( (*ppStr) + 1, "?" ) ) - { // Write help to standard output - nCommands |= CommandFlags::Help; - } - else if( !rsc_stricmp( (*ppStr) + 1, "p" ) ) - { // No preprocessor - nCommands |= CommandFlags::NoPrePro; - } - else if( !rsc_stricmp( (*ppStr) + 1, "s" ) ) - { // Syntax analysis, creates .srs file - nCommands |= CommandFlags::NoLink; - } - else if( !rsc_stricmp( (*ppStr) + 1, "l" ) ) - { // links, no syntax and no preprocessing - nCommands |= CommandFlags::NoPrePro; - nCommands |= CommandFlags::NoSyntax; - } - else if( !rsc_stricmp( (*ppStr) + 1, "r" ) ) - { // generate no .res file - nCommands |= CommandFlags::NoResFile; - } - else if( !rsc_strnicmp( (*ppStr) + 1, "sub", 3 ) ) - { - const char* pEqual; - for( pEqual = (*ppStr)+4; *pEqual && *pEqual != '='; ++pEqual ) - ; - if( *pEqual ) - { - m_aReplacements.push_back( std::pair< OString, OString >( OString( (*ppStr)+4, pEqual - *ppStr - 4 ), - OString( pEqual + 1 ) ) ); - } - } - else if( !rsc_stricmp( (*ppStr) + 1, "PreLoad" ) ) - { // all resources with Preload - nCommands |= CommandFlags::Preload; - } - else if( !rsc_stricmp( (*ppStr) + 1, "LITTLEENDIAN" ) ) - { // endianness when writing - nByteOrder = RSC_LITTLEENDIAN; - } - else if( !rsc_stricmp( (*ppStr) + 1, "BIGENDIAN" ) ) - { // endianness when writing - nByteOrder = RSC_BIGENDIAN; - } - else if( !rsc_strnicmp( (*ppStr) + 1, "d", 1 ) ) - { // define symbols - nCommands |= CommandFlags::Define; - } - else if( !rsc_strnicmp( (*ppStr) + 1, "i", 1 ) ) - { // define include path - nCommands |= CommandFlags::Include; - OStringBuffer aBuffer(aPath); - if (!aBuffer.isEmpty()) - aBuffer.append(SAL_PATHSEPARATOR); - aBuffer.append((*ppStr) + 2); - aPath = aBuffer.makeStringAndClear(); - } - else if( !rsc_strnicmp( (*ppStr) + 1, "fs=", 3 ) ) - { // define name of .res file - if( m_aOutputFiles.back().aOutputRc.getLength() ) - m_aOutputFiles.push_back( OutputFile() ); - m_aOutputFiles.back().aOutputRc = (*ppStr) + 4; - } - else if( !rsc_strnicmp( (*ppStr) + 1, "lip=", 4 ) ) - { // additional language specific include for system dependent files - const OString aSysSearchDir( (*ppStr)+5 ); - - // ignore empty -lip= arguments that we get lots of these days - if (!aSysSearchDir.isEmpty()) - { - m_aOutputFiles.back().aSysSearchDirs.push_back(aSysSearchDir); - OString aLangSearchPath = m_aOutputFiles.back().aLangSearchPath; - if( !aLangSearchPath.isEmpty() ) - { - aLangSearchPath = aLangSearchPath + OString( SAL_PATHSEPARATOR ); - } - aLangSearchPath = aLangSearchPath + aSysSearchDir; - - m_aOutputFiles.back().aLangSearchPath = aLangSearchPath; - } - } - else if( !rsc_strnicmp( (*ppStr) + 1, "fp=", 3 ) ) - { // define name of .srs file - aOutputSrs = (*ppStr) + 4; - bOutputSrsIsSet = true; - } - else if( !rsc_stricmp( (*ppStr) + 1, "NoSysResTest" ) ) - { // don't check Bitmap, Pointers, Icons - nCommands |= CommandFlags::NoSysResTest; - } - else if( !rsc_stricmp( (*ppStr) + 1, "SrsDefault" ) ) - { // Only write one language to srs file - nCommands |= CommandFlags::SrsDefault; - } - else if( !rsc_stricmp( (*ppStr) + 1, "lg" ) ) - { - m_aOutputFiles.back().aLangName.clear(); - } - else if( !rsc_strnicmp( (*ppStr) + 1, "lg", 2 ) ) - { - if( !m_aOutputFiles.back().aLangName.isEmpty() ) - m_aOutputFiles.push_back( OutputFile() ); - m_aOutputFiles.back().aLangName = OString((*ppStr)+3); - } - else - pEH->FatalError( ERR_UNKNOWNSW, RscId(), *ppStr ); - } - else - { - // input file - aInputList.push_back( new OString(*ppStr) ); - } - ppStr++; - i++; - } - - if( nCommands & CommandFlags::Help ) - pEH->FatalError( ERR_USAGE, RscId() ); - // was an inputted file specified - else if( !aInputList.empty() ) - { - ::std::list<OutputFile>::iterator it; - for( it = m_aOutputFiles.begin(); it != m_aOutputFiles.end(); ++it ) - { - if( it->aOutputRc.isEmpty() ) - it->aOutputRc = ::OutputFile( *aInputList.front(), "rc" ); - } - if( ! bOutputSrsIsSet ) - aOutputSrs = ::OutputFile( *aInputList.front(), "srs" ); - } - else - pEH->FatalError( ERR_NOINPUT, RscId() ); -} - -RscCmdLine::~RscCmdLine() -{ - for ( size_t i = 0, n = aInputList.size(); i < n; ++i ) - delete aInputList[ i ]; - aInputList.clear(); -} - -OString RscCmdLine::substitutePaths( const OString& rIn ) -{ - // prepare return value - OStringBuffer aRet( 256 ); - std::list< std::pair< OString, OString > >::const_iterator last_match = m_aReplacements.end(); - - // search for longest replacement match - for( std::list< std::pair< OString, OString > >::const_iterator repl = m_aReplacements.begin(); repl != m_aReplacements.end(); ++repl ) - { - if( rIn.startsWith( repl->second ) ) // path matches - { - if( last_match == m_aReplacements.end() || last_match->second.getLength() < repl->second.getLength() ) - last_match = repl; - } - } - - // copy replacement found and rest of rIn - sal_Int32 nIndex = 0; - if( last_match != m_aReplacements.end() ) - { - aRet.append( "%" ); - aRet.append( last_match->first ); - aRet.append( "%" ); - nIndex = last_match->second.getLength(); - } - - if( rIn.match( "/", nIndex ) ) - aRet.append( rIn.copy( nIndex ) ); - else - aRet.append( rIn.copy( nIndex - 1 ) ); - - return aRet.makeStringAndClear(); -} - -RscCompiler::RscCompiler( RscCmdLine * pLine, RscTypCont * pTypCont ) -{ - fExitFile = nullptr; - - //Set Command Line, set Type Container - pCL = pLine; - pTC = pTypCont; -} - -RscCompiler::~RscCompiler() -{ - pTC->pEH->SetListFile( nullptr ); - - if( fExitFile ) - fclose( fExitFile ); -} - -ERRTYPE RscCompiler::Start() -{ - ERRTYPE aError; - RscFile* pFName; - - if( pCL->aInputList.empty() ) - pTC->pEH->FatalError( ERR_NOINPUT, RscId() ); - - for( size_t i = 0, n = pCL->aInputList.size(); i < n; ++i ) - pTC->aFileTab.NewCodeFile( *pCL->aInputList[ i ] ); - - if( !(pCL->nCommands & CommandFlags::NoSyntax) ) - { - if( pCL->nCommands & CommandFlags::NoPrePro ) - { - - pTC->pEH->SetListFile( nullptr ); - - RscFileTab::Index aIndex = pTC->aFileTab.FirstIndex(); - while( aIndex != RscFileTab::IndexNotFound && aError.IsOk() ) - { - pFName = pTC->aFileTab.Get( aIndex ); - if( !pFName->bScanned && !pFName->IsIncFile() ) - { - aError = IncludeParser( aIndex ); - // set current pointer correctly - aIndex = pTC->aFileTab.GetIndexOf( pFName ); - } - aIndex = pTC->aFileTab.NextIndex( aIndex ); - } - - pTC->pEH->SetListFile( nullptr ); - } - } - - if ( pTC->pEH->GetVerbosity() >= RscVerbosityVerbose ) - { - pTC->pEH->StdOut( "Files: " ); - RscFileTab::Index aIndex = pTC->aFileTab.FirstIndex(); - while( aIndex != RscFileTab::IndexNotFound ) - { - pFName = pTC->aFileTab.Get( aIndex ); - pTC->pEH->StdOut( pFName->aFileName.getStr() ); - pTC->pEH->StdOut( " " ); - aIndex = pTC->aFileTab.NextIndex( aIndex ); - } - pTC->pEH->StdOut( "\n" ); - } - - if( aError.IsOk() ) - aError = Link(); - - if( aError.IsOk() ) - EndCompile(); - - if( aError.IsError() ) - pTC->pEH->Error( ERR_ERROR, nullptr, RscId() ); - - return aError; -} - -void RscCompiler::EndCompile() -{ - if( !pCL->aOutputSrs.isEmpty() && (pCL->nCommands & CommandFlags::NoLink) ) - { - pTC->pEH->StdOut( "Writing file ", RscVerbosityVerbose ); - pTC->pEH->StdOut( pCL->aOutputSrs.getStr(), RscVerbosityVerbose ); - pTC->pEH->StdOut( ".\n", RscVerbosityVerbose ); - - // copy from TMP to real names - unlink( pCL->aOutputSrs.getStr() ); // delete target file - if( !(pCL->nCommands & CommandFlags::NoSyntax) ) - { - FILE * foutput; - - if( nullptr == (foutput = fopen( pCL->aOutputSrs.getStr(), "w" )) ) - pTC->pEH->FatalError( ERR_OPENFILE, RscId(), pCL->aOutputSrs.getStr() ); - else - { - // write file - RscFileTab::Index aIndex = pTC->aFileTab.FirstIndex(); - while( aIndex != RscFileTab::IndexNotFound ) - { - RscFile* pFN = pTC->aFileTab.Get( aIndex ); - if( !pFN->IsIncFile() ) - { - pTC->WriteSrc( foutput, RscFileTab::IndexNotFound ); - break; // ?T 281091MM only one source file - } - } - - fclose( foutput ); - } - } - } -} - -ERRTYPE RscCompiler::IncludeParser( RscFileTab::Index lFileKey ) -{ - FILE * finput; - RscFile * pFName; - ERRTYPE aError; - - pFName = pTC->aFileTab.Get( lFileKey ); - if( !pFName ) - aError = ERR_ERROR; - else if( !pFName->bScanned ) - { - finput = fopen( pFName->aPathName.getStr(), "r" ); - if( !finput ) - { - aError = ERR_OPENFILE; - pTC->pEH->Error( aError, nullptr, RscId(), - pFName->aPathName.getStr() ); - } - else - { - RscFileInst aFileInst( pTC, lFileKey, lFileKey, finput ); - - pFName->bScanned = true; - ::IncludeParser( &aFileInst ); - fclose( finput ); - - // look into include path - for ( size_t i = 0, n = pFName->aDepLst.size(); i < n; ++i ) - { - RscDepend * pDep = pFName->aDepLst[ i ]; - RscFile * pFNTmp = pTC->aFileTab.GetFile( pDep->GetFileKey() ); - // no path and include file - if( pFNTmp && !pFNTmp->bLoaded ) - { - pFNTmp->aPathName = pFNTmp->aFileName; - } - }; - }; - }; - - return aError; -} - -ERRTYPE RscCompiler::ParseOneFile( RscFileTab::Index lFileKey, - const RscCmdLine::OutputFile* pOutputFile, - const WriteRcContext* pContext ) -{ - FILE * finput = nullptr; - ERRTYPE aError; - RscFile * pFName; - - pFName = pTC->aFileTab.Get( lFileKey ); - if( !pFName ) - aError = ERR_ERROR; - else if( !pFName->bLoaded ) - { - - // first read include file - pFName->bLoaded = true; // avoid endless recursion - - for ( size_t i = 0; i < pFName->aDepLst.size() && aError.IsOk(); ++i ) - { - RscDepend* pDep = pFName->aDepLst[ i ]; - aError = ParseOneFile( pDep->GetFileKey(), pOutputFile, pContext ); - } - - if( aError.IsError() ) - pFName->bLoaded = false; // not loaded upon error - else - { - OUString aTmpPath; - OUString aSrsPath = OStringToOUString( pFName->aPathName, RTL_TEXTENCODING_ASCII_US ); - - osl::FileBase::createTempFile( nullptr, nullptr, &aTmpPath ); - osl::FileBase::getFileURLFromSystemPath( aSrsPath, aSrsPath ); - - if( pContext && pOutputFile ) - PreprocessSrsFile( *pOutputFile, *pContext, aSrsPath, aTmpPath ); - else - osl::File::copy( aSrsPath, aTmpPath ); - - OUString aParseFile; - osl::FileBase::getSystemPathFromFileURL( aTmpPath, aParseFile ); - finput = fopen(OUStringToOString(aParseFile, RTL_TEXTENCODING_ASCII_US).getStr(), "r"); - - if( !finput ) - { - pTC->pEH->Error( ERR_OPENFILE, nullptr, RscId(), pFName->aPathName.getStr() ); - aError = ERR_OPENFILE; - } - else - { - RscFileInst aFileInst( pTC, lFileKey, lFileKey, finput ); - - pTC->pEH->StdOut( "reading file ", RscVerbosityVerbose ); - pTC->pEH->StdOut( OUStringToOString(aParseFile, RTL_TEXTENCODING_ASCII_US).getStr(), RscVerbosityVerbose ); - pTC->pEH->StdOut( " ", RscVerbosityVerbose ); - - aError = ::parser( &aFileInst ); - if( aError.IsError() ) - pTC->Delete( lFileKey );// delete resource objects - pTC->pEH->StdOut( "\n", RscVerbosityVerbose ); - fclose( finput ); - }; - - osl::File::remove( aTmpPath ); - }; - }; - - return aError; -} - -namespace -{ - using namespace ::osl; - class RscIoError { }; - - inline OUString lcl_getAbsoluteUrl(const OUString& i_sBaseUrl, const OString& i_sPath) - { - OUString sRelUrl, sAbsUrl; - if(FileBase::getFileURLFromSystemPath(OStringToOUString(i_sPath, RTL_TEXTENCODING_MS_1252), sRelUrl) != FileBase::E_None) - throw RscIoError(); - if(FileBase::getAbsoluteFileURL(i_sBaseUrl, sRelUrl, sAbsUrl) != FileBase::E_None) - throw RscIoError(); - return sAbsUrl; - }; - - inline OString lcl_getSystemPath(const OUString& i_sUrl) - { - OUString sSys; - if(FileBase::getSystemPathFromFileURL(i_sUrl, sSys) != FileBase::E_None) - throw RscIoError(); - return OUStringToOString(sSys, RTL_TEXTENCODING_MS_1252); - }; - - inline OString lcl_getTempFile(OUString& sTempDirUrl) - { - // get a temp file name for the rc file - OUString sTempUrl; - if(FileBase::createTempFile(&sTempDirUrl, nullptr, &sTempUrl) != FileBase::E_None) - throw RscIoError(); - return lcl_getSystemPath(sTempUrl); - }; -} - -ERRTYPE RscCompiler::Link() -{ - FILE * foutput; - ERRTYPE aError; - RscFile* pFName; - - if( !(pCL->nCommands & CommandFlags::NoLink) ) - { - ::std::list<RscCmdLine::OutputFile>::const_iterator it; - - for( it = pCL->m_aOutputFiles.begin(); it != pCL->m_aOutputFiles.end(); ++it ) - { - // cleanup nodes - for( RscFileTab::Index aIndex = pTC->aFileTab.FirstIndex(); - aIndex != RscFileTab::IndexNotFound && aError.IsOk(); - aIndex = pTC->aFileTab.NextIndex( aIndex ) ) - { - pFName = pTC->aFileTab.Get( aIndex ); - if( !pFName->IsIncFile() ) - { - pTC->Delete( aIndex ); - aIndex = pTC->aFileTab.GetIndexOf( pFName ); - pFName->bLoaded = false; - } - } - - - // get two temp file urls - OString aRcTmp, aSysListTmp, aSysList; - try - { - OUString sPwdUrl; - osl_getProcessWorkingDir( &sPwdUrl.pData ); - OUString sRcUrl = lcl_getAbsoluteUrl(sPwdUrl, it->aOutputRc); - // TempDir is either the directory where the rc file is located or pwd - OUString sTempDirUrl = sRcUrl.copy(0,sRcUrl.lastIndexOf('/')); - - aRcTmp = lcl_getTempFile(sTempDirUrl); - - OUString sOilDirUrl = sTempDirUrl; - - aSysListTmp = lcl_getTempFile(sOilDirUrl); - - OUString sIlstUrl; - sIlstUrl = sRcUrl.copy(sRcUrl.lastIndexOf('/')+1); - sIlstUrl = sIlstUrl.copy(0,sIlstUrl.lastIndexOf('.')); - sIlstUrl += ".ilst"; - sIlstUrl = lcl_getAbsoluteUrl(sOilDirUrl, OUStringToOString(sIlstUrl, RTL_TEXTENCODING_UTF8)); - - aSysList = lcl_getSystemPath(sIlstUrl); - } - catch (RscIoError&) - { - OString sMsg = "Error with paths:\n" - "temporary rc file: " + aRcTmp + "\n" - "temporary ilst file: " + aSysListTmp + "\n" - "ilst file: " + aSysList + "\n"; - pTC->pEH->FatalError(ERR_OPENFILE, RscId(), sMsg.getStr()); - } - if ( nullptr == (fExitFile = foutput = fopen( aRcTmp.getStr(), "wb" )) ) - pTC->pEH->FatalError( ERR_OPENFILE, RscId(), aRcTmp.getStr() ); - - // write file - pTC->ChangeLanguage( it->aLangName ); - pTC->SetSourceCharSet( RTL_TEXTENCODING_UTF8 ); - - WriteRcContext aContext; - - aContext.fOutput = foutput; - aContext.aOutputRc = it->aOutputRc; - aContext.aOutputSysList = aSysListTmp; - aContext.pCmdLine = pCL; - - // create empty sys list - if( !aContext.aOutputSysList.isEmpty() ) - { - FILE* pSysListFile = fopen( aContext.aOutputSysList.getStr(), "wb" ); - - if( !pSysListFile ) - pTC->pEH->FatalError( ERR_OPENFILE, RscId(), aContext.aOutputSysList.getStr() ); - else - fclose( pSysListFile ); - } - - // parse files for specific language - for( RscFileTab::Index aIndex = pTC->aFileTab.FirstIndex(); - aIndex != RscFileTab::IndexNotFound && aError.IsOk(); - aIndex = pTC->aFileTab.NextIndex( aIndex ) ) - { - pFName = pTC->aFileTab.Get( aIndex ); - if( !pFName->IsIncFile() ) - { - aError = ParseOneFile( aIndex, &*it, &aContext ); - aIndex = pTC->aFileTab.GetIndexOf( pFName ); - } - }; - - aError = pTC->WriteRc( aContext ); - - fclose( foutput ); - fExitFile = nullptr; - unlink( it->aOutputRc.getStr() ); - if( rename( aRcTmp.getStr(), it->aOutputRc.getStr() ) ) - { - OStringBuffer aBuf; - aBuf.append( aRcTmp ); - aBuf.append( " -> " ); - aBuf.append( it->aOutputRc ); - pTC->pEH->FatalError( ERR_RENAMEFILE, RscId(), aBuf.getStr() ); - } - else - { -#ifdef UNX - (void)chmod( it->aOutputRc.getStr(), S_IRWXU | S_IRWXG | S_IROTH ); -#endif - } - - unlink( aSysList.getStr() ); - if( rename( aSysListTmp.getStr(), aSysList.getStr() ) ) - { - OStringBuffer aBuf; - aBuf.append( aSysListTmp ); - aBuf.append( " -> " ); - aBuf.append( aSysList ); - pTC->pEH->FatalError( ERR_RENAMEFILE, RscId(), aBuf.getStr() ); - } - else - { -#ifdef UNX - (void)chmod( aSysList.getStr(), S_IRWXU | S_IRWXG | S_IROTH ); -#endif - } - } - } - else - { - // parse files - for( RscFileTab::Index aIndex = pTC->aFileTab.FirstIndex(); - aIndex != RscFileTab::IndexNotFound && aError.IsOk(); - aIndex = pTC->aFileTab.NextIndex( aIndex ) ) - { - pFName = pTC->aFileTab.Get( aIndex ); - if( !pFName->IsIncFile() ) - { - aError = ParseOneFile( aIndex, nullptr, nullptr ); - aIndex = pTC->aFileTab.GetIndexOf( pFName ); - } - }; - } - - return aError; -} - -bool RscCompiler::GetImageFilePath( const RscCmdLine::OutputFile& rOutputFile, - const WriteRcContext& rContext, - const OString& rBaseFileName, - OString& rImagePath, - FILE* pSysListFile ) -{ - ::std::list< OString > aFileNames; - bool bFound = false; - - aFileNames.push_back( rBaseFileName + OString(".png") ); - aFileNames.push_back( rBaseFileName + OString(".bmp") ); - - ::std::list< OString >::iterator aFileIter( aFileNames.begin() ); - - while( ( aFileIter != aFileNames.end() ) && !bFound ) - { - ::std::list< OString >::const_iterator aDirIter( rOutputFile.aSysSearchDirs.begin() ); - - while( ( aDirIter != rOutputFile.aSysSearchDirs.end() ) && !bFound ) - { - const OString aSysPath = *aDirIter + "/" + *aFileIter; - OUString aAbsPath = OStringToOUString( aSysPath, RTL_TEXTENCODING_ASCII_US ); - - - osl::FileBase::getFileURLFromSystemPath( aAbsPath, aAbsPath ); - osl::DirectoryItem aDirectoryItem; - bool bFile = false; - if (osl::DirectoryItem::E_None == osl::DirectoryItem::get( aAbsPath, aDirectoryItem )) - { - osl::FileStatus aFS(osl_FileStatus_Mask_Type); - if (osl::DirectoryItem::E_None == aDirectoryItem.getFileStatus( aFS )) - bFile = aFS.isRegular(); - } - -#if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, "Searching image: %s\n", aSysPath.getStr() ); -#endif - - if( bFile ) - { - std::list< std::pair< OString, OString > >::const_iterator aReplIter( rContext.pCmdLine->m_aReplacements.begin() ); - OString aRelPathStr( aSysPath ); - - while( ( aReplIter != rContext.pCmdLine->m_aReplacements.end() ) && !bFound ) - { - OString aSearch(aReplIter->second.toAsciiLowerCase()); - OString aSearchIn(aRelPathStr.toAsciiLowerCase()); - if( aSearchIn.startsWith(aSearch) ) - { - sal_Int32 nCopyPos = aReplIter->second.getLength(), nLength = aRelPathStr.getLength(); - const sal_Char* pChars = aRelPathStr.getStr(); - - while( ( nCopyPos < nLength ) && ( pChars[ nCopyPos ] == '/' || pChars[ nCopyPos ] == '\\' || pChars[ nCopyPos ] == ':' ) ) - { - ++nCopyPos; - } - - if( nCopyPos < nLength ) - rImagePath = aRelPathStr.copy( nCopyPos ).replace( '\\', '/' ); - - bFound = true; - } - - ++aReplIter; - } - - if( bFound && pSysListFile ) - { - fprintf( pSysListFile, "%s\n", rContext.pCmdLine->substitutePaths( aSysPath ).getStr() ); - } - -#if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, "ImagePath to add: %s\n", rImagePath.getStr() ); -#endif - } - - ++aDirIter; - } - - ++aFileIter; - } - - return bFound; -} - -void RscCompiler::PreprocessSrsFile( const RscCmdLine::OutputFile& rOutputFile, - const WriteRcContext& rContext, - const OUString& rSrsInPath, - const OUString& rSrsOutPath ) -{ - SvFileStream aIStm( rSrsInPath, StreamMode::READ ); - SvFileStream aOStm( rSrsOutPath, StreamMode::WRITE | StreamMode::TRUNC ); - ::std::vector< OString > aMissingImages; - FILE* pSysListFile = rContext.aOutputSysList.isEmpty() ? nullptr : fopen( rContext.aOutputSysList.getStr(), "ab" ); - - if( !aIStm.GetError() && !aOStm.GetError() ) - { - OString aLine; - OString aFilePath; - - while( aIStm.ReadLine( aLine ) ) - { - if( ( getTokenCount(aLine, '=') == 2 ) && - ( aLine.getToken(0, '=').indexOf("File") != -1 ) ) - { - OString aBaseFileName( aLine.getToken(1, '"').getToken(0, '.') ); - - if( GetImageFilePath( rOutputFile, rContext, aBaseFileName, aFilePath, pSysListFile ) ) - { - aLine = OStringBuffer("File = \""). - append(aFilePath).append("\";"). - makeStringAndClear(); - } - else - aMissingImages.push_back( aBaseFileName ); - - aOStm.WriteLine(aLine); - } - else - aOStm.WriteLine(aLine); - } - } - - if( aMissingImages.size() > 0 ) - { - OStringBuffer aImagesStr; - - for( size_t i = 0; i < aMissingImages.size(); ++i ) - { - if( i ) - aImagesStr.append(' '); - - aImagesStr.append(aMissingImages[i]); - } - - pTC->pEH->FatalError( ERR_NOIMAGE, RscId(), aImagesStr.getStr() ); - } - - if( pSysListFile ) - fclose( pSysListFile ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/rscpp/cpp.h b/rsc/source/rscpp/cpp.h deleted file mode 100644 index 4dcf1c89abd9..000000000000 --- a/rsc/source/rscpp/cpp.h +++ /dev/null @@ -1,340 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_RSC_SOURCE_RSCPP_CPP_H -#define INCLUDED_RSC_SOURCE_RSCPP_CPP_H - -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif - -/* in cpp1.c: file-pointer on stdout file file */ -extern FILE* pCppOut; /* BP */ -#define PUTCHAR( d ) fprintf( pCppOut, "%c", (d) ) /* BP */ -#if OSL_DEBUG_LEVEL > 1 -extern FILE* pDefOut; /* ER */ -#ifdef EVALDEFS -#define NEVALBUF 2048 -#endif -#endif - -/* limit for reading commandfiles */ -#define PARALIMIT 100 - -#define EOS '\0' /* End of string */ -#define EOF_CHAR 0 /* Returned by get() on eof */ -#define NULLST ((char *) NULL) /* Pointer to nowhere (linked) */ -#define DEF_NOARGS (-1) /* #define foo vs #define foo() */ - -/* - * The following may need to change if the host system doesn't use ASCII. - */ -#define DEF_MAGIC 0x1D /* Magic for #defines */ -#define TOK_SEP 0x1E /* Token concatenation delim. */ -#define COM_SEP 0x1F /* Magic comment separator */ - -#define HT 0x09 /* horizontal tab */ -#define NL 0x0A /* new line */ -#define CR 0x0D /* carriage return */ -#define DEL 0x7F - - - -#ifdef SOLAR -#define MAC_PARM 0x01 /* Macro formals start here */ -#else -/* - * Note -- in Ascii, the following will map macro formals onto DEL + the - * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will - * be ok as long as PAR_MAC is less than 33). Note that the last PAR_MAC - * value is reserved for string substitution. - */ - -#define MAC_PARM DEL /* Macro formals start here */ -#if PAR_MAC >= 33 - assertion fails -- PAR_MAC is not less than 33 -#endif -#endif -#define LASTPARM (PAR_MAC - 1) - -/* - * Character type codes. - */ - -#define INV 0 /* Invalid, must be zero */ -#define OP_EOE INV /* End of expression */ -#define DIG 1 /* Digit */ -#define LET 2 /* Identifier start */ -#define FIRST_BINOP OP_ADD -#define OP_ADD 3 -#define OP_SUB 4 -#define OP_MUL 5 -#define OP_DIV 6 -#define OP_MOD 7 -#define OP_ASL 8 -#define OP_ASR 9 -#define OP_AND 10 /* &, not && */ -#define OP_OR 11 /* |, not || */ -#define OP_XOR 12 -#define OP_EQ 13 -#define OP_NE 14 -#define OP_LT 15 -#define OP_LE 16 -#define OP_GE 17 -#define OP_GT 18 -#define OP_ANA 19 /* && */ -#define OP_ORO 20 /* || */ -#define OP_QUE 21 /* ? */ -#define OP_COL 22 /* : */ -#define OP_CMA 23 /* , (relevant?) */ -#define LAST_BINOP OP_CMA /* Last binary operand */ -/* - * The following are unary. - */ -#define OP_PLU 24 /* + (draft ANSI standard) */ -#define OP_NEG 25 /* - */ -#define OP_COM 26 /* ~ */ -#define OP_NOT 27 /* ! */ -#define OP_LPA 28 /* ( */ -#define OP_RPA 29 /* ) */ -#define OP_END 30 /* End of expression marker */ -#define OP_MAX (OP_END + 1) /* Number of operators */ -#define OP_FAIL (OP_END + 1) /* For error returns */ - -/* - * The following are for lexical scanning only. - */ - -#define QUO 65 /* Both flavors of quotation */ -#define DOT 66 /* . might start a number */ -#define SPA 67 /* Space and tab */ -#define BSH 68 /* Just a backslash */ -#define END 69 /* EOF */ - -/* - * These bits are set in ifstack[] - */ -#define WAS_COMPILING 1 /* TRUE if compile set at entry */ -#define ELSE_SEEN 2 /* TRUE when #else processed */ -#define TRUE_SEEN 4 /* TRUE when #if TRUE processed */ - -/* - * Define bits for the basic types and their adjectives - */ - -#define T_CHAR 1 -#define T_INT 2 -#define T_FLOAT 4 -#define T_DOUBLE 8 -#define T_SHORT 16 -#define T_LONG 32 -#define T_SIGNED 64 -#define T_UNSIGNED 128 -#define T_PTR 256 /* Pointer */ -#define T_FPTR 512 /* Pointer to functions */ - -/* - * The DEFBUF structure stores information about #defined - * macros. Note that the defbuf->repl information is always - * in malloc storage. - */ - -typedef struct defbuf -{ - struct defbuf* link; /* Next define in chain */ - char* repl; /* -> replacement */ - int hash; /* Symbol table hash */ - int nargs; /* For define(args) */ - char name[]; /* #define name */ -} DEFBUF; - -/* - * The FILEINFO structure stores information about open files - * and macros being expanded. - */ - -typedef struct fileinfo -{ - char* bptr; /* Buffer pointer */ - int line; /* for include or macro */ - FILE* fp; /* File if non-null */ - struct fileinfo* parent; /* Link to includer */ - char* filename; /* File/macro name */ - char* progname; /* From #line statement */ - unsigned int unrecur; /* For macro recursion */ - char buffer[1]; /* current input line */ -} FILEINFO; - -/* - * The SIZES structure is used to store the values for #if sizeof - */ - -typedef struct sizes -{ - short bits; /* If this bit is set, */ - int size; /* this is the datum size value */ - int psize; /* this is the pointer size */ -} SIZES; - -#define cput(c) { if (c != TOK_SEP) PUTCHAR(c); } -#define streq(s1, s2) (strcmp(s1, s2) == 0) - -/* - * Error codes. - */ -#define IO_NORMAL 0 -#define IO_ERROR 1 - -/* - * Externs - */ - -extern int line; /* Current line number */ -extern int wrongline; /* Force #line to cc pass 1 */ -extern char type[]; /* Character classifier */ -extern char token[IDMAX + 1]; /* Current input token */ -extern int instring; /* TRUE if scanning string */ -extern int inmacro; /* TRUE if scanning #define */ -extern int errors; /* Error counter */ -extern int recursion; /* Macro depth counter */ -extern char ifstack[BLK_NEST]; /* #if information */ -#define compiling ifstack[0] -extern char* ifptr; /* -> current ifstack item */ -extern char* incdir[NINCLUDE]; /* -i directories */ -extern char** incend; /* -> active end of incdir */ -extern int cflag; /* -C option (keep comments) */ -extern int eflag; /* -E option (ignore errors) */ -extern int nflag; /* -N option (no pre-defines) */ -extern int rec_recover; /* unwind recursive macros */ -extern char* preset[]; /* Standard predefined symbols */ -extern char* magic[]; /* Magic predefined symbols */ -extern FILEINFO* infile; /* Current input file */ -extern char work[NWORK + 1]; /* #define scratch */ -extern char* workp; /* Free space in work */ -#if OSL_DEBUG_LEVEL > 1 -extern int debug; /* Debug level */ -/* ER dump & evaluate #define's */ -extern int bDumpDefs; /* TRUE if #define's dump req. */ -extern int bIsInEval; /* TRUE if #define dumping now */ -#ifdef EVALDEFS -extern char EvalBuf[NEVALBUF + 1]; /* evaluation buffer */ -extern int nEvalOff; /* offset to free buffer pos */ -#endif -#endif -extern int keepcomments; /* Don't remove comments if set */ -extern SIZES size_table[]; /* For #if sizeof sizes */ - -#ifdef NOMAIN /* BP */ -#ifndef _NO_PROTO -int rscpp_main( int argc, char **argv ); -#endif -#define MAIN rscpp_main /* main() needs to be changed for the cpp.lib */ -#else -#ifdef _WIN32 -#define MAIN __cdecl main -#else -#define MAIN main -#endif -#endif - - -void InitCpp1( void ); -void InitCpp4( void ); -void InitCpp6( void ); - -#define HELLO() fprintf( stderr, "[Hello at %s, %d] ", __FILE__, __LINE__ ) - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -/* cpp1.c */ -void output( int c ); -void sharp( void ); -void cppmain( void ); -#if OSL_DEBUG_LEVEL > 1 -#ifdef EVALDEFS -int outputEval( int c ); -#endif -#endif - - -/* cpp2.c */ -int control( int counter ); -void dodefine( void ); -int openfile( char* ); - -/* cpp3.c */ -void addfile( FILE* fp, char* filename ); -void setincdirs( void ); -int AddInclude( char* pIncStr ); - -void initdefines( void ); -int dooptions( int argc, char* argv[] ); -int readoptions( char* filename, char*** pfargv ); - -/* cpp4.c */ -void checkparm( int c, DEFBUF* dp ); - -void stparmscan( int delim ); -#if OSL_DEBUG_LEVEL > 1 -void dumpparm( char* why ); -#endif - -void doundef( void ); -void textput( char* text ); -void charput( int c ); -void expand( DEFBUF* tokenp ); - -/* cpp5.c */ -int eval( void ); - -/* cpp6.c */ - -void skipnl( void ); -int skipws( void ); -void scanid( int c ); -int macroid( int c ); -int catenate(void); -int scanstring( int c, void (*outfun)( int c ) ); -void scannumber( int c, void (*outfun)( int c ) ); -void save( int c ); -char* savestring( char* text ); -FILEINFO* getfile( size_t bufsize, char* name ); -char *getmem( size_t size ); -DEFBUF* lookid( int c ); -DEFBUF* defendel( char* name, int delete ); -int get( void ); -int cget( void ); -void unget( void ); -void ungetstring( char* text ); -void cerror( char* format, char* sarg ); -void cwarn( char* format, char* sarg ); -void cfatal( char* format, char* sarg ); -void cierror( char* format, int n ); -void ciwarn( char* format, int n ); -#if OSL_DEBUG_LEVEL > 1 -void dumpdef( char* why ); -void dumpadef( char* why, DEFBUF *dp ); -#endif - -#endif // INCLUDED_RSC_SOURCE_RSCPP_CPP_H - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/rscpp/cpp1.c b/rsc/source/rscpp/cpp1.c deleted file mode 100644 index 13518a264187..000000000000 --- a/rsc/source/rscpp/cpp1.c +++ /dev/null @@ -1,574 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#define NOMAIN - -#include <stdio.h> -#include "cppdef.h" -#include "cpp.h" - -FILE* pCppOut = NULL; -static FILE* pCppIn = NULL; - -#if OSL_DEBUG_LEVEL > 1 -FILE* pDefOut = NULL; /* ER possible #define's dump */ -#endif - -#ifdef B200 -/* only possibility under BC to set stack and head */ -extern unsigned _stklen = 24000; -extern unsigned _heaplen = 30000; -#endif - - - -/* - * Commonly used global variables: - * line is the current input line number. - * wrongline is set in many places when the actual output - * line is out of sync with the numbering, e.g, - * when expanding a macro with an embedded newline. - * - * token holds the last identifier scanned (which might - * be a candidate for macro expansion). - * errors is the running cpp error counter. - * infile is the head of a linked list of input files (extended by - * #include and macros being expanded). infile always points - * to the current file/macro. infile->parent to the includer, - * etc. infile->fd is NULL if this input stream is a macro. - */ -int line; /* Current line number */ -int wrongline; /* Force #line to compiler */ -char token[IDMAX + 1]; /* Current input token */ -int errors; /* cpp error counter */ -FILEINFO* infile = NULL; /* Current input file */ -#if OSL_DEBUG_LEVEL > 1 -int debug; /* TRUE if debugging now */ -int bDumpDefs; /* TRUE if #define's dump req. */ -#ifdef EVALDEFS -int bIsInEval; /* TRUE if #define eval now */ -char EvalBuf[NEVALBUF + 1]; /* evaluation buffer */ -int nEvalOff = 0; /* offset to free buffer pos */ -#endif -#endif -/* - * This counter is incremented when a macro expansion is initiated. - * If it exceeds a built-in value, the expansion stops -- this tests - * for a runaway condition: - * #define X Y - * #define Y X - * X - * This can be disabled by falsifying rec_recover. (Nothing does this - * currently: it is a hook for an eventual invocation flag.) - */ -int recursion; /* Infinite recursion counter */ -int rec_recover = TRUE; /* Unwind recursive macros */ - -/* - * instring is set TRUE when a string is scanned. It modifies the - * behavior of the "get next character" routine, causing all characters - * to be passed to the caller (except <DEF_MAGIC>). Note especially that - * comments and \<newline> are not removed from the source. (This - * prevents cpp output lines from being arbitrarily long). - * - * inmacro is set by #define -- it absorbs comments and converts - * form-feed and vertical-tab to space, but returns \<newline> - * to the caller. Strictly speaking, this is a bug as \<newline> - * shouldn't delimit tokens, but we'll worry about that some other - * time -- it is more important to prevent infinitly long output lines. - * - * instring and inmacro are parameters to the get() routine which - * were made global for speed. - */ -int instring = FALSE; /* TRUE if scanning string */ -int inmacro = FALSE; /* TRUE if #defining a macro */ - -/* - * work[] and workp are used to store one piece of text in a temporary - * buffer. To initialize storage, set workp = work. To store one - * character, call save(c); (This will fatally exit if there isn't - * room.) To terminate the string, call save(EOS). Note that - * the work buffer is used by several subroutines -- be sure your - * data won't be overwritten. The extra byte in the allocation is - * needed for string formal replacement. - */ -char work[NWORK + 1]; /* Work buffer */ -char* workp; /* Work buffer pointer */ - -/* - * keepcomments is set TRUE by the -C option. If TRUE, comments - * are written directly to the output stream. This is needed if - * the output from cpp is to be passed to lint (which uses commands - * embedded in comments). cflag contains the permanent state of the - * -C flag. keepcomments is always falsified when processing #control - * commands and when compilation is suppressed by a false #if - * - * If eflag is set, CPP returns "success" even if non-fatal errors - * were detected. - * - * If nflag is non-zero, no symbols are predefined except __LINE__. - * __FILE__, and __DATE__. If nflag > 1, absolutely no symbols - * are predefined. - */ -int keepcomments = FALSE; /* Write out comments flag */ -int cflag = FALSE; /* -C option (keep comments) */ -int eflag = FALSE; /* -E option (never fail) */ -int nflag = 0; /* -N option (no predefines) */ - -/* - * ifstack[] holds information about nested #if's. It is always - * accessed via *ifptr. The information is as follows: - * WAS_COMPILING state of compiling flag at outer level. - * ELSE_SEEN set TRUE when #else seen to prevent 2nd #else. - * TRUE_SEEN set TRUE when #if or #elif succeeds - * ifstack[0] holds the compiling flag. It is TRUE if compilation - * is currently enabled. Note that this must be initialized TRUE. - */ -char ifstack[BLK_NEST] = { TRUE }; /* #if information */ -char* ifptr = ifstack; /* -> current ifstack[] */ - -/* - * incdir[] stores the -i directories (and the system-specific - * #include <...> directories. - */ -char* incdir[NINCLUDE]; /* -i directories */ -char** incend = incdir; /* -> free space in incdir[] */ - -/* - * This is the table used to predefine target machine and operating - * system designators. It may need hacking for specific circumstances. - * Note: it is not clear that this is part of the Ansi Standard. - * The -N option suppresses preset definitions. - */ -char* preset[] = -{ /* names defined at cpp start */ -#ifdef MACHINE - MACHINE, -#endif -#ifdef SYSTEM - SYSTEM, -#endif -#ifdef COMPILER - COMPILER, -#endif -#if OSL_DEBUG_LEVEL > 1 - "decus_cpp", /* Ourselves! */ -#endif - NULL /* Must be last */ -}; - -/* - * The value of these predefined symbols must be recomputed whenever - * they are evaluated. The order must not be changed. - */ -char* magic[] = -{ /* Note: order is important */ - "__LINE__", - "__FILE__", - NULL /* Must be last */ -}; - -static char* sharpfilename = NULL; - -static int nRunde = 0; - -void InitCpp1() -{ - int i; - /* in LIB-Version all variables must be initialized */ - - line = wrongline = errors = recursion = 0; - for( i = 0; i < IDMAX; i++ ) - token[ i ] = 0; - - for( i = 0; i < NWORK; i++ ) - work[ i ] = 0; - - for( i = 0; i < NINCLUDE; i++ ) - incdir[ i ] = NULL; - - workp = NULL; - for( i = 0; i < BLK_NEST; i++ ) - ifstack[ i ] = TRUE; - ifptr = ifstack; - - pCppOut = stdout; - pCppIn = stdin; -#if OSL_DEBUG_LEVEL > 1 - debug = 0; - bDumpDefs = 0; - pDefOut = stdout; -#ifdef EVALDEFS - bIsInEval = 0; - for( i = 0; i < NEVALBUF; i++ ) - EvalBuf[ i ] = 0; - nEvalOff = 0; -#endif -#endif - rec_recover = TRUE; - infile = NULL; - instring = inmacro = keepcomments = cflag = eflag = FALSE; - nflag = 0; - incend = incdir; - sharpfilename = NULL; -} - -int MAIN(int argc, char** argv) -{ - int i; - char** useargv = NULL; - char** pfargv = NULL; - - if( nRunde == 0 ) - { - pCppIn = stdin; - pCppOut = stdout; - } - - nRunde++; - InitCpp1(); - InitCpp4(); - InitCpp6(); - - initdefines(); /* O.S. specific def's */ - if ( argv[argc-1][0] == '@' ) - { - i = readoptions( argv[1], &pfargv ); /* Command file */ - useargv=pfargv; - } - else - { - i = dooptions(argc, argv); /* Command line -flags */ - useargv=argv; - } - switch (i) - { -#if OSL_DEBUG_LEVEL > 1 - case 4: - if ( bDumpDefs ) - { - /* - * Get defBase file, "-" means use stdout. - */ - if (!streq(useargv[3], "-")) - { - pDefOut = fopen( useargv[3], "w" ); - if( pDefOut == NULL ) - { - perror(useargv[3]); - cerror("Can't open output file \"%s\"", useargv[3]); - exit(IO_ERROR); - } - } /* Continue by opening output */ - } - /* fall through */ -#endif - case 3: - /* - * Get output file, "-" means use stdout. - */ - if (!streq(useargv[2], "-")) - { - pCppOut = fopen( useargv[2], "w" ); - if( pCppOut == NULL ) - { - perror(useargv[2]); - cerror("Can't open output file \"%s\"", useargv[2]); - exit(IO_ERROR); - } - } /* Continue by opening input */ - /* fall through */ - case 2: /* One file -> stdin */ - /* - * Open input file, "-" means use stdin. - */ - if (!streq(useargv[1], "-")) - { - pCppIn = fopen( useargv[1], "r" ); - if( pCppIn == NULL) - { - perror(useargv[1]); - cerror("Can't open input file \"%s\"", useargv[1]); - exit(IO_ERROR); - } - strncpy(work, useargv[1], NWORK); /* Remember input filename */ - break; - } /* Else, just get stdin */ - /* fall through */ - case 0: /* No args? */ - case 1: /* No files, stdin -> stdout */ - work[0] = EOS; /* Unix can't find stdin name */ - break; - - default: - exit(IO_ERROR); /* Can't happen */ - } - - setincdirs(); /* Setup -I include directories */ - addfile( pCppIn, work); /* "open" main input file */ -#if OSL_DEBUG_LEVEL > 1 - if (debug > 0 || bDumpDefs) - dumpdef("preset #define symbols"); -#endif - if( pCppIn != stdin ) - rewind( pCppIn ); - - cppmain(); /* Process main file */ - - if ((i = (ifptr - &ifstack[0])) != 0) - { - cierror("Inside #ifdef block at end of input, depth = %d", i); - } -#if OSL_DEBUG_LEVEL > 1 - if( pDefOut != stdout && pDefOut != stderr ) - fclose( pDefOut ); -#endif - if( pCppOut != stdout && pCppOut != stderr ) - fclose( pCppOut ); - - if (errors > 0) - { - fprintf(stderr, (errors == 1) - ? "%d error in preprocessor\n" - : "%d errors in preprocessor\n", errors); - if (!eflag) - exit(IO_ERROR); - } - if( pfargv ) - free(pfargv); - return IO_NORMAL; - -} - -/* - * Main process for cpp -- copies tokens from the current input - * stream (main file, include file, or a macro) to the output - * file. - */ -void cppmain() -{ - int c; /* Current character */ - int counter; /* newlines and spaces */ - - /* - * Explicitly output a #line at the start of cpp output so - * that lint (etc.) knows the name of the original source - * file. If we don't do this explicitly, we may get - * the name of the first #include file instead. - * We also seem to need a blank line following that first #line. - */ -#ifdef EVALDEFS - if ( !bIsInEval ) -#endif - { - sharp(); - PUTCHAR('\n'); - } - /* - * This loop is started "from the top" at the beginning of each line - * wrongline is set TRUE in many places if it is necessary to write - * a #line record. (But we don't write them when expanding macros.) - * - * The counter variable has two different uses: at - * the start of a line, it counts the number of blank lines that - * have been skipped over. These are then either output via - * #line records or by outputting explicit blank lines. - * When expanding tokens within a line, the counter remembers - * whether a blank/tab has been output. These are dropped - * at the end of the line, and replaced by a single blank - * within lines. - */ - for (;;) - { - counter = 0; /* Count empty lines */ - for (;;) - { /* For each line, ... */ - while (type[(c = get())] == SPA) /* Skip leading blanks */ - ; /* in this line. */ - if (c == '\n') /* If line's all blank, */ - ++counter; /* Do nothing now */ - else if (c == '#') - { /* Is 1st non-space '#' */ - keepcomments = FALSE; /* Don't pass comments */ - counter = control(counter); /* Yes, do a #command */ - keepcomments = (cflag && compiling); - } - else if (c == EOF_CHAR) /* At end of file? */ - { - break; - } - else if (!compiling) - { /* #ifdef false? */ - skipnl(); /* Skip to newline */ - counter++; /* Count it, too. */ - } - else - { - break; /* Actual token */ - } - } - if (c == EOF_CHAR) /* Exit process at */ - break; /* End of file */ - /* - * If the loop didn't terminate because of end of file, we - * know there is a token to compile. First, clean up after - * absorbing newlines. counter has the number we skipped. - */ - if ((wrongline && infile->fp != NULL) || counter > 4) - sharp(); /* Output # line number */ - else - { /* If just a few, stuff */ - while (--counter >= 0) /* them out ourselves */ - PUTCHAR('\n'); - } - /* - * Process each token on this line. - */ - unget(); /* Reread the char. */ - for (;;) - { /* For the whole line, */ - do - { /* Token concat. loop */ - for (counter = 0; type[(c = get())] == SPA;) - { - counter++; /* Skip over blanks */ - - } - if (c == EOF_CHAR || c == '\n') - goto end_line; /* Exit line loop */ - else if (counter > 0) /* If we got any spaces */ - PUTCHAR(' '); /* Output one space */ - c = macroid(c); /* Grab the token */ - } - while (type[c] == LET && catenate()); - - if (c == EOF_CHAR || c == '\n') /* From macro exp error */ - goto end_line; /* Exit line loop */ - - switch (type[c]) - { - case LET: - fputs(token, pCppOut); /* Quite ordinary token */ -#ifdef EVALDEFS - { - int len; - if ( bIsInEval - && nEvalOff + (len=strlen(token)) < NEVALBUF ) - { - strcpy( &EvalBuf[nEvalOff], token ); - nEvalOff += len; - } - } -#endif - break; - - - case DIG: /* Output a number */ - case DOT: /* Dot may begin floats */ -#ifdef EVALDEFS - if ( bIsInEval ) - scannumber(c, outputEval); - else - scannumber(c, output); -#else - scannumber(c, output); -#endif - break; - - case QUO: /* char or string const */ - scanstring(c, output); /* Copy it to output */ - break; - - default: /* Some other character */ - cput(c); /* Just output it */ -#ifdef EVALDEFS - if ( bIsInEval && nEvalOff < NEVALBUF ) - EvalBuf[nEvalOff++] = c; -#endif - break; - } /* Switch ends */ - } /* Line for loop */ - end_line: - if (c == '\n') - { /* Compiling at EOL? */ - PUTCHAR('\n'); /* Output newline, if */ - if (infile->fp == NULL) /* Expanding a macro, */ - wrongline = TRUE; /* Output # line later */ - } - } /* Continue until EOF */ -#ifdef EVALDEFS - if ( bIsInEval ) - EvalBuf[nEvalOff++] = '\0'; -#endif -} - -/* - * Output one character to stdout -- output() is passed as an - * argument to scanstring() - */ -void output(int c) -{ - if (c != TOK_SEP) - PUTCHAR(c); -} - -#ifdef EVALDEFS -/* - * Output one character to stdout -- output() is passed as an - * argument to scanstring() - */ -int outputEval(int c) -{ - if (c != TOK_SEP) - { - PUTCHAR(c); - if ( bIsInEval && nEvalOff < NEVALBUF ) - EvalBuf[nEvalOff++] = c; - } -} -#endif - - -/* - * Output a line number line. - */ -void sharp() -{ - char* name; - - if (keepcomments) /* Make sure # comes on */ - PUTCHAR('\n'); /* a fresh, new line. */ - - fprintf( pCppOut, "#%s %d", LINE_PREFIX, line); - if (infile->fp != NULL) - { - name = (infile->progname != NULL) ? infile->progname : infile->filename; - if (sharpfilename == NULL || (!streq(name, sharpfilename))) - { - if (sharpfilename != NULL) - free(sharpfilename); - sharpfilename = savestring(name); - fprintf( pCppOut, " \"%s\"", name); - } - } - PUTCHAR('\n'); - wrongline = FALSE; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/rscpp/cpp2.c b/rsc/source/rscpp/cpp2.c deleted file mode 100644 index e55dc384018f..000000000000 --- a/rsc/source/rscpp/cpp2.c +++ /dev/null @@ -1,552 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <stdio.h> -#include <ctype.h> -#include "cppdef.h" -#include "cpp.h" - -static void doinclude( void ); -static void doif( int hash ); -static int openinclude( char*, int ); -static int hasdirectory( char*, char*, int ); - -/* - * Generate (by hand-inspection) a set of unique values for each control - * operator. Note that this is not guaranteed to work for non-Ascii - * machines. CPP won't compile if there are hash conflicts. - */ - -#define L_assert ('a' + ('s' << 1)) -#define L_define ('d' + ('f' << 1)) -#define L_elif ('e' + ('i' << 1)) -#define L_else ('e' + ('s' << 1)) -#define L_endif ('e' + ('d' << 1)) -#define L_if ('i' + (EOS << 1)) -#define L_ifdef ('i' + ('d' << 1)) -#define L_ifndef ('i' + ('n' << 1)) -#define L_include ('i' + ('c' << 1)) -#define L_line ('l' + ('n' << 1)) -#define L_nogood (EOS + (EOS << 1)) /* To catch #i */ -#define L_pragma ('p' + ('a' << 1)) -#define L_undef ('u' + ('d' << 1)) -#define L_error ('e' + ('r' << 1)) /* BP 5.3.92, #error */ -#if OSL_DEBUG_LEVEL > 1 -#define L_debug ('d' + ('b' << 1)) /* #debug */ -#define L_nodebug ('n' + ('d' << 1)) /* #nodebug */ -#endif - - -/* - * Process #control lines. Simple commands are processed inline, - * while complex commands have their own subroutines. - * - * The counter is used to force out a newline before #line, and - * #pragma commands. This prevents these commands from ending up at - * the end of the previous line if cpp is invoked with the -C option. - */ -int control(int counter) -{ - int c; - char* tp; - int hash; - char* ep; - - c = skipws(); - if (c == '\n' || c == EOF_CHAR) - return counter + 1; - if (!isdigit(c)) - scanid(c); /* Get #word to token[] */ - else - { - unget(); /* Hack -- allow #123 as a */ - strcpy(token, "line"); /* synonym for #line 123 */ - } - hash = (token[1] == EOS) ? L_nogood : (token[0] + (token[2] << 1)); - switch (hash) - { - case L_assert: tp = "assert"; break; - case L_define: tp = "define"; break; - case L_elif: tp = "elif"; break; - case L_else: tp = "else"; break; - case L_endif: tp = "endif"; break; - case L_if: tp = "if"; break; - case L_ifdef: tp = "ifdef"; break; - case L_ifndef: tp = "ifndef"; break; - case L_include: tp = "include"; break; - case L_line: tp = "line"; break; - case L_pragma: tp = "pragma"; break; - case L_undef: tp = "undef"; break; - case L_error: tp = "error"; break; -#if OSL_DEBUG_LEVEL > 1 - case L_debug: tp = "debug"; break; - case L_nodebug: tp = "nodebug"; break; -#endif - default: hash = L_nogood; - /*fall-through*/ - case L_nogood: tp = ""; break; - } - if (!streq(tp, token)) - hash = L_nogood; - /* - * hash is set to a unique value corresponding to the - * control keyword (or L_nogood if we think it's nonsense). - */ - if (infile->fp == NULL) - cwarn("Control line \"%s\" within macro expansion", token); - if (!compiling) - { /* Not compiling now */ - switch (hash) - { - case L_if: /* These can't turn */ - case L_ifdef: /* compilation on, but */ - case L_ifndef: /* we must nest #if's */ - if (++ifptr >= &ifstack[BLK_NEST]) - goto if_nest_err; - *ifptr = 0; /* !WAS_COMPILING */ - /* fall through */ - case L_line: /* Many */ - /* - * Are pragma's always processed? - */ - case L_pragma: /* options */ - case L_include: /* are uninteresting */ - case L_define: /* if we */ - case L_undef: /* aren't */ - case L_assert: /* compiling. */ - case L_error: /* BP 5.3.92, #error */ - dump_line: skipnl(); /* Ignore rest of line */ - return counter + 1; - } - } - /* - * Make sure that #line and #pragma are output on a fresh line. - */ - if (counter > 0 && (hash == L_line || hash == L_pragma)) - { - PUTCHAR('\n'); - counter--; - } - - switch (hash) - { - case L_line: - /* - * Parse the line to update the line number and "progname" - * field and line number for the next input line. - * Set wrongline to force it out later. - */ - c = skipws(); - workp = work; /* Save name in work */ - while (c != '\n' && c != EOF_CHAR) - { - save(c); - c = get(); - } - unget(); - save(EOS); - /* - * Split #line argument into <line-number> and <name> - * We subtract 1 as we want the number of the next line. - */ - line = atoi(work) - 1; /* Reset line number */ - for (tp = work; isdigit((unsigned char)*tp) || type[(int)*tp] == SPA; tp++) - ; /* Skip over digits */ - if (*tp != EOS) /* Got a filename, so: */ - { - if (*tp == '"' && (ep = strrchr(tp + 1, '"')) != NULL) - { - tp++; /* Skip over left quote */ - *ep = EOS; /* And ignore right one */ - } - if (infile->progname != NULL) /* Give up the old name */ - free(infile->progname); /* if it's allocated. */ - infile->progname = savestring(tp); - } - wrongline = TRUE; /* Force output later */ - break; - - case L_include: - doinclude(); - break; - - case L_define: - dodefine(); - break; - - case L_undef: - doundef(); - break; - - case L_else: - if (ifptr == &ifstack[0]) - goto nest_err; - else if ((*ifptr & ELSE_SEEN) != 0) - goto else_seen_err; - *ifptr |= ELSE_SEEN; - if ((*ifptr & WAS_COMPILING) != 0) - { - if (compiling || (*ifptr & TRUE_SEEN) != 0) - compiling = FALSE; - else - { - compiling = TRUE; - } - } - break; - - case L_elif: - if (ifptr == &ifstack[0]) - goto nest_err; - else if ((*ifptr & ELSE_SEEN) != 0) - { - else_seen_err: cerror("#%s may not follow #else", token); - goto dump_line; - } - if ((*ifptr & (WAS_COMPILING | TRUE_SEEN)) != WAS_COMPILING) - { - compiling = FALSE; /* Done compiling stuff */ - goto dump_line; /* Skip this clause */ - } - doif(L_if); - break; - - case L_if: - case L_ifdef: - case L_ifndef: - if (++ifptr >= &ifstack[BLK_NEST]) - if_nest_err: cfatal("Too many nested #%s statements", token); - *ifptr = WAS_COMPILING; - doif(hash); - break; - - case L_endif: - if (ifptr == &ifstack[0]) - { - nest_err: cerror("#%s must be in an #if", token); - goto dump_line; - } - if (!compiling && (*ifptr & WAS_COMPILING) != 0) - wrongline = TRUE; - compiling = ((*ifptr & WAS_COMPILING) != 0); - --ifptr; - break; - - case L_assert: - if (eval() == 0) - cerror("Preprocessor assertion failure", NULLST); - break; - - case L_pragma: - /* - * #pragma is provided to pass "options" to later - * passes of the compiler. cpp doesn't have any yet. - */ - fprintf( pCppOut, "#pragma "); - while ((c = get()) != '\n' && c != EOF_CHAR) - cput(c); - unget(); - break; - -#if OSL_DEBUG_LEVEL > 1 - case L_debug: - if (debug == 0) - dumpdef("debug set on"); - debug++; - break; - - case L_nodebug: - debug--; - break; -#endif - case L_error: /* BP 5.3.92, #error */ - fprintf( pCppOut, "cpp: line %d, Error directive: ", line ); - while ((c = get()) != '\n' && c != EOF_CHAR) - cput(c); - fprintf( pCppOut, "\n" ); - exit( 1 ); - - default: - /* - * Undefined #control keyword. - * Note: the correct behavior may be to warn and - * pass the line to a subsequent compiler pass. - * This would allow #asm or similar extensions. - */ - cerror("Illegal # command \"%s\"", token); - break; - } - if (hash != L_include) - { - if (skipws() != '\n') - { - cwarn("Unexpected text in #control line ignored", NULLST); - skipnl(); - } - } - return counter + 1; -} - -/* - * Process an #if, #ifdef, or #ifndef. The latter two are straightforward, - * while #if needs a subroutine of its own to evaluate the expression. - * - * doif() is called only if compiling is TRUE. If false, compilation - * is always suppressed, so we don't need to evaluate anything. This - * suppresses unnecessary warnings. - */ -static void doif(int hash) -{ - int c; - int found; - - if ((c = skipws()) == '\n' || c == EOF_CHAR) - { - unget(); - goto badif; - } - if (hash == L_if) - { - unget(); - found = (eval() != 0); /* Evaluate expr, != 0 is TRUE */ - hash = L_ifdef; /* #if is now like #ifdef */ - } - else - { - if (type[c] != LET) /* Next non-blank isn't letter */ - goto badif; /* ... is an error */ - found = (lookid(c) != NULL); /* Look for it in symbol table */ - } - if (found == (hash == L_ifdef)) - { - compiling = TRUE; - *ifptr |= TRUE_SEEN; - } - else - { - compiling = FALSE; - } - return; - - badif: cerror("#if, #ifdef, or #ifndef without an argument", NULLST); - skipnl(); /* Prevent an extra */ - unget(); /* Error message */ - return; -} - -/* - * Process the #include control line. - * There are three variations: - * #include "file" search somewhere relative to the - * current source file, if not found, - * treat as #include <file>. - * #include <file> Search in an implementation-dependent - * list of places. - * #include token Expand the token, it must be one of - * "file" or <file>, process as such. - * - * Note: the November 12 draft forbids '>' in the #include <file> format. - * This restriction is unnecessary and not implemented. - */ -static void doinclude() -{ - int c; - int delim; - - delim = macroid(skipws()); - if (delim != '<' && delim != '"') - goto incerr; - if (delim == '<') - delim = '>'; - workp = work; - instring = TRUE; /* Accept all characters */ -#ifdef CONTROL_COMMENTS_NOT_ALLOWED - while ((c = get()) != '\n' && c != EOF_CHAR) - save(c); /* Put it away. */ - unget(); /* Force nl after include */ - /* - * The draft is unclear if the following should be done. - */ - while (--workp >= work && *workp == ' ') - ; /* Trim blanks from filename */ - if (*workp != delim) - goto incerr; -#else - while ((c = get()) != delim && c != EOF_CHAR) - save(c); -#endif - *workp = EOS; /* Terminate filename */ - instring = FALSE; - if (openinclude(work, (delim == '"'))) - return; - /* - * No sense continuing if #include file isn't there. - */ - cfatal("Cannot open include file \"%s\"", work); - - incerr: cerror("#include syntax error", NULLST); - return; -} - -/* - * Actually open an include file. This routine is only called from - * doinclude() above, but was written as a separate subroutine for - * programmer convenience. It searches the list of directories - * and actually opens the file, linking it into the list of - * active files. Returns TRUE if the file was opened, FALSE - * if openinclude() fails. No error message is printed. - */ -static int openinclude(char* filename, int searchlocal) -{ - char** incptr; - char tmpname[NFWORK]; /* Filename work area */ - - if (searchlocal) - { - /* - * Look in local directory first - */ -#if HOST == SYS_UNIX - /* - * Try to open filename relative to the directory of the current - * source file (as opposed to the current directory). (ARF, SCK). - */ - if (filename[0] != '/' && - hasdirectory(infile->filename, tmpname, NFWORK)) - { - int len = strlen(tmpname); - int len2 = strlen(filename); - if(len + len2 < NFWORK) - { - memcpy(tmpname + len, filename, len2); - tmpname[len + len2] = 0; - } - else - { - cfatal("Filename work buffer overflow", NULLST); - } - } - else - { - int len = strlen(filename); - if(len < NFWORK) - { - memcpy(tmpname, filename, len); - tmpname[len] = 0; - } - else - { - cfatal("Filename work buffer overflow", NULLST); - } - } -#else - if (!hasdirectory(filename, tmpname, NFWORK) && - hasdirectory(infile->filename, tmpname, NFWORK)) - { - strcat(tmpname, filename); - } - else - { - strcpy(tmpname, filename); - } -#endif - if (openfile(tmpname)) - return TRUE; - } - /* - * Look in any directories specified by -I command line - * arguments, then in the builtin search list. - */ - for (incptr = incdir; incptr < incend; incptr++) - { - if (strlen(*incptr) + strlen(filename) >= (NFWORK - 1)) - cfatal("Filename work buffer overflow", NULLST); - else - { -#if HOST == SYS_UNIX - if (filename[0] == '/') - strcpy(tmpname, filename); - else - sprintf(tmpname, "%s/%s", *incptr, filename); - -#elif HOST == SYS_UNKNOWN - if (filename[0] == '\\') - strcpy(tmpname, filename); - else - sprintf(tmpname, "%s\\%s", *incptr, filename); -#else - if (!hasdirectory(filename, tmpname, NFWORK)) - sprintf(tmpname, "%s%s", *incptr, filename); -#endif - if (openfile(tmpname)) - return TRUE; - } - } - return FALSE; -} - -/* - * If a device or directory is found in the source filename string, the - * node/device/directory part of the string is copied to result and - * hasdirectory returns TRUE. Else, nothing is copied and it returns FALSE. - */ -static int hasdirectory(char* source, char* result, int max) -{ -#if HOST == SYS_UNIX - char* tp; - - if ((tp = strrchr(source, '/')) == NULL) - return FALSE; - else - { - int len = (int)(tp - source); - if(len < max) - { - memcpy(result, source, len); - result[len] = 0; - } - else - { - cfatal("Filename work buffer overflow", NULLST); - } - return TRUE; - } -#else - /* - * Random DEC operating system (RSTS/E) - */ - char* tp; - - (void)max; - - if ((tp = strrchr(source, ']')) == NULL && - (tp = strrchr(source, ':')) == NULL) - { - return FALSE; - } - else - { - strncpy(result, source, tp - source + 1); - result[tp - source + 1] = EOS; - return TRUE; - } -#endif -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/rscpp/cpp3.c b/rsc/source/rscpp/cpp3.c deleted file mode 100644 index c26ef0b665b4..000000000000 --- a/rsc/source/rscpp/cpp3.c +++ /dev/null @@ -1,428 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#include <stdio.h> -#ifdef UNX -#include <stdlib.h> -#endif -#include <ctype.h> -#include "cppdef.h" -#include "cpp.h" - -#include "time.h" /* BP */ - -#include <string.h> - -#if (OSL_DEBUG_LEVEL > 1) && (HOST == SYS_UNIX) -#include <signal.h> -#endif - -/* - * Open a file, add it to the linked list of open files. - * This is called only from openfile() above. - */ -int openfile(char* filename) -{ - FILE* fp; - - if ((fp = fopen(filename, "r")) == NULL) - { -#if OSL_DEBUG_LEVEL > 1 - if ( debug || !bDumpDefs ) - perror(filename); -#endif - return (FALSE); - } -#if OSL_DEBUG_LEVEL > 1 - if (debug) - fprintf(stderr, "Reading from \"%s\"\n", filename); -#endif - addfile(fp, filename); - return (TRUE); -} - -/* - * Initialize tables for this open file. This is called from openfile() - * above (for #include files), and from the entry to cpp to open the main - * input file. It calls a common routine, getfile() to build the FILEINFO - * structure which is used to read characters. (getfile() is also called - * to setup a macro replacement.) - */ -void addfile(FILE* fp, char* filename) -{ - FILEINFO* file; - - file = getfile(NBUFF, filename); - file->fp = fp; /* Better remember FILE * */ - file->buffer[0] = EOS; /* Initialize for first read */ - line = 1; /* Working on line 1 now */ - wrongline = TRUE; /* Force out initial #line */ -} - -/* - * Append system-specific directories to the include directory list. - * Called only when cpp is started. - */ -void setincdirs() -{ - -#ifdef CPP_INCLUDE - *incend++ = CPP_INCLUDE; -#define IS_INCLUDE 1 -#else -#define IS_INCLUDE 0 -#endif - -#if HOST == SYS_UNIX - *incend++ = "/usr/include"; -#define MAXINCLUDE (NINCLUDE - 1 - IS_INCLUDE) -#endif - - -#if HOST == SYS_UNKNOWN -/* - * Context: GenMake - * Under DOS also the environment variable INCLUDE is used. - * To make it difficult all entries separated by ';' have to be - * included in the list and this is done with strtok(). - * Be careful using malloc() !!! - * In savestring() as a matter of fact getmem() is used and probably these - * two functions are getting in the way of each other. - * When I used malloc() instead of savestring() an error occurred in strcpy(). - */ - -#if !defined(_WIN32) && !defined(UNX) - extern char* getenv( char *pStr ); /* BP */ -#endif - char* pIncGetEnv = NULL; /* Pointer to INCLUDE */ - - if ( ( pIncGetEnv = getenv("INCLUDE") ) != NULL ) - AddInclude( pIncGetEnv ); - -#define MAXINCLUDE (NINCLUDE - 3 - IS_INCLUDE) -#endif - -} - - -/* Context: Extension of the INCLUDE service - * So far the cpp couldn't use include statements in the command line - * where the directories are separated with ';'. - * This totally understandable because this cpp is fitted to UNIX - * systems and under UNIX ';' is used to terminate commandos. - */ - -int AddInclude( char* pIncStr ) -{ - char* pIncEnv = NULL; /* copy of INCLUDE */ - char* pIncPos; /* goes to the next */ - - pIncEnv = savestring( pIncStr ); - pIncPos = strtok( pIncEnv, ";" ); - - while( pIncPos != NULL ) - { - if (incend >= &incdir[MAXINCLUDE]) - cfatal("Too many include directories", NULLST); - *incend++ = pIncPos; - pIncPos = strtok( NULL, ";" ); - } - /* coverity[leaked_storage] - we know this leaks, but it doesn't matter in this short lived utility */ - return 1; -} - -/* - * dooptions is called to process command line arguments (-Detc). - * It is called only at cpp startup. - */ -int dooptions(int argc, char** argv) -{ - char* ap; - DEFBUF* dp; - int c; - int i, j; - char* arg; - SIZES* sizp; /* For -S */ - int size; /* For -S */ - int isdatum; /* FALSE for -S* */ - int endtest; /* For -S */ - - for (i = j = 1; i < argc; i++) - { - arg = ap = argv[i]; - - if (*ap++ != '-' || *ap == EOS) - { - argv[j++] = argv[i]; - } - else - { - c = *ap++; /* Option byte */ - if (islower((unsigned char)c)) /* Normalize case */ - c = toupper(c); - switch (c) /* Command character */ - { - case 'C': /* Keep comments */ - cflag = TRUE; - keepcomments = TRUE; - break; - - case 'D': /* Define symbol */ - /* - * If the option is just "-Dfoo", make it -Dfoo=1 - */ - while (*ap != EOS && *ap != '=') - ap++; - if (*ap == EOS) - ap = "1"; - else - *ap++ = EOS; - /* - * Now, save the word and its definition. - */ - dp = defendel(argv[i] + 2, FALSE); - dp->repl = savestring(ap); - dp->nargs = DEF_NOARGS; - break; - - case 'E': /* Ignore non-fatal */ - eflag = TRUE; /* errors. */ - break; - - case 'I': /* Include directory */ - AddInclude( ap ); /* BP, 11.09.91 */ - break; - - case 'N': /* No predefined */ - nflag++; /* Repeat to undefine */ - break; /* __LINE__, etc. */ - - case 'S': - sizp = size_table; - if (0 != (isdatum = (*ap != '*'))) /* If it's just -S, */ - endtest = T_FPTR; /* Stop here */ - else /* But if it's -S* */ - { - ap++; /* Step over '*' */ - endtest = 0; /* Stop at end marker */ - } - while (sizp->bits != endtest && *ap != EOS) - { - if (!isdigit((unsigned char)*ap)) /* Skip to next digit */ - { - ap++; - continue; - } - size = 0; /* Compile the value */ - while (isdigit((unsigned char)*ap)) - { - size *= 10; - size += (*ap++ - '0'); - } - if (isdatum) - sizp->size = size; /* Datum size */ - else - sizp->psize = size; /* Pointer size */ - sizp++; - } - if (sizp->bits != endtest) - cwarn("-S, too few values specified in %s", argv[i]); - else if (*ap != EOS) - cwarn("-S, too many values, \"%s\" unused", ap); - break; - - case 'U': /* Undefine symbol */ - if (defendel(ap, TRUE) == NULL) - cwarn("\"%s\" wasn't defined", ap); - break; - -#if OSL_DEBUG_LEVEL > 1 - case 'X': /* Debug */ - debug = (isdigit((unsigned char)*ap)) ? atoi(ap) : 1; -#if (HOST == SYS_UNIX) - signal(SIGINT, (void (*)(int)) abort); /* Trap "interrupt" */ -#endif - fprintf(stderr, "Debug set to %d\n", debug); - break; -#endif - -#if OSL_DEBUG_LEVEL > 1 - case 'P': /* #define's dump */ - bDumpDefs = 1; - fprintf(stderr, "Dump #define's is on\n"); - break; -#endif - - default: /* What is this one? */ - cwarn("Unknown option \"%s\"", arg); - fprintf(stderr, "The following options are valid:\n\ - -C\t\t\tWrite source file comments to output\n\ - -Dsymbol=value\tDefine a symbol with the given (optional) value\n\ - -Idirectory\t\tAdd a directory to the #include search list\n\ - -N\t\t\tDon't predefine target-specific names\n\ - -Stext\t\tSpecify sizes for #if sizeof\n\ - -Usymbol\t\tUndefine symbol\n"); -#if OSL_DEBUG_LEVEL > 1 - fprintf(stderr, " -Xvalue\t\tSet internal debug flag\n"); - fprintf(stderr, " -P\t\t\tdump #define's\n"); -#endif - break; - } /* Switch on all options */ - } /* If it's a -option */ - } /* For all arguments */ -#if OSL_DEBUG_LEVEL > 1 - if ( (bDumpDefs ? j > 4 : j > 3) ) -#else - if (j > 3) -#endif - { - cerror( "Too many file arguments. Usage: cpp [input [output]]", - NULLST); - } - return j; /* Return new argc */ -} - -int readoptions(char* filename, char*** pfargv) -{ - FILE* fp; - int c; - int bInQuotes = 0; - char optbuff[1024]; - char* poptbuff; - int fargc=0; - int back; - char* fargv[PARALIMIT]; - char** pfa; - - pfa = *pfargv = malloc(sizeof(fargv)); - - poptbuff = &optbuff[0]; - filename++; - if ((fp = fopen(filename, "r")) == NULL) - { -#if OSL_DEBUG_LEVEL > 1 - if ( debug || !bDumpDefs ) - perror(filename); -#endif - return (FALSE); - } - do - { - /* - * #i27914# double ticks '"' now have a duplicate function: - * 1. they define a string ( e.g. -DFOO="baz" ) - * 2. a string can contain spaces, so -DFOO="baz zum" defines one - * argument no two ! - */ - c = fgetc(fp); - if ( c != ' ' && c != CR && c != NL && c != HT && c != EOF) - { - *poptbuff++ = (char)c; - if( c == '"' ) - bInQuotes = ~bInQuotes; - } - else - { - if( c != EOF && bInQuotes ) - *poptbuff++ = (char)c; - else - { - *poptbuff = EOS; - if (optbuff[0] != '\0') - { - pfa[fargc + 1] = strdup(optbuff); - fargc++; - pfa[fargc + 1] = NULL; - poptbuff = &optbuff[0]; - } - } - } - } - while ( c != EOF ); - - fclose(fp); - back=dooptions(fargc+1,pfa); - - return back; -} - -/* - * Initialize the built-in #define's. There are two flavors: - * #define decus 1 (static definitions) - * #define __FILE__ ?? (dynamic, evaluated by magic) - * Called only on cpp startup. - * - * Note: the built-in static definitions are suppressed by the -N option. - * __LINE__, __FILE__, and __DATE__ are always present. - */ -void initdefines() -{ - char** pp; - char* tp; - DEFBUF* dp; - int i; - time_t tvec; - - /* - * Predefine the built-in symbols. Allow the - * implementor to pre-define a symbol as "" to - * eliminate it. - */ - if (nflag == 0) - { - for (pp = preset; *pp != NULL; pp++) - { - if (*pp[0] != EOS) - { - dp = defendel(*pp, FALSE); - dp->repl = savestring("1"); - dp->nargs = DEF_NOARGS; - } - } - } - /* - * The magic pre-defines (__FILE__ and __LINE__ are - * initialized with negative argument counts. expand() - * notices this and calls the appropriate routine. - * DEF_NOARGS is one greater than the first "magic" definition. - */ - if (nflag < 2) - { - for (pp = magic, i = DEF_NOARGS; *pp != NULL; pp++) - { - dp = defendel(*pp, FALSE); - dp->nargs = --i; - } -#if OK_DATE - /* - * Define __DATE__ as today's date. - */ - dp = defendel("__DATE__", FALSE); - dp->repl = tp = getmem(27); - dp->nargs = DEF_NOARGS; - time( &tvec); - *tp++ = '"'; - strcpy(tp, ctime(&tvec)); - tp[24] = '"'; /* Overwrite newline */ -#endif - } -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/rscpp/cpp4.c b/rsc/source/rscpp/cpp4.c deleted file mode 100644 index 6e1811164e62..000000000000 --- a/rsc/source/rscpp/cpp4.c +++ /dev/null @@ -1,630 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <sal/types.h> -#include <stdio.h> -#include "cppdef.h" -#include "cpp.h" - -/* - * parm[], parmp, and parlist[] are used to store #define() argument - * lists. nargs contains the actual number of parameters stored. - */ -static char parm[NPARMWORK + 1]; /* define param work buffer */ -static char* parmp; /* Free space in parm */ -static char* parlist[LASTPARM]; /* -> start of each parameter */ -static int nargs; /* Parameters for this macro */ - -static int expcollect( void ); -static void expstuff( DEFBUF* dp ); - -void InitCpp4() -{ - int i; - for( i = 0; i < NPARMWORK; i++ ) - parm[ i ] = 0; - for( i = 0; i < LASTPARM; i++ ) - parlist[ i ] = NULL; - - nargs = 0; -} - - -/* - * Called from control when a #define is scanned. This module - * parses formal parameters and the replacement string. When - * the formal parameter name is encountered in the replacement - * string, it is replaced by a character in the range 128 to - * 128+NPARAM (this allows up to 32 parameters within the - * Dec Multinational range). - * - * There is some special case code to distinguish - * #define foo bar - * from #define foo() bar - * - * Also, we make sure that - * #define foo foo - * expands to "foo" but doesn't put cpp into an infinite loop. - * - * A warning message is printed if you redefine a symbol to a - * different text. I.e, - * #define foo 123 - * #define foo 123 - * is ok, but - * #define foo 123 - * #define foo +123 - * is not. - * - * The following subroutines are called from define(): - * checkparm called when a token is scanned. It checks through the - * array of formal parameters. If a match is found, the - * token is replaced by a control byte which will be used - * to locate the parameter when the macro is expanded. - * textput puts a string in the macro work area (parm[]), updating - * parmp to point to the first free byte in parm[]. - * textput() tests for work buffer overflow. - * charput puts a single character in the macro work area (parm[]) - * in a manner analogous to textput(). - */ -void dodefine() -{ - int c; - DEFBUF* dp; /* -> new definition */ - int isredefine; /* TRUE if redefined */ - char* old = NULL; /* Remember redefined */ - - if (type[(c = skipws())] != LET) - goto bad_define; - isredefine = FALSE; /* Set if redefining */ - if ((dp = lookid(c)) == NULL) /* If not known now */ - dp = defendel(token, FALSE); /* Save the name */ - else /* It's known: */ - { - isredefine = TRUE; /* Remember this fact */ - old = dp->repl; /* Remember replacement */ - dp->repl = NULL; /* No replacement now */ - } - parlist[0] = parmp = parm; /* Setup parm buffer */ - if ((c = get()) == '(') /* With arguments? */ - { - nargs = 0; /* Init formals counter */ - do /* Collect formal parms */ - { - if (nargs >= LASTPARM) - cfatal("Too many arguments for macro", NULLST); - else if ((c = skipws()) == ')') - break; /* Got them all */ - else if (type[c] != LET) /* Bad formal syntax */ - goto bad_define; - scanid(c); /* Get the formal param */ - parlist[nargs++] = parmp; /* Save its start */ - textput(token); /* Save text in parm[] */ - } - while ((c = skipws()) == ','); /* Get another argument */ - if (c != ')') /* Must end at ) */ - goto bad_define; - c = ' '; /* Will skip to body */ - } - else - { - /* - * DEF_NOARGS is needed to distinguish between - * "#define foo" and "#define foo()". - */ - nargs = DEF_NOARGS; /* No () parameters */ - } - if (type[c] == SPA) /* At whitespace? */ - c = skipws(); /* Not any more. */ - workp = work; /* Replacement put here */ - inmacro = TRUE; /* Keep \<newline> now */ - while (c != EOF_CHAR && c != '\n') /* Compile macro body */ - { - if (c == '#') /* Token concatenation? */ - { - while (workp > work && type[(int)workp[-1]] == SPA) - --workp; /* Erase leading spaces */ - save(TOK_SEP); /* Stuff a delimiter */ - c = skipws(); /* Eat whitespace */ - if (type[c] == LET) /* Another token here? */ - ; /* Stuff it normally */ - else if (type[c] == DIG) /* Digit string after? */ - { - while (type[c] == DIG) /* Stuff the digits */ - { - save(c); - c = get(); - } - save(TOK_SEP); /* Delimit 2nd token */ - } - else - { - ciwarn("Strange character after # (%d.)", c); - } - continue; - } - switch (type[c]) - { - case LET: - checkparm(c, dp); /* Might be a formal */ - break; - - case DIG: /* Number in mac. body */ - case DOT: /* Maybe a float number */ - scannumber(c, save); /* Scan it off */ - break; - - case QUO: /* String in mac. body */ - stparmscan(c); - break; - - case BSH: /* Backslash */ - save('\\'); - if ((c = get()) == '\n') - wrongline = TRUE; - save(c); - break; - - case SPA: /* Absorb whitespace */ - /* - * Note: the "end of comment" marker is passed on - * to allow comments to separate tokens. - */ - if (workp[-1] == ' ') /* Absorb multiple */ - break; /* spaces */ - else if (c == '\t') - c = ' '; /* Normalize tabs */ - /* fall through *//* to store character */ - default: /* Other character */ - save(c); - break; - } - c = get(); - } - inmacro = FALSE; /* Stop newline hack */ - unget(); /* For control check */ - if (workp > work && workp[-1] == ' ') /* Drop trailing blank */ - workp--; - *workp = EOS; /* Terminate work */ - dp->repl = savestring(work); /* Save the string */ - dp->nargs = nargs; /* Save arg count */ -#if OSL_DEBUG_LEVEL > 1 - if (debug) - dumpadef("macro definition", dp); - else if (bDumpDefs) - dumpadef(NULL, dp); -#endif - if (isredefine) /* Error if redefined */ - { - if ((old != NULL && dp->repl != NULL && !streq(old, dp->repl)) || - (old == NULL && dp->repl != NULL) || - (old != NULL && dp->repl == NULL)) - { -#ifdef STRICT_UNDEF - cerror("Redefining defined variable \"%s\"", dp->name); -#else - cwarn("Redefining defined variable \"%s\"", dp->name); -#endif - } - if (old != NULL) /* We don't need the */ - free(old); /* old definition now. */ - } - return; - - bad_define: - cerror("#define syntax error", NULLST); - inmacro = FALSE; /* Stop <newline> hack */ -} - -/* - * Replace this param if it's defined. Note that the macro name is a - * possible replacement token. We stuff DEF_MAGIC in front of the token - * which is treated as a LETTER by the token scanner and eaten by - * the output routine. This prevents the macro expander from - * looping if someone writes "#define foo foo". - */ -void checkparm(int c, DEFBUF* dp) -{ - int i; - char* cp; - - scanid(c); /* Get parm to token[] */ - for (i = 0; i < nargs; i++) /* For each argument */ - { - if (streq(parlist[i], token)) /* If it's known */ - { -#ifdef SOLAR - save(DEL); -#endif - save(i + MAC_PARM); /* Save a magic cookie */ - return; /* And exit the search */ - } - } - if (streq(dp->name, token)) /* Macro name in body? */ - save(DEF_MAGIC); /* Save magic marker */ - for (cp = token; *cp != EOS;) /* And save */ - save(*cp++); /* The token itself */ -} - -/* - * Normal string parameter scan. - */ -void stparmscan(int delim) -{ - char* wp; - int i; - - wp = workp; /* Here's where it starts */ - if (!scanstring(delim, save)) - return; /* Exit on scanstring error */ - workp[-1] = EOS; /* Erase trailing quote */ - wp++; /* -> first string content byte */ - for (i = 0; i < nargs; i++) - { - if (streq(parlist[i], wp)) - { -#ifdef SOLAR - *wp++ = DEL; -#if defined __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wconstant-conversion" -#endif - *wp++ = MAC_PARM + PAR_MAC; /* Stuff a magic marker */ -#if defined __clang__ -#pragma clang diagnostic pop -#endif - *wp++ = (char)(i + MAC_PARM); /* Make a formal marker */ - *wp = wp[-4]; /* Add on closing quote */ - workp = wp + 1; /* Reset string end */ -#else - *wp++ = MAC_PARM + PAR_MAC; /* Stuff a magic marker */ - *wp++ = (i + MAC_PARM); /* Make a formal marker */ - *wp = wp[-3]; /* Add on closing quote */ - workp = wp + 1; /* Reset string end */ -#endif - return; - } - } - workp[-1] = wp[-1]; /* Nope, reset end quote. */ -} - -/* - * Remove the symbol from the defined list. - * Called from the #control processor. - */ -void doundef() -{ - int c; - - if (type[(c = skipws())] != LET) - cerror("Illegal #undef argument", NULLST); - else - { - scanid(c); /* Get name to token[] */ - if (defendel(token, TRUE) == NULL) - { -#ifdef STRICT_UNDEF - cwarn("Symbol \"%s\" not defined in #undef", token); -#endif - } - } -} - -/* - * Put the string in the parm[] buffer. - */ -void textput(char* text) -{ - size_t size; - - size = strlen(text) + 1; - if ((parmp + size) >= &parm[NPARMWORK]) - cfatal("Macro work area overflow", NULLST); - else - { - strcpy(parmp, text); - parmp += size; - } -} - -/* - * Put the byte in the parm[] buffer. - */ -void charput(int c) -{ - if (parmp >= &parm[NPARMWORK]) - cfatal("Macro work area overflow", NULLST); - else - { - *parmp++ = (char)c; - } -} - -/* - * M a c r o E x p a n s i o n - */ - -static DEFBUF* macro; /* Catches start of infinite macro */ - -/* - * Expand a macro. Called from the cpp mainline routine (via subroutine - * macroid()) when a token is found in the symbol table. It calls - * expcollect() to parse actual parameters, checking for the correct number. - * It then creates a "file" containing a single line containing the - * macro with actual parameters inserted appropriately. This is - * "pushed back" onto the input stream. (When the get() routine runs - * off the end of the macro line, it will dismiss the macro itself.) - */ -void expand(DEFBUF* tokenp) -{ - int c; - FILEINFO* file; - -#if OSL_DEBUG_LEVEL > 1 - if (debug) - dumpadef("expand entry", tokenp); -#endif - /* - * If no macro is pending, save the name of this macro - * for an eventual error message. - */ - if (recursion++ == 0) - macro = tokenp; - else if (recursion == RECURSION_LIMIT) - { - cerror("Recursive macro definition of \"%s\"", tokenp->name); - fprintf(stderr, "(Defined by \"%s\")\n", macro->name); - if (rec_recover) - { - do - { - c = get(); - } - while (infile != NULL && infile->fp == NULL); - unget(); - recursion = 0; - return; - } - } - /* - * Here's a macro to expand. - */ - nargs = 0; /* Formals counter */ - parmp = parm; /* Setup parm buffer */ - switch (tokenp->nargs) - { - case (-2): /* __LINE__ */ - sprintf(work, "%d", line); - ungetstring(work); - break; - - case (-3): /* __FILE__ */ - for (file = infile; file != NULL; file = file->parent) - { - if (file->fp != NULL) - { - sprintf(work, "\"%s\"", (file->progname != NULL) - ? file->progname : file->filename); - ungetstring(work); - break; - } - } - break; - - default: - /* - * Nothing funny about this macro. - */ - if (tokenp->nargs < 0) - cfatal("Bug: Illegal __ macro \"%s\"", tokenp->name); - while ((c = skipws()) == '\n') /* Look for (, skipping */ - wrongline = TRUE; /* spaces and newlines */ - if (c != '(') - { - /* - * If the programmer writes - * #define foo() ... - * ... - * foo [no ()] - * just write foo to the output stream. - */ - unget(); - cwarn("Macro \"%s\" needs arguments", tokenp->name); - fputs(tokenp->name, pCppOut ); - return; - } - else if (expcollect()) /* Collect arguments */ - { - if (tokenp->nargs != nargs) /* Should be an error? */ - { - cwarn("Wrong number of macro arguments for \"%s\"", - tokenp->name); - } -#if OSL_DEBUG_LEVEL > 1 - if (debug) - dumpparm("expand"); -#endif - } /* Collect arguments */ - /* fall through */ - case DEF_NOARGS: /* No parameters just stuffs */ - expstuff(tokenp); /* Do actual parameters */ - } /* nargs switch */ -} - -/* - * Collect the actual parameters for this macro. TRUE if ok. - */ -static int expcollect() -{ - int c; - int paren; /* For embedded ()'s */ - for (;;) - { - paren = 0; /* Collect next arg. */ - while ((c = skipws()) == '\n') /* Skip over whitespace */ - wrongline = TRUE; /* and newlines. */ - if (c == ')') /* At end of all args? */ - { - /* - * Note that there is a guard byte in parm[] - * so we don't have to check for overflow here. - */ - *parmp = EOS; /* Make sure terminated */ - break; /* Exit collection loop */ - } - else if (nargs >= LASTPARM) - cfatal("Too many arguments in macro expansion", NULLST); - parlist[nargs++] = parmp; /* At start of new arg */ - for (;; c = cget()) /* Collect arg's bytes */ - { - if (c == EOF_CHAR) - { - cerror("end of file within macro argument", NULLST); - return FALSE; /* Sorry. */ - } - else if (c == '\\') /* Quote next character */ - { - charput(c); /* Save the \ for later */ - charput(cget()); /* Save the next char. */ - continue; /* And go get another */ - } - else if (type[c] == QUO) /* Start of string? */ - { - scanstring(c, charput); /* Scan it off */ - continue; /* Go get next char */ - } - else if (c == '(') /* Worry about balance */ - paren++; /* To know about commas */ - else if (c == ')') /* Other side too */ - { - if (paren == 0) /* At the end? */ - { - unget(); /* Look at it later */ - break; /* Exit arg getter. */ - } - paren--; /* More to come. */ - } - else if (c == ',' && paren == 0) /* Comma delimits args */ - break; - else if (c == '\n') /* Newline inside arg? */ - wrongline = TRUE; /* We'll need a #line */ - charput(c); /* Store this one */ - } /* Collect an argument */ - charput(EOS); /* Terminate argument */ -#if OSL_DEBUG_LEVEL > 1 - if (debug) - fprintf( pCppOut, "parm[%d] = \"%s\"\n", nargs, parlist[nargs - 1]); -#endif - } /* Collect all args. */ - return TRUE; /* Normal return */ -} - -/* - * Stuff the macro body, replacing formal parameters by actual parameters. - */ -static void expstuff(DEFBUF* tokenp) -{ - int c; /* Current character */ - char* inp; /* -> repl string */ - char* defp; /* -> macro output buff */ - size_t size; /* Actual parm. size */ - char* defend; /* -> output buff end */ - int string_magic; /* String formal hack */ - FILEINFO* file; /* Funny #include */ - - file = getfile(NBUFF, tokenp->name); - inp = tokenp->repl; /* -> macro replacement */ - defp = file->buffer; /* -> output buffer */ - defend = defp + (NBUFF - 1); /* Note its end */ - if (inp != NULL) - { - while ((c = (*inp++ & 0xFF)) != EOS) - { -#ifdef SOLAR - if (c == DEL) - { - c = (*inp++ & 0xFF); -#else - if (c >= MAC_PARM && c <= (MAC_PARM + PAR_MAC)) - { -#endif - string_magic = (c == (MAC_PARM + PAR_MAC)); - if (string_magic) - c = (*inp++ & 0xFF); - /* - * Replace formal parameter by actual parameter string. - */ - if ((c -= MAC_PARM) < nargs) - { - size = strlen(parlist[c]); - if ((defp + size) >= defend) - goto nospace; - /* - * Erase the extra set of quotes. - */ - if (string_magic && defp[-1] == parlist[c][0]) - { - strcpy(defp-1, parlist[c]); - defp += (size - 2); - } - else - { - strcpy(defp, parlist[c]); - defp += size; - } - } - } - else if (defp >= defend) - { - nospace: - cfatal("Out of space in macro \"%s\" arg expansion", - tokenp->name); - } - else - { - *defp++ = (char)c; - } - } - } - *defp = EOS; -#if OSL_DEBUG_LEVEL > 1 - if (debug > 1) - fprintf( pCppOut, "macroline: \"%s\"\n", file->buffer); -#endif - } - -#if OSL_DEBUG_LEVEL > 1 - - /* - * Dump parameter list. - */ - void dumpparm(char* why) - { - int i; - - fprintf( pCppOut, "dump of %d parameters (%" SAL_PRI_SIZET "u bytes total) %s\n", - nargs, parmp - parm, why); - for (i = 0; i < nargs; i++) - { - fprintf( pCppOut, "parm[%d] (%d) = \"%s\"\n", - i + 1, (int)strlen(parlist[i]), parlist[i]); - } - } -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/rscpp/cpp5.c b/rsc/source/rscpp/cpp5.c deleted file mode 100644 index e64a3e01327d..000000000000 --- a/rsc/source/rscpp/cpp5.c +++ /dev/null @@ -1,949 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <stdio.h> -#include <ctype.h> -#include "cppdef.h" -#include "cpp.h" - -static int evallex(int skip); -static int dosizeof(void); -static int bittest(int value); -static int evalnum(int c); -static int evalchar(int skip); -static int *evaleval(int* valp, int op, int skip); - -/* - * Evaluate an #if expression. - */ - -static char* opname[] = { /* For debug and error messages */ -"end of expression", "val", "id", - "+", "-", "*", "/", "%", - "<<", ">>", "&", "|", "^", - "==", "!=", "<", "<=", ">=", ">", - "&&", "||", "?", ":", ",", - "unary +", "unary -", "~", "!", "(", ")", "(none)", -}; - -/* - * opdope[] has the operator precedence: - * Bits - * 7 Unused (so the value is always positive) - * 6-2 Precedence (000x .. 017x) - * 1-0 Binary op. flags: - * 01 The binop flag should be set/cleared when this op is seen. - * 10 The new value of the binop flag. - * Note: Expected, New binop - * constant 0 1 Binop, end, or ) should follow constants - * End of line 1 0 End may not be preceded by an operator - * binary 1 0 Binary op follows a value, value follows. - * unary 0 0 Unary op doesn't follow a value, value follows - * ( 0 0 Doesn't follow value, value or unop follows - * ) 1 1 Follows value. Op follows. - */ - -static char opdope[OP_MAX] = { - 0001, /* End of expression */ - 0002, /* Digit */ - 0000, /* Letter (identifier) */ - 0141, 0141, 0151, 0151, 0151, /* ADD, SUB, MUL, DIV, MOD */ - 0131, 0131, 0101, 0071, 0071, /* ASL, ASR, AND, OR, XOR */ - 0111, 0111, 0121, 0121, 0121, 0121, /* EQ, NE, LT, LE, GE, GT */ - 0061, 0051, 0041, 0041, 0031, /* ANA, ORO, QUE, COL, CMA */ -/* - * Unary op's follow - */ - 0160, 0160, 0160, 0160, /* NEG, PLU, COM, NOT */ - 0170, 0013, 0023, /* LPA, RPA, END */ -}; -/* - * OP_QUE and OP_RPA have alternate precedences: - */ -#define OP_RPA_PREC 0013 -#define OP_QUE_PREC 0034 - -/* - * S_ANDOR and S_QUEST signal "short-circuit" boolean evaluation, so that - * #if FOO != 0 && 10 / FOO ... - * doesn't generate an error message. They are stored in optab.skip. - */ -#define S_ANDOR 2 -#define S_QUEST 1 - -typedef struct optab -{ - char op; /* Operator */ - char prec; /* Its precedence */ - char skip; /* Short-circuit: TRUE to skip */ -} OPTAB; -static int evalue; /* Current value from evallex() */ - -#define isbinary(op) (op >= FIRST_BINOP && op <= LAST_BINOP) - -/* - * The following definitions are used to specify basic variable sizes. - */ - -#ifndef S_CHAR -#define S_CHAR (sizeof (char)) -#endif -#ifndef S_SINT -#define S_SINT (sizeof (short int)) -#endif -#ifndef S_INT -#define S_INT (sizeof (int)) -#endif -#ifndef S_LINT -#define S_LINT (sizeof (long int)) -#endif -#ifndef S_FLOAT -#define S_FLOAT (sizeof (float)) -#endif -#ifndef S_DOUBLE -#define S_DOUBLE (sizeof (double)) -#endif -#ifndef S_PCHAR -#define S_PCHAR (sizeof (char *)) -#endif -#ifndef S_PSINT -#define S_PSINT (sizeof (short int *)) -#endif -#ifndef S_PINT -#define S_PINT (sizeof (int *)) -#endif -#ifndef S_PLINT -#define S_PLINT (sizeof (long int *)) -#endif -#ifndef S_PFLOAT -#define S_PFLOAT (sizeof (float *)) -#endif -#ifndef S_PDOUBLE -#define S_PDOUBLE (sizeof (double *)) -#endif -#ifndef S_PFPTR -#define S_PFPTR (sizeof (int (*)(void))) -#endif - -typedef struct types -{ - short type; /* This is the bit if */ - char *name; /* this is the token word */ -} TYPES; - -static TYPES basic_types[] = { - { T_CHAR, "char", }, - { T_INT, "int", }, - { T_FLOAT, "float", }, - { T_DOUBLE, "double", }, - { T_SHORT, "short", }, - { T_LONG, "long", }, - { T_SIGNED, "signed", }, - { T_UNSIGNED, "unsigned", }, - { 0, NULL, }, /* Signal end */ -}; - -/* - * Test_table[] is used to test for illegal combinations. - */ -static short test_table[] = { - T_FLOAT | T_DOUBLE | T_LONG | T_SHORT, - T_FLOAT | T_DOUBLE | T_CHAR | T_INT, - T_FLOAT | T_DOUBLE | T_SIGNED | T_UNSIGNED, - T_LONG | T_SHORT | T_CHAR, - 0 /* end marker */ -}; - -/* - * The order of this table is important -- it is also referenced by - * the command line processor to allow run-time overriding of the - * built-in size values. The order must not be changed: - * char, short, int, long, float, double (func pointer) - */ -SIZES size_table[] = { - { T_CHAR, S_CHAR, S_PCHAR }, /* char */ - { T_SHORT, S_SINT, S_PSINT }, /* short int */ - { T_INT, S_INT, S_PINT }, /* int */ - { T_LONG, S_LINT, S_PLINT }, /* long */ - { T_FLOAT, S_FLOAT, S_PFLOAT }, /* float */ - { T_DOUBLE, S_DOUBLE, S_PDOUBLE }, /* double */ - { T_FPTR, 0, S_PFPTR }, /* int (*()) */ - { 0, 0, 0 }, /* End of table */ -}; - -/* - * Evaluate an expression. Straight-forward operator precedence. - * This is called from control() on encountering an #if statement. - * It calls the following routines: - * evallex Lexical analyser -- returns the type and value of - * the next input token. - * evaleval Evaluate the current operator, given the values on - * the value stack. Returns a pointer to the (new) - * value stack. - * For compatibility with older cpp's, this return returns 1 (TRUE) - * if a syntax error is detected. - */ -int eval() -{ - int op; /* Current operator */ - int* valp; /* -> value vector */ - OPTAB* opp; /* Operator stack */ - int prec; /* Op precedence */ - int binop; /* Set if binary op. needed */ - int op1; /* Operand from stack */ - int skip; /* For short-circuit testing */ - int value[NEXP]; /* Value stack */ - OPTAB opstack[NEXP]; /* Operand stack */ - - valp = value; - opp = opstack; - opp->op = OP_END; /* Mark bottom of stack */ - opp->prec = opdope[OP_END]; /* And its precedence */ - opp->skip = 0; /* Not skipping now */ - binop = 0; - -again: -#ifdef DEBUG_EVAL - fprintf( pCppOut, "In #if at again: skip = %d, binop = %d, line is: %s", - opp->skip, binop, infile->bptr); -#endif - if ((op = evallex(opp->skip)) == OP_SUB && binop == 0) - op = OP_NEG; /* Unary minus */ - else if (op == OP_ADD && binop == 0) - op = OP_PLU; /* Unary plus */ - else if (op == OP_FAIL) - return 1; /* Error in evallex */ -#ifdef DEBUG_EVAL - fprintf( pCppOut, "op = %s, opdope = %03o, binop = %d, skip = %d\n", - opname[op], opdope[op], binop, opp->skip); -#endif - if (op == DIG) /* Value? */ - { - if (binop != 0) - { - cerror("misplaced constant in #if", NULLST); - return 1; - } - else if (valp >= &value[NEXP-1]) - { - cerror("#if value stack overflow", NULLST); - return 1; - } - else - { -#ifdef DEBUG_EVAL - fprintf( pCppOut, "pushing %d onto value stack[%td]\n", - evalue, valp - value); -#endif - *valp++ = evalue; - binop = 1; - } - goto again; - } - else if (op > OP_END) - { - cerror("Illegal #if line", NULLST); - return 1; - } - prec = opdope[op]; - if (binop != (prec & 1)) - { - cerror("Operator %s in incorrect context", opname[op]); - return 1; - } - binop = (prec & 2) >> 1; - for (;;) - { -#ifdef DEBUG_EVAL - fprintf( pCppOut, "op %s, prec %d., stacked op %s, prec %d, skip %d\n", - opname[op], prec, opname[opp->op], opp->prec, opp->skip); -#endif - if (prec > opp->prec) - { - if (op == OP_LPA) - prec = OP_RPA_PREC; - else if (op == OP_QUE) - prec = OP_QUE_PREC; - op1 = opp->skip; /* Save skip for test */ - /* - * Push operator onto op. stack. - */ - opp++; - if (opp >= &opstack[NEXP]) - { - cerror("expression stack overflow at op \"%s\"", - opname[op]); - return 1; - } - opp->op = (char)op; - opp->prec = (char)prec; - /* - * Do the short-circuit stuff here. Short-circuiting - * stops automagically when operators are evaluated. - */ - if ((op == OP_ANA && valp[-1] == 0) || - (op == OP_ORO && valp[-1] != 0)) - { - opp->skip = S_ANDOR; /* And/or skip starts */ - } - else if (op == OP_QUE) /* Start of ?: operator */ - opp->skip = (char)((op1 & S_ANDOR) | ((valp[-1] == 0) ? S_QUEST : 0)); - else if (op == OP_COL) /* : inverts S_QUEST */ - { - opp->skip = (char)((op1 & S_ANDOR) - | (((op1 & S_QUEST) != 0) ? 0 : S_QUEST)); - } - else /* Other ops leave */ - { - opp->skip = (char)op1; /* skipping unchanged. */ - } -#ifdef DEBUG_EVAL - fprintf( pCppOut, "stacking %s, valp[-1] == %d at %s", - opname[op], valp[-1], infile->bptr); - dumpstack(opstack, opp, value, valp); -#endif - goto again; - } - /* - * Pop operator from op. stack and evaluate it. - * End of stack and '(' are specials. - */ - skip = opp->skip; /* Remember skip value */ - switch ((op1 = opp->op)) /* Look at stacked op */ - { - case OP_END: /* Stack end marker */ - if (op == OP_EOE) - return valp[-1]; /* Finished ok. */ - goto again; /* Read another op. */ - - case OP_LPA: /* ( on stack */ - if (op != OP_RPA) /* Matches ) on input */ - { - cerror("unbalanced paren's, op is \"%s\"", opname[op]); - return 1; - } - opp--; /* Unstack it */ - /* goto again; -- Fall through */ - - case OP_QUE: - goto again; /* Evaluate true expr. */ - - case OP_COL: /* : on stack. */ - opp--; /* Unstack : */ - if (opp->op != OP_QUE) /* Matches ? on stack? */ - { - cerror("Misplaced '?' or ':', previous operator is %s", - opname[(int)opp->op]); - return 1; - } - /* fall through */ - /* - * Evaluate op1. - */ - default: /* Others: */ - opp--; /* Unstack the operator */ -#ifdef DEBUG_EVAL - fprintf( pCppOut, "Stack before evaluation of %s\n", opname[op1]); - dumpstack(opstack, opp, value, valp); -#endif - valp = evaleval(valp, op1, skip); -#ifdef DEBUG_EVAL - fprintf( pCppOut, "Stack after evaluation\n"); - dumpstack(opstack, opp, value, valp); -#endif - } /* op1 switch end */ - } /* Stack unwind loop */ -} - -/* - * Return next eval operator or value. Called from eval(). It - * calls a special-purpose routines for 'char' strings and - * numeric values: - * evalchar called to evaluate 'x' - * evalnum called to evaluate numbers. - */ -static int evallex(int skip) -{ - int c; - int c1; - int t; - -again: - do /* Collect the token */ - { - c = skipws(); - if ((c = macroid(c)) == EOF_CHAR || c == '\n') - { - unget(); - return OP_EOE; /* End of expression */ - } - } - while ((t = type[c]) == LET && catenate()); - if (t == INV) /* Total nonsense */ - { - if (!skip) - { - if (isascii(c) && isprint(c)) - cierror("illegal character '%c' in #if", c); - else - cierror("illegal character (%d decimal) in #if", c); - } - return OP_FAIL; - } - else if (t == QUO) /* ' or " */ - { - if (c == '\'') /* Character constant */ - { - evalue = evalchar(skip); /* Somewhat messy */ -#ifdef DEBUG_EVAL - fprintf( pCppOut, "evalchar returns %d.\n", evalue); -#endif - return DIG; /* Return a value */ - } - cerror("Can't use a string in an #if", NULLST); - return OP_FAIL; - } - else if (t == LET) /* ID must be a macro */ - { - if (streq(token, "defined")) /* Or defined name */ - { - c1 = c = skipws(); - if (c == '(') /* Allow defined(name) */ - c = skipws(); - if (type[c] == LET) - { - evalue = (lookid(c) != NULL); - if (c1 != '(' || /* Need to balance */ - skipws() == ')') /* Did we balance? */ - { - return DIG; /* Parsed ok */ - } - } - cerror("Bad #if ... defined() syntax", NULLST); - return OP_FAIL; - } - else if (streq(token, "sizeof")) /* New sizeof hackery */ - return dosizeof(); /* Gets own routine */ - /* - * The Draft ANSI C Standard says that an undefined symbol - * in an #if has the value zero. We are a bit pickier, - * warning except where the programmer was careful to write - * #if defined(foo) ? foo : 0 - */ -#ifdef STRICT_UNDEF - if (!skip) - cwarn("undefined symbol \"%s\" in #if, 0 used", token); -#endif - evalue = 0; - return DIG; - } - else if (t == DIG) /* Numbers are harder */ - { - evalue = evalnum(c); -#ifdef DEBUG_EVAL - fprintf( pCppOut, "evalnum returns %d.\n", evalue); -#endif - } - else if (strchr("!=<>&|\\", c) != NULL) - { - /* - * Process a possible multi-byte lexeme. - */ - c1 = cget(); /* Peek at next char */ - switch (c) - { - case '!': - if (c1 == '=') - return OP_NE; - break; - - case '=': - if (c1 != '=') /* Can't say a=b in #if */ - { - unget(); - cerror("= not allowed in #if", NULLST); - return OP_FAIL; - } - return OP_EQ; - - case '>': - case '<': - if (c1 == c) - return ((c == '<') ? OP_ASL : OP_ASR); - else if (c1 == '=') - return ((c == '<') ? OP_LE : OP_GE); - break; - - case '|': - case '&': - if (c1 == c) - return ((c == '|') ? OP_ORO : OP_ANA); - break; - - case '\\': - if (c1 == '\n') /* Multi-line if */ - goto again; - cerror("Unexpected \\ in #if", NULLST); - return OP_FAIL; - } - unget(); - } - return t; -} - -/* - * Process the sizeof (basic type) operation in an #if string. - * Sets evalue to the size and returns - * DIG success - * OP_FAIL bad parse or something. - */ -static int dosizeof(void) -{ - int c; - TYPES* tp; - SIZES* sizp; - short* testp; - short typecode; - - if ((c = skipws()) != '(') - goto nogood; - /* - * Scan off the tokens. - */ - typecode = 0; - while (0 != (c = skipws())) - { - if ((c = macroid(c)) == EOF_CHAR || c == '\n') - goto nogood; /* End of line is a bug */ - else if (c == '(') /* thing (*)() func ptr */ - { - if (skipws() == '*' && skipws() == ')') - { /* We found (*) */ - if (skipws() != '(') /* Let () be optional */ - unget(); - else if (skipws() != ')') - goto nogood; - typecode |= T_FPTR; /* Function pointer */ - } - else /* Junk is a bug */ - goto nogood; - } - else if (type[c] != LET) /* Exit if not a type */ - break; - else if (!catenate()) /* Maybe combine tokens */ - { - /* - * Look for this unexpandable token in basic_types. - * The code accepts "int long" as well as "long int" - * which is a minor bug as bugs go (and one shared with - * a lot of C compilers). - */ - for (tp = basic_types; tp->name != NULLST; tp++) - { - if (streq(token, tp->name)) - break; - } - if (tp->name == NULLST) - { - cerror("#if sizeof, unknown type \"%s\"", token); - return OP_FAIL; - } - typecode |= tp->type; /* Or in the type bit */ - } - } - /* - * We are at the end of the type scan. Chew off '*' if necessary. - */ - if (c == '*') - { - typecode |= T_PTR; - c = skipws(); - } - if (c == ')') /* Last syntax check */ - { - for (testp = test_table; *testp != 0; testp++) - { - if (!bittest(typecode & *testp)) - { - cerror("#if ... sizeof: illegal type combination", NULLST); - return OP_FAIL; - } - } - /* - * We assume that all function pointers are the same size: - * sizeof (int (*)()) == sizeof (float (*)()) - * We assume that signed and unsigned don't change the size: - * sizeof (signed int) == (sizeof unsigned int) - */ - if ((typecode & T_FPTR) != 0) /* Function pointer */ - typecode = T_FPTR | T_PTR; - else /* Var or var * datum */ - { - typecode &= ~(T_SIGNED | T_UNSIGNED); - if ((typecode & (T_SHORT | T_LONG)) != 0) - typecode &= ~T_INT; - } - if ((typecode & ~T_PTR) == 0) - { - cerror("#if sizeof() error, no type specified", NULLST); - return OP_FAIL; - } - /* - * Exactly one bit (and possibly T_PTR) may be set. - */ - for (sizp = size_table; sizp->bits != 0; sizp++) - { - if ((typecode & ~T_PTR) == sizp->bits) - { - evalue = ((typecode & T_PTR) != 0) - ? sizp->psize : sizp->size; - return DIG; - } - } /* We shouldn't fail */ - cierror("#if ... sizeof: bug, unknown type code 0x%x", typecode); - return OP_FAIL; - } - - nogood: - unget(); - cerror("#if ... sizeof() syntax error", NULLST); - return OP_FAIL; -} - -/* - * TRUE if value is zero or exactly one bit is set in value. - */ -static int bittest(int value) -{ -/* whoaa!! really worried about non 2's complement machines... - * but not at all about cross-compiling ? - */ -#if (4096 & ~(-4096)) == 0 - return ((value & ~(-value)) == 0); -#else - /* - * Do it the hard way (for non 2's complement machines) - */ - return (value == 0 || value ^ (value - 1) == (value * 2 - 1)); -#endif -} - -/* - * Expand number for #if lexical analysis. Note: evalnum recognizes - * the unsigned suffix, but only returns a signed int value. - */ -static int evalnum(int c) -{ - int value; - int base; - int c1; - - if (c != '0') - base = 10; - else if ((c = cget()) == 'x' || c == 'X') - { - base = 16; - c = cget(); - } - else base = 8; - value = 0; - for (;;) - { - c1 = c; - if (isascii(c) && isupper(c1)) - c1 = tolower(c1); - if (c1 >= 'a') - c1 -= ('a' - 10); - else - c1 -= '0'; - if (c1 < 0 || c1 >= base) - break; - value *= base; - value += c1; - c = cget(); - } - if (c == 'u' || c == 'U') /* Unsigned nonsense */ - cget(); - unget(); - return value; -} - -/* - * Get a character constant - */ -static int evalchar(int skip) -{ - int c; - int value; - int count; - - instring = TRUE; - if ((c = cget()) == '\\') - { - switch ((c = cget())) - { - case 'a': /* New in Standard */ -#if ('a' == '\a' || '\a' == ALERT) - value = ALERT; /* Use predefined value */ -#else - value = '\a'; /* Use compiler's value */ -#endif - break; - - case 'b': - value = '\b'; - break; - - case 'f': - value = '\f'; - break; - - case 'n': - value = '\n'; - break; - - case 'r': - value = '\r'; - break; - - case 't': - value = '\t'; - break; - - case 'v': /* New in Standard */ -#if ('v' == '\v' || '\v' == VT) - value = VT; /* Use predefined value */ -#else - value = '\v'; /* Use compiler's value */ -#endif - break; - - case 'x': /* '\xFF' */ - count = 3; - value = 0; - while ((((c = get()) >= '0' && c <= '9') || - (c >= 'a' && c <= 'f') || - (c >= 'A' && c <= 'F')) && - (--count >= 0)) - { - value *= 16; - value += (c - '0'); - } - unget(); - break; - - default: - if (c >= '0' && c <= '7') - { - count = 3; - value = 0; - while (c >= '0' && c <= '7' && --count >= 0) - { - value *= 8; - value += (c - '0'); - c = get(); - } - unget(); - } - else value = c; - break; - } - } - else if (c == '\'') - value = 0; - else - value = c; - /* - * We warn on multi-byte constants and try to hack - * (big|little)endian machines. - */ - while ((c = get()) != '\'' && c != EOF_CHAR && c != '\n') - { - if (!skip) - ciwarn("multi-byte constant '%c' isn't portable", c); - value <<= BITS_CHAR; - value += c; - } - instring = FALSE; - return value; -} - -/* - * Apply the argument operator to the data on the value stack. - * One or two values are popped from the value stack and the result - * is pushed onto the value stack. - * - * OP_COL is a special case. - * - * evaleval() returns the new pointer to the top of the value stack. - */ -static int * evaleval(int* valp, int op, int skip) -{ - int v1; - int v2 = 0; - - if (isbinary(op)) - v2 = *--valp; - v1 = *--valp; -#ifdef DEBUG_EVAL - fprintf( pCppOut, "%s op %s", (isbinary(op)) ? "binary" : "unary", - opname[op]); - if (isbinary(op)) - fprintf( pCppOut, ", v2 = %d.", v2); - fprintf( pCppOut, ", v1 = %d.\n", v1); -#endif - switch (op) - { - case OP_EOE: - break; - - case OP_ADD: - v1 += v2; - break; - - case OP_SUB: - v1 -= v2; - break; - - case OP_MUL: - v1 *= v2; - break; - - case OP_DIV: - case OP_MOD: - if (v2 == 0) - { - if (!skip) - { - cwarn("%s by zero in #if, zero result assumed", - (op == OP_DIV) ? "divide" : "mod"); - } - v1 = 0; - } - else if (op == OP_DIV) - v1 /= v2; - else - v1 %= v2; - break; - - case OP_ASL: - v1 <<= v2; - break; - - case OP_ASR: - v1 >>= v2; - break; - - case OP_AND: - v1 &= v2; - break; - - case OP_OR: - v1 |= v2; - break; - - case OP_XOR: - v1 ^= v2; - break; - - case OP_EQ: - v1 = (v1 == v2); - break; - - case OP_NE: - v1 = (v1 != v2); - break; - - case OP_LT: - v1 = (v1 < v2); - break; - - case OP_LE: - v1 = (v1 <= v2); - break; - - case OP_GE: - v1 = (v1 >= v2); - break; - - case OP_GT: - v1 = (v1 > v2); - break; - - case OP_ANA: - v1 = (v1 && v2); - break; - - case OP_ORO: - v1 = (v1 || v2); - break; - - case OP_COL: - /* - * v1 has the "true" value, v2 the "false" value. - * The top of the value stack has the test. - */ - v1 = (*--valp) ? v1 : v2; - break; - - case OP_NEG: - v1 = (-v1); - break; - - case OP_PLU: - break; - - case OP_COM: - v1 = ~v1; - break; - - case OP_NOT: - v1 = !v1; - break; - - default: - cierror("#if bug, operand = %d.", op); - v1 = 0; - } - *valp++ = v1; - return valp; -} - -#ifdef DEBUG_EVAL -dumpstack(opstack, opp, value, valp) -OPTAB opstack[NEXP]; /* Operand stack */ -OPTAB *opp; /* Operator stack */ -int value[NEXP]; /* Value stack */ -int *valp; /* -> value vector */ -{ - fprintf( pCppOut, "index op prec skip name -- op stack at %s", infile->bptr); - while (opp > opstack) - { - fprintf( pCppOut, " [%2d] %2d %03o %d %s\n", opp - opstack, - opp->op, opp->prec, opp->skip, opname[opp->op]); - opp--; - } - while (--valp >= value) - { - fprintf( pCppOut, "value[%d] = %d\n", (valp - value), *valp); - } -} -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/rscpp/cpp6.c b/rsc/source/rscpp/cpp6.c deleted file mode 100644 index 1f6bd68a44d3..000000000000 --- a/rsc/source/rscpp/cpp6.c +++ /dev/null @@ -1,1135 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <sal/types.h> -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include "cppdef.h" -#include "cpp.h" - -/*ER evaluate macros to pDefOut */ - -/* - * skipnl() skips over input text to the end of the line. - * skipws() skips over "whitespace" (spaces or tabs), but - * not skip over the end of the line. It skips over - * TOK_SEP, however (though that shouldn't happen). - * scanid() reads the next token (C identifier) into token[]. - * The caller has already read the first character of - * the identifier. Unlike macroid(), the token is - * never expanded. - * macroid() reads the next token (C identifier) into token[]. - * If it is a #defined macro, it is expanded, and - * macroid() returns TRUE, otherwise, FALSE. - * catenate() Does the dirty work of token concatenation, TRUE if it did. - * scanstring() Reads a string from the input stream, calling - * a user-supplied function for each character. - * This function may be output() to write the - * string to the output file, or save() to save - * the string in the work buffer. - * scannumber() Reads a C numeric constant from the input stream, - * calling the user-supplied function for each - * character. (output() or save() as noted above.) - * save() Save one character in the work[] buffer. - * savestring() Saves a string in malloc() memory. - * getfile() Initialize a new FILEINFO structure, called when - * #include opens a new file, or a macro is to be - * expanded. - * getmem() Get a specified number of bytes from malloc memory. - * output() Write one character to stdout (calling PUTCHAR) -- - * implemented as a function so its address may be - * passed to scanstring() and scannumber(). - * lookid() Scans the next token (identifier) from the input - * stream. Looks for it in the #defined symbol table. - * Returns a pointer to the definition, if found, or NULL - * if not present. The identifier is stored in token[]. - * defnedel() Define enter/delete subroutine. Updates the - * symbol table. - * get() Read the next byte from the current input stream, - * handling end of (macro/file) input and embedded - * comments appropriately. Note that the global - * instring is -- essentially -- a parameter to get(). - * cget() Like get(), but skip over TOK_SEP. - * unget() Push last gotten character back on the input stream. - * cerror(), cwarn(), cfatal(), cierror(), ciwarn() - * These routines format an print messages to the user. - * cerror & cwarn take a format and a single string argument. - * cierror & ciwarn take a format and a single int (char) argument. - * cfatal takes a format and a single string argument. - */ - -/* - * This table must be rewritten for a non-Ascii machine. - * - * Note that several "non-visible" characters have special meaning: - * Hex 1D DEF_MAGIC -- a flag to prevent #define recursion. - * Hex 1E TOK_SEP -- a delimiter for token concatenation - * Hex 1F COM_SEP -- a zero-width whitespace for comment concatenation - */ -#if TOK_SEP != 0x1E || COM_SEP != 0x1F || DEF_MAGIC != 0x1D - << error type table is not correct >> -#endif - -#define DOL LET - - -char type[256] = { /* Character type codes Hex */ - END, 000, 000, 000, 000, 000, 000, 000, /* 00 */ - 000, SPA, 000, 000, 000, 000, 000, 000, /* 08 */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 10 */ - 000, 000, 000, 000, 000, LET, 000, SPA, /* 18 */ - SPA,OP_NOT, QUO, 000, DOL,OP_MOD,OP_AND, QUO, /* 20 !"#$%&' */ -OP_LPA,OP_RPA,OP_MUL,OP_ADD, 000,OP_SUB, DOT,OP_DIV, /* 28 ()*+,-./ */ - DIG, DIG, DIG, DIG, DIG, DIG, DIG, DIG, /* 30 01234567 */ - DIG, DIG,OP_COL, 000, OP_LT, OP_EQ, OP_GT,OP_QUE, /* 38 89:;<=>? */ - 000, LET, LET, LET, LET, LET, LET, LET, /* 40 @ABCDEFG */ - LET, LET, LET, LET, LET, LET, LET, LET, /* 48 HIJKLMNO */ - LET, LET, LET, LET, LET, LET, LET, LET, /* 50 PQRSTUVW */ - LET, LET, LET, 000, BSH, 000,OP_XOR, LET, /* 58 XYZ[\]^_ */ - 000, LET, LET, LET, LET, LET, LET, LET, /* 60 `abcdefg */ - LET, LET, LET, LET, LET, LET, LET, LET, /* 68 hijklmno */ - LET, LET, LET, LET, LET, LET, LET, LET, /* 70 pqrstuvw */ - LET, LET, LET, 000, OP_OR, 000,OP_NOT, 000, /* 78 xyz{|}~ */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ -}; - - -/* - * C P P S y m b o l T a b l e s - */ - -/* - * SBSIZE defines the number of hash-table slots for the symbol table. - * It must be a power of 2. - */ -#ifndef SBSIZE -#define SBSIZE 64 -#endif -#define SBMASK (SBSIZE - 1) -#if (SBSIZE ^ SBMASK) != ((SBSIZE * 2) - 1) - << error, SBSIZE must be a power of 2 >> -#endif - - -static DEFBUF *symtab[SBSIZE]; /* Symbol table queue headers */ - -void InitCpp6() -{ - int i; - for( i = 0; i < SBSIZE; i++ ) - symtab[ i ] = NULL; -} - - - -/* - * Skip to the end of the current input line. - */ -void skipnl() -{ - int c; - - do - { /* Skip to newline */ - c = get(); - } - while (c != '\n' && c != EOF_CHAR); -} - -/* - * Skip over whitespace - */ -int skipws() -{ - int c; - - do { /* Skip whitespace */ - c = get(); - } while (type[c] == SPA); - return c; -} - -/* - * Get the next token (an id) into the token buffer. - * Note: this code is duplicated in lookid(). - * Change one, change both. - */ -void scanid(int c) -{ - char* bp; - - if (c == DEF_MAGIC) /* Eat the magic token */ - c = get(); /* undefiner. */ - bp = token; - do - { - if (bp < &token[IDMAX]) /* token dim is IDMAX+1 */ - *bp++ = (char)c; - c = get(); - } - while (type[c] == LET || type[c] == DIG); - unget(); - *bp = EOS; -} - -/* - * If c is a letter, scan the id. if it's #defined, expand it and scan - * the next character and try again. - * - * Else, return the character. If type[c] is a LET, the token is in token. - */ -int macroid(int c) -{ - DEFBUF* dp; - - if (infile != NULL && infile->fp != NULL) - recursion = 0; - while (type[c] == LET && (dp = lookid(c)) != NULL) - { - expand(dp); - c = get(); - } - return c; -} - -/* - * A token was just read (via macroid). - * If the next character is TOK_SEP, concatenate the next token - * return TRUE -- which should recall macroid after refreshing - * macroid's argument. If it is not TOK_SEP, unget() the character - * and return FALSE. - */ -int catenate() -{ - int c; - char* token1; - - if (get() != TOK_SEP) /* Token concatenation */ - { - unget(); - return FALSE; - } - else - { - token1 = savestring(token); /* Save first token */ - c = macroid(get()); /* Scan next token */ - switch(type[c]) /* What was it? */ - { - case LET: /* An identifier, ... */ - if (strlen(token1) + strlen(token) >= NWORK) - cfatal("work buffer overflow doing %s #", token1); - sprintf(work, "%s%s", token1, token); - break; - - case DIG: /* A digit string */ - strcpy(work, token1); - workp = work + strlen(work); - do - { - save(c); - } - while ((c = get()) != TOK_SEP); - /* - * The trailing TOK_SEP is no longer needed. - */ - save(EOS); - break; - - default: /* An error, ... */ - if (isprint(c)) - cierror("Strange character '%c' after #", c); - else - cierror("Strange character (%d.) after #", c); - strcpy(work, token1); - unget(); - break; - } - /* - * work has the concatenated token and token1 has - * the first token (no longer needed). Unget the - * new (concatenated) token after freeing token1. - * Finally, setup to read the new token. - */ - free(token1); /* Free up memory */ - ungetstring(work); /* Unget the new thing, */ - return TRUE; - } -} - -/* - * Scan off a string. Warning if terminated by newline or EOF. - * outfun() outputs the character -- to a buffer if in a macro. - * TRUE if ok, FALSE if error. - */ -int scanstring(int delim, -#ifndef _NO_PROTO - void (*outfun)( int ) /* BP */ /* Output function */ -#else - void (*outfun)() /* BP */ -#endif - ) -{ - int c; - - instring = TRUE; /* Don't strip comments */ - (*outfun)(delim); - while ((c = get()) != delim && - c != '\n' && - c != EOF_CHAR) - { - if (c != DEF_MAGIC) - (*outfun)(c); - if (c == '\\') - (*outfun)(get()); - } - instring = FALSE; - if (c == delim) - { - (*outfun)(c); - return TRUE; - } - else - { - cerror("Unterminated string", NULLST); - unget(); - return FALSE; - } -} - -/* - * Process a number. We know that c is from 0 to 9 or dot. - * Algorithm from Dave Conroy's Decus C. - */ -void scannumber(int c, -#ifndef _NO_PROTO - void (*outfun)( int ) /* BP */ /* Output/store func */ -#else - void (*outfun)() /* BP */ -#endif - ) -{ - int radix; /* 8, 10, or 16 */ - int expseen; /* 'e' seen in floater */ - int signseen; /* '+' or '-' seen */ - int octal89; /* For bad octal test */ - int dotflag; /* TRUE if '.' was seen */ - - expseen = FALSE; /* No exponent seen yet */ - signseen = TRUE; /* No +/- allowed yet */ - octal89 = FALSE; /* No bad octal yet */ - radix = 10; /* Assume decimal */ - if ((dotflag = (c == '.')) != FALSE) /* . something? */ - { - (*outfun)('.'); /* Always out the dot */ - if (type[(c = get())] != DIG) /* If not a float numb, */ - { - unget(); /* Rescan strange char */ - return; /* All done for now */ - } - } /* End of float test */ - else if (c == '0') /* Octal or hex? */ - { - (*outfun)(c); /* Stuff initial zero */ - radix = 8; /* Assume it's octal */ - c = get(); /* Look for an 'x' */ - if (c == 'x' || c == 'X') /* Did we get one? */ - { - radix = 16; /* Remember new radix */ - (*outfun)(c); /* Stuff the 'x' */ - c = get(); /* Get next character */ - } - } - for (;;) /* Process curr. char. */ - { - /* - * Note that this algorithm accepts "012e4" and "03.4" - * as legitimate floating-point numbers. - */ - if (radix != 16 && (c == 'e' || c == 'E')) - { - if (expseen) /* Already saw 'E'? */ - break; /* Exit loop, bad nbr. */ - expseen = TRUE; /* Set exponent seen */ - signseen = FALSE; /* We can read '+' now */ - radix = 10; /* Decimal exponent */ - } - else if (radix != 16 && c == '.') - { - if (dotflag) /* Saw dot already? */ - break; /* Exit loop, two dots */ - dotflag = TRUE; /* Remember the dot */ - radix = 10; /* Decimal fraction */ - } - else if (c == '+' || c == '-') /* 1.0e+10 */ - { - if (signseen) /* Sign in wrong place? */ - break; /* Exit loop, not nbr. */ - /* signseen = TRUE; */ /* Remember we saw it */ - } - else /* Check the digit */ - { - switch (c) - { - case '8': case '9': /* Sometimes wrong */ - octal89 = TRUE; /* Do check later */ - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - break; /* Always ok */ - - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - if (radix == 16) /* Alpha's are ok only */ - break; /* if reading hex. */ - default: /* At number end */ - goto done; /* Break from for loop */ - } /* End of switch */ - } /* End general case */ - (*outfun)(c); /* Accept the character */ - signseen = TRUE; /* Don't read sign now */ - c = get(); /* Read another char */ - } /* End of scan loop */ - /* - * When we break out of the scan loop, c contains the first - * character (maybe) not in the number. If the number is an - * integer, allow a trailing 'L' for long and/or a trailing 'U' - * for unsigned. If not those, push the trailing character back - * on the input stream. Floating point numbers accept a trailing - * 'L' for "long double". - */ - done: - if (dotflag || expseen) /* Floating point? */ - { - if (c == 'l' || c == 'L') - { - (*outfun)(c); - get(); /* Ungotten later */ - } - } - else /* Else it's an integer */ - { - /* - * We know that dotflag and expseen are both zero, now: - * dotflag signals "saw 'L'", and - * expseen signals "saw 'U'". - */ - for (;;) - { - switch (c) - { - case 'l': - case 'L': - if (dotflag) - goto nomore; - dotflag = TRUE; - break; - - case 'u': - case 'U': - if (expseen) - goto nomore; - expseen = TRUE; - break; - - default: - goto nomore; - } - (*outfun)(c); /* Got 'L' or 'U'. */ - c = get(); /* Look at next, too. */ - } - } - nomore: - unget(); /* Not part of a number */ - if (octal89 && radix == 8) - cwarn("Illegal digit in octal number", NULLST); -} - -void save(int c) -{ - if (workp >= &work[NWORK]) - { - work[NWORK-1] = '\0'; - cfatal("Work buffer overflow: %s", work); - } - else - *workp++ = (char)c; -} - -/* - * Store a string into free memory. - */ -char* savestring(char* text) -{ - char* result; - - size_t size = strlen(text) + 1; - result = getmem(size); - strcpy(result, text); - return result; -} - -/* - * Common FILEINFO buffer initialization for a new file or macro. - */ -FILEINFO* getfile(size_t bufsize, char* name) -{ - FILEINFO* file; - size_t size; - - size = strlen(name); /* File/macro name */ - file = (FILEINFO*) getmem(sizeof (FILEINFO) + bufsize + size); - file->parent = infile; /* Chain files together */ - file->fp = NULL; /* No file yet */ - file->filename = savestring(name); /* Save file/macro name */ - file->progname = NULL; /* No #line seen yet */ - file->unrecur = 0; /* No macro fixup */ - file->bptr = file->buffer; /* Initialize line ptr */ - file->buffer[0] = EOS; /* Force first read */ - file->line = 0; /* (Not used just yet) */ - if (infile != NULL) /* If #include file */ - infile->line = line; /* Save current line */ - infile = file; /* New current file */ - line = 1; /* Note first line */ - return file; /* All done. */ -} - -/* - * Get a block of free memory. - */ -char* getmem(size_t size) -{ - char* result; - - if ((result = malloc((unsigned) size)) == NULL) - cfatal("Out of memory", NULLST); - return result; -} - -/* - * Look for the next token in the symbol table. Returns token in "token". - * If found, returns the table pointer; Else returns NULL. - */ -DEFBUF* lookid(int c) -{ - int nhash; - DEFBUF* dp; - char* np; - int temp = 0; - int isrecurse; /* For #define foo foo */ - - np = token; - nhash = 0; - if (0 != (isrecurse = (c == DEF_MAGIC)))/* If recursive macro */ - c = get(); /* hack, skip DEF_MAGIC */ - do - { - if (np < &token[IDMAX]) /* token dim is IDMAX+1 */ - { - *np++ = (char)c; /* Store token byte */ - nhash += c; /* Update hash value */ - } - c = get(); /* And get another byte */ - } - while (type[c] == LET || type[c] == DIG); - unget(); /* Rescan terminator */ - *np = EOS; /* Terminate token */ - if (isrecurse) /* Recursive definition */ - return NULL; /* undefined just now */ - nhash += (np - token); /* Fix hash value */ - dp = symtab[nhash & SBMASK]; /* Starting bucket */ - while (dp != (DEFBUF*) NULL) /* Search symbol table */ - { - if (dp->hash == nhash && /* Fast precheck */ - (temp = strcmp(dp->name, token)) >= 0) - { - break; - } - dp = dp->link; /* Nope, try next one */ - } - return ((temp == 0) ? dp : NULL); -} - -/* - * Enter this name in the lookup table (delete = FALSE) - * or delete this name (delete = TRUE). - * Returns a pointer to the define block (delete = FALSE) - * Returns NULL if the symbol wasn't defined (delete = TRUE). - */ -DEFBUF* defendel(char* name, int delete) -{ - DEFBUF* dp; - DEFBUF** prevp; - char* np; - int nhash; - int temp=0; - int size; - - for (nhash = 0, np = name; *np != EOS;) - nhash += *np++; - size = (np - name); - nhash += size; - prevp = &symtab[nhash & SBMASK]; - while ((dp = *prevp) != (DEFBUF*) NULL) - { - if (dp->hash == nhash && - (temp = strcmp(dp->name, name)) >= 0) - { - if (temp > 0) - dp = NULL; /* Not found */ - else - { - *prevp = dp->link; /* Found, unlink and */ - if (dp->repl != NULL) /* Free the replacement */ - free(dp->repl); /* if any, and then */ - free((char*) dp); /* Free the symbol */ - dp = NULL; - } - break; - } - prevp = &dp->link; - } - if (!delete) - { - dp = (DEFBUF*) getmem(sizeof (DEFBUF) + size + 1); - dp->link = *prevp; - *prevp = dp; - dp->hash = nhash; - dp->repl = NULL; - dp->nargs = 0; - strcpy(dp->name, name); - } - return dp; -} - -#if OSL_DEBUG_LEVEL > 1 - -void dumpdef(char* why) -{ - DEFBUF* dp; - DEFBUF** syp; - FILE* pRememberOut = NULL; - - if ( bDumpDefs ) /*ER */ - { - pRememberOut = pCppOut; - pCppOut = pDefOut; - } - fprintf( pCppOut, "CPP symbol table dump %s\n", why); - for (syp = symtab; syp < &symtab[SBSIZE]; syp++) - { - if ((dp = *syp) != (DEFBUF*) NULL) - { - fprintf( pCppOut, "symtab[%" SAL_PRI_PTRDIFFT "d]\n", (syp - symtab)); - do - { - dumpadef((char*) NULL, dp); - } - while ((dp = dp->link) != (DEFBUF*) NULL); - } - } - if ( bDumpDefs ) - { - fprintf( pCppOut, "\n"); - pCppOut = pRememberOut; - } -} - -void dumpadef(char* why, DEFBUF* dp) -{ - char* cp; - int c; - FILE* pRememberOut = NULL; - -/*ER dump #define's to pDefOut */ - if ( bDumpDefs ) - { - pRememberOut = pCppOut; - pCppOut = pDefOut; - } - fprintf( pCppOut, " \"%s\" [%d]", dp->name, dp->nargs); - if (why != NULL) - fprintf( pCppOut, " (%s)", why); - if (dp->repl != NULL) - { - fprintf( pCppOut, " => "); - for (cp = dp->repl; (c = *cp++ & 0xFF) != EOS;) - { -#ifdef SOLAR - if (c == DEL) - { - c = *cp++ & 0xFF; - if( c == EOS ) break; - fprintf( pCppOut, "<%%%d>", c - MAC_PARM); - } -#else - if (c >= MAC_PARM && c <= (MAC_PARM + PAR_MAC)) - fprintf( pCppOut, "<%%%d>", c - MAC_PARM); -#endif - else if (isprint(c) || c == '\n' || c == '\t') - PUTCHAR(c); - else if (c < ' ') - fprintf( pCppOut, "<^%c>", c + '@'); - else - fprintf( pCppOut, "<\\0%o>", c); - } -/*ER evaluate macros to pDefOut */ -#ifdef EVALDEFS - if ( bDumpDefs && !bIsInEval && dp->nargs <= 0 ) - { - FILEINFO* infileSave = infile; - char* tokenSave = savestring( token ); - char* workSave = savestring( work ); - int lineSave = line; - int wronglineSave = wrongline; - int recursionSave = recursion; - FILEINFO* file; - EVALTYPE valEval; - - bIsInEval = 1; - infile = NULL; /* start from scrap */ - line = 0; - wrongline = 0; - *token = EOS; - *work = EOS; - recursion = 0; - file = getfile( strlen( dp->repl ), dp->name ); - strcpy( file->buffer, dp->repl ); - fprintf( pCppOut, " ===> "); - nEvalOff = 0; - cppmain(); /* get() frees also *file */ - valEval = 0; - if ( 0 == evaluate( EvalBuf, &valEval ) ) - { -#ifdef EVALFLOATS - if ( valEval != (EVALTYPE)((long)valEval ) ) - fprintf( pCppOut, " ==eval=> %f", valEval ); - else -#endif - fprintf( pCppOut, " ==eval=> %ld", (long)valEval ); - } - recursion = recursionSave; - wrongline = wronglineSave; - line = lineSave; - strcpy( work, workSave ); - free( workSave ); - strcpy( token, tokenSave ); - free( tokenSave ); - infile = infileSave; - bIsInEval = 0; - } -#endif - } - else - { - fprintf( pCppOut, ", no replacement."); - } - PUTCHAR('\n'); - if ( bDumpDefs ) - pCppOut = pRememberOut; -} -#endif - -/* - * G E T - */ - -/* - * Return the next character from a macro or the current file. - * Handle end of file from #include files. - */ -int get() -{ - int c; - FILEINFO* file; - int popped; /* Recursion fixup */ - - popped = 0; - get_from_file: - if ((file = infile) == NULL) - return EOF_CHAR; - newline: - - /* - * Read a character from the current input line or macro. - * At EOS, either finish the current macro (freeing temp. - * storage) or read another line from the current input file. - * At EOF, exit the current file (#include) or, at EOF from - * the cpp input file, return EOF_CHAR to finish processing. - */ - if ((c = *file->bptr++ & 0xFF) == EOS) - { - /* - * Nothing in current line or macro. Get next line (if - * input from a file), or do end of file/macro processing. - * In the latter case, jump back to restart from the top. - */ - if (file->fp == NULL) /* NULL if macro */ - { - popped++; - recursion -= file->unrecur; - if (recursion < 0) - recursion = 0; - infile = file->parent; /* Unwind file chain */ - } - else /* Else get from a file */ - { - if ((file->bptr = fgets(file->buffer, NBUFF, file->fp)) != NULL) - { -#if OSL_DEBUG_LEVEL > 1 - if (debug > 1) /* Dump it to stdout */ - { - fprintf( pCppOut, "\n#line %d (%s), %s", - line, file->filename, file->buffer); - } -#endif - goto newline; /* process the line */ - } - else - { - if( file->fp != stdin ) - fclose(file->fp); /* Close finished file */ - if ((infile = file->parent) != NULL) - { - /* - * There is an "ungotten" newline in the current - * infile buffer (set there by doinclude() in - * cpp1.c). Thus, we know that the mainline code - * is skipping over blank lines and will do a - * #line at its convenience. - */ - wrongline = TRUE; /* Need a #line now */ - } - } - } - /* - * Free up space used by the (finished) file or macro and - * restart input from the parent file/macro, if any. - */ - free(file->filename); /* Free name and */ - if (file->progname != NULL) /* if a #line was seen, */ - free(file->progname); /* free it, too. */ - free((char*) file); /* Free file space */ - if (infile == NULL) /* If at end of file */ - return EOF_CHAR; /* Return end of file */ - line = infile->line; /* Reset line number */ - goto get_from_file; /* Get from the top. */ - } - /* - * Common processing for the new character. - */ - if (c == DEF_MAGIC && file->fp != NULL) /* Don't allow delete */ - goto newline; /* from a file */ - if (file->parent != NULL) /* Macro or #include */ - { - if (popped != 0) - file->parent->unrecur += popped; - else - { - recursion -= file->parent->unrecur; - if (recursion < 0) - recursion = 0; - file->parent->unrecur = 0; - } - } -#if (HOST == SYS_UNIX) - if (c == '\r') - return get(); /* DOS fuck */ -#endif - if (c == '\n') /* Maintain current */ - ++line; /* line counter */ - if (instring) /* Strings just return */ - return c; /* the character. */ - else if (c == '/') /* Comment? */ - { - instring = TRUE; /* So get() won't loop */ - - c = get(); - if ((c != '*') && (c != '/')) /* Next byte '*'? */ - { - instring = FALSE; /* Nope, no comment */ - unget(); /* Push the char. back */ - return '/'; /* Return the slash */ - } - if (keepcomments) /* If writing comments */ - { - PUTCHAR('/'); /* Write out the */ - /* initializer */ - if( '*' == c ) - PUTCHAR('*'); - else - PUTCHAR('/'); - } - if( '*' == c ) - { - for (;;) /* Eat a comment */ - { - c = get(); - test: - if (keepcomments && c != EOF_CHAR) - cput(c); - switch (c) - { - case EOF_CHAR: - cerror("EOF in comment", NULLST); - return EOF_CHAR; - - case '/': - if ((c = get()) != '*') /* Don't let comments */ - goto test; /* Nest. */ -#ifdef STRICT_COMMENTS - cwarn("Nested comments", NULLST); -#endif - /* fall through *//* into * stuff */ - case '*': - if ((c = get()) != '/') /* If comment doesn't */ - goto test; /* end, look at next */ - instring = FALSE; /* End of comment, */ - if (keepcomments) /* Put out the comment */ - { - cput(c); /* terminator, too */ - } - /* - * A comment is syntactically "whitespace" -- - * however, there are certain strange sequences - * such as - * #define foo(x) (something) - * foo|* comment *|(123) - * these are '/' ^ ^ - * where just returning space (or COM_SEP) will cause - * problems. This can be "fixed" by overwriting the - * '/' in the input line buffer with ' ' (or COM_SEP) - * but that may mess up an error message. - * So, we peek ahead -- if the next character is - * "whitespace" we just get another character, if not, - * we modify the buffer. All in the name of purity. - */ - if (*file->bptr == '\n' || type[*file->bptr & 0xFF] == SPA) - goto newline; - return (file->bptr[-1] = ' '); - - case '\n': /* we'll need a #line */ - if (!keepcomments) - wrongline = TRUE; /* later... */ - default: /* Anything else is */ - break; /* Just a character */ - } /* End switch */ - } /* End comment loop */ - } - else /* c++ comment */ - { - for (;;) /* Eat a comment */ - { - c = get(); - if (keepcomments && c != EOF_CHAR) - cput(c); - if( EOF_CHAR == c ) - return EOF_CHAR; - else if( '\n' == c ) - { - instring = FALSE; /* End of comment, */ - return c; - } - } - } - } /* End if in comment */ - else if (!inmacro && c == '\\') /* If backslash, peek */ - { - if ((c = get()) == '\n') /* for a <nl>. If so, */ - { - wrongline = TRUE; - goto newline; - } - else /* Backslash anything */ - { - unget(); /* Get it later */ - return '\\'; /* Return the backslash */ - } - } - else if (c == '\f' || c == VT) /* Form Feed, Vertical */ - { - c = ' '; /* Tab are whitespace */ - } - else if (c == 0xef) /* eat up UTF-8 BOM */ - { - if((c = get()) == 0xbb) - { - if((c = get()) == 0xbf) - { - c = get(); - return c; - } - else - { - unget(); - unget(); - return 0xef; - } - } - else - { - unget(); - return 0xef; - } - } - return c; /* Just return the char */ -} - -/* - * Backup the pointer to reread the last character. Fatal error - * (code bug) if we backup too far. unget() may be called, - * without problems, at end of file. Only one character may - * be ungotten. If you need to unget more, call ungetstring(). - */ -void unget() -{ - FILEINFO* file; - - if ((file = infile) == NULL) - return; /* Unget after EOF */ - if (--file->bptr < file->buffer) - cfatal("Too much pushback", NULLST); - if (*file->bptr == '\n') /* Ungetting a newline? */ - --line; /* Unget the line number, too */ -} - -/* - * Push a string back on the input stream. This is done by treating - * the text as if it were a macro. - */ -void ungetstring(char* text) -{ - FILEINFO* file; - file = getfile(strlen(text) + 1, ""); - strcpy(file->buffer, text); -} - -/* - * Get one character, absorb "funny space" after comments or - * token concatenation - */ -int cget() -{ - int c; - - do - { - c = get(); - } - while (c == TOK_SEP); - return c; -} - -/* - * Error messages and other hacks. The first byte of severity - * is 'S' for string arguments and 'I' for int arguments. This - * is needed for portability with machines that have int's that - * are shorter than char *'s. - */ - -/* - * Print filenames, macro names, and line numbers for error messages. - */ -static void domsg(char* severity, char* format, void* arg) -{ - char* tp; - FILEINFO* file; - - fprintf(stderr, "%sline %d, %s: ", MSG_PREFIX, line, &severity[1]); - if (*severity == 'S') - fprintf(stderr, format, (char*)arg); - else - fprintf(stderr, format, *((int*)arg) ); - putc('\n', stderr); - if ((file = infile) == NULL) - return; /* At end of file */ - if (file->fp != NULL) - { - tp = file->buffer; /* Print current file */ - fprintf(stderr, "%s", tp); /* name, making sure */ - if (tp[strlen(tp) - 1] != '\n') /* there's a newline */ - putc('\n', stderr); - } - while ((file = file->parent) != NULL) /* Print #includes, too */ - { - if (file->fp == NULL) - fprintf(stderr, "from macro %s\n", file->filename); - else - { - tp = file->buffer; - fprintf(stderr, "from file %s, line %d:\n%s", - (file->progname != NULL) - ? file->progname : file->filename, - file->line, tp); - if (tp[strlen(tp) - 1] != '\n') - putc('\n', stderr); - } - } -} - -/* - * Print a normal error message, string argument. - */ -void cerror(char* format, char* sarg) -{ - domsg("SError", format, sarg); - errors++; -} - -/* - * Print a normal error message, numeric argument. - */ -void cierror(char* format, int narg) -{ - domsg("IError", format, &narg); - errors++; -} - -/* - * A real disaster - */ -void cfatal(char* format, char* sarg) -{ - domsg("SFatal error", format, sarg); - exit(IO_ERROR); -} - -/* - * A non-fatal error, string argument. - */ -void cwarn(char* format, char* sarg) -{ - domsg("SWarning", format, sarg); -} - -/* - * A non-fatal error, numeric argument. - */ -void ciwarn(char* format, int narg) -{ - domsg("IWarning", format, &narg); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/rscpp/cppdef.h b/rsc/source/rscpp/cppdef.h deleted file mode 100644 index 32d35a87d252..000000000000 --- a/rsc/source/rscpp/cppdef.h +++ /dev/null @@ -1,178 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_RSC_SOURCE_RSCPP_CPPDEF_H -#define INCLUDED_RSC_SOURCE_RSCPP_CPPDEF_H - -/* - * This redundant definition of TRUE and FALSE works around - * a limitation of Decus C. - */ -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif - -/* - * Define the HOST operating system. This is needed so that - * cpp can use appropriate filename conventions. - */ -#define SYS_UNKNOWN 0 -#define SYS_UNIX 1 - -#ifndef HOST -#ifdef unix -#define HOST SYS_UNIX -#else -#endif -#endif - -#ifndef HOST -#define HOST SYS_UNKNOWN -#endif - -/* - * We assume that the target is the same as the host system - */ -#ifndef TARGET -#define TARGET HOST -#endif - -/* - * In order to predefine machine-dependent constants, - * several strings are defined here: - * - * MACHINE defines the target cpu (by name) - * SYSTEM defines the target operating system - * COMPILER defines the target compiler - * - * The above may be #defined as "" if they are not wanted. - * They should not be #defined as NULL. - * - * LINE_PREFIX defines the # output line prefix, if not "line" - * This should be defined as "" if cpp is to replace - * the "standard" C pre-processor. - * - * OK_DATE Predefines the compilation date if set TRUE. - * Not permitted by the Nov. 12, 1984 Draft Standard. - * - * S_CHAR etc. Define the sizeof the basic TARGET machine word types. - * By default, sizes are set to the values for the HOST - * computer. If this is inappropriate, see the code in - * cpp3.c for details on what to change. Also, if you - * have a machine where sizeof (signed int) differs from - * sizeof (unsigned int), you will have to edit code and - * tables in cpp3.c (and extend the -S option definition.) - * - * CPP_LIBRARY May be defined if you have a site-specific include directory - * which is to be searched *before* the operating-system - * specific directories. - */ - -#if TARGET == SYS_UNIX -#define SYSTEM "unix" -#endif - -/* - * defaults - */ - -#ifndef MSG_PREFIX -#define MSG_PREFIX "cpp: " -#endif - -#ifndef LINE_PREFIX -#define LINE_PREFIX "" -#endif - -/* - * RECURSION_LIMIT may be set to -1 to disable the macro recursion test. - */ -#ifndef RECURSION_LIMIT -#define RECURSION_LIMIT 1000 -#endif - -/* - * BITS_CHAR may be defined to set the number of bits per character. - * it is needed only for multi-byte character constants. - */ -#ifndef BITS_CHAR -#define BITS_CHAR 8 -#endif - -/* - * OK_DATE may be enabled to predefine today's date as a string - * at the start of each compilation. This is apparently not permitted - * by the Draft Ansi Standard. - */ -#ifndef OK_DATE -#define OK_DATE TRUE -#endif - -/* - * The following definitions are used to allocate memory for - * work buffers. In general, they should not be modified - * by implementors. - * - * PAR_MAC The maximum number of #define parameters (31 per Standard) - * Note: we need another one for strings. - * IDMAX The longest identifier, 31 per Ansi Standard - * NBUFF Input buffer size - * NWORK Work buffer size -- the longest macro - * must fit here after expansion. - * NEXP The nesting depth of #if expressions - * NINCLUDE The number of directories that may be specified - * on a per-system basis, or by the -I option. - * BLK_NEST The number of nested #if's permitted. - * NFWORK FileNameWorkBuffer (added by erAck, was NWORK) - */ - -#ifndef IDMAX -#define IDMAX 127 -#endif -#ifdef SOLAR -#define PAR_MAC (253 + 1) -#else -#define PAR_MAC (31 + 1) -#endif -/* - * NWORK increased due to large macros in *.src, - * added a proper bunch right away, because we are soon going to have 10 languages. - */ -#define NWORK 128000 -#define NBUFF NWORK -#define NFWORK 1024 -#define NEXP 128 -#define NINCLUDE 100 -#define NPARMWORK (NWORK * 2) -#define BLK_NEST 32 - - -#ifndef ALERT -#define ALERT '\007' /* '\a' is "Bell" */ -#endif - -#ifndef VT -#define VT '\013' /* Vertical Tab CTRL/K */ -#endif - - -#endif // INCLUDED_RSC_SOURCE_RSCPP_CPPDEF_H - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/tools/rscchar.cxx b/rsc/source/tools/rscchar.cxx deleted file mode 100644 index f081773344cc..000000000000 --- a/rsc/source/tools/rscchar.cxx +++ /dev/null @@ -1,172 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <stdio.h> -#include <string.h> - -#include <rsctools.hxx> - -#include <rtl/textcvt.h> -#include <rtl/textenc.h> -#include <rtl/alloc.h> -#include <rtl/character.hxx> - -char * RscChar::MakeUTF8( char * pStr, sal_uInt16 nTextEncoding ) -{ - std::size_t nMaxUniCodeBuf = strlen( pStr ) + 1; - if( nMaxUniCodeBuf * 6 > 0x0FFFFF ) - RscExit( 10 ); - - char * pOrgStr = new char[ nMaxUniCodeBuf ]; - sal_uInt32 nOrgLen = 0; - - char cOld = '1'; - while( cOld != 0 ) - { - char c; - - if( *pStr == '\\' ) - { - ++pStr; - switch( *pStr ) - { - case 'a': - c = '\a'; - break; - case 'b': - c = '\b'; - break; - case 'f': - c = '\f'; - break; - case 'n': - c = '\n'; - break; - case 'r': - c = '\r'; - break; - case 't': - c = '\t'; - break; - case 'v': - c = '\v'; - break; - case '\\': - c = '\\'; - break; - case '?': - c = '\?'; - break; - case '\'': - c = '\''; - break; - case '\"': - c = '\"'; - break; - default: - { - if( '0' <= *pStr && '7' >= *pStr ) - { - sal_uInt16 nChar = 0; - int i = 0; - while( '0' <= *pStr && '7' >= *pStr && i != 3 ) - { - nChar = nChar * 8 + (sal_uInt8)*pStr - (sal_uInt8)'0'; - ++pStr; - i++; - } - if( nChar > 255 ) - { - // value is too big, or more than 3 digits - delete [] pOrgStr; - return nullptr; - } - c = (char)nChar; - pStr--; - } - else if( 'x' == *pStr ) - { - sal_uInt16 nChar = 0; - int i = 0; - ++pStr; - while( rtl::isAsciiHexDigit( static_cast<unsigned char>(*pStr) ) && i != 2 ) - { - if( rtl::isAsciiDigit( static_cast<unsigned char>(*pStr) ) ) - nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'0'; - else if( rtl::isAsciiUpperCase( static_cast<unsigned char>(*pStr) ) ) - nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'A' +10; - else - nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'a' +10; - ++pStr; - i++; - } - c = (char)nChar; - pStr--; - } - else - c = *pStr; - }; - } - } - else - c = *pStr; - pOrgStr[ nOrgLen++ ] = c; - cOld = *pStr; - pStr++; - } - - sal_Unicode * pUniCode = new sal_Unicode[ nMaxUniCodeBuf ]; - rtl_TextToUnicodeConverter hConv = rtl_createTextToUnicodeConverter( nTextEncoding ); - - sal_uInt32 nInfo; - sal_Size nSrcCvtBytes; - sal_Size nUniSize = rtl_convertTextToUnicode( hConv, nullptr, - pOrgStr, nOrgLen, - pUniCode, nMaxUniCodeBuf, - RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT - | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT - | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT - | RTL_TEXTTOUNICODE_FLAGS_FLUSH, - &nInfo, - &nSrcCvtBytes ); - - rtl_destroyTextToUnicodeConverter( hConv ); - delete[] pOrgStr; - pOrgStr = nullptr; - - hConv = rtl_createUnicodeToTextConverter( RTL_TEXTENCODING_UTF8 ); - // factor of 6 is the maximum size of an UNICODE character as utf8 - char * pUtf8 = static_cast<char *>(rtl_allocateMemory( nUniSize * 6 )); - rtl_convertUnicodeToText( hConv, nullptr, - pUniCode, nUniSize, - pUtf8, nUniSize * 6, - RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT - | RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT - | RTL_UNICODETOTEXT_FLAGS_FLUSH, - &nInfo, - &nSrcCvtBytes ); - - rtl_destroyTextToUnicodeConverter( hConv ); - delete[] pUniCode; - pUniCode = nullptr; - - return pUtf8; -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/tools/rscdef.cxx b/rsc/source/tools/rscdef.cxx deleted file mode 100644 index f721e925fb5d..000000000000 --- a/rsc/source/tools/rscdef.cxx +++ /dev/null @@ -1,664 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -// overall program includes -#include <rscdef.hxx> - -#include <limits.h> - -bool RscId::bNames = true; - -void RscId::SetNames( bool bSet ) -{ - bNames = bSet; -} - -sal_Int32 RscId::GetNumber() const -{ - sal_Int32 lVal; - aExp.Evaluate( &lVal ); - return lVal; -} - -void RscId::Create( const RscExpType & rExpType ) -{ - aExp = rExpType; - if( aExp.IsDefinition() ) - aExp.aExp.pDef->IncRef(); - else if( aExp.IsExpression() ) - { - sal_Int32 lValue; - - aExp.Evaluate( &lValue ); - aExp.SetLong( lValue ); - } -} - -void RscId::Destroy() -{ - if( aExp.IsDefinition() ) - aExp.aExp.pDef->DecRef(); - aExp.cType = RSCEXP_NOTHING; -} - -RscId::RscId( const RscId& rRscId ) -{ - aExp = rRscId.aExp; - if( aExp.IsDefinition() ) - aExp.aExp.pDef->IncRef(); -} - -RscId::RscId( RscDefine * pDef ) -{ - RscExpType aExpType; - - aExpType.aExp.pDef = pDef; - aExpType.cType = RSCEXP_DEF; - aExpType.cUnused = false; - Create( aExpType ); -} - -RscId& RscId::operator = ( const RscId& rRscId ) -{ - if( rRscId.aExp.IsDefinition() ) - rRscId.aExp.aExp.pDef->IncRef(); - Destroy(); - aExp = rRscId.aExp; - return *this; -} - -bool RscId::operator == ( const RscId& rRscId ) const -{ - return GetNumber() == rRscId.GetNumber(); -} - -bool RscId::operator < ( const RscId& rRscId ) const -{ - return GetNumber() < rRscId.GetNumber(); -} - -bool RscId::operator > ( const RscId& rRscId ) const -{ - return GetNumber() > rRscId.GetNumber(); -} - -OString RscId::GetName() const -{ - OStringBuffer aStr; - - if ( !aExp.IsNothing() ) - { - if( bNames ) - aExp.AppendMacro(aStr); - else - aStr.append(GetNumber()); - } - - return aStr.makeStringAndClear(); -} - -RscDefine::RscDefine( RscFileTab::Index lKey, const OString& rDefName, sal_Int32 lDefId ) - : m_aName( rDefName ) -{ - nRefCount = 0; - lFileKey = lKey; - lId = lDefId; - pExp = nullptr; -} - -RscDefine::RscDefine( RscFileTab::Index lKey, const OString& rDefName, - RscExpression * pExpression ) - : lId(0), m_aName( rDefName ) -{ - nRefCount = 0; - lFileKey = lKey; - pExpression->Evaluate( &lId ); - pExp = pExpression; -} - -RscDefine::~RscDefine() -{ - delete pExp; - if( nRefCount ) - RscExit( 14 ); -} - -void RscDefine::DecRef() -{ - nRefCount--; - if( 0 == nRefCount ) - { - delete this; - } -} - -void RscDefine::DefineToNumber() -{ - delete pExp; - pExp = nullptr; - m_aName = OString::number(lId); -} - -void RscDefine::Evaluate() -{ - if( pExp ) - pExp->Evaluate( &lId ); -} - -RscDefine * RscDefine::Search( const char * pSearch ) const -{ - return static_cast<RscDefine *>(NameNode::Search( static_cast<const void *>(pSearch) )); -} - -COMPARE RscDefine::Compare( const NameNode * pSearch ) const -{ - int nCmp = m_aName.compareTo( static_cast<const RscDefine *>(pSearch)->m_aName ); - if( nCmp < 0 ) - return LESS; - else if( nCmp > 0 ) - return GREATER; - else - return EQUAL; -} - -// pSearch is a pointer to const char * -COMPARE RscDefine::Compare( const void * pSearch ) const -{ - int nCmp = m_aName.compareTo( static_cast<const char *>(pSearch) ); - - if( nCmp < 0 ) - return LESS; - else if( nCmp > 0 ) - return GREATER; - else - return EQUAL; -} - -RscDefine * RscDefineList::New( RscFileTab::Index lFileKey, const OString& rDefName, - sal_Int32 lDefId, size_t lPos ) -{ - RscDefine * pDef; - - pDef = new RscDefine( lFileKey, rDefName, lDefId ); - pDef->IncRef(); - if ( lPos < maList.size() ) - { - RscSubDefList::iterator it = maList.begin(); - ::std::advance( it, lPos ); - maList.insert( it, pDef ); - } - else - { - maList.push_back( pDef ); - } - return pDef; -} - -RscDefine * RscDefineList::New( RscFileTab::Index lFileKey, const OString& rDefName, - RscExpression * pExpression, size_t lPos ) -{ - RscDefine * pDef; - - pDef = new RscDefine( lFileKey, rDefName, pExpression ); - pDef->IncRef(); - if ( lPos < maList.size() ) - { - RscSubDefList::iterator it = maList.begin(); - ::std::advance( it, lPos ); - maList.insert( it, pDef ); - } - else - { - maList.push_back( pDef ); - } - return pDef; -} - -bool RscDefineList::Remove() -{ - if ( maList.empty() ) - return false; - - maList[ 0 ]->DefineToNumber(); - maList[ 0 ]->DecRef(); - maList.erase( maList.begin() ); - return true; -} - -bool RscExpType::Evaluate( sal_Int32 * plValue ) const -{ - if( IsDefinition() ) - { - aExp.pDef->Evaluate(); - // ignore potential errors - *plValue = aExp.pDef->GetNumber(); - } - else if( IsExpression() ) - return aExp.pExp->Evaluate( plValue ); - else if( IsNothing() ) - *plValue = 0; - else - *plValue = GetLong(); - - return true; -} - -void RscExpType::AppendMacro(OStringBuffer& rStr) const -{ - if( IsDefinition() ) - rStr.append(aExp.pDef->GetName()); - else if( IsExpression() ) - rStr.append(aExp.pExp->GetMacro()); - else if( IsNumber() ) - rStr.append(GetLong()); -} - - -RscExpression::RscExpression( RscExpType aLE, char cOp, RscExpType aRE ) -{ - aLeftExp = aLE; - cOperation = cOp; - aRightExp = aRE; - if( aLeftExp.IsDefinition() ) - aLeftExp.aExp.pDef->IncRef(); - if( aRightExp.IsDefinition() ) - aRightExp.aExp.pDef->IncRef(); -} - -RscExpression::~RscExpression() -{ - if( aLeftExp.IsDefinition() ) - aLeftExp.aExp.pDef->DecRef(); - else if( aLeftExp.IsExpression() ) - delete aLeftExp.aExp.pExp; - - if( aRightExp.IsDefinition() ) - aRightExp.aExp.pDef->DecRef(); - else if( aRightExp.IsExpression() ) - delete aRightExp.aExp.pExp; -} - -bool RscExpression::Evaluate( sal_Int32 * plValue ) -{ - sal_Int32 lLeft; - sal_Int32 lRight; - - // interpret left and right branches - if( aLeftExp.Evaluate( &lLeft ) && aRightExp.Evaluate( &lRight ) ) - { - if( cOperation == '&' ) - *plValue = lLeft & lRight; - else if( cOperation == '|' ) - *plValue = lLeft | lRight; - else if( cOperation == '+' ) - *plValue = lLeft + lRight; - else if( cOperation == '-' ) - *plValue = lLeft - lRight; - else if( cOperation == '*' ) - *plValue = lLeft * lRight; - else if( cOperation == 'r' ) - *plValue = lLeft >> lRight; - else if( cOperation == 'l' ) - *plValue = lLeft << lRight; - else - { - if( 0 == lRight ) - return false; - *plValue = lLeft / lRight; - } - return true; - } - return false; -} - -OString RscExpression::GetMacro() -{ - OStringBuffer aLeft; - - // output optimization - if( aLeftExp.IsNothing() ) - { - if ( '-' == cOperation ) - { - aLeft.append('('); - aLeft.append('-'); - } - aRightExp.AppendMacro(aLeft); - if( '-' == cOperation ) - { - aLeft.append(')'); - } - } - else if( aRightExp.IsNothing() ) - aLeftExp.AppendMacro(aLeft); - else - { - aLeft.append('('); - // interpret left branch - aLeftExp.AppendMacro(aLeft); - - aLeft.append(cOperation); - - aLeft.append('('); - // interpret right branch - aRightExp.AppendMacro(aLeft); - aLeft.append(')'); - - aLeft.append(')'); - } - - return aLeft.makeStringAndClear(); -} - -RscFile::RscFile() -{ - bLoaded = false; - bIncFile = false; - bScanned = false; -} - -RscFile::~RscFile() -{ - for ( size_t i = 0, n = aDepLst.size(); i < n; ++i ) - delete aDepLst[ i ]; - aDepLst.clear(); - - // from back to front is better because of dependencies - // objects are destroyed when reference counter is NULL - while( aDefLst.Remove() ) ; -} - -bool RscFile::Depend( RscFileTab::Index lDepend, RscFileTab::Index lFree ) -{ - for ( size_t i = aDepLst.size(); i > 0; ) - { - RscDepend * pDep = aDepLst[ --i ]; - if( pDep->GetFileKey() == lDepend ) - { - for ( size_t j = i ? --i : 0; j > 0; ) - { - pDep = aDepLst[ --j ]; - if( pDep->GetFileKey() == lFree ) - return true; - } - return false; - } - } - return true; -} - -void RscFile::InsertDependFile( RscFileTab::Index lIncFile ) -{ - for ( size_t i = 0, n = aDepLst.size(); i < n; ++i ) - { - RscDepend* pDep = aDepLst[ i ]; - if( pDep->GetFileKey() == lIncFile ) - return; - } - - aDepLst.push_back( new RscDepend( lIncFile ) ); -} - -RscDefTree::~RscDefTree() -{ - Remove(); -} - -void RscDefTree::Remove() -{ - while( pDefRoot ) - { - RscDefine * pDef = pDefRoot; - pDefRoot = static_cast<RscDefine *>(pDefRoot->Remove( pDefRoot )); - pDef->DecRef(); - } -} - -RscDefine * RscDefTree::Search( const char * pName ) -{ - if( pDefRoot ) - return pDefRoot->Search( pName ); - return nullptr; -} - -void RscDefTree::Insert( RscDefine * pDef ) -{ - if( pDefRoot ) - pDefRoot->Insert( pDef ); - else - pDefRoot = pDef; - pDef->IncRef(); -} - -void RscDefTree::Remove( RscDefine * pDef ) -{ - if( pDefRoot ) - { - // in case pDef == pDefRoot - pDefRoot = static_cast<RscDefine *>(pDefRoot->Remove( pDef )); - } - pDef->DecRef(); -} - -bool RscDefTree::Evaluate( RscDefine * pDef ) -{ - if( pDef ) - { - if( !Evaluate( static_cast<RscDefine *>(pDef->Left()) ) ) - return false; - if( !Evaluate( static_cast<RscDefine *>(pDef->Right()) ) ) - return false; - } - return true; -} - -RscFileTab::RscFileTab() -{ -} - -RscFileTab::~RscFileTab() -{ - - aDefTree.Remove(); - - Index aIndex = LastIndex(); - while( aIndex != IndexNotFound ) - { - delete Remove( aIndex ); - aIndex = LastIndex(); - }; -} - -RscFileTab::Index RscFileTab::Find( const OString& rName ) -{ - Index aIndex = FirstIndex(); - while( aIndex != IndexNotFound && (Get(aIndex)->aFileName != rName) ) - aIndex = NextIndex(aIndex); - - return aIndex; -} - -RscDefine * RscFileTab::FindDef( const char * pName ) -{ - return aDefTree.Search( pName ); -} - -/* This method gives back true when lDepend - exists and is behind lFree, or when lDepend does not exist. */ -bool RscFileTab::Depend( Index lDepend, Index lFree ) -{ - if( lDepend == lFree ) - return true; - - Index aIndex = FirstIndex(); - while( aIndex != IndexNotFound ) - { - RscFile * pFile = Get(aIndex); - if( !pFile->IsIncFile() ) - { - if( !pFile->Depend( lDepend, lFree ) ) - return false; - } - aIndex = NextIndex(aIndex); - } - - return true; -} - -bool RscFileTab::TestDef( Index lFileKey, size_t lPos, - const RscDefine * pDefDec ) -{ - if( lFileKey == pDefDec->GetFileKey() ) - { - RscFile * pFile = GetFile( pDefDec->GetFileKey() ); - if( pFile && (lPos <= pFile->aDefLst.GetPos( const_cast<RscDefine *>(pDefDec) )) - && (lPos != ULONG_MAX ) ) - { - return false; - } - } - else if( !Depend( lFileKey, pDefDec->GetFileKey() ) ) - return false; - - return TestDef( lFileKey, lPos, pDefDec->pExp ); -} - -bool RscFileTab::TestDef( Index lFileKey, size_t lPos, - const RscExpression * pExpDec ) -{ - if( !pExpDec ) - return true; - - if( pExpDec->aLeftExp.IsExpression() ) - if( !TestDef( lFileKey, lPos, pExpDec->aLeftExp.aExp.pExp ) ) - return false; - - if( pExpDec->aLeftExp.IsDefinition() ) - if( !TestDef( lFileKey, lPos, pExpDec->aLeftExp.aExp.pDef ) ) - return false; - - if( pExpDec->aRightExp.IsExpression() ) - if( !TestDef( lFileKey, lPos, pExpDec->aRightExp.aExp.pExp ) ) - return false; - - if( pExpDec->aRightExp.IsDefinition() ) - if( !TestDef( lFileKey, lPos, pExpDec->aRightExp.aExp.pDef ) ) - return false; - - return true; -} - -RscDefine * RscFileTab::NewDef( Index lFileKey, const OString& rDefName, - sal_Int32 lId ) -{ - RscDefine * pDef = FindDef( rDefName ); - - if( !pDef ) - { - RscFile * pFile = GetFile( lFileKey ); - - if( pFile ) - { - pDef = pFile->aDefLst.New( lFileKey, rDefName, lId, ULONG_MAX ); - aDefTree.Insert( pDef ); - } - } - else - pDef = nullptr; - - return pDef; -} - -RscDefine * RscFileTab::NewDef( Index lFileKey, const OString& rDefName, - RscExpression * pExp ) -{ - RscDefine * pDef = FindDef( rDefName ); - - if( !pDef ) - { - // are macros in expressions defined? - if( TestDef( lFileKey, ULONG_MAX, pExp ) ) - { - RscFile * pFile = GetFile( lFileKey ); - - if( pFile ) - { - pDef = pFile->aDefLst.New( lFileKey, rDefName, pExp, ULONG_MAX ); - aDefTree.Insert( pDef ); - } - } - } - else - pDef = nullptr; - - if( !pDef ) - { - // pExp is always owned and must be deleted after used - delete pExp; - } - return pDef; -} - -void RscFileTab::DeleteFileContext( Index lFileKey ) -{ - RscFile* pFName = GetFile( lFileKey ); - if( pFName ) - { - for ( size_t i = 0, n = pFName->aDefLst.maList.size(); i < n; ++i ) - { - RscDefine * pDef = pFName->aDefLst.maList[ i ]; - aDefTree.Remove( pDef ); - }; - - while( pFName->aDefLst.Remove() ) ; - } -} - -RscFileTab::Index RscFileTab::NewCodeFile( const OString& rName ) -{ - Index lKey = Find( rName ); - if( lKey == IndexNotFound ) - { - RscFile * pFName = new RscFile(); - pFName->aFileName = rName; - pFName->aPathName = rName; - lKey = Insert( pFName ); - pFName->InsertDependFile( lKey ); - } - return lKey; -} - -RscFileTab::Index RscFileTab::NewIncFile(const OString& rName, - const OString& rPath) -{ - Index lKey = Find( rName ); - if( lKey == IndexNotFound ) - { - RscFile * pFName = new RscFile(); - pFName->aFileName = rName; - pFName->aPathName = rPath; - pFName->SetIncFlag(); - lKey = Insert( pFName ); - pFName->InsertDependFile( lKey ); - } - return lKey; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/tools/rschash.cxx b/rsc/source/tools/rschash.cxx deleted file mode 100644 index 65388ec91ca2..000000000000 --- a/rsc/source/tools/rschash.cxx +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <rschash.hxx> - - -AtomContainer::AtomContainer() -{ - m_aStringToID[ OString() ] = 0; - m_aIDToString[ 0 ].clear(); - m_nNextID = 1; -} - -AtomContainer::~AtomContainer() -{ -} - -Atom AtomContainer::getID( const OString& rStr, bool bOnlyIfExists ) -{ - OString aKey = rStr.toAsciiLowerCase(); - std::unordered_map< OString, Atom, OStringHash >::const_iterator it = - m_aStringToID.find( aKey ); - if( it != m_aStringToID.end() ) - return it->second; - - if( bOnlyIfExists ) - return InvalidAtom; - - Atom aRet = m_nNextID; - m_aStringToID[ aKey ] = m_nNextID; - m_aIDToString[ m_nNextID ] = rStr; - m_nNextID++; - return aRet; -} - -const OString& AtomContainer::getString( Atom nAtom ) -{ - std::unordered_map< Atom, OString >::const_iterator it = - m_aIDToString.find( nAtom ); - return (it != m_aIDToString.end()) ? it->second : m_aIDToString[0]; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/tools/rsctools.cxx b/rsc/source/tools/rsctools.cxx deleted file mode 100644 index e65874a10b0e..000000000000 --- a/rsc/source/tools/rsctools.cxx +++ /dev/null @@ -1,255 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> -#if defined(_WIN32) -#include <direct.h> -#endif -#include <string.h> - -#include <rscdef.hxx> -#include <rsctools.hxx> - -#include <osl/file.h> -#include <rtl/alloc.h> -#include <rtl/character.hxx> -#include <sal/log.hxx> - -/* case insensitive compare of two strings up to a given length */ -int rsc_strnicmp( const char *string1, const char *string2, size_t count ) -{ - return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( - string1, strlen (string1), string2, strlen (string2), count); -} - -/* case insensitive compare of two strings */ -int rsc_stricmp( const char *string1, const char *string2 ) -{ - return rtl_str_compareIgnoreAsciiCase( string1, string2 ); -} - -char* rsc_strdup( const char* pStr ) -{ - int nLen = strlen( pStr ); - char* pBuffer = static_cast<char*>(rtl_allocateMemory( nLen+1 )); - memcpy( pBuffer, pStr, nLen+1 ); - return pBuffer; -} - -OString GetTmpFileName() -{ - OUString aTmpURL, aTmpFile; - osl_createTempFile( nullptr, nullptr, &aTmpURL.pData ); - osl_getSystemPathFromFileURL( aTmpURL.pData, &aTmpFile.pData ); - return OUStringToOString( aTmpFile, RTL_TEXTENCODING_MS_1252 ); -} - -/* replaces extension of a file name */ -OString OutputFile(const OString &rInput, const char * pExt) -{ - sal_Int32 nSepInd = rInput.lastIndexOf('.'); - - if( nSepInd != -1 ) - { - return rInput.copy(0, nSepInd + 1).concat(OString(pExt)); - } - - return rInput.concat(OString(".")).concat(OString(pExt)); -} - -char * ResponseFile( RscPtrPtr * ppCmd, char ** ppArgv, sal_uInt32 nArgc ) -{ - FILE *fFile; - int nItems; - char szBuffer[4096]; // file buffer - sal_uInt32 i; - bool bInQuotes = false; - - // program name - ppCmd->Append( rsc_strdup( *ppArgv ) ); - for( i = 1; i < nArgc; i++ ) - { - if( '@' == **(ppArgv +i) ){ // when @, then response file - if( nullptr == (fFile = fopen( (*(ppArgv +i)) +1, "r" )) ) - return *(ppArgv +i); - nItems = fread( &szBuffer[ 0 ], 1, sizeof( char ), fFile ); - while( nItems ) - { - if( !rtl::isAsciiWhiteSpace( - static_cast<unsigned char>(szBuffer[ 0 ]) ) ) - { - /* - * #i27914# double ticks '"' now have a duplicate function: - * 1. they define a string ( e.g. -DFOO="baz" ) - * 2. a string can contain spaces, so -DFOO="baz zum" defines one - * argument no two ! - */ - unsigned int n = 0; - while( nItems && - (!rtl::isAsciiWhiteSpace( - static_cast<unsigned char>(szBuffer[ n ]) ) || - bInQuotes) && - n +1 < sizeof( szBuffer ) ) - { - n++; - nItems = fread( &szBuffer[ n ], 1, - sizeof( char ), fFile ); - if( szBuffer[n] == '"' ) - bInQuotes = !bInQuotes; - } - szBuffer[ n ] = '\0'; - ppCmd->Append( rsc_strdup( szBuffer ) ); - } - nItems = fread( &szBuffer[ 0 ], 1, sizeof( char ), fFile ); - } - - fclose( fFile ); - } - else - ppCmd->Append( rsc_strdup( *(ppArgv +i) ) ); - } - ppCmd->Append( static_cast<void *>(nullptr) ); - return nullptr; -} - - -RscPtrPtr::RscPtrPtr() -{ - nCount = 0; - pMem = nullptr; -} - -RscPtrPtr::~RscPtrPtr() -{ - Reset(); -} - -void RscPtrPtr::Reset() -{ - sal_uInt32 i; - - if( pMem ) - { - for( i = 0; i < nCount; i++ ) - { - if( pMem[ i ] ) - rtl_freeMemory( pMem[ i ] ); - } - rtl_freeMemory( static_cast<void *>(pMem) ); - }; - nCount = 0; - pMem = nullptr; -} - -sal_uInt32 RscPtrPtr::Append( void * pBuffer ) -{ - if( !pMem ) - pMem = static_cast<void **>(rtl_allocateMemory( (nCount +1) * sizeof( void * ) )); - else - pMem = static_cast<void **>(rtl_reallocateMemory( static_cast<void *>(pMem), - ((nCount +1) * sizeof( void * ) - ) )); - pMem[ nCount ] = pBuffer; - return nCount++; -} - -void * RscPtrPtr::GetEntry( sal_uInt32 nEntry ) -{ - if( nEntry < nCount ) - return pMem[ nEntry ]; - return nullptr; -} - -RscWriteRc::RscWriteRc( RSCBYTEORDER_TYPE nOrder ) -{ - bSwap = false; - if( nOrder != RSC_SYSTEMENDIAN ) - { - RSCBYTEORDER_TYPE nMachineOrder; -#if defined OSL_LITENDIAN - nMachineOrder = RSC_LITTLEENDIAN; -#else - nMachineOrder = RSC_BIGENDIAN; -#endif - bSwap = nOrder != nMachineOrder; - } - nLen = 0; - pMem = nullptr; -} - -RscWriteRc::~RscWriteRc() -{ - if( pMem ) - rtl_freeMemory( pMem ); -} - -sal_uInt32 RscWriteRc::IncSize( sal_uInt32 nSize ) -{ - sal_uInt32 nOrigPos = nLen; - nLen += nSize; - if( pMem ) - pMem = static_cast<char*>(rtl_reallocateMemory( pMem, nLen )); - if( pMem ) - memset( pMem + nOrigPos, 0, nSize ); - return nOrigPos; -} - -char * RscWriteRc::GetPointer( sal_uInt32 nSize ) -{ - if( !pMem ) - { - pMem = static_cast<char *>(rtl_allocateMemory( nLen )); - memset( pMem, 0, nLen ); - } - return pMem + nSize; -} - - -void RscWriteRc::Put( sal_uInt16 nVal ) -{ - sal_uInt32 nOldLen; - - nOldLen = IncSize( sizeof( nVal ) ); - PutAt( nOldLen, nVal ); -} - -void RscWriteRc::PutUTF8( char * pStr ) -{ - sal_uInt32 nStrLen = 0; - if( pStr ) - nStrLen = strlen( pStr ); - - sal_uInt32 n = nStrLen +1; - if( n % 2 ) - // align to 2 - n++; - - sal_uInt32 nOldLen = IncSize( n ); - char * p = GetPointer( nOldLen ); - if (nStrLen != 0) - { - memcpy( p, pStr, nStrLen ); - } - // 0 terminated - pMem[ nOldLen + nStrLen ] = '\0'; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/tools/rsctree.cxx b/rsc/source/tools/rsctree.cxx deleted file mode 100644 index 6add08277267..000000000000 --- a/rsc/source/tools/rsctree.cxx +++ /dev/null @@ -1,359 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <tools/link.hxx> -#include <rsctree.hxx> - - -NameNode::NameNode() -{ - pLeft = pRight = nullptr; -} - -NameNode::~NameNode() -{ -} - -void NameNode::EnumNodes( Link<const NameNode&,void> aLink ) const -{ - if( Left() ) - Left()->EnumNodes( aLink ); - aLink.Call( *this ); - if( Right() ) - Right()->EnumNodes( aLink ); -} - -NameNode * NameNode::ChangeDLListBTree( NameNode * pList ) -{ - NameNode * pMiddle; - NameNode * pTmp; - sal_uInt32 nEle, i; - - if( pList ) - { - while( pList->Left() ) - pList = pList->Left(); - pTmp = pList; - - for( nEle = 0; pTmp->Right(); nEle++ ) - pTmp = pTmp->Right(); - - pMiddle = pList; - if( nEle / 2 ) - { - for( i = 0; i < (nEle / 2); i++ ) - { - pMiddle = pMiddle->Right(); - } - } - else - { - pList = nullptr; - } - if( nullptr != (pTmp = pMiddle->Left()) ) // set right pointer to NULL - pTmp->pRight = nullptr; - - // set left pointer to NULL - NameNode * pRightNode = pMiddle->Right(); - if (pRightNode) - pRightNode->pLeft = nullptr; - - pMiddle->pLeft = ChangeDLListBTree( pList ); - pMiddle->pRight = ChangeDLListBTree( pRightNode ); - - return pMiddle; - } - return pList; -} - -NameNode * NameNode::ChangeBTreeDLList() -{ - NameNode * pList; - NameNode * pLL_RN; // right node of left list - - if( Right() ) - { - pList = Right()->ChangeBTreeDLList(); - pRight = pList; - pList->pLeft = this; - } - pList = this; - if( Left() ) - { - pLL_RN = pList = Left()->ChangeBTreeDLList(); - - while( pLL_RN->Right() ) - pLL_RN = pLL_RN->Right(); - - pLeft = pLL_RN; - pLL_RN->pRight = this; - } - return pList; -} - -NameNode * NameNode::Remove( NameNode * pRemove ) -{ - NameNode * pRoot = this; - NameNode * pParent = SearchParent( pRemove ); - - if( pParent ) - { - if( pParent->Left() && - (EQUAL == pRemove->Compare( pParent->Left() ) ) ) - { - pParent->pLeft = pRemove->Left(); - if( pRemove->Right() ) - pParent->Insert( pRemove->Right() ); - } - else if( pParent->Right() && - (EQUAL == pRemove->Compare( pParent->Right() ) ) ) - { - pParent->pRight = pRemove->Right(); - if( pRemove->Left() ) - pParent->Insert( pRemove->Left() ); - } - } - else if( EQUAL == this->Compare( pRemove ) ) - { - if( Right() ) - { - pRoot = Right(); - if( Left() ) - Right()->Insert( Left() ); - } - else - { - pRoot = Left(); - } - } - pRemove->pLeft = pRemove->pRight = nullptr; - - return pRoot; -} - - -COMPARE NameNode::Compare( const NameNode * pCompare ) const -{ - if( reinterpret_cast<sal_uIntPtr>(this) < reinterpret_cast<sal_uIntPtr>(pCompare) ) - return LESS; - else if( reinterpret_cast<sal_uIntPtr>(this) > reinterpret_cast<sal_uIntPtr>(pCompare) ) - return GREATER; - else - return EQUAL; -} - -COMPARE NameNode::Compare( const void * pCompare ) const -{ - if( reinterpret_cast<sal_uIntPtr>(this) < reinterpret_cast<sal_uIntPtr>(pCompare) ) - return LESS; - else if( reinterpret_cast<sal_uIntPtr>(this) > reinterpret_cast<sal_uIntPtr>(pCompare) ) - return GREATER; - else - return EQUAL; -} - -// search for a parent node. -// return a pointer to the parent node if found. -// otherwise return 0. -NameNode* NameNode::SearchParent( const NameNode * pSearch ) const -{ - int nCmp = Compare( pSearch ); - - if( nCmp == GREATER ) - { - if( Left() ) - { - if( Left()->Compare( pSearch ) == EQUAL ) - return const_cast<NameNode *>(this); - return Left()->SearchParent( pSearch ); - } - } - else if( nCmp == LESS ) - { - if( Right() ) - { - if( Right()->Compare( pSearch ) == EQUAL ) - return const_cast<NameNode *>(this); - return Right()->SearchParent( pSearch ); - } - } - return nullptr; -} - -// search for a node. -// return a pointer to the node if found. -// otherwise return 0. -NameNode* NameNode::Search( const NameNode * pSearch ) const -{ - int nCmp = Compare( pSearch ); - - if( nCmp == GREATER ) - { - if( Left() ) - return Left()->Search( pSearch ); - } - else if( nCmp == LESS ) - { - if( Right() ) - return Right()->Search( pSearch ); - } - else - return const_cast<NameNode *>(this); - - return nullptr; -} - -// search for a node. -// return a pointer to the node if found. -// otherwise return 0. -NameNode* NameNode::Search( const void * pSearch ) const -{ - int nCmp = Compare( pSearch ); - - if( nCmp == GREATER ) - { - if( Left() ) - return Left()->Search( pSearch ); - } - else if( nCmp == LESS ) - { - if( Right() ) - return Right()->Search( pSearch ); - } - else - return const_cast<NameNode *>(this); - - return nullptr; -} - -// A node is inserted into the tree -// If a node with the same name already exists, then returns false -// otherwise, returns true, In any case, the node will be inserted -bool NameNode::Insert( NameNode * pTN, sal_uInt32* pnDepth ) -{ - bool bRet = true; - int nCmp = Compare( pTN ); - - *pnDepth += 1; - if( nCmp == GREATER ) - { - if( Left() ) - bRet = Left()->Insert( pTN, pnDepth ); - else - pLeft = pTN; - } - else - { - if( Right() ) - bRet = Right()->Insert( pTN, pnDepth ); - else - pRight = pTN; - - if( nCmp == EQUAL ) - bRet = false; - } - return bRet; -} - -// insert a node in the tree. -// if the node with the same name is in, return false and no insert. -// if not return true. -bool NameNode::Insert( NameNode * pTN ) -{ - sal_uInt32 nDepth = 0; - bool bRet; - - bRet = Insert( pTN, &nDepth ); - if( bRet ) - { - if( nDepth > 20 ) - { - if( Left() ) - pLeft = ChangeDLListBTree( Left()->ChangeBTreeDLList() ); - if( Right() ) - pRight = ChangeDLListBTree( Right()->ChangeBTreeDLList() ); - } - } - - return bRet; -} - -void NameNode::OrderTree() -{ - NameNode * pTmpLeft = Left(); - NameNode * pTmpRight = Right(); - - pLeft = nullptr; - pRight = nullptr; - SubOrderTree( pTmpLeft ); - SubOrderTree( pTmpRight ); -} - -void NameNode::SubOrderTree( NameNode * pOrderNode ) -{ - if( pOrderNode ) - { - NameNode * pTmpLeft = pOrderNode->Left(); - NameNode * pTmpRight = pOrderNode->Right(); - pOrderNode->pLeft = nullptr; - pOrderNode->pRight = nullptr; - Insert( pOrderNode ); - SubOrderTree( pTmpLeft ); - SubOrderTree( pTmpRight ); - } -} - -IdNode * IdNode::Search( sal_uInt32 nTypeName ) const -{ - return static_cast<IdNode *>(NameNode::Search( static_cast<const void *>(&nTypeName) )); -} - -COMPARE IdNode::Compare( const NameNode * pSearch ) const -{ - if( GetId() < static_cast<const IdNode *>(pSearch)->GetId() ) - return LESS; - else if( GetId() > static_cast<const IdNode *>(pSearch)->GetId() ) - return GREATER; - else - return EQUAL; -} - -// pSearch is a pointer to sal_uInt32 -COMPARE IdNode::Compare( const void * pSearch ) const -{ - if( GetId() < *static_cast<const sal_uInt32 *>(pSearch) ) - return LESS; - else if( GetId() > *static_cast<const sal_uInt32 *>(pSearch) ) - return GREATER; - else - return EQUAL; -} - -sal_uInt32 IdNode::GetId() const -{ - return 0xFFFFFFFF; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |