NS_IMETHODIMP nsAnnotationService::RemoveAnnotation(nsIURI* aURI, const nsACString& aName) { nsresult rv; nsNavHistory* history = nsNavHistory::GetHistoryService(); NS_ENSURE_TRUE(history, NS_ERROR_FAILURE); PRInt64 uriID; rv = history->GetUrlIdFor(aURI, &uriID, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); if (uriID == 0) // Check if URI exists. return NS_OK; mozStorageStatementScoper resetter(mDBRemoveAnnotation); rv = mDBRemoveAnnotation->BindInt64Parameter(0, uriID); NS_ENSURE_SUCCESS(rv, rv); rv = mDBRemoveAnnotation->BindUTF8StringParameter(1, aName); NS_ENSURE_SUCCESS(rv, rv); rv = mDBRemoveAnnotation->Execute(); NS_ENSURE_SUCCESS(rv, rv); resetter.Abandon(); // Update observers for (PRInt32 i = 0; i < mObservers.Count(); i ++) mObservers[i]->OnAnnotationRemoved(aURI, aName); return NS_OK; }
Lattice *LatticeBuilder::Build( const KkciString &str, const Token begin_token, const Token end_token) { ScopedDictionaryResetter resetter(dictionary_); const size_t size = str.size(); vector<Node*> *nodes(new vector<Node*>()); vector<NodeList> *begin_nodes(new vector<NodeList>(size + 2)); vector<NodeList> *end_nodes(new vector<NodeList>(size + 2 + 1)); nodes->push_back(new Node({begin_token, nullptr, nullptr, 0})); (*begin_nodes)[0].push_back((*nodes)[0]); (*end_nodes)[1].push_back((*nodes)[0]); nodes->push_back(new Node({end_token, nullptr, nullptr, 0})); (*begin_nodes)[size + 1].push_back((*nodes)[1]); (*end_nodes)[size + 2].push_back((*nodes)[1]); for (size_t pos = 0; pos < size; pos++) { vector<const Entry*> entries; dictionary_->PushBack(str[pos]); dictionary_->Lookup(&entries); for (auto iter = begin(entries); iter != end(entries); ++iter) { Node *node = new Node({(*iter)->token, *iter, nullptr, 0}); nodes->push_back(node); const size_t begin_pos = pos - node->entry->kkci_string.size() + 2; const size_t end_pos = pos + 2; (*begin_nodes)[begin_pos].push_back(node); (*end_nodes)[end_pos].push_back(node); } } return new Lattice(size + 3, nodes, begin_nodes, end_nodes); }
NS_IMETHODIMP nsAnnotationService::GetAnnotationInfo(nsIURI* aURI, const nsACString& aName, PRInt32 *aFlags, PRInt32 *aExpiration, nsACString& aMimeType, PRInt32 *aStorageType) { nsresult rv = StartGetAnnotationFromURI(aURI, aName); if (NS_FAILED(rv)) return rv; mozStorageStatementScoper resetter(mDBGetAnnotationFromURI); *aFlags = mDBGetAnnotationFromURI->AsInt32(kAnnoIndex_Flags); *aExpiration = mDBGetAnnotationFromURI->AsInt32(kAnnoIndex_Expiration); rv = mDBGetAnnotationFromURI->GetUTF8String(kAnnoIndex_MimeType, aMimeType); NS_ENSURE_SUCCESS(rv, rv); rv = mDBGetAnnotationFromURI->GetTypeOfIndex(kAnnoIndex_Content, aStorageType); return rv; }
nsresult nsAnnotationService::HasAnnotationInternal(PRInt64 aURLID, const nsACString& aName, PRBool* hasAnnotation, PRInt64* annotationID) { mozStorageStatementScoper resetter(mDBGetAnnotation); nsresult rv; rv = mDBGetAnnotation->BindInt64Parameter(0, aURLID); NS_ENSURE_SUCCESS(rv, rv); rv = mDBGetAnnotation->BindUTF8StringParameter(1, aName); NS_ENSURE_SUCCESS(rv, rv); rv = mDBGetAnnotation->ExecuteStep(hasAnnotation); NS_ENSURE_SUCCESS(rv, rv); if (! annotationID || ! *hasAnnotation) return NS_OK; return mDBGetAnnotation->GetInt64(0, annotationID); }
bool Process::run(JT::ObjectNode **returnedObjectNode) { if (returnedObjectNode) *returnedObjectNode = 0; if (!m_project_name.size() || !m_phase.size()) { fprintf(stderr, "project name or phase is empty when executing command: %s : %s\n", m_project_name.c_str(), m_phase.c_str()); return false; } bool return_val = true; LogFileResetter resetter(*this); if (m_log_file < 0 && Configuration::isDir(m_configuration.buildShellMetaDir())) { Configuration::ensurePath(m_configuration.scriptExecutionLogDir()); std::string log_file_str = m_configuration.scriptExecutionLogDir() + "/" + m_project_name + "_" + m_phase + ".log"; setLogFile(log_file_str, false); resetter.resetLog = true; } std::string temp_file; if (!flushProjectNodeToTemporaryFile(m_project_name, m_project_node, temp_file)) return false; std::string primary_script = m_phase + "_" + m_project_name; std::string fallback_script = m_fallback.size() ? m_phase + "_" + m_fallback : ""; auto scripts = m_configuration.findScript(primary_script, fallback_script); if (m_script_has_to_exist && scripts.size() == 0) { fprintf(stderr, "Could not find mandatory script for: \"%s\" with fallback \"%s\"\n", primary_script.c_str(), fallback_script.c_str()); return false; } bool temp_file_removed = false; std::string arguments = m_project_name + " " + temp_file; for (auto it = scripts.begin(); it != scripts.end(); ++it) { int exit_code = runScript(m_environement_script, (*it), arguments, m_log_file); if (exit_code) { fprintf(stderr, "Script %s for project %s failed in execution\n", it->c_str(), m_project_name.c_str()); return_val = false; break; } if (access(temp_file.c_str(), F_OK)) { temp_file_removed = true; fprintf(stderr, "The script removed the temporary input file, assuming failur\n"); return_val = false; break; } if (returnedObjectNode) { TreeBuilder tree_builder(temp_file); tree_builder.load(); JT::ObjectNode *root = tree_builder.rootNode(); if (root) { if (root->booleanAt("arguments.propogate_to_next_script")) continue; *returnedObjectNode = tree_builder.takeRootNode(); } else { fprintf(stderr, "Failed to demarshal the temporary file returned from the script %s\n", (*it).c_str()); return_val = false; } } break; } if (!temp_file_removed) { unlink(temp_file.c_str()); } return return_val; }
BOOL Grammar::readBinary(const CHAR* pszFilename) { // Attempt to read grammar from binary file. // Returns true if successful, otherwise false. #ifdef DEBUG printf("Reading binary grammar file %s\n", pszFilename); #endif this->reset(); File f(pszFilename, "rb"); if (!f) return false; const UINT SIGNATURE_LENGTH = 16; BYTE abSignature[SIGNATURE_LENGTH]; UINT n = f.read(abSignature, sizeof(abSignature)); if (n < sizeof(abSignature)) return false; // Check the signature - should start with 'Reynir ' if (memcmp(abSignature, "Reynir ", 7) != 0) { #ifdef DEBUG printf("Signature mismatch\n"); #endif return false; } UINT nNonterminals, nTerminals; if (!f.read_UINT(nTerminals)) return false; if (!f.read_UINT(nNonterminals)) return false; #ifdef DEBUG printf("Reading %u terminals and %u nonterminals\n", nTerminals, nNonterminals); #endif if (!nNonterminals) // No nonterminals to read: we're done return true; INT iRoot; if (!f.read_INT(iRoot)) return false; #ifdef DEBUG printf("Root nonterminal index is %d\n", iRoot); #endif // Initialize the nonterminals array Nonterminal** ppnts = new Nonterminal*[nNonterminals]; memset(ppnts, 0, nNonterminals * sizeof(Nonterminal*)); this->m_nts = ppnts; this->m_nNonterminals = nNonterminals; this->m_nTerminals = nTerminals; this->m_iRoot = iRoot; // Ensure we clean up properly in case of exit with error GrammarResetter resetter(this); // Loop through the nonterminals for (n = 0; n < nNonterminals; n++) { // How many productions? UINT nLenPlist; if (!f.read_UINT(nLenPlist)) return false; Nonterminal* pnt = new Nonterminal(L""); // Loop through the productions for (UINT j = 0; j < nLenPlist; j++) { UINT nId; if (!f.read_UINT(nId)) return false; UINT nPriority; if (!f.read_UINT(nPriority)) return false; UINT nLenProd; if (!f.read_UINT(nLenProd)) return false; const UINT MAX_LEN_PROD = 256; if (nLenProd > MAX_LEN_PROD) { // Production too long #ifdef DEBUG printf("Production too long\n"); #endif return false; } // Read the production INT aiProd[MAX_LEN_PROD]; f.read(aiProd, nLenProd * sizeof(INT)); // Create a fresh production object Production* pprod = new Production(nId, nPriority, nLenProd, aiProd); // Add it to the nonterminal pnt->addProduction(pprod); } // Add the nonterminal to the grammar this->setNonterminal(-1 -(INT)n, pnt); } #ifdef DEBUG printf("Reading completed\n"); fflush(stdout); #endif // No error: we disarm the resetter resetter.disarm(); return true; }