bool CSVwrite::Open( string filename, const Flags flags /* = none */ ) { if( _error ) return false; if( _file.is_open() ) { _error = true; _error_msg = "A file is already open. Call Close() to close the file."; return false; } if( _output_ptr ) { _error = true; _error_msg = "A stream is already associated. Call Close() to dissociate."; return false; } ios::openmode mode = ( ( flags & text_mode ) ) ? 0 : ios::binary; mode |= ( ( flags & truncate ) ) ? ios::trunc : ios::app; _file.open( filename, mode ); if( !_file ) { _error = true; _error_msg = "Failed opening " + filename; return false; } return Associate( &_file, flags ); }
inline DirectoryEntry LocalServiceLocatorDataStore::MakeAccount( const std::string& name, const std::string& password, const DirectoryEntry& parent, const boost::posix_time::ptime& registrationTime) { bool accountExists; try { DirectoryEntry existingAccount = LoadAccount(name); accountExists = true; } catch(const ServiceLocatorDataStoreException&) { accountExists = false; } if(accountExists) { BOOST_THROW_EXCEPTION(ServiceLocatorDataStoreException( "An account with the specified name exists.")); } DirectoryEntry newEntry(DirectoryEntry::Type::ACCOUNT, m_nextId, name); ++m_nextId; m_accounts.push_back(newEntry); m_passwords.insert(std::make_pair(newEntry, HashPassword(newEntry, password))); m_registrationTimes.insert(std::make_pair(newEntry, registrationTime)); m_lastLoginTimes.insert(std::make_pair(newEntry, boost::posix_time::neg_infin)); Associate(newEntry, parent); return newEntry; }
CSVwrite::CSVwrite( ostream *stream, Flags flags /* = none */ ) : buffer_size( _buffer_size), error( _error ), error_msg( _error_msg ) { if( !Init() ) return; Associate( stream, flags ); }
void Creature::addAssociate(Creature &henchman, AssociateType type) { removeAssociate(henchman); assert(!henchman.getMaster()); _associates.push_back(Associate(type, &henchman)); henchman.setMaster(this); }
/* Load a dictionary */ void Niall_LoadDictionary(char *FileName) { char Buffer[BUFSIZ]; FILE *fHandle; int nWords,i,d; int nAsocs,j,w,p,k; WORD *Word; fHandle=fopen(FileName,"r"); if(!fHandle) { Niall_Warning("File %s not found.",FileName); return; } fscanf(fHandle,"%s %d\n",Buffer,&nWords); if((strcmp(Buffer,FILE_ID))||(nWords<2)) { Niall_Warning("File %s is not a valid Niall file.",FileName); return; } ClearDictionary(); for(i=0;i<nWords;i++) { fscanf(fHandle,"%4d: %s %d|",&d,Buffer,&nAsocs); if((d!=i)||(nAsocs<1)) { Niall_Warning("Word %d is corrupted.",i); Niall_NewDictionary(); return; } if(Buffer[0]=='>') { if(i!=0) { Niall_Warning("Word %d is corrupted.",i); Niall_NewDictionary(); return; } Buffer[0]=0; } Word=AddWord(Buffer); if(Word==NULL) Niall_Error("Out of memory."); for(j=0;j<nAsocs;) { fscanf(fHandle," %d(%d)",&w,&p); if(w>=nWords) { Niall_Warning("Word %d/Assoc %d is corrupted.",i,j); Niall_NewDictionary(); return; } for(k=0;k<p;k++) Associate(Word,w); j+=p; } } }
void ManualPilot::AutoToggle(CONTROLMODE dead) { if (dead==PILOTDEAD) controlmode=PILOTDEAD; else if (controlmode!=PILOTDEAD) //JIM 11Oct96 { //JIM 11Oct96 ControlledAC2->information=IF_ALLBAD; ControlledAC2->slowdownleader=FALSE; if (dead==TOGGLE) //JIM 11Oct96 { dead=controlmode==AUTO?MANUAL:AUTO; Associate(ControlledAC2,dead); } else AutoToggleAircraft(ControlledAC2,dead); //rdh 6/4/98 } //JIM 11Oct96 }
inline DirectoryEntry LocalServiceLocatorDataStore::MakeDirectory( const std::string& name, const DirectoryEntry& parent) { bool accountExists; try { DirectoryEntry existingAccount = LoadAccount(name); accountExists = true; } catch(const ServiceLocatorDataStoreException&) { accountExists = false; } if(accountExists) { BOOST_THROW_EXCEPTION(ServiceLocatorDataStoreException( "An account with the specified name exists.")); } DirectoryEntry newEntry(DirectoryEntry::Type::DIRECTORY, m_nextId, name); ++m_nextId; m_directories.push_back(newEntry); Associate(newEntry, parent); return newEntry; }
bool ProcessMgmtPktSendRequest ( int mgmtMask ) { if ( mgmtMask & MGMT_PKT_BEACON ) { Beacon (); } if ( mgmtMask & MGMT_PKT_AUTH ) { Auth (); } if ( mgmtMask & MGMT_PKT_ASSO) { Associate (); } if ( mgmtMask & MGMT_PKT_TEST) { TestPkt (); } return true; }
/* Add one word to the dictionary. */ static int IndexWord(char *Word,int Follows) { WORD *thisWord,*lastWord; int wordIndex; if(Word != END_SENTENCE) { thisWord = FindWord(Word); if(!thisWord) { thisWord = AddWord(Word); if(!thisWord) Niall_Error("Out of memory."); } wordIndex = WordIndex(thisWord); } else wordIndex = -1; lastWord = GetWord(Follows); if(!lastWord) Niall_Error("Corrupted brain (Can't find last word)."); Associate(lastWord,wordIndex); return(wordIndex); }
/* Correct a spelling */ void Niall_CorrectSpelling(char *Original, char *Correct) { WORD *OrigWord,*CorrWord,*Word; int OrigIndex,CorrIndex; ASCN *Assoc,*nextAscn,*prevAscn; int i; /* Clean up the words */ StripPunctuation(Original); StripPunctuation(Correct); /* Check they are not empty */ if((strlen(Original)==0)||(strlen(Correct)==0)) { Niall_Warning("You must enter a word to be corrected and a corrected version."); return; } /* Check they aren't the same */ if(!strcmp(Original,Correct)) { Niall_Warning("The words are the same!"); return; } /* Find the original (mis-spelt) word */ OrigWord=FindWord(Original); if(OrigWord==NULL) { Niall_Warning("Can't find word '%s' in dictionary.",Original); return; } /* Check if the corrected version already exists */ CorrWord=FindWord(Correct); if(CorrWord==NULL) { /* This is the easy one. Just replace the word. */ free(OrigWord->Data); OrigWord->Data = calloc(sizeof(char),strlen(Correct)+1); strcpy(OrigWord->Data,Correct); } else { /* More complex. Any links to the incorrect word must be ** destroyed and re-made for the correct word. Links from ** the incorrect word must be applied to the correct word. ** The incorrect word must be removed from the dictionary, ** and all links updated to reflect the change of index. */ OrigIndex = WordIndex(OrigWord); CorrIndex = WordIndex(CorrWord); /* Recreate associations to the incorrect word. */ for(Word=WordList;Word;Word=Word->Next) { for(Assoc=Word->Associations;Assoc;Assoc=Assoc->Next) { if(Assoc->Word != OrigIndex) continue; /* Unlink the association. */ if(Assoc == Word->Associations) { Word->Associations = Assoc->Next; } else { for(prevAscn=Word->Associations;prevAscn;prevAscn=prevAscn->Next) { if(Assoc == prevAscn->Next) { prevAscn->Next = Assoc->Next; break; } } } /* Re-make the association on the correct word */ for(i=0;i<Assoc->Probability;i++) Associate(Word,CorrIndex); /* Free the association. */ free(Assoc); break; } } /* Copy old associations to the correct word. */ for(Assoc=OrigWord->Associations;Assoc;Assoc=Assoc->Next) { for(i=0;i<Assoc->Probability;i++) Associate(CorrWord,Assoc->Word); } /* Delete the old associations. */ for(Assoc=OrigWord->Associations;Assoc;Assoc=nextAscn) { nextAscn=Assoc->Next; free(Assoc); } OrigWord->Associations=NULL; /* Unlink and free the old word. */ if(OrigWord == WordList) { WordList = OrigWord->Next; } else { for(Word=WordList;Word;Word=Word->Next) { if(OrigWord == Word->Next) { Word->Next = OrigWord->Next; break; } } } free(OrigWord->Data); free(OrigWord); /* Update the indexes in all associations. */ for(Word=WordList;Word;Word=Word->Next) { for(Assoc=Word->Associations;Assoc;Assoc=Assoc->Next) { if(Assoc->Word > OrigIndex) Assoc->Word--; } } } }