void TPluginSpecPrivate::ReadDependencyEntry(QXmlStreamReader &XmlReader) { TPluginDependency Dep; Dep.Name = XmlReader.attributes().value(DEPENDENCY_NAME).toString(); if(Dep.Name.isEmpty()) { XmlReader.raiseError(QString("TPluginSpecPrivate::Read(const QString &SpecFile): '%1' misses attribute '%2'") .arg(QLatin1String(DEPENDENCY), QLatin1String(DEPENDENCY_NAME))); return; } Dep.Version = XmlReader.attributes().value(DEPENDENCY_VERSION).toString(); if(!Dep.Version.isEmpty() && !IsValidVersion(Dep.Version)) { XmlReader.raiseError(QString("TPluginSpecPrivate::Read(const QString &SpecFile): '%1' has invalid format") .arg(DEPENDENCY_VERSION)); return; } Dependencies.push_back(Dep); XmlReader.readNext(); if(XmlReader.tokenType() != QXmlStreamReader::EndElement) XmlReader.raiseError(QString("TPluginSpecPrivate::Read(const QString &SpecFile): Unexpected token")); }
// ----------------------------------------------------------------------------- // bool ParseFile() // Parse the file, validating where possible // ----------------------------------------------------------------------------- bool CCSDSEMReader::ParseFile() { if (isInitialized) return true; // Open the file for reading std::string line; std::ifstream ephFile(emFile.c_str()); if (!ephFile) return false; // Ignore leading white space ephFile.setf(std::ios::skipws); // check for an empty file if (ephFile.eof()) { std::string errmsg = "Error reading ephemeris message file \""; errmsg += emFile + "\". "; errmsg += "File appears to be empty.\n"; throw UtilityException(errmsg); } // Read the header data first - version number must be // on the first non-blank line std::string firstWord, firstAllCaps; std::string eqSign; // read the first line for the version number getline(ephFile,line); #ifdef DEBUG_PARSE_EM_FILE MessageInterface::ShowMessage("In CCSDSEMReader, line= %s\n", line.c_str()); #endif std::istringstream lineStr; lineStr.str(line); lineStr >> firstWord; firstAllCaps = GmatStringUtil::ToUpper(firstWord); if (firstAllCaps == versionFieldName) { lineStr >> eqSign; if (eqSign != "=") { std::string errmsg = "Error reading ephemeris message file \""; errmsg += emFile + "\". "; errmsg += "Equal sign missing or incorrect.\n"; throw UtilityException(errmsg); } std::string versionValue; lineStr >> versionValue; if (!GmatStringUtil::IsNumber(versionValue)) { std::string errmsg = "Error reading ephemeris message file \""; errmsg += emFile + "\". "; errmsg += "Version number is not a valid real number.\n"; throw UtilityException(errmsg); } if (!IsValidVersion(versionValue)) { std::string errmsg = "Error reading ephemeris message file \""; errmsg += emFile + "\". "; errmsg += "Version number is not valid.\n"; throw UtilityException(errmsg); } versionNumber = versionValue; versionFound = true; }
DWORD CNWCFile::Load(wxFile& in, FILE* out, FILELOAD fl) { char buf[64]; if ( sizeof(szNWCHeader) != in.Read(buf, sizeof(szNWCHeader)) || memcmp(szNWCHeader, buf, sizeof(szNWCHeader)) != 0 ) { if ( memcmp(szCompressHeader1, buf, sizeof(szCompressHeader1)) == 0 ) { return LoadCompressed(in, out, fl); } wxFprintf(stderr, _T("invalid szNWCHeader\n")); return ERROR_INVALID_DATA; } if ( !ReadLEShort(in, nVersion) ) { wxFprintf(stderr, _T("unexpected EOF while reading version\n")); wxASSERT(false); return ERROR_INVALID_DATA; } if ( IsValidVersion(nVersion) ) { wxFprintf(out, _T("version:%d.%d\n"), nVerMajor, nVerMinor); } else { wxFprintf(stderr, _T("unknown version number\n")); return ERROR_INVALID_VERSION; } long nPos = in.Tell(); char _szHeader2[4] = "\x02\x00\x00"; // implies NUL at last if ( !ReadBytes(in, btUnknown2) || btUnknown2[0] != _szHeader2[0] || btUnknown2[1] != _szHeader2[1] || btUnknown2[3] != _szHeader2[3] ) { //wxFprintf(stderr, "invalid btUnknown2 at 0x%08x\n", nPos); //wxASSERT(false); } if ( btUnknown2[2] == 5 ) { wxFprintf(out, _T("saved by unregistered version\n")); } else if ( btUnknown2[2] != 0 ) { //wxFprintf(stderr, "invalid btUnknown2 at 0x%08x\n", nPos); } strUser = LoadStringNULTerminated(in); strUnknown1 = LoadStringNULTerminated(in); wxFprintf(out, _T("user:'******', '%s'\n"), strUser.c_str(), strUnknown1.c_str()); nPos = in.Tell(); char szHeader3[8] = "\x00\x00\x00\x00\x00\x00\x00"; // implies NUL at last if ( sizeof(szHeader3) != in.Read(buf, sizeof(szHeader3)) || memcmp(szHeader3, buf, sizeof(szHeader3)) != 0 ) { wxFprintf(stderr, _T("invalid btUnknown2 at 0x%08x\n"), nPos); //wxASSERT(false); } short nUnknown4; if ( !ReadBytes(in, nUnknown4) ) { wxFprintf(stderr, _T("unexpected EOF while reading\n")); wxASSERT(false); return ERROR_INVALID_DATA; } strTitle = LoadStringNULTerminated(in); strAuthor = LoadStringNULTerminated(in); if ( nVersion >= NWC_Version200 ) strLyricist = LoadStringNULTerminated(in); strCopyright1 = LoadStringNULTerminated(in); strCopyright2 = LoadStringNULTerminated(in); strComment = LoadStringNULTerminated(in); wxFprintf(out, _T("title:'%s'\n"), strTitle.c_str()); wxFprintf(out, _T("author:'%s'\n"), strAuthor.c_str()); if ( nVersion >= NWC_Version200 ) wxFprintf(out, _T("lyricist:'%s'\n"), strLyricist.c_str()); wxFprintf(out, _T("copyright1:'%s'\n"), strCopyright1.c_str()); wxFprintf(out, _T("copyright2:'%s'\n"), strCopyright2.c_str()); wxFprintf(out, _T("comment:'%s'\n"), strComment.c_str()); nPos = in.Tell(); char _szReserved5[] = "\x5F\x00\x46\x32\x00"; bool bResult = ReadBytes(in, chExtendLastSystem) && ReadBytes(in, chIncreaseNoteSpacing) && ReadBytes(in, btUnknown3) && ReadBytes(in, btMeasureNumbers) && ReadBytes(in, btUnknown4) && ReadLEShort(in, nMeasureStart); if ( !bResult || memcmp(_szReserved5, btUnknown3, sizeof(btUnknown3)) != 0 ) { // wxFprintf(stderr, "invalid szReserved5 at 0x%08x\n", nPos); // wxASSERT(false); // return ERROR_INVALID_DATA; } wxFprintf(out, _T("extend last system:'%c'\n"), chExtendLastSystem); wxFprintf(out, _T("increase note spacing:'%c'\n"), chIncreaseNoteSpacing); wxFprintf(out, _T("measurenumbers:'%s'\n"), GetMeasureNumbersAsString(btMeasureNumbers)); wxFprintf(out, _T("measurestart:%d\n"), nMeasureStart); if ( nVersion >= NWC_Version130 ) { strMarginTop = LoadStringSpaceTerminated(in); strMarginInside = LoadStringSpaceTerminated(in); strMarginOutside = LoadStringSpaceTerminated(in); strMarginBottom = LoadStringSpaceTerminated(in); } wxFprintf(out, _T("margin:%s %s %s %s\n"), strMarginTop.c_str(), strMarginInside.c_str(), strMarginOutside.c_str(), strMarginBottom.c_str()); ReadBytes(in, bMirrorMargin); wxFprintf(out, _T("mirrormargin:%d\n"), bMirrorMargin); nPos = in.Tell(); if ( !ReadBytes(in, btUnknown5) ) { return ERROR_INVALID_DATA; } if ( nVersion > NWC_Version130 ) { ReadBytes(in, nGroupVisibility); ReadBytes(in, bAllowLayering); wxFprintf(out, _T("group visibility:")); CObj::DumpBinary(out, nGroupVisibility, sizeof(nGroupVisibility), false); wxFprintf(out, _T("\nallowlayering:%d\n"), bAllowLayering); } nPos = in.Tell(); if ( nVersion >= NWC_Version200 ) { strNotationTypeface = LoadStringNULTerminated(in); wxFprintf(out, _T("notationtypeface:%s\n"), strNotationTypeface.c_str()); } ReadLEShort(in, nStaffHeight); wxFprintf(out, _T("staffheight=%d\n"), nStaffHeight); nPos = in.Tell(); int nFontCount = 0; if ( nVersion > NWC_Version130 ) nFontCount = ( nVersion <= NWC_Version170 ? 10 : 12 ); mFontInfos.SetCount(nFontCount); int i; for ( i=0; i<nFontCount; i++ ) { mFontInfos[i].Load(in); } // some 1.70 version have 12 fontinfo if ( nVersion == NWC_Version170 ) { nPos = in.Tell(); unsigned char ch; if ( in.Read(&ch, 1) != 1 ) return ERROR_INVALID_DATA; in.Seek(nPos, wxFromStart); if ( ch == 0 || ch == 0xFF ) { } else { nFontCount += 2; mFontInfos.SetCount(nFontCount); for ( ; i<nFontCount; i++ ) { mFontInfos[i].Load(in); } } } wxFprintf(out, _T("#font=%d\n"), nFontCount); for ( i=0; i<nFontCount; i++ ) { mFontInfos[i].Dump(out, i); } ReadBytes(in, btTitlePageInfo); ReadBytes(in, btStaffLabels); // index of [None, First Systems, Top Systems, All Systems] ReadLEShort(in, nStartPageNo); if ( nVersion >= NWC_Version200 ) { unsigned char ch; if ( in.Read(&ch, 1) != 1 ) return ERROR_INVALID_DATA; if ( ch != 0xFF ) in.Seek(-1, wxFromCurrent); //ReadBytes(in, btJustifyPrintedSystemVertically); } ReadLEShort(in, nStaffCount); wxFprintf(out, _T("titlepageinfo=%d\n"), btTitlePageInfo); wxFprintf(out, _T("stafflabels=%s\n"), GetStaffLabelsAsString(btStaffLabels)); wxFprintf(out, _T("startpageno=%d\n"), nStartPageNo); //if ( nVersion >= NWC_Version200 ) // wxFprintf(out, _T("justifyprintedsystemvertically=%d\n"), btJustifyPrintedSystemVertically); wxFprintf(out, _T("staffcount=%d\n"), nStaffCount); fflush(out); for ( i=0; i<nStaffCount; i++ ) { nPos = in.Tell(); CStaff* pStaff = new CStaff; pStaff->SetParent(this); wxFprintf(out, _T("\nstaff%d\n"), i); if ( false == pStaff->Load(in, out, fl) ) { delete pStaff; return ERROR_INVALID_STAFF; } mStaffs.Add(pStaff); fflush(out); // load until staff which has lyric //if ( fl == FILELOAD_INFO && pStaff->m_strLyric.size() ) // break; } return ERROR_SUCCESS; }
void TPluginSpecPrivate::ReadPluginSpec(QXmlStreamReader &XmlReader) { QString Element = XmlReader.name().toString(); if(Element != QString(PLUGIN)) { XmlReader.raiseError(QString("PluginSpec: Expected element '%1' as top level element").arg(PLUGIN)); return; } Name = XmlReader.attributes().value(PLUGIN_NAME).toString(); if(Name.isEmpty()) { XmlReader.raiseError(QString("TPluginSpecPrivate::ReadPluginSpec: '%1' misses attribute '%2'") .arg(QLatin1String(PLUGIN), QLatin1String(PLUGIN_NAME))); return; } Version = XmlReader.attributes().value(PLUGIN_VERSION).toString(); if(Version.isEmpty()) { XmlReader.raiseError(QString("TPluginSpecPrivate::ReadPluginSpec: '%1' misses attribute '%2'") .arg(QLatin1String(PLUGIN), QLatin1String(PLUGIN_VERSION))); return; } if(!IsValidVersion(Version)) { XmlReader.raiseError(QString("TPluginSpecPrivate::ReadPluginSpec: '%1' has invalid format") .arg(PLUGIN_VERSION)); return; } while(!XmlReader.atEnd()) { XmlReader.readNext(); switch(XmlReader.tokenType()) { case QXmlStreamReader::StartElement: Element = XmlReader.name().toString(); if(Element == VENDOR) Vendor = XmlReader.readElementText().trimmed(); else if(Element == COPYRIGHT) Copyright = XmlReader.readElementText().trimmed(); else if(Element == LICENSE) License = XmlReader.readElementText().trimmed(); else if(Element == DESCRIPTION) Description = XmlReader.readElementText().trimmed(); else if(Element == URL) Url = XmlReader.readElementText().trimmed(); else if(Element == DEPENDENCYLIST) ReadDependencies(XmlReader); //else if(Element == ARGUMENTLIST) // ReadArgumentDescriptions(XmlReader); else XmlReader.raiseError(QString("TPluginSpecPrivate::ReadPluginSpec: Invalid element '%1'").arg(Name)); break; case QXmlStreamReader::EndDocument: case QXmlStreamReader::Comment: case QXmlStreamReader::EndElement: case QXmlStreamReader::Characters: break; default: XmlReader.raiseError(QString("TPluginSpecPrivate::ReadPluginSpec: Unexpected token")); break; } } }