global void KillAllSounds() { Sound *sn; Handle theHandle; /* Stop and delete each node in the sound list */ while(!EmptyList(&soundList)) { sn = (Sound *) Native(FirstNode(&soundList)); if (sn->sSample) { audArgs.count = 2; audArgs.func = STOP; audArgs.arg2 = sn->sNumber; KDoAudio ((word *)&audArgs); } else { DoSound(SEnd,(char far *) sn); ResLock(RES_SOUND,sn->sNumber,FALSE); if(theHandle = (Handle) Native(GetProperty((Obj *) Native(sn->sKey), s_handle))) { if ((int)theHandle != 1) { CriticalHandle(theHandle,FALSE); UnlockHandle(theHandle); } } } DeleteNode(&soundList,Pseudo(sn)); } }
/* BSTreeForEach * executes a function on each tree element */ LIB_EXPORT void CC BSTreeForEach ( const BSTree *bt, bool reverse, void ( CC * f ) ( BSTNode *n, void *data ), void *data ) { if ( bt != NULL ) { BSTNode *n, *next; if ( reverse ) { n = LastNode ( bt ); while ( n != NULL ) { next = BSTNodePrev ( n ); ( * f ) ( n, data ); n = next; } } else { n = FirstNode ( bt ); while ( n != NULL ) { next = BSTNodeNext ( n ); ( * f ) ( n, data ); n = next; } } } }
/* BSTreeDoUntil * executes a function on each element * until the function returns 1 */ LIB_EXPORT bool CC BSTreeDoUntil ( const BSTree *bt, bool reverse, bool ( CC * f ) ( BSTNode *n, void *data ), void *data ) { if ( bt != NULL ) { BSTNode *n, *next; if ( reverse ) { n = LastNode ( bt ); while ( n != NULL ) { next = BSTNodePrev ( n ); if ( ( * f ) ( n, data ) ) return true; n = next; } } else { n = FirstNode ( bt ); while ( n != NULL ) { next = BSTNodeNext ( n ); if ( ( * f ) ( n, data ) ) return true; n = next; } } } return false; }
void nsQuoteList::PrintChain() { printf("Chain: \n"); for (nsQuoteNode* node = FirstNode(); node; node = Next(node)) { printf(" %p %d - ", static_cast<void*>(node), node->mDepthBefore); switch(node->mType) { case (eStyleContentType_OpenQuote): printf("open"); break; case (eStyleContentType_NoOpenQuote): printf("noOpen"); break; case (eStyleContentType_CloseQuote): printf("close"); break; case (eStyleContentType_NoCloseQuote): printf("noClose"); break; default: printf("unknown!!!"); } printf(" %d - %d,", node->Depth(), node->DepthAfter()); if (node->mText) { nsAutoString data; node->mText->GetData(data); printf(" \"%s\",", NS_ConvertUTF16toUTF8(data).get()); } printf("\n"); } }
/*---------------------------------------------------------------------*/ BOOL ArchiveClose(H_ARCHIVE harchive) { NODE *node; STREAM *stream; if (!ValidateHandle(harchive)) return (FALSE); _archive[harchive].last_error = ARC_NO_ERROR; _archive_error = ARC_NO_ERROR; ArchiveLog(ARC_LOG_VERBOSE, "Close archive: %s", _archive[harchive].path); /* Close all open event files on archive... */ if ((node = FirstNode(&_archive[harchive].streams))) { do { stream = (STREAM *) node->data; if (_archive[harchive].access == ARC_WRITE) CloseEventFileAndRename(harchive, stream); else CloseEventFile(stream); } while ((node = NextNode(node)) != NULL); } /* If open for write... */ if (_archive[harchive].access == ARC_WRITE) { MUTEX_LOCK(&_archive[harchive].purge.mutex); if(_archive[harchive].purge.active ) { _archive[harchive].purge.stop = TRUE; MUTEX_UNLOCK(&_archive[harchive].purge.mutex); ArchiveLog(ARC_LOG_VERBOSE, "Stopping purge thread"); SEM_POST(&_archive[harchive].purge.semaphore); THREAD_JOIN(&_archive[harchive].purge.thread_id); } else MUTEX_UNLOCK(&_archive[harchive].purge.mutex); /* Mark as closed and write state to disk */ _archive[harchive].state.write = FALSE; if (!WriteState(harchive)) return (FALSE); } /* Close the state file */ if (!FileClose(_archive[harchive].file)) { _archive[harchive].last_error = ARC_FILE_IO_ERROR; return (FALSE); } _n_archives--; /* Clear state */ MUTEX_DESTROY(&_archive[harchive].mutex); DestroyList(&_archive[harchive].streams); DestroyPurge(&_archive[harchive].purge); InitArchive(harchive); return (TRUE); }
void nsQuoteList::RecalcAll() { nsQuoteNode *node = FirstNode(); if (!node) return; do { int32_t oldDepth = node->mDepthBefore; Calc(node); if (node->mDepthBefore != oldDepth && node->mText && node->IsRealQuote()) node->mText->SetData(*node->Text()); // Next node node = Next(node); } while (node != FirstNode()); }
void nsQuoteList::Calc(nsQuoteNode* aNode) { if (aNode == FirstNode()) { aNode->mDepthBefore = 0; } else { aNode->mDepthBefore = Prev(aNode)->DepthAfter(); } }
//---------------------------------------------------------------------------// // AsInt // //---------------------------------------------------------------------------// int CNodeFile::CNode::AsInt(const string &sName, int iDefault) { CNode *pNode = FirstNode(sName); if (pNode) { pNode = pNode->FirstNode(); if (pNode && pNode->Value()) return atoi(pNode->Value()); } return iDefault; }
//---------------------------------------------------------------------------// // AsString // //---------------------------------------------------------------------------// string CNodeFile::CNode::AsString(const string &sName, const string &sDefault) { CNode *pNode = FirstNode(sName); if (pNode) { pNode = pNode->FirstNode(); if (pNode && pNode->Value()) return pNode->Value(); } return sDefault; }
//---------------------------------------------------------------------------// // AsBool // //---------------------------------------------------------------------------// bool CNodeFile::CNode::AsBool(const string &sName, bool bDefault) { CNode *pNode = FirstNode(sName); if (pNode) { pNode = pNode->FirstNode(); if (pNode && pNode->Value()) return (atoi(pNode->Value()) == 0 ? false : true); } return bDefault; }
//---------------------------------------------------------------------------// // AsFloat // //---------------------------------------------------------------------------// float CNodeFile::CNode::AsFloat(const string &sName, float fDefault) { CNode *pNode = FirstNode(sName); if (pNode) { pNode = pNode->FirstNode(); if (pNode && pNode->Value()) return strtofloat(pNode->Value()); } return fDefault; }
void nsQuoteList::RecalcAll() { for (nsQuoteNode* node = FirstNode(); node; node = Next(node)) { int32_t oldDepth = node->mDepthBefore; Calc(node); if (node->mDepthBefore != oldDepth && node->mText && node->IsRealQuote()) node->mText->SetData(*node->Text()); } }
/*---------------------------------------------------------------------*/ VOID DestroyList(LIST * list) { NODE *node; ASSERT(list != NULL); /* Release the list */ if ((node = FirstNode(list)) != NULL) while ((node = DestroyNode(node)) != NULL); return; }
void nsQuoteList::PrintChain() { printf("Chain: \n"); if (!FirstNode()) { return; } nsQuoteNode* node = FirstNode(); do { printf(" %p %d - ", NS_STATIC_CAST(void*, node), node->mDepthBefore); switch(node->mType) { case (eStyleContentType_OpenQuote): printf("open"); break; case (eStyleContentType_NoOpenQuote): printf("noOpen"); break; case (eStyleContentType_CloseQuote): printf("close"); break; case (eStyleContentType_NoCloseQuote): printf("noClose"); break; default: printf("unknown!!!"); } printf(" %d - %d,", node->Depth(), node->DepthAfter()); if (node->mText) { nsAutoString data; node->mText->GetData(data); printf(" \"%s\",", NS_ConvertUCS2toUTF8(data).get()); } printf("\n"); node = Next(node); } while (node != FirstNode()); }
global void RestoreAllSounds() { Sound *sn; Obj *soundObj; Handle sHandle; int soundId; /* For every node on the sound list, load the resource in * the s_number property. If the sState property of the node * is non-zero, restart the sound using the SRestore function * in MIDI.S */ sn = (Sound *) Native(FirstNode(&soundList)); while(sn) { soundObj = (Obj *) Native(GetKey(Pseudo(sn))); soundId = GetProperty (soundObj, s_number); if(sn->sSample) { /* put sample stuff here */ } else { if(soundId) { ResLoad(RES_SOUND,soundId); } if(sn->sState) { sHandle = ResLoad(RES_SOUND,soundId); CriticalHandle(sHandle,TRUE); ResLock(RES_SOUND,soundId,TRUE); SetProperty(soundObj,s_handle,(uint) Pseudo(sHandle)); sn->sPointer = (char far *) sHandle; DoSound(SRestore,(char far *) sn); // if(sn->sSample) { // LockHandle(sHandle); // } UpdateCues(soundObj); } } sn = (Sound *) Native(NextNode(Pseudo(sn))); } /* Reset the default reverb mode */ DoSound(SSetReverb,reverbDefault); }
/* BSTreeDepth * returns number of layers in b-tree * * if "exact" is 1, then the maximum * depth is returned. otherwise, the depth of * an arbitrary leaf node is returned */ LIB_EXPORT uint32_t CC BSTreeDepth ( const BSTree *bt, bool exact ) { BSTNode *p; uint32_t depth; if ( bt == NULL || bt -> root == NULL ) return 0; depth = 1; if ( exact ) { for ( p = FirstNode ( bt ); p != NULL; p = BSTNodeNext ( p ) ) { BSTNode *q; unsigned int ndepth; if ( p -> child [ 0 ] != NULL || p -> child [ 1 ] != NULL ) continue; for ( ndepth = 1, q = PARENT ( p ); q != NULL; q = PARENT ( q ) ) ++ ndepth; if ( ndepth > depth ) depth = ndepth; } } else { for ( p = bt -> root;; ++ depth ) { if ( p -> child [ 0 ] != NULL ) p = p -> child [ 0 ]; else if ( p -> child [ 1 ] != NULL ) p = p -> child [ 1 ]; else break; } } return depth; }
/*---------------------------------------------------------------------*/ BOOL WriteState(H_ARCHIVE harchive) { UINT32 i; STREAM *stream; NODE *node; if (!ValidateHandle(harchive)) return (FALSE); _archive[harchive].last_error = ARC_NO_ERROR; _archive_error = ARC_NO_ERROR; if (_archive[harchive].access != ARC_WRITE) { _archive[harchive].last_error = ARC_PERMISSION_DENIED; return (FALSE); } /* Go to top of file */ if (!FileRewind(_archive[harchive].file)) { _archive[harchive].last_error = ARC_FILE_IO_ERROR; return (FALSE); } ArchiveLog(ARC_LOG_MAXIMUM, "Writing state file: %s", _archive[harchive].filespec); /* Write state structure */ if (SerializedWrite(&_archive[harchive].state, _state_template, _archive[harchive].file) == VOID_UINT32) { ArchiveLog(ARC_LOG_ERRORS, "WriteState: Error writing state file (state): %s", _archive[harchive].filespec); return (FALSE); } /* If we have streams... */ if (_archive[harchive].state.n_streams == 0) return (TRUE); /* Write stream list structures */ if ((node = FirstNode(&_archive[harchive].streams)) == NULL) { printf("\nERROR: WriteState: Unexpected empty stream list!"); _archive[harchive].last_error = ARC_INTERNAL_ERROR; return (FALSE); } i = 0; while (TRUE) { stream = (STREAM *) node->data; if (SerializedWrite(stream, _stream_template, _archive[harchive].file) == VOID_UINT32) { ArchiveLog(ARC_LOG_ERRORS, "WriteState: Error writing state file (stream): %s", _archive[harchive].filespec); return (FALSE); } if (++i >= _archive[harchive].state.n_streams) break; if ((node = NextNode(node)) == NULL) { printf("\nERROR: WriteState: Unexpected end of stream list!"); _archive[harchive].last_error = ARC_INTERNAL_ERROR; return (FALSE); } } /* Flush buffers to disk */ if (!FileFlush(_archive[harchive].file)) { _archive[harchive].last_error = ARC_FILE_IO_ERROR; return (FALSE); } return (TRUE); }
/* BSTreeFirst * returns first node */ LIB_EXPORT BSTNode* CC BSTreeFirst ( const BSTree *bt ) { if ( bt == NULL ) return NULL; return FirstNode ( bt ); }