bool ComponentList::LoadComponents(string filename) { if (m_componentXMLDocument.LoadFile(filename.c_str()) != tinyxml2::XMLError::XML_SUCCESS) return false; m_xmlFilepath = "testComponent.xml"; tinyxml2::XMLNode* pBase = m_componentXMLDocument.FirstChild(); tinyxml2::XMLElement* pEntityComponents = pBase->FirstChildElement("Entities"); tinyxml2::XMLElement* pComp = pEntityComponents->FirstChildElement("Component"); while (pComp) { Component newComp; newComp.xmlElement = pComp; newComp.isItemComponent = false; if (ParseComponent(pComp, newComp)) m_components[reinterpret_cast<int>(HashedString::hash_name(newComp.name.c_str()))] = newComp; pComp = pComp->NextSiblingElement("Component"); } tinyxml2::XMLElement* pItemComponents = pBase->FirstChildElement("Items"); pComp = pItemComponents->FirstChildElement("Component"); while (pComp) { Component newComp; newComp.xmlElement = pComp; newComp.isItemComponent = true; if (ParseComponent(pComp, newComp)) m_components[reinterpret_cast<int>(HashedString::hash_name(newComp.name.c_str()))] = newComp; pComp = pComp->NextSiblingElement("Component"); } }
void main() { struct Aoc chan; #ifdef ASN1_DEBUG ParseASN1(data, end, 0); #endif ParseComponent(&chan, data, end); }
// Constructor Bs2PhiKKBackground::Bs2PhiKKBackground(PDFConfigurator* config) : Bs2PhiKK(config) { std::cout << "\nBuilding Bs → ϕ K+ K− background PDF\n\n"; std::vector<std::string> componentlist = StringProcessing::SplitString(config->getConfigurationValue("components"), ' '); std::cout << "┏━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┓\n"; std::cout << "┃ Component │ Type ┃\n"; std::cout << "┠───────────────┼───────────────┨\n"; for(const auto& name: componentlist) { if(name=="") continue; components[name] = ParseComponent(config,name); } std::cout << "┗━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┛" << std::endl; MakePrototypes(); Initialise(); }
void RepoInfoFetcher::handleComponentUnarchFinished (int exitCode, QProcess::ExitStatus) { sender ()->deleteLater (); if (exitCode) { emit gotEntity (Util::MakeNotification (tr ("Component unpack error"), tr ("Unable to unpack the component file. gunzip error: %1. " "Problematic file is at %2.") .arg (exitCode) .arg (sender ()->property ("Filename").toString ()), PCritical_)); return; } QByteArray data = qobject_cast<QProcess*> (sender ())->readAllStandardOutput (); QFile::remove (sender ()->property ("Filename").toString ()); PackageShortInfoList infos; try { infos = ParseComponent (data); } catch (const std::exception& e) { qWarning () << Q_FUNC_INFO << e.what (); emit gotEntity (Util::MakeNotification (tr ("Component parse error"), tr ("Unable to parse component %1 description file. " "More information is available in logs.") .arg (sender ()->property ("Component").toString ()), PCritical_)); return; } emit componentFetched (infos, sender ()->property ("Component").toString (), sender ()->property ("RepoID").toInt ()); }
//-------------------------------------------------------------------------------------------------- void ParseComponent ( Component* componentPtr, ///< The Component object to populate. const BuildParams_t& buildParams ///< Build parameters obtained from the command line. ) //-------------------------------------------------------------------------------------------------- { ComponentPtr = componentPtr; BuildParamsPtr = &buildParams; // Open the component's Component.cdef file for reading. std::string path = FindComponent(componentPtr->Path(), buildParams.SourceDirs()); if (path == "") { throw Exception("Couldn't find component '" + componentPtr->Path() + "'."); } componentPtr->Path(path); std::string cdefFilePath = CombinePath(path, "/Component.cdef"); FILE* file = fopen(cdefFilePath.c_str(), "r"); if (file == NULL) { int error = errno; std::stringstream errorMessage; errorMessage << "Failed to open file '" << cdefFilePath << "'." << " Errno = " << error << "(" << strerror(error) << ")."; throw Exception(errorMessage.str()); } if (buildParams.IsVerbose()) { std::cout << "Parsing '" << cdefFilePath << "'\n"; } // Tell the parser to reset itself and connect to the new file stream for future parsing. cyy_FileName = cdefFilePath.c_str(); cyy_IsVerbose = (BuildParamsPtr->IsVerbose() ? 1 : 0); cyy_EndOfFile = 0; cyy_ErrorCount = 0; cyy_set_lineno(1); cyy_restart(file); // Until the parsing is done, int parsingResult; do { // Start parsing. parsingResult = cyy_parse(); } while ((parsingResult != 0) && (!cyy_EndOfFile)); // Close the file fclose(file); // Halt if there were errors. if (cyy_ErrorCount > 0) { throw Exception("Errors encountered while parsing '" + cdefFilePath + "'."); } ComponentPtr = NULL; if (buildParams.IsVerbose()) { std::cout << "Finished parsing '" << cdefFilePath << "'\n"; } // Recursively, for each of the new component's sub-components, for (auto& mapEntry : componentPtr->SubComponents()) { mapEntry.second = Component::FindComponent(mapEntry.first); // If the sub-component has not yet been parsed, create an object for it and parse it now. if (mapEntry.second == NULL) { mapEntry.second = Component::CreateComponent(mapEntry.first); ParseComponent(mapEntry.second, buildParams); } } }
int nsSetupTypeDlg::Parse(nsINIParser *aParser) { int err = OK; int bufsize = 0; char *showDlg = NULL; int i, j; char *currSec = (char *) malloc(strlen(SETUP_TYPE) + 3); // e.g. SetupType12 if (!currSec) return E_MEM; char *currKey = (char *) malloc(1 + 3); // e.g. C0, C1, C12 if (!currKey) return E_MEM; char *currVal = NULL; nsComponent *currComp = NULL; int currNumComps = 0; nsSetupType *currST = NULL; char *currDescShort = NULL; char *currDescLong = NULL; XI_VERIFY(gCtx); XI_ERR_BAIL(aParser->GetStringAlloc(DLG_SETUP_TYPE, MSGEXISTING, &mExistingMsg, &bufsize)); if (bufsize == 0) XI_IF_FREE(mExistingMsg); /* optional keys */ err = aParser->GetStringAlloc(DLG_SETUP_TYPE, MSG0, &mMsg0, &bufsize); if (err != OK && err != nsINIParser::E_NO_KEY) goto BAIL; else err = OK; bufsize = 5; err = aParser->GetStringAlloc(DLG_SETUP_TYPE, SHOW_DLG, &showDlg, &bufsize); if (err != OK && err != nsINIParser::E_NO_KEY) goto BAIL; else err = OK; if (bufsize != 0 && showDlg) { if (0 == strncmp(showDlg, "TRUE", 4)) mShowDlg = nsXInstallerDlg::SHOW_DIALOG; else if (0 == strncmp(showDlg, "FALSE", 5)) mShowDlg = nsXInstallerDlg::SKIP_DIALOG; } bufsize = 0; err = aParser->GetStringAlloc(DLG_SETUP_TYPE, TITLE, &mTitle, &bufsize); if (err != OK && err != nsINIParser::E_NO_KEY) goto BAIL; else err = OK; if (bufsize == 0) XI_IF_FREE(mTitle); aParser->GetStringAlloc(DLG_SETUP_TYPE, SUBTITLE, &mSubTitle, &bufsize); if (bufsize == 0) XI_IF_FREE(mSubTitle); /* setup types */ for (i=0; i<MAX_SETUP_TYPES; i++) { sprintf(currSec, SETUP_TYPEd, i); bufsize = 0; err = aParser->GetStringAlloc(currSec, DESC_SHORT, &currDescShort, &bufsize); if (err != OK && err != nsINIParser::E_NO_SEC) goto fin_iter; if (bufsize == 0 || err == nsINIParser::E_NO_SEC) // no more setup types { err = OK; break; } bufsize = 0; err = aParser->GetStringAlloc(currSec, DESC_LONG, &currDescLong, &bufsize); if (err != OK || bufsize == 0) goto fin_iter; currST = new nsSetupType(); if (!currST) goto fin_iter; // The short description may contain mnemonics by prefixing // characters with "&". We need to change these to "_" for GTK. for (char *c = currDescShort; *c != '\0'; ++c) { if (*c == '&') // XXX this doesn't quite handle "&&" *c = '_'; } currST->SetDescShort(currDescShort); currST->SetDescLong(currDescLong); currNumComps = 0; for (j=0; j<MAX_COMPONENTS; j++) { sprintf(currKey, Cd, j); bufsize = 0; err = aParser->GetStringAlloc(currSec, currKey, &currVal, &bufsize); if (err != OK && err != nsINIParser::E_NO_KEY) continue; if (bufsize == 0 || err == nsINIParser::E_NO_KEY) { err = OK; break; } currComp = ParseComponent(aParser, currVal); if (currComp) { currST->SetComponent(currComp); ++currNumComps; } } if (currNumComps > 0) { AddSetupType(currST); currST = NULL; } fin_iter: XI_IF_DELETE(currST); } err = OK; BAIL: XI_IF_FREE(currSec); XI_IF_FREE(currKey); return err; }
bool RXNFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv) { OBMol* pmol = pOb->CastAndClear<OBMol>(); if (pmol == NULL) return false; OBFormat* pMolFormat = pConv->FindFormat("MOL"); if (pMolFormat==NULL) return false; istream &ifs = *pConv->GetInStream(); string ln; // When MDLFormat reads the last product it may also read and discard // the line with $RXN for the next reaction. But it then sets $RXNread option. if(pConv->IsOption("$RXNread")) pConv->RemoveOption("$RXNread", OBConversion::OUTOPTIONS); else { if (!getline(ifs,ln)) return(false); if(Trim(ln).find("$RXN")!=0) return false; //Has to start with $RXN } if (!getline(ifs,ln)) return false; //reaction title pmol->SetTitle(Trim(ln)); if (!getline(ifs,ln)) return false; //creator if (!getline(ifs, ln)) return false; //comment // Originally the comment was added to the reaction via: // pmol->SetComment(Trim(ln)); if (!getline(ifs, ln)) return false; // num reactants, products, and optionally agents unsigned int nReactants = 0, nProducts = 0, nAgents = 0; bool ok = ParseComponent(ln.c_str() + 0, &nReactants); if (!ok) return false; ok = ParseComponent(ln.c_str() + 3, &nProducts); if (!ok) return false; if (ln[6] != '\0') { // optional agents ok = ParseComponent(ln.c_str() + 6, &nAgents); if (!ok) return false; } if(nReactants + nProducts + nAgents) { //Read the first $MOL. The others are read at the end of the previous MOL if(!getline(ifs, ln)) return false; if(Trim(ln).find("$MOL")==string::npos) return false; } OBReactionFacade rxnfacade(pmol); // Note: If we supported it, we could read each of the rxn components directly // into the returned OBMol instead of having to do a copy. Unfortunately, // this isn't possible at the moment (MOL format will need some work first). // Here is some example code to do it: // //unsigned int old_numatoms = 0; //unsigned int compid = 1; //for (int i = 0; i<nReactants; i++) //{ // //Read a MOL file using the same OBConversion object but with a different format // if (!pMolFormat->ReadMolecule(pmol, pConv)) // obErrorLog.ThrowError(__FUNCTION__, "Failed to read a reactant", obWarning); // unsigned int numatoms = pmol->NumAtoms(); // for (unsigned int idx = old_numatoms + 1; idx <= numatoms; ++idx) { // OBAtom* atom = pmol->GetAtom(idx); // rxnfacade.SetRole(atom, REACTANT); // rxnfacade.SetComponentId(atom, compid); // } // old_numatoms = numatoms; // compid++; //} const char* type[3] = {"a reactant", "a product", "an agent"}; OBReactionRole role; unsigned int num_components; for(unsigned int N=0; N<3; N++) { switch(N) { case 0: role = REACTANT; num_components = nReactants; break; case 1: role = PRODUCT; num_components = nProducts; break; case 2: role = AGENT; num_components = nAgents; break; } for (int i=0; i<num_components; i++) { //Read a MOL file using the same OBConversion object but with a different format OBMol mol; if (!pMolFormat->ReadMolecule(&mol, pConv)) { std::string error = "Failed to read "; error += type[N]; obErrorLog.ThrowError(__FUNCTION__, error, obWarning); continue; } if (mol.NumAtoms() == 0) { OBAtom* dummy = mol.NewAtom(); // Treat the empty OBMol as having a single dummy atom OBPairData *pd = new OBPairData(); pd->SetAttribute("rxndummy"); pd->SetValue(""); pd->SetOrigin(fileformatInput); dummy->SetData(pd); } rxnfacade.AddComponent(&mol, role); } } pmol->SetIsReaction(); return true; }