home *** CD-ROM | disk | FTP | other *** search
- /*
- File: NmSpcUtl.cpp
-
- Contains: Utilities for working with NameSpaces.
-
- Owned by: David McCusker
-
- Copyright: © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef _NMSPCUTL_
- #include <NmSpcUtl.h>
- #endif
-
- #ifndef SOM_ODNameSpaceManager_xh
- #include <NmSpcMg.xh>
- #endif
-
- #ifndef SOM_ODValueNameSpace_xh
- #include <ValueNS.xh>
- #endif
-
- #ifndef SOM_ODValueIterator_xh
- #include <ValueItr.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _MEMMGR_
- #include <MemMgr.h>
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
-
- void ValueNameSpaceRegister(ODValueNameSpace* ns,
- Environment* ev,
- ODISOStr key,
- ODPtr buffer,
- ODULong size)
- {
- ODByteArray ba;
- ba._buffer = (octet*) buffer;
- ba._length = size;
- ba._maximum = size;
-
- ns->Register(ev, key, &ba);
- }
-
- ODBoolean ValueNameSpaceGetEntry(ODValueNameSpace* ns,
- Environment* ev,
- ODISOStr key,
- ODPtr* value,
- ODULong* valueLength)
- {
- ODByteArray ba;
-
- if (ns->GetEntry(ev, key, &ba))
- {
- *value = ba._buffer;
- *valueLength = ba._length;
- return kODTrue;
- }
- else
- {
- *value = kODNULL;
- return kODFalse;
- }
- }
-
- ODBoolean ValueNameSpaceGetODName(ODValueNameSpace* ns,
- Environment* ev,
- ODISOStr key,
- ODName** value)
- {
- ODByteArray ba;
-
- if (ns->GetEntry(ev, key, &ba))
- {
- ODTradITextData* theIName = (ODTradITextData*)ODNewPtrClear(ba._length, kDefaultHeapID);
- ODBlockMove(ba._buffer, theIName, ba._length);
- ODDisposePtr( ba._buffer );
- ODULong textLen = ba._length - sizeof(ODTradITextDataHeader);
- StringPtr thePString = (StringPtr)ODNewPtrClear(textLen+1);
- thePString[0] = textLen;
- ODBlockMove((ODPtr)theIName->theText, (ODPtr)&thePString[1], textLen );
- *value = CreateITextPString(theIName->theScriptCode,
- theIName->theLangCode,
- thePString);
- ODDisposePtr( theIName );
- ODDisposePtr( thePString );
- return kODTrue;
- }
- else
- {
- *value = kODNULL;
- return kODFalse;
- }
- }
-
- void ValueIteratorFirst(ODValueIterator* iter,
- Environment* ev,
- ODISOStr* key,
- ODPtr* value,
- ODULong* valueLength)
- {
- ODByteArray ba;
- ba._length = 0;
-
- iter->First(ev, key, &ba);
-
- if (ba._length > 0)
- {
- *value = ba._buffer;
- *valueLength = ba._length;
- }
- else
- *value = kODNULL;
- }
-
- void ValueIteratorNext(ODValueIterator* iter,
- Environment* ev,
- ODISOStr* key,
- ODPtr* value,
- ODULong* valueLength)
- {
- ODByteArray ba;
- ba._length = 0;
-
- iter->Next(ev, key, &ba);
-
- if (ba._length > 0)
- {
- *value = ba._buffer;
- *valueLength = ba._length;
- }
- else
- *value = kODNULL;
- }
-
-
- ODISOStr ValueNameSpaceGetString( ODSession* sessn, ODISOStr nameSpaceName, ODISOStr key )
- {
- ODByteArray ba;
- ODISOStr result = kODNULL;
- Environment* ev = somGetGlobalEnvironment();
- ODNameSpaceManager* mgr = sessn->GetNameSpaceManager(ev);
- ODValueNameSpace* ns = (ODValueNameSpace*) mgr->HasNameSpace(ev, nameSpaceName);
- if ( ns && ns->GetEntry(ev, key, &ba) && ba._length > 0 )
- result = (ODISOStr) ba._buffer;
-
- // The old version of this function used to allocate space for a terminating
- // null byte; but as near as I can tell, the only ways that strings become
- // values also allocate the null byte space (as they should) when the entry
- // is orginally created.
-
- return result;
- }
-
- void ValueNameSpaceWriteToFile( ODValueNameSpace* ns, PlatformFile* file )
- {
- Environment* ev = somGetGlobalEnvironment();
- ODByteArray ba;
- ba._buffer = (octet*) file;
- ba._length = sizeof(PlatformFile);
- ns->WriteToFile( ev, &ba );
- }
-
- void ValueNameSpaceReadFromFile( ODValueNameSpace* ns, PlatformFile* file )
- {
- Environment* ev = somGetGlobalEnvironment();
- ODByteArray ba;
- ba._buffer = (octet*) file;
- ba._length = sizeof(PlatformFile);
- ns->ReadFromFile( ev, &ba );
- }
-
-
- //------------------------------------------------------------------------------
- // CreateFlatIText
- //------------------------------------------------------------------------------
-
- ODTradITextData* CreateFlatIText(ODScriptCode theScriptCode, ODLangCode theLangCode,
- char* theText, ODUShort textLen)
- {
- ODTradITextData* result = (ODTradITextData*)
- ODNewPtrClear(textLen+sizeof(ODTradITextDataHeader), kDefaultHeapID);
- result->theScriptCode = theScriptCode;
- result->theLangCode = theLangCode;
-
- ODBlockMove((ODPtr)theText, (ODPtr)result->theText, textLen);
-
- return result;
- }
-
-
-