Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #ifndef __MSVCDOTNET__
20 #pragma warning(disable: 4710)
21 #endif //__MSVCDOTNET__
23 int const MajorVersion=1;
24 int const MinorVersion=6;
37 #else //!__MSVCDOTNET__
41 #endif //__MSVCDOTNET__
43 char const* const Margin=" ";
45 template <class T> inline T min(T a,T b) {return a<b ? a : b;}
46 template <class T> inline T max(T a,T b) {return a>b ? a : b;}
61 inline Handle(unsigned aValue) :iValue(aValue) {}
62 inline bool IsNull() const {return iValue==0;}
63 inline int Avail() const {return iValue&AvailBit;}
64 inline int IsDelta() const {return iValue&TocDelta;}
65 inline bool IsTocBase() const {return iValue==TocBase;}
66 inline int Generation() const {return (iValue&GenMask)>>GenShift;}
67 inline int Index() const {return iValue&IndexMask;}
68 inline int operator==(Handle aHandle) const {return iValue==aHandle.iValue;}
69 inline int operator!=(Handle aHandle) const {return iValue!=aHandle.iValue;}
73 friend class StreamId;
74 friend ostream& operator<<(ostream&,Handle);
77 class StreamId : public Handle
79 enum {Mask=0xfffffff};
81 inline StreamId(Handle aHandle) :Handle(aHandle.iValue&Mask) {}
88 inline FramePos(int aPos) :iValue(aPos) {}
89 inline int Pos() const {return iValue;}
93 friend ostream& operator<<(ostream&,FramePos);
99 inline FileOffset(int anOffset) :iValue(anOffset) {}
100 inline int Offset() const {return iValue;}
101 // offset/pos conversion
102 FileOffset(FramePos aPos);
103 operator FramePos() const;
107 friend ostream& operator<<(ostream&,FileOffset);
112 enum {TypeMask=0xc000,TypeShift=14,LengthMask=0x3fff};
114 enum {First=0x20,Size=2,Interval=0x4002,FullShift=14};
115 enum {Free=0,Data,Toc,Continuation};
118 inline FrameDes(unsigned aDes) :iDes((unsigned short)aDes) {}
119 inline int Type() const {return iDes>>TypeShift;}
120 inline int Length() const {return iDes&LengthMask;}
124 friend ostream& operator<<(ostream&,FrameDes);
125 friend istream& operator>>(istream&,FrameDes&);
130 enum {dirty=0x1,backupshift=1};
132 enum {tocoffset=-12};
139 enum {Offset=0x10,Size=14};
141 inline int Empty() const {return Toc().Pos()<0;}
142 inline int Dirty() const {return iBackupToc&dirty;}
143 FramePos Toc() const;
144 Reloc const* GetReloc() const;
156 unsigned long iHandle;
162 ostream& operator<<(ostream&,Header const&);
172 typedef Element const* Iterator;
177 void Add(FramePos aPos,FrameDes aDes);
179 Iterator Find(FramePos aPos) const;
180 inline Iterator Begin() const {return iRep;}
181 inline Iterator End() const {return iRep+iElements;}
183 static int Compare(void const* aLeft,void const* aRight);
193 inline Stream(Frames const& aFrames,FramePos aPos) :iFrame(aFrames.Find(aPos)) {}
194 inline Stream(Frames::Iterator aFrame) :iFrame(aFrame) {}
195 inline int IsGood() const {return iFrame!=NULL;}
196 inline int Type() const {return iFrame->iDes.Type();}
197 inline Frames::Iterator Frame() const {return iFrame;}
199 void* Load(istream& aStream) const;
201 Frames::Iterator iFrame;
210 inline StreamId Root() const {return StreamId(iRoot);}
211 inline int IsDelta() const {return iRoot.IsDelta();}
220 unsigned short iMagic;
221 unsigned char iCount;
225 enum {BaseSize=5,BaseRedundant=3,DeltaSize=8};
226 inline Handle Link() const {return iLink;}
227 inline FramePos Pos() const {return iPos;}
236 typedef Entry const* Iterator;
241 void Load(istream& aStream,Frames const& aFrames,Frames::Iterator aFrame,Header::Reloc const* aReloc);
242 inline Head const& Header() const {return iHeader;}
243 inline Iterator Begin() const {return iRep;}
244 inline Iterator End() const {return iRep+iHeader.iCount;}
245 inline Entry const& operator[](int anIndex) {return iRep[anIndex-1];}
247 void Base(const char* aPtr,int aCount);
255 friend ostream& operator<<(ostream&,Toc const&);
260 enum {HexInterval=0x10};
266 void Dump(istream& aStream,int aBytes);
272 char iChar[HexInterval+4];
277 enum {PermanentFileStoreUid=268435536};
279 StoreFile(char const* aFile);
282 inline int Empty() const {return iHeader.Empty();}
300 class binbuf : public streambuf
312 enum {frame=0x1,quiet=0x2,verbose=0x4,compare=0x8};
316 int ProcessCommandLine(int argc,char ** argv);
320 inline int Option(int type) const {return iOptions&type;}
321 inline int TocRevision() const {return iTocRevision;}
323 static void Abort(char const* message);
324 static void Corrupt(char const* message);
325 static ostream& Error();
326 static ostream& Warning();
336 extern Program TheProgram;