📄 undname.inl
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of your Microsoft Windows CE
// Source Alliance Program license form. If you did not accept the terms of
// such a license, you are not authorized to use this source code.
//
/*
* This module contains the definitions for the inline functions used by the
* name undecorator. It is intended that this file should be included
* somewhere in the source file for the undecorator to maximise the chance
* that they will be truly inlined.
*/
// The following class is a special node class, used in the implementation
// of the internal chaining mechanism of the 'DName's
class charNode;
class pcharNode;
class pDNameNode;
class DNameStatusNode;
#if ( NO_VIRTUAL )
enum NodeType
{
charNode_t,
pcharNode_t,
pDNameNode_t,
DNameStatusNode_t
};
#endif // NO_VIRTUAL
class DNameNode
{
private:
#if NO_VIRTUAL
NodeType typeIndex;
#endif // NO_VIRTUAL
DNameNode * next;
protected:
#if ( !NO_VIRTUAL )
__near DNameNode ();
#else // } elif NO_VIRTUAL {
__near DNameNode ( NodeType );
#endif // NO_VIRTUAL
__near DNameNode ( const DNameNode & );
public:
virtual int __near length () const PURE;
virtual char __near getLastChar () const PURE;
virtual pchar_t __near getString ( pchar_t, int ) const PURE;
DNameNode * __near clone ();
DNameNode * __near nextNode () const;
DNameNode & __near operator += ( DNameNode * );
};
class charNode : public DNameNode
{
private:
char me;
public:
__near charNode ( char );
virtual int __near length () const;
virtual char __near getLastChar () const;
virtual pchar_t __near getString ( pchar_t, int ) const;
};
class pcharNode : public DNameNode
{
private:
pchar_t me;
int myLen;
public:
__near pcharNode ( pcchar_t, int = 0 );
virtual int __near length () const;
virtual char __near getLastChar () const;
virtual pchar_t __near getString ( pchar_t, int ) const;
};
class pDNameNode : public DNameNode
{
private:
DName * me;
public:
__near pDNameNode ( DName * );
virtual int __near length () const;
virtual char __near getLastChar () const;
virtual pchar_t __near getString ( pchar_t, int ) const;
};
class DNameStatusNode : public DNameNode
{
private:
#define TruncationMessage (" ?? ")
#define TruncationMessageLength (4)
DNameStatus me;
int myLen;
public:
__near DNameStatusNode ( DNameStatus );
virtual int __near length () const;
virtual char __near getLastChar () const;
virtual pchar_t __near getString ( pchar_t, int ) const;
};
// Memory allocation functions
inline void __far * __near __pascal operator new ( unsigned int sz, HeapManager &, int noBuffer )
{ return heap.getMemory ( sz, noBuffer ); }
void __far * __near HeapManager::getMemory ( unsigned int sz, int noBuffer )
{
// Align the allocation on an appropriate boundary
sz = (( sz + PACK_SIZE-1 ) & ~(PACK_SIZE-1) );
if ( noBuffer )
return ( *pOpNew )( sz );
else
{
// Handler a potential request for no space
if ( !sz )
sz = 1;
if ( blockLeft < sz )
{
// Is the request greater than the largest buffer size ?
if ( sz > memBlockSize )
return 0; // If it is, there is nothing we can do
// Allocate a new block
Block * pNewBlock = rnew Block;
// Did the allocation succeed ? If so connect it up
if ( pNewBlock )
{
// Handle the initial state
if ( tail )
tail = tail->next = pNewBlock;
else
head = tail = pNewBlock;
// Compute the remaining space
blockLeft = memBlockSize - sz;
} // End of IF then
else
return 0; // Oh-oh! Memory allocation failure
} // End of IF then
else
blockLeft -= sz; // Deduct the allocated amount
// And return the buffer address
return &( tail->memBlock[ blockLeft ]);
} // End of IF else
} // End of "HeapManager" FUNCTION "getMemory(unsigned int,int)"
// Friend functions of 'DName'
inline DName __near __pascal operator + ( char c, const DName & rd )
{ return DName ( c ) + rd; }
inline DName __near __pascal operator + ( DNameStatus st, const DName & rd )
{ return DName ( st ) + rd; }
inline DName __near __pascal operator + ( pcchar_t s, const DName & rd )
{ return DName ( s ) + rd; }
// The 'DName' constructors
inline __near DName::DName () { node = 0; stat = DN_valid; isIndir = 0; isAUDC = 0; isAUDTThunk = 0; NoTE = 0; }
inline __near DName::DName ( DNameNode * pd ) { node = pd; stat = DN_valid; isIndir = 0; isAUDC = 0; isAUDTThunk = 0; NoTE = 0; }
__near DName::DName ( char c )
{
stat = DN_valid;
isIndir = 0;
isAUDC = 0;
isAUDTThunk = 0;
node = 0;
NoTE = 0;
// The NULL character is boring, do not copy
if ( c )
doPchar ( &c, 1 );
} // End of "DName" CONSTRUCTOR '(char)'
#if 1
inline __near DName::DName ( const DName & rd )
{
stat = rd.stat;
isIndir = rd.isIndir;
isAUDC = rd.isAUDC;
isAUDTThunk = rd.isAUDTThunk;
node = rd.node;
NoTE = rd.NoTE;
} // End of "DName" CONSTRUCTOR '(const DName&)'
#endif
__near DName::DName ( DName * pd )
{
if ( pd )
{
node = gnew pDNameNode ( pd );
stat = ( node ? DN_valid : DN_error );
} // End of IF else
else
{
stat = DN_valid;
node = 0;
} // End of IF else
isIndir = 0;
isAUDC = 0;
isAUDTThunk = 0;
NoTE = 0;
} // End of "DName" CONSTRUCTOR '( DName* )'
__near DName::DName ( pcchar_t s )
{
stat = DN_valid;
node = 0;
isIndir = 0;
isAUDC = 0;
isAUDTThunk = 0;
NoTE = 0;
if ( s )
doPchar ( s, strlen ( s ));
} // End of "DName" CONSTRUCTOR '(pcchar_t)'
__near DName::DName ( pcchar_t & name, char terminator )
{
stat = DN_valid;
isIndir = 0;
isAUDC = 0;
isAUDTThunk = 0;
node = 0;
NoTE = 0;
// Is there a string ?
if ( name )
if ( *name )
{
int len = 0;
// How long is the string ?
for ( pcchar_t s = name; *name && ( *name != terminator ); name++ )
if ( isValidIdentChar ( *name ) || UnDecorator::doNoIdentCharCheck () )
len++;
else
{
stat = DN_invalid;
return;
} // End of IF else
// Copy the name string fragment
doPchar ( s, len );
// Now gobble the terminator if present, handle error conditions
if ( *name )
{
if ( *name++ != terminator )
{
stat = DN_error;
node = 0;
} // End of IF then
else
stat = DN_valid;
} // End of IF then
elif ( status () == DN_valid )
stat = DN_truncated;
} // End of IF then
else
stat = DN_truncated;
else
stat = DN_invalid;
} // End of "DName" CONSTRUCTOR '(pcchar_t&,char)'
__near DName::DName ( unsigned long num )
{
char buf[ 11 ];
char * pBuf = buf + 10;
stat = DN_valid;
node = 0;
isIndir = 0;
isAUDC = 0;
isAUDTThunk = 0;
NoTE = 0;
// Essentially, 'ultoa ( num, buf, 10 )' :-
*pBuf = 0;
do
{
*( --pBuf ) = (char)(( num % 10 ) + '0' );
num /= 10UL;
} while ( num );
doPchar ( pBuf, ( 10 - (int) ( pBuf - buf )));
} // End of "DName" CONSTRUCTOR '(unsigned long)'
__near DName::DName ( DNameStatus st )
{
stat = ((( st == DN_invalid ) || ( st == DN_error )) ? st : DN_valid );
node = gnew DNameStatusNode ( st );
isIndir = 0;
isAUDC = 0;
isAUDTThunk = 0;
NoTE = 0;
if ( !node )
stat = DN_error;
} // End of "DName" CONSTRUCTOR '(DNameStatus)'
// Now the member functions for 'DName'
int __near DName::isValid () const { return (( status () == DN_valid ) || ( status () == DN_truncated )); }
int __near DName::isEmpty () const { return (( node == 0 ) || !isValid ()); }
inline DNameStatus __near DName::status () const { return (DNameStatus)stat; } // The cast is to keep Glockenspiel quiet
inline DName & __near DName::setPtrRef () { isIndir = 1; return *this; }
inline int __near DName::isPtrRef () const { return isIndir; }
inline int __near DName::isUDC () const { return ( !isEmpty () && isAUDC ); }
inline void __near DName::setIsUDC () { if ( !isEmpty ()) isAUDC = TRUE; }
inline int __near DName::isUDTThunk () const { return ( !isEmpty () && isAUDTThunk ); }
inline void __near DName::setIsUDTThunk () { if ( !isEmpty ()) isAUDTThunk = TRUE; }
inline int DName::isNoTE () const { return NoTE; }
inline void DName::setIsNoTE () { NoTE = TRUE; }
int __near DName::length () const
{
int len = 0;
if ( !isEmpty ())
for ( DNameNode * pNode = node; pNode; pNode = pNode->nextNode ())
len += pNode->length ();
return len;
} // End of "DName" FUNCTION "length"
char __near DName::getLastChar () const
{
DNameNode * pLast = 0;
if ( !isEmpty ())
for ( DNameNode * pNode = node; pNode; pNode = pNode->nextNode ())
if ( pNode->length () != 0 )
pLast = pNode;
return pLast != 0 ? pLast->getLastChar () : '\0';
} // End of "DName" FUNCTION "getLastChar"
pchar_t __near DName::getString ( pchar_t buf, int max ) const
{
if ( !isEmpty ())
{
// Does the caller want a buffer allocated ?
if ( !buf )
{
max = length () + 1;
buf = gnew char[ max ]; // Get a buffer big enough
} // End of IF then
// If memory allocation failure, then return no buffer
if ( buf )
{
// Now, go through the process of filling the buffer (until max is reached)
int curLen = max;
DNameNode * curNode = node;
pchar_t curBuf = buf;
while ( curNode && ( curLen > 0 ))
{
int fragLen = curNode->length ();
pchar_t fragBuf = 0;
// Skip empty nodes
if ( fragLen )
{
// Handle buffer overflow
if (( curLen - fragLen ) < 0 )
fragLen = curLen;
// Now copy 'len' number of bytes of the piece to the buffer
fragBuf = curNode->getString ( curBuf, fragLen );
// Should never happen, but handle it anyway
if ( fragBuf )
{
// Update string position
curLen -= fragLen;
curBuf += fragLen;
} // End of IF
} // End of IF
// Move on to the next name fragment
curNode = curNode->nextNode ();
} // End of WHILE
*curBuf = 0; // Always NULL terminate the resulting string
} // End of IF
} // End of IF then
elif ( buf )
*buf = 0;
// Return the buffer
return buf;
} // End of "DName" FUNCTION "getString(pchar_t,int)"
DName __near DName::operator + ( char ch ) const
{
DName local ( *this );
if ( local.isEmpty ())
local = ch;
else
local += ch;
// And return the newly formed 'DName'
return local;
} // End of "DName" OPERATOR "+(char)"
DName __near DName::operator + ( pcchar_t str ) const
{
DName local ( *this );
if ( local.isEmpty ())
local = str;
else
local += str;
// And return the newly formed 'DName'
return local;
} // End of "DName" OPERATOR "+(pcchar_t)"
DName __near DName::operator + ( const DName & rd ) const
{
DName local ( *this );
if ( local.isEmpty ())
local = rd;
elif ( rd.isEmpty ())
local += rd.status ();
else
local += rd;
// And return the newly formed 'DName'
return local;
} // End of "DName" OPERATOR "+(const DName&)"
DName __near DName::operator + ( DName * pd ) const
{
DName local ( *this );
if ( local.isEmpty ())
local = pd;
else
local += pd;
// And return the newly formed 'DName'
return local;
} // End of "DName" OPERATOR "+(DName*)"
DName __near DName::operator + ( DNameStatus st ) const
{
DName local ( *this );
if ( local.isEmpty ())
local = st;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -