void GstEnginePipeline::TagMessageReceived(GstMessage* msg) { GstTagList* taglist = nullptr; gst_message_parse_tag(msg, &taglist); Engine::SimpleMetaBundle bundle; bundle.title = ParseTag(taglist, GST_TAG_TITLE); bundle.artist = ParseTag(taglist, GST_TAG_ARTIST); bundle.comment = ParseTag(taglist, GST_TAG_COMMENT); bundle.album = ParseTag(taglist, GST_TAG_ALBUM); gst_tag_list_free(taglist); if (ignore_tags_) return; if (!bundle.title.isEmpty() || !bundle.artist.isEmpty() || !bundle.comment.isEmpty() || !bundle.album.isEmpty()) emit MetadataFound(id(), bundle); }
MathCell* MathParser::ParseFunTag(wxXmlNode* node) { FunCell *fun = new FunCell; wxXmlNode* child = node->GetChildren(); if (child) { fun->SetName(ParseTag(child, false)); child = child->GetNext(); if (child) { fun->SetType(m_ParserStyle); fun->SetStyle(TS_VARIABLE); fun->SetArg(ParseTag(child, false)); return fun; } } delete fun; return NULL; }
MathCell* MathParser::ParseAbsTag(wxXmlNode* node) { wxXmlNode* child = node->GetChildren(); AbsCell* cell = new AbsCell; cell->SetInner(ParseTag(child, true)); cell->SetType(m_ParserStyle); cell->SetStyle(TS_VARIABLE); cell->SetHighlight(m_highlight); return cell; }
MathCell* MathParser::ParseAtTag(wxXmlNode* node) { AtCell *at = new AtCell; wxXmlNode* child = node->GetChildren(); if (child) { at->SetBase(ParseTag(child, false)); at->SetHighlight(m_highlight); child = child->GetNext(); if (child) { at->SetIndex(ParseTag(child, false)); at->SetType(m_ParserStyle); at->SetStyle(TS_VARIABLE); return at; } } delete at; return NULL; }
MathCell* MathParser::ParseSubTag(wxXmlNode* node) { SubCell *sub = new SubCell; wxXmlNode* child = node->GetChildren(); if (child) { sub->SetBase(ParseTag(child, false)); child = child->GetNext(); if (child) { MathCell* index = ParseTag(child, false); index->SetExponentFlag(); sub->SetIndex(index); sub->SetType(m_ParserStyle); sub->SetStyle(TS_VARIABLE); return sub; } } delete sub; return NULL; }
// Parse node tags at the current level recursively. See notes above // Return number of node tags parsed int LicutSVG::ParseTags( char *& s, int stackLevel, char *tagStack[1024], bool ignore ) { int tagsParsed = 0; while (*s) { if (m_verbose) printf( "calling [%s]\n", _fmt_sample( s, 6 ) ); int parsed = ParseTag( s, stackLevel, tagStack, ignore ); if (m_verbose) printf( "returned %d\n", parsed ); tagsParsed += parsed; } return tagsParsed; }
MathCell* MathParser::ParseDiffTag(wxXmlNode* node) { DiffCell *diff = new DiffCell; wxXmlNode* child = node->GetChildren(); if (child) { int fc = m_FracStyle; m_FracStyle = FC_DIFF; diff->SetDiff(ParseTag(child, false)); m_FracStyle = fc; child = child->GetNext(); if (child) { diff->SetBase(ParseTag(child, true)); diff->SetType(m_ParserStyle); diff->SetStyle(TS_VARIABLE); return diff; } } delete diff; return NULL; }
// ParseHeader // . Grabs any tag, alias, or anchor tokens and deals with them. void Node::ParseHeader(Scanner *pScanner, const ParserState& state) { while(1) { if(pScanner->empty()) return; switch(pScanner->peek().type) { case Token::TAG: ParseTag(pScanner, state); break; case Token::ANCHOR: ParseAnchor(pScanner, state); break; case Token::ALIAS: ParseAlias(pScanner, state); break; default: return; } } }
MathCell* MathParser::ParseTableTag(wxXmlNode* node) { MatrCell *matrix = new MatrCell; matrix->SetHighlight(m_highlight); #if wxCHECK_VERSION(2,9,0) if (node->GetAttribute(wxT("special"), wxT("false")) == wxT("true")) matrix->SetSpecialFlag(true); if (node->GetAttribute(wxT("inference"), wxT("false")) == wxT("true")) { matrix->SetInferenceFlag(true); matrix->SetSpecialFlag(true); } if (node->GetAttribute(wxT("colnames"), wxT("false")) == wxT("true")) matrix->ColNames(true); if (node->GetAttribute(wxT("rownames"), wxT("false")) == wxT("true")) matrix->RowNames(true); #else if (node->GetPropVal(wxT("special"), wxT("false")) == wxT("true")) matrix->SetSpecialFlag(true); if (node->GetPropVal(wxT("inference"), wxT("false")) == wxT("true")) { matrix->SetInferenceFlag(true); matrix->SetSpecialFlag(true); } if (node->GetPropVal(wxT("colnames"), wxT("false")) == wxT("true")) matrix->ColNames(true); if (node->GetPropVal(wxT("rownames"), wxT("false")) == wxT("true")) matrix->RowNames(true); #endif wxXmlNode* rows = node->GetChildren(); while (rows) { matrix->NewRow(); wxXmlNode* cells = rows->GetChildren(); while (cells) { matrix->NewColumn(); matrix->AddNewCell(ParseTag(cells, false)); cells = cells->GetNext(); } rows = rows->GetNext(); } matrix->SetType(m_ParserStyle); matrix->SetStyle(TS_VARIABLE); matrix->SetDimension(); return matrix; }
MathCell* MathParser::ParseLimitTag(wxXmlNode* node) { LimitCell *limit = new LimitCell; wxXmlNode* child = node->GetChildren(); if (child) { limit->SetName(ParseTag(child, false)); child = child->GetNext(); if (child) { limit->SetUnder(ParseTag(child, false)); child = child->GetNext(); if (child) { limit->SetBase(ParseTag(child, false)); limit->SetType(m_ParserStyle); limit->SetStyle(TS_VARIABLE); return limit; } } } delete limit; return NULL; }
void GstEnginePipeline::TagMessageReceived(GstMessage* msg) { GstTagList* taglist = nullptr; gst_message_parse_tag(msg, &taglist); Engine::SimpleMetaBundle bundle; bundle.title = ParseTag(taglist, GST_TAG_TITLE); if (IsAkamaiTag(bundle.title)) { QPair<QString, QString> artistTitlePair = ParseAkamaiTag(bundle.title); bundle.artist = artistTitlePair.first; bundle.title = artistTitlePair.second; } else { bundle.artist = ParseTag(taglist, GST_TAG_ARTIST); bundle.comment = ParseTag(taglist, GST_TAG_COMMENT); bundle.album = ParseTag(taglist, GST_TAG_ALBUM); } gst_tag_list_free(taglist); if (ignore_tags_) return; if (!bundle.title.isEmpty() || !bundle.artist.isEmpty() || !bundle.comment.isEmpty() || !bundle.album.isEmpty()) emit MetadataFound(id(), bundle); }
MathCell* MathParser::ParseParenTag(wxXmlNode* node) { wxXmlNode* child = node->GetChildren(); ParenCell* cell = new ParenCell; cell->SetInner(ParseTag(child, true), m_ParserStyle); cell->SetHighlight(m_highlight); cell->SetStyle(TS_VARIABLE); #if wxCHECK_VERSION(2,9,0) if (node->GetAttributes() != NULL) cell->SetPrint(false); #else if (node->GetProperties() != NULL) cell->SetPrint(false); #endif return cell; }
void TreeParser::ParseFile(const char *fname) { int c; PushFile(fname); while((c = Next()) != EOF) { if (c == '<') { TreeNode *p = ParseTag(); if (p && !p->mbIsText) { if (!mpDocument->mpRoot) mpDocument->mpRoot = p; else error("multiple high-level tags detected (first is <%s>, second is <%s>)", mpDocument->mpRoot->mName.c_str(), p->mName.c_str()); } } } }
MathCell* MathParser::ParseIntTag(wxXmlNode* node) { IntCell *in = new IntCell; wxXmlNode* child = node->GetChildren(); in->SetHighlight(m_highlight); #if wxCHECK_VERSION(2,9,0) if (node->GetAttributes() == NULL) #else if (node->GetProperties() == NULL) #endif { in->SetIntStyle(INT_DEF); if (child) { in->SetUnder(ParseTag(child, false)); child = child->GetNext(); if (child) { in->SetOver(ParseTag(child, false)); child = child->GetNext(); if (child) { in->SetBase(ParseTag(child, false)); child = child->GetNext(); if (child) { in->SetVar(ParseTag(child, true)); in->SetType(m_ParserStyle); in->SetStyle(TS_VARIABLE); return in; } } } } } else { if (child) { in->SetBase(ParseTag(child, false)); child = child->GetNext(); if (child) { in->SetVar(ParseTag(child, true)); in->SetType(m_ParserStyle); in->SetStyle(TS_VARIABLE); return in; } } } delete in; return NULL; }
void ParseString(const FString& StringToParse) { DataIndex = 0; DataString = StringToParse; if (DataIndex >= DataString.Len()) { return; } const FString TabString(TEXT(" ")); FColor TagColor; FNode CurrentNode(DefaultColor); for (EStringParserToken Token = ReadToken(); Token != EStringParserToken::EndOfString; Token = ReadToken()) { switch (Token) { case EStringParserToken::RegularChar: CurrentNode.String.AppendChar(DataString[DataIndex]); break; case EStringParserToken::NewLine: NodeList.Add(CurrentNode); CurrentNode = FNode(NodeList.Last().Color); CurrentNode.bNewLine = true; break; case EStringParserToken::Tab: CurrentNode.String.Append(TabString); break; case EStringParserToken::OpenTag: if (ParseTag(TagColor)) { NodeList.Add(CurrentNode); CurrentNode = FNode(TagColor); } break; } DataIndex++; } NodeList.Add(CurrentNode); }
int ParseASN1(u_char *p, u_char *end, int level) { int tag, len; int ret; int j; u_char *tag_end, *beg; beg = p; CallASN1(ret, p, end, ParseTag(p, end, &tag)); CallASN1(ret, p, end, ParseLen(p, end, &len)); #ifdef ASN1_DEBUG for (j = 0; j < level*5; j++) print_asn1msg(PRT_DEBUG_DECODE, " "); print_asn1msg(PRT_DEBUG_DECODE, "TAG 0x%02x LEN %3d\n", tag, len); #endif if (tag & ASN1_TAG_CONSTRUCTED) { if (len == -1) { // indefinite while (*p) { CallASN1(ret, p, end, ParseASN1(p, end, level + 1)); } p++; if (*p) return -1; p++; } else { tag_end = p + len; while (p < tag_end) { CallASN1(ret, p, end, ParseASN1(p, end, level +1)); } } } else { for (j = 0; j < level*5; j++) print_asn1msg(PRT_DEBUG_DECODE, " "); while (len--) { print_asn1msg(PRT_DEBUG_DECODE, "%02x ", *p); p++; } print_asn1msg(PRT_DEBUG_DECODE, "\n"); } for (j = 0; j < level*5; j++) print_asn1msg(PRT_DEBUG_DECODE, " "); print_asn1msg(PRT_DEBUG_DECODE, "END (%d)\n", p - beg - 2); return p - beg; }
CString Template::ParseCode(LPCTSTR codePtr, LPCTSTR bolPtr, WWhizTemplate* file) { // Build our master string. CharArray buffer; // Remove leading whitespace. while (*codePtr != 0 && *codePtr != '\n' && *codePtr == ' ') { codePtr++; } TokenHelper helper; helper.m_tabSize = 4; helper.m_outBolPtr = bolPtr; helper.m_file = file; helper.m_helper = WNEW TemplateHelper(NULL); // Get the parameter. while (*codePtr != 0) { if (*codePtr == '@' && *(codePtr + 1) == '@') { CString out; if (ParseTag(codePtr, out, &helper)) { // Move the output string into the buffer. for (int i = 0; i < out.GetLength(); i++) buffer.Add(out[i]); } } else { // Copy it straight. buffer.Add(*codePtr++); } } buffer.Add(0); delete helper.m_helper; return CString(buffer.GetData()); }
//***************************************************************************** void CHTMLWidget::EndElement( //Expat callback function: Process XML end tag. // //Params: const XML_Char* name) { //Get tag type (assume no special chars). const HTMLTagType eTagType = ParseTag(name); if (wstrBuffer.length()) Flush(); if (aeTagLevel[eTagType]) --aeTagLevel[eTagType]; switch (eTagType) { case H3_Tag: this->wX = 0; this->wY += static_cast<UINT>(g_pTheFM->GetFontLineHeight(FONTLIB::F_TextHead3)); this->bSkipSpace = true; break; case UL_Tag: case OL_Tag: this->wOLcounter = swOLstack.top(); this->swOLstack.pop(); this->wMargin -= LISTINDENT; NewLine(); break; case LI_Tag: case P_Tag: case TR_Tag: NewLine(); break; case TD_Tag: if (this->wTDWidth) this->wX = vwColumns[this->wCurrentColumn - 1] + this->wTDWidth; break; default: break; } }
const TCHAR * CXmlParser::ParseTag(CXmlNode& Node, TCHAR * pStart, const TCHAR * pEnd) { while (pStart < pEnd) { // Ищем начало открывающего тэга const TCHAR * itStartTag = std::find(static_cast< const TCHAR * > (pStart), pEnd, '<'); const TCHAR * itStartTagName = std::find_if(itStartTag, pEnd, boost::algorithm::is_alnum()); // Нашли закрывающий тэг if (itStartTag == itStartTagName || *(itStartTag + 1) == '/') return std::find(const_cast< const TCHAR * > (pStart), pEnd, '>') + 1; // Ищем окончание открывающего тэга const TCHAR * itEndOpenTag = std::find(itStartTag, pEnd, '>'); // Ищем имя тэга const TCHAR * itEndName = std::find_if(itStartTagName, itEndOpenTag, !boost::algorithm::is_alnum()); _tstring sTagName = _tstring(itStartTagName, itEndName); Node.Data[TAG_NAME] = sTagName; // Ищем тип тэга (?, <--) _tstring sTagType = _tstring(itStartTag + 1, itStartTagName); //Находим все атрибуты тэга _tstring sTagData(itStartTagName, itEndOpenTag); if (!sTagType.empty()) // Удаляем тип тэга из строки атрибутов boost::algorithm::replace_all(sTagData, sTagType, ""); GetTagAttributes(Node, sTagData); /*if (!sTagType.empty()) { std::find(const_cast< const TCHAR * > (pStart), pEnd, '>') + 1; }*/ // У тэга нет значения и вложенных тэгов if (*(itEndOpenTag - 1) == '/') { return itEndOpenTag + 1; } else { // Ищем вложенные узлы pStart = const_cast< TCHAR * > (std::find(itStartTagName, pEnd, '>')); while (true) { // Находим вложенные узлы и добавляем в Childs CXmlNode Child; pStart = const_cast< TCHAR * > (ParseTag(Child, pStart, pEnd)); if (!Child.Data.empty()) Node.Childs.push_back(Child); if (pStart >= pEnd) break; // Ищем закрывающий тэг </tag_name> TCHAR * itTagEnd = 0; while (true) { itTagEnd = const_cast< TCHAR * > (std::find(static_cast< const TCHAR * > (pStart), pEnd, '/')); if (*(itTagEnd - 1) == '<' || itTagEnd >= pEnd) break; } const TCHAR * itCloseTagNameEnd = std::find(static_cast< const TCHAR * > (itTagEnd), pEnd, '>'); _tstring sCloseTagName; if (itTagEnd < itCloseTagNameEnd) sCloseTagName.assign(itTagEnd + 1, itCloseTagNameEnd); if (!sCloseTagName.empty() && sCloseTagName == sTagName) { _tstring sValue(pStart, itTagEnd - 1); if (!sValue.empty() && sValue != _T("\n")) Node.Data[TAG_VALUE] = sValue; break; } } } } return pEnd; }
void CXmlParser::Parse(const TCHAR * szSource, const long nLength) { ParseTag(m_Data, const_cast< TCHAR * >(&szSource[0]), &szSource[nLength]); }
bool dng_info::ParseMakerNoteIFD (dng_host &host, dng_stream &stream, uint64 ifdSize, uint64 ifdOffset, int64 offsetDelta, uint64 minOffset, uint64 maxOffset, uint32 parentCode) { uint32 tagIndex; uint32 tagCode; uint32 tagType; uint32 tagCount; // Assume there is no next IFD pointer. fMakerNoteNextIFD = 0; // If size is too small to hold a single entry IFD, abort. if (ifdSize < 14) { return false; } // Get entry count. stream.SetReadPosition (ifdOffset); uint32 ifdEntries = stream.Get_uint16 (); // Make the entry count if reasonable for the MakerNote size. if (ifdEntries < 1 || 2 + ifdEntries * 12 > ifdSize) { return false; } // Scan IFD to verify all the tag types are all valid. for (tagIndex = 0; tagIndex < ifdEntries; tagIndex++) { stream.SetReadPosition (ifdOffset + 2 + tagIndex * 12 + 2); tagType = stream.Get_uint16 (); // Kludge: Some Canon MakerNotes contain tagType = 0 tags, so we // need to ignore them. This was a "firmware 1.0.4" Canon 40D raw file. if (parentCode == tcCanonMakerNote && tagType == 0) { continue; } if (TagTypeSize (tagType) == 0) { return false; } } // OK, the IFD looks reasonable enough to parse. #if qDNGValidate if (gVerbose) { printf ("%s: Offset = %u, Entries = %u\n\n", LookupParentCode (parentCode), (unsigned) ifdOffset, (unsigned) ifdEntries); } #endif for (tagIndex = 0; tagIndex < ifdEntries; tagIndex++) { stream.SetReadPosition (ifdOffset + 2 + tagIndex * 12); tagCode = stream.Get_uint16 (); tagType = stream.Get_uint16 (); tagCount = stream.Get_uint32 (); if (tagType == 0) { continue; } uint32 tagSize = tagCount * TagTypeSize (tagType); uint64 tagOffset = ifdOffset + 2 + tagIndex * 12 + 8; if (tagSize > 4) { tagOffset = stream.Get_uint32 () + offsetDelta; if (tagOffset < minOffset || tagOffset + tagSize > maxOffset) { // Tag data is outside the valid offset range, // so ignore this tag. continue; } stream.SetReadPosition (tagOffset); } // Olympus switched to using IFDs in version 3 makernotes. if (parentCode == tcOlympusMakerNote && tagType == ttIFD && tagCount == 1) { uint32 olympusMakerParent = 0; switch (tagCode) { case 8208: olympusMakerParent = tcOlympusMakerNote8208; break; case 8224: olympusMakerParent = tcOlympusMakerNote8224; break; case 8240: olympusMakerParent = tcOlympusMakerNote8240; break; case 8256: olympusMakerParent = tcOlympusMakerNote8256; break; case 8272: olympusMakerParent = tcOlympusMakerNote8272; break; case 12288: olympusMakerParent = tcOlympusMakerNote12288; break; default: break; } if (olympusMakerParent) { stream.SetReadPosition (tagOffset); uint64 subMakerNoteOffset = stream.Get_uint32 () + offsetDelta; if (subMakerNoteOffset >= minOffset && subMakerNoteOffset < maxOffset) { if (ParseMakerNoteIFD (host, stream, maxOffset - subMakerNoteOffset, subMakerNoteOffset, offsetDelta, minOffset, maxOffset, olympusMakerParent)) { continue; } } } stream.SetReadPosition (tagOffset); } ParseTag (host, stream, fExif.Get (), fShared.Get (), NULL, parentCode, tagCode, tagType, tagCount, tagOffset, offsetDelta); } // Grab next IFD pointer, for possible use. if (ifdSize >= 2 + ifdEntries * 12 + 4) { stream.SetReadPosition (ifdOffset + 2 + ifdEntries * 12); fMakerNoteNextIFD = stream.Get_uint32 (); } #if qDNGValidate if (gVerbose) { printf ("\n"); } #endif return true; }
void dng_info::ParseIFD (dng_host &host, dng_stream &stream, dng_exif *exif, dng_shared *shared, dng_ifd *ifd, uint64 ifdOffset, int64 offsetDelta, uint32 parentCode) { #if qDNGValidate bool isMakerNote = (parentCode >= tcFirstMakerNoteIFD && parentCode <= tcLastMakerNoteIFD); #endif stream.SetReadPosition (ifdOffset); if (ifd) { ifd->fThisIFD = ifdOffset; } uint32 ifdEntries = stream.Get_uint16 (); #if qDNGValidate if (gVerbose) { printf ("%s: Offset = %u, Entries = %u\n\n", LookupParentCode (parentCode), (unsigned) ifdOffset, (unsigned) ifdEntries); } if ((ifdOffset & 1) && !isMakerNote) { char message [256]; sprintf (message, "%s has odd offset (%u)", LookupParentCode (parentCode), (unsigned) ifdOffset); ReportWarning (message); } #endif uint32 prev_tag_code = 0; for (uint32 tag_index = 0; tag_index < ifdEntries; tag_index++) { stream.SetReadPosition (ifdOffset + 2 + tag_index * 12); uint32 tagCode = stream.Get_uint16 (); uint32 tagType = stream.Get_uint16 (); // Minolta 7D files have a bug in the EXIF block where the count // is wrong, and we run off into next IFD link. So if abort parsing // if we get a zero code/type combinations. if (tagCode == 0 && tagType == 0) { #if qDNGValidate char message [256]; sprintf (message, "%s had zero/zero tag code/type entry", LookupParentCode (parentCode)); ReportWarning (message); #endif return; } uint32 tagCount = stream.Get_uint32 (); #if qDNGValidate { if (tag_index > 0 && tagCode <= prev_tag_code && !isMakerNote) { char message [256]; sprintf (message, "%s tags are not sorted in ascending numerical order", LookupParentCode (parentCode)); ReportWarning (message); } } #endif prev_tag_code = tagCode; uint32 tag_type_size = TagTypeSize (tagType); if (tag_type_size == 0) { #if qDNGValidate { char message [256]; sprintf (message, "%s %s has unknown type (%u)", LookupParentCode (parentCode), LookupTagCode (parentCode, tagCode), (unsigned) tagType); ReportWarning (message); } #endif continue; } uint64 tagOffset = ifdOffset + 2 + tag_index * 12 + 8; if (tagCount * tag_type_size > 4) { tagOffset = stream.Get_uint32 (); #if qDNGValidate { if (!(ifdOffset & 1) && (tagOffset & 1) && !isMakerNote && parentCode != tcKodakDCRPrivateIFD && parentCode != tcKodakKDCPrivateIFD) { char message [256]; sprintf (message, "%s %s has odd data offset (%u)", LookupParentCode (parentCode), LookupTagCode (parentCode, tagCode), (unsigned) tagOffset); ReportWarning (message); } } #endif tagOffset += offsetDelta; stream.SetReadPosition (tagOffset); } ParseTag (host, stream, exif, shared, ifd, parentCode, tagCode, tagType, tagCount, tagOffset, offsetDelta); } stream.SetReadPosition (ifdOffset + 2 + ifdEntries * 12); uint32 nextIFD = stream.Get_uint32 (); #if qDNGValidate if (gVerbose) { printf ("NextIFD = %u\n", (unsigned) nextIFD); } #endif if (ifd) { ifd->fNextIFD = nextIFD; } #if qDNGValidate if (nextIFD) { if (parentCode != 0 && (parentCode < tcFirstChainedIFD || parentCode > tcLastChainedIFD )) { char message [256]; sprintf (message, "%s has an unexpected non-zero NextIFD (%u)", LookupParentCode (parentCode), (unsigned) nextIFD); ReportWarning (message); } } if (gVerbose) { printf ("\n"); } #endif }
void dng_info::ParseDNGPrivateData (dng_host &host, dng_stream &stream) { if (fShared->fDNGPrivateDataCount < 2) { return; } // DNG private data should always start with a null-terminated // company name, to define the format of the private data. dng_string privateName; { char buffer [64]; stream.SetReadPosition (fShared->fDNGPrivateDataOffset); uint32 readLength = Min_uint32 (fShared->fDNGPrivateDataCount, sizeof (buffer) - 1); stream.Get (buffer, readLength); buffer [readLength] = 0; privateName.Set (buffer); } // Pentax is storing their MakerNote in the DNGPrivateData data. if (privateName.StartsWith ("PENTAX" ) || privateName.StartsWith ("SAMSUNG")) { #if qDNGValidate if (gVerbose) { printf ("Parsing Pentax/Samsung DNGPrivateData\n\n"); } #endif stream.SetReadPosition (fShared->fDNGPrivateDataOffset + 8); bool bigEndian = stream.BigEndian (); uint16 endianMark = stream.Get_uint16 (); if (endianMark == byteOrderMM) { bigEndian = true; } else if (endianMark == byteOrderII) { bigEndian = false; } TempBigEndian temp_endian (stream, bigEndian); ParseMakerNoteIFD (host, stream, fShared->fDNGPrivateDataCount - 10, fShared->fDNGPrivateDataOffset + 10, fShared->fDNGPrivateDataOffset, fShared->fDNGPrivateDataOffset, fShared->fDNGPrivateDataOffset + fShared->fDNGPrivateDataCount, tcPentaxMakerNote); return; } // Stop parsing if this is not an Adobe format block. if (!privateName.Matches ("Adobe")) { return; } TempBigEndian temp_order (stream); uint32 section_offset = 6; while (section_offset + 8 < fShared->fDNGPrivateDataCount) { stream.SetReadPosition (fShared->fDNGPrivateDataOffset + section_offset); uint32 section_key = stream.Get_uint32 (); uint32 section_count = stream.Get_uint32 (); if (section_key == DNG_CHAR4 ('M','a','k','N') && section_count > 6) { #if qDNGValidate if (gVerbose) { printf ("Found MakerNote inside DNGPrivateData\n\n"); } #endif uint16 order_mark = stream.Get_uint16 (); uint64 old_offset = stream.Get_uint32 (); uint32 tempSize = section_count - 6; AutoPtr<dng_memory_block> tempBlock (host.Allocate (tempSize)); uint64 positionInOriginalFile = stream.PositionInOriginalFile(); stream.Get (tempBlock->Buffer (), tempSize); dng_stream tempStream (tempBlock->Buffer (), tempSize, positionInOriginalFile); tempStream.SetBigEndian (order_mark == byteOrderMM); ParseMakerNote (host, tempStream, tempSize, 0, 0 - old_offset, 0, tempSize); } else if (section_key == DNG_CHAR4 ('S','R','2',' ') && section_count > 6) { #if qDNGValidate if (gVerbose) { printf ("Found Sony private data inside DNGPrivateData\n\n"); } #endif uint16 order_mark = stream.Get_uint16 (); uint64 old_offset = stream.Get_uint32 (); uint64 new_offset = fShared->fDNGPrivateDataOffset + section_offset + 14; TempBigEndian sr2_order (stream, order_mark == byteOrderMM); ParseSonyPrivateData (host, stream, section_count - 6, old_offset, new_offset); } else if (section_key == DNG_CHAR4 ('R','A','F',' ') && section_count > 4) { #if qDNGValidate if (gVerbose) { printf ("Found Fuji RAF tags inside DNGPrivateData\n\n"); } #endif uint16 order_mark = stream.Get_uint16 (); uint32 tagCount = stream.Get_uint32 (); uint64 tagOffset = stream.Position (); if (tagCount) { TempBigEndian raf_order (stream, order_mark == byteOrderMM); ParseTag (host, stream, fExif.Get (), fShared.Get (), NULL, tcFujiRAF, tcFujiHeader, ttUndefined, tagCount, tagOffset, 0); stream.SetReadPosition (tagOffset + tagCount); } tagCount = stream.Get_uint32 (); tagOffset = stream.Position (); if (tagCount) { TempBigEndian raf_order (stream, order_mark == byteOrderMM); ParseTag (host, stream, fExif.Get (), fShared.Get (), NULL, tcFujiRAF, tcFujiRawInfo1, ttUndefined, tagCount, tagOffset, 0); stream.SetReadPosition (tagOffset + tagCount); } tagCount = stream.Get_uint32 (); tagOffset = stream.Position (); if (tagCount) { TempBigEndian raf_order (stream, order_mark == byteOrderMM); ParseTag (host, stream, fExif.Get (), fShared.Get (), NULL, tcFujiRAF, tcFujiRawInfo2, ttUndefined, tagCount, tagOffset, 0); stream.SetReadPosition (tagOffset + tagCount); } } else if (section_key == DNG_CHAR4 ('C','n','t','x') && section_count > 4) { #if qDNGValidate if (gVerbose) { printf ("Found Contax Raw header inside DNGPrivateData\n\n"); } #endif uint16 order_mark = stream.Get_uint16 (); uint32 tagCount = stream.Get_uint32 (); uint64 tagOffset = stream.Position (); if (tagCount) { TempBigEndian contax_order (stream, order_mark == byteOrderMM); ParseTag (host, stream, fExif.Get (), fShared.Get (), NULL, tcContaxRAW, tcContaxHeader, ttUndefined, tagCount, tagOffset, 0); } } else if (section_key == DNG_CHAR4 ('C','R','W',' ') && section_count > 4) { #if qDNGValidate if (gVerbose) { printf ("Found Canon CRW tags inside DNGPrivateData\n\n"); } #endif uint16 order_mark = stream.Get_uint16 (); uint32 entries = stream.Get_uint16 (); uint64 crwTagStart = stream.Position (); for (uint32 parsePass = 1; parsePass <= 2; parsePass++) { stream.SetReadPosition (crwTagStart); for (uint32 index = 0; index < entries; index++) { uint32 tagCode = stream.Get_uint16 (); uint32 tagCount = stream.Get_uint32 (); uint64 tagOffset = stream.Position (); // We need to grab the model id tag first, and then all the // other tags. if ((parsePass == 1) == (tagCode == 0x5834)) { TempBigEndian tag_order (stream, order_mark == byteOrderMM); ParseTag (host, stream, fExif.Get (), fShared.Get (), NULL, tcCanonCRW, tagCode, ttUndefined, tagCount, tagOffset, 0); } stream.SetReadPosition (tagOffset + tagCount); } } } else if (section_count > 4) { uint32 parentCode = 0; bool code32 = false; bool hasType = true; switch (section_key) { case DNG_CHAR4 ('M','R','W',' '): { parentCode = tcMinoltaMRW; code32 = true; hasType = false; break; } case DNG_CHAR4 ('P','a','n','o'): { parentCode = tcPanasonicRAW; break; } case DNG_CHAR4 ('L','e','a','f'): { parentCode = tcLeafMOS; break; } case DNG_CHAR4 ('K','o','d','a'): { parentCode = tcKodakDCRPrivateIFD; break; } case DNG_CHAR4 ('K','D','C',' '): { parentCode = tcKodakKDCPrivateIFD; break; } default: break; } if (parentCode) { #if qDNGValidate if (gVerbose) { printf ("Found %s tags inside DNGPrivateData\n\n", LookupParentCode (parentCode)); } #endif uint16 order_mark = stream.Get_uint16 (); uint32 entries = stream.Get_uint16 (); for (uint32 index = 0; index < entries; index++) { uint32 tagCode = code32 ? stream.Get_uint32 () : stream.Get_uint16 (); uint32 tagType = hasType ? stream.Get_uint16 () : ttUndefined; uint32 tagCount = stream.Get_uint32 (); uint32 tagSize = tagCount * TagTypeSize (tagType); uint64 tagOffset = stream.Position (); TempBigEndian tag_order (stream, order_mark == byteOrderMM); ParseTag (host, stream, fExif.Get (), fShared.Get (), NULL, parentCode, tagCode, tagType, tagCount, tagOffset, 0); stream.SetReadPosition (tagOffset + tagSize); } } } section_offset += 8 + section_count; if (section_offset & 1) { section_offset++; } } }
bool Template::ParseHelper() { // Build our master string. m_helper->m_buffer.SetCount(0, 1024); m_helper->m_outBolPos = 0; // Start copying the string in. m_helper->m_codePtr = (LPCTSTR)m_code; m_helper->m_codeBolPtr = m_helper->m_codePtr; LPCTSTR& codePtr = m_helper->m_codePtr; CharArray& buffer = m_helper->m_buffer; // Conditional stack. CList<CondInfo, CondInfo&> conditionalStack; int nestedFalseConditionals = 0; // Go 'til the end. while (*codePtr != 0) { LPCTSTR outBolPtr = buffer.GetData() + m_helper->m_outBolPos; TokenHelper helper; helper.m_tabSize = m_helper->m_tabSize; helper.m_outBolPtr = outBolPtr; helper.m_file = this; helper.m_helper = m_helper; // See if it is a command. Commands can only occur at the beginning // of a line. if (*codePtr == '!' && *(codePtr + 1) == '!' && codePtr == m_helper->m_codeBolPtr) { // Move past the exclamation points. codePtr += 2; // Is it a command comment? // !!// This is a comment. if (*codePtr == '/' && *(codePtr + 1) == '/') { // Move past the double slash. codePtr += 2; SkipToEol(codePtr); continue; } /////////////////////////////////////////////////////////////////// // Lex the command token. char command[256]; char *comPtr = command; while (*codePtr != 0) { // Is it a space? if (*codePtr == ' ') { // Break at a space. codePtr++; break; } else if (*codePtr == '\n' || *codePtr == '\r') { break; } else { // Copy the command or flag. *comPtr++ = *codePtr++; } } *comPtr = 0; /////////////////////////////////////////////////////////////////// // "Conditional" commands /////////////////////////////////////////////////////////////////// // If the last conditional was false, then we ignore until the next // endif. if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { CondInfo condInfo = conditionalStack.GetTail(); if (stricmp(command, "if") == 0) { SkipToEol(codePtr); nestedFalseConditionals++; continue; } else if (stricmp(command, "elif") == 0 || stricmp(command, "else") == 0) { // If we're in nested false conditionals, then ignore. if (nestedFalseConditionals > 0) { SkipToEol(codePtr); continue; } } else if (stricmp(command, "endif") == 0) { // If we're in nested false conditionals, then ignore. if (nestedFalseConditionals > 0) { SkipToEol(codePtr); nestedFalseConditionals--; continue; } } } if (stricmp(command, "if") == 0 || stricmp(command, "elif") == 0) { // Our CondInfo structure. CondInfo condInfo; // If the command is an elif, then pop the old state. if (tolower(command[0]) == 'e') { // The conditional stack can't be empty on an elif. if (conditionalStack.IsEmpty()) { CString err; err.Format("!!elif used with no preceding !!if."); throw TException(TException::CONDSTACK_EMPTY, err); } // Get the current conditionalStack state. We are most // interested in retaining the m_thisLevelTrue variable. condInfo = conditionalStack.GetTail(); // Remove the old state, because it was false. conditionalStack.RemoveTail(); } // if and elif are setup in this format: // !!if var [cond] [condCheck] // condCheck is only optional if cond doesn't exist. // var is required. // Get the requested dictionary entry name. CString var = ParseToken(codePtr, &helper); /* if (var.IsEmpty()) { CString err; err.Format("The variable is missing."); throw TException(TException::IF_VAR_MISSING, err); } */ CString cond = ParseToken(codePtr, &helper); CString condCheck = ParseToken(codePtr, &helper); /* if (!cond.IsEmpty() && condCheck.IsEmpty()) { CString err; err.Format("The conditional is missing."); throw TException(TException::IF_COND_CHECKVAR_MISSING, err); } */ // Check for a ! symbol. bool isNot = false; if (!var.IsEmpty() && var[0] == '!') { isNot = true; var = var.Mid(1); } // Lookup the value. CString value = var; SkipToEol(codePtr); bool result; if (cond.IsEmpty()) { if (value != "0") result = true; else result = false; } else { // There is a conditional expression. Do it. result = CheckCondition(value, cond, condCheck); } if (isNot) result ^= 1; if (tolower(command[0]) == 'e' && result) result ^= condInfo.m_thisLevelTrue; condInfo.m_curState = result; condInfo.m_thisLevelTrue |= result; // Retain the old state. conditionalStack.AddTail(condInfo); continue; } /////////////////////////////////////////////////////////////////// else if (stricmp(command, "else") == 0) { SkipToEol(codePtr); if (conditionalStack.IsEmpty()) { CString err; err.Format("!!else used with no preceding !!if."); throw TException(TException::CONDSTACK_EMPTY, err); } // Get the current conditionalStack state. We are most // interested in retaining the m_thisLevelTrue variable. CondInfo condInfo = conditionalStack.GetTail(); conditionalStack.RemoveTail(); condInfo.m_curState = condInfo.m_thisLevelTrue ^ 1; conditionalStack.AddTail(condInfo); continue; } else if (stricmp(command, "endif") == 0) { SkipToEol(codePtr); if (conditionalStack.IsEmpty()) { CString err; err.Format("!!endif used with no preceding !!if."); throw TException(TException::CONDSTACK_EMPTY, err); } conditionalStack.RemoveTail(); continue; } if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { continue; } /////////////////////////////////////////////////////////////////// // Look up the command in the map. /////////////////////////////////////////////////////////////////// WWhizTemplateCommand* commandObject = m_helper->GetCommand(command); if (commandObject) { TemplateCommandArgs args; // Found a command. Build the arg list. while (true) { CString arg = ParseToken(codePtr, &helper); if (arg.IsEmpty()) break; args.m_argList.Add(arg); } // Skip anything else. SkipToEol(codePtr); // Run the command. commandObject->Run(this, args); RefreshFileInfo(); // Parse the next part. continue; } else { CString err; err.Format("Unable to find the command [%s].", command); if (AfxMessageBox(err + "\n\nKeep executing?", MB_YESNO) == IDNO) { throw TException(TException::MISSING_COMMAND, err); } } } /////////////////////////////////////////////////////////////////////// else if (*codePtr == '@' && *(codePtr + 1) == '@') { // If we're ignoring text, then skip. if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { codePtr += 2; continue; } // Is it a line continuation? // @@backslash if (*(codePtr + 2) == '\\') { SkipToEol(codePtr); continue; } CString out; // Ugly, but we need that \0 in there. buffer.Add(0); buffer.RemoveAt(buffer.GetCount() - 1); if (ParseTag(codePtr, out, &helper)) { // Move the output string into the buffer. for (int i = 0; i < out.GetLength(); i++) buffer.Add(out[i]); } } else { // See if it is an EOL. if (*codePtr == '\n') { m_helper->m_outBolPos = buffer.GetCount() + 1; m_helper->m_codeBolPtr = codePtr + 1; } // If we're ignoring text, then skip. if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { codePtr++; continue; } // Copy it straight. buffer.Add(*codePtr++); } } // Flush what's left. FlushText(); buffer.RemoveAll(); return true; }
//***************************************************************************** void CHTMLWidget::StartElement( //Expat callback function: Process XML start tag, and attributes. // //Params: const XML_Char *name, const XML_Char **atts) { //Get tag type (assume no special chars). const HTMLTagType eTagType = ParseTag(name); if (wstrBuffer.length()) Flush(); ++aeTagLevel[eTagType]; //Get id/name attribute { static const WCHAR wszID[] = {We('i'),We('d'),We(0)}; static const WCHAR wszNAME[] = {We('n'),We('a'),We('m'),We('e'),We(0)}; WSTRING tmp = GetAttr(wszID, atts); if (tmp.empty()) tmp = GetAttr(wszNAME, atts); if (!tmp.empty()) mIdmap.insert(std::make_pair(tmp, this->wY)); } switch (eTagType) { case BODY_Tag: { static const WCHAR wszBgcolor[] = {We('b'),We('g'),We('c'),We('o'),We('l'),We('o'),We('r'),We(0)}; WSTRING bgcolor = GetAttr(wszBgcolor, atts); if (bgcolor.size()) this->wstrBGColor = bgcolor; break; } case UL_Tag: case OL_Tag: this->swOLstack.push(this->wOLcounter); this->wOLcounter = (eTagType == OL_Tag ? 1 : 0); this->wMargin += LISTINDENT; NewLine(this->swOLstack.size() == 1); break; case H1_Tag: case H2_Tag: case H3_Tag: NewLine(); break; case TITLE_Tag: wstrTitle = wszEmpty; break; case A_Tag: swstrLink.push(GetAttr(wszHREF, atts)); break; case B_Tag: break; case HR_Tag: case BR_Tag: NewLine(true); break; case IMG_Tag: { static const WCHAR wszSrc[] = {We('s'),We('r'),We('c'),We(0)}; WSTRING imageURL = this->wstrBasePath; imageURL += wszSlash; imageURL += GetAttr(wszSrc, atts); CImageWidget *pImage = new CImageWidget(0, this->wX + this->wMargin, this->wY, imageURL.c_str()); ASSERT(pImage); AddWidget(pImage); this->wY += pImage->GetH(); this->wX = 0; //next thing goes on new line break; } case P_Tag: this->wY += static_cast<UINT>(g_pTheFM->GetFontLineHeight(FONTLIB::F_Text) * 2/3); break; case LI_Tag: { //Use image as bullet in stead ? static const WCHAR wszItem[] = {We('*'),We(' '),We(0)}; NewLine(); if (this->wOLcounter) { WCHAR wszBuf[33]; wstrBuffer = (WSTRING)_itow(this->wOLcounter, wszBuf, 10) + wszPeriod + wszSpace; ++this->wOLcounter; } else wstrBuffer = wszItem; Flush(true); this->bSkipSpace = true; break; } case TABLE_Tag: NewLine(); vwColumns.clear(); //Fall through case TR_Tag: this->wCurrentColumn = 0; break; case TD_Tag: { if (this->wCurrentColumn >= vwColumns.size()) { static const WCHAR wszWidth[] = {We('w'),We('i'),We('d'),We('t'),We('h'),We(0)}; WSTRING wstrWidthAttr = GetAttr(wszWidth, atts); this->wTDWidth = wstrWidthAttr.length() > 0 ? _Wtoi(wstrWidthAttr.c_str()) : 0; vwColumns.push_back(this->wX += 32); } else { this->wX = vwColumns[this->wCurrentColumn]; this->wTDWidth = 0; } ++this->wCurrentColumn; this->bSkipSpace = true; break; } default: break; } }
// ParseCellTag // This function is responsible for creating // a tree of groupcells when loading XML document. // Any changes in GroupCell structure or methods // has to be reflected here in order to ensure proper // loading of WXMX files. MathCell* MathParser::ParseCellTag(wxXmlNode* node) { GroupCell *group = NULL; // read hide status #if wxCHECK_VERSION(2,9,0) bool hide = (node->GetAttribute(wxT("hide"), wxT("false")) == wxT("true")) ? true : false; #else bool hide = (node->GetPropVal(wxT("hide"), wxT("false")) == wxT("true")) ? true : false; #endif // read (group)cell type #if wxCHECK_VERSION(2,9,0) wxString type = node->GetAttribute(wxT("type"), wxT("text")); #else wxString type = node->GetPropVal(wxT("type"), wxT("text")); #endif if (type == wxT("code")) { group = new GroupCell(GC_TYPE_CODE); wxXmlNode *children = node->GetChildren(); while (children) { if (children->GetName() == wxT("input")) { MathCell *editor = ParseTag(children->GetChildren()); group->SetEditableContent(editor->GetValue()); delete editor; } if (children->GetName() == wxT("output")) group->AppendOutput(ParseTag(children->GetChildren())); children = children->GetNext(); } } else if (type == wxT("image")) { group = new GroupCell(GC_TYPE_IMAGE); wxXmlNode *children = node->GetChildren(); while (children) { if (children->GetName() == wxT("editor")) { MathCell *ed = ParseEditorTag(children); group->SetEditableContent(ed->GetValue()); delete ed; } else group->AppendOutput(ParseTag(children)); children = children->GetNext(); } } else if (type == wxT("pagebreak")) { group = new GroupCell(GC_TYPE_PAGEBREAK); } else if (type == wxT("text")) { group = new GroupCell(GC_TYPE_TEXT); MathCell *editor = ParseTag(node->GetChildren()); group->SetEditableContent(editor->GetValue()); delete editor; } else { // text types if (type == wxT("title")) group = new GroupCell(GC_TYPE_TITLE); else if (type == wxT("section")) group = new GroupCell(GC_TYPE_SECTION); else if (type == wxT("subsection")) group = new GroupCell(GC_TYPE_SUBSECTION); else return NULL; wxXmlNode *children = node->GetChildren(); while (children) { if (children->GetName() == wxT("editor")) { MathCell *ed = ParseEditorTag(children); group->SetEditableContent(ed->GetValue()); delete ed; } else if (children->GetName() == wxT("fold")) { // we have folded groupcells wxXmlNode *xmlcells = children->GetChildren(); MathCell *tree = NULL; MathCell *last = NULL; if (xmlcells) { last = tree = ParseTag(xmlcells, false); // first cell while (xmlcells->GetNext()) { xmlcells = xmlcells->GetNext(); MathCell *cell = ParseTag(xmlcells, false); last->m_next = last->m_nextToDraw = cell; last->m_next->m_previous = last->m_next->m_previousToDraw = last; last = last->m_next; } if (tree) group->HideTree((GroupCell *)tree); } } children = children->GetNext(); } } group->SetParent(group, false); group->Hide(hide); return group; }
MathCell* MathParser::ParseTag(wxXmlNode* node, bool all) { // wxYield(); MathCell* tmp = NULL; MathCell* cell = NULL; bool warning = all; wxString altCopy; while (node) { // Parse tags if (node->GetType() == wxXML_ELEMENT_NODE) { wxString tagName(node->GetName()); if (tagName == wxT("v")) { // Variables (atoms) if (cell == NULL) cell = ParseText(node->GetChildren(), TS_VARIABLE); else cell->AppendCell(ParseText(node->GetChildren(), TS_VARIABLE)); } else if (tagName == wxT("t")) { // Other text if (cell == NULL) cell = ParseText(node->GetChildren(), TS_DEFAULT); else cell->AppendCell(ParseText(node->GetChildren(), TS_DEFAULT)); } else if (tagName == wxT("n")) { // Numbers if (cell == NULL) cell = ParseText(node->GetChildren(), TS_NUMBER); else cell->AppendCell(ParseText(node->GetChildren(), TS_NUMBER)); } else if (tagName == wxT("h")) { // Hidden cells (*) MathCell* tmp = ParseText(node->GetChildren()); tmp->m_isHidden = true; if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("p")) { // Parenthesis if (cell == NULL) cell = ParseParenTag(node); else cell->AppendCell(ParseParenTag(node)); } else if (tagName == wxT("f")) { // Fractions if (cell == NULL) cell = ParseFracTag(node); else cell->AppendCell(ParseFracTag(node)); } else if (tagName == wxT("e")) { // Exponentials if (cell == NULL) cell = ParseSupTag(node); else cell->AppendCell(ParseSupTag(node)); } else if (tagName == wxT("i")) { // Subscripts if (cell == NULL) cell = ParseSubTag(node); else cell->AppendCell(ParseSubTag(node)); } else if (tagName == wxT("fn")) { // Functions if (cell == NULL) cell = ParseFunTag(node); else cell->AppendCell(ParseFunTag(node)); } else if (tagName == wxT("g")) { // Greek constants MathCell* tmp = ParseText(node->GetChildren(), TS_GREEK_CONSTANT); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("s")) { // Special constants %e,... MathCell* tmp = ParseText(node->GetChildren(), TS_SPECIAL_CONSTANT); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("fnm")) { // Function names MathCell* tmp = ParseText(node->GetChildren(), TS_FUNCTION); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("q")) { // Square roots if (cell == NULL) cell = ParseSqrtTag(node); else cell->AppendCell(ParseSqrtTag(node)); } else if (tagName == wxT("d")) { // Differentials if (cell == NULL) cell = ParseDiffTag(node); else cell->AppendCell(ParseDiffTag(node)); } else if (tagName == wxT("sm")) { // Sums if (cell == NULL) cell = ParseSumTag(node); else cell->AppendCell(ParseSumTag(node)); } else if (tagName == wxT("in")) { // integrals if (cell == NULL) cell = ParseIntTag(node); else cell->AppendCell(ParseIntTag(node)); } else if (tagName == wxT("mspace")) { if (cell == NULL) cell = new TextCell(wxT(" ")); else cell->AppendCell(new TextCell(wxT(" "))); } else if (tagName == wxT("at")) { if (cell == NULL) cell = ParseAtTag(node); else cell->AppendCell(ParseAtTag(node)); } else if (tagName == wxT("a")) { if (cell == NULL) cell = ParseAbsTag(node); else cell->AppendCell(ParseAbsTag(node)); } else if (tagName == wxT("ie")) { if (cell == NULL) cell = ParseSubSupTag(node); else cell->AppendCell(ParseSubSupTag(node)); } else if (tagName == wxT("lm")) { if (cell == NULL) cell = ParseLimitTag(node); else cell->AppendCell(ParseLimitTag(node)); } else if (tagName == wxT("r")) { if (cell == NULL) cell = ParseTag(node->GetChildren()); else cell->AppendCell(ParseTag(node->GetChildren())); } else if (tagName == wxT("tb")) { if (cell == NULL) cell = ParseTableTag(node); else cell->AppendCell(ParseTableTag(node)); } else if ((tagName == wxT("mth")) || (tagName == wxT("line"))) { MathCell *tmp = ParseTag(node->GetChildren()); if (tmp != NULL) tmp->ForceBreakLine(true); else tmp = new TextCell(wxT(" ")); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("lbl")) { MathCell* tmp = ParseText(node->GetChildren(), TS_LABEL); tmp->ForceBreakLine(true); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("st")) { MathCell* tmp = ParseText(node->GetChildren(), TS_STRING); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("hl")) { bool highlight = m_highlight; m_highlight = true; MathCell* tmp = ParseTag(node->GetChildren()); m_highlight = highlight; if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("img")) { wxString filename(node->GetChildren()->GetContent()); #if !wxUSE_UNICODE wxString filename1(filename.wc_str(wxConvUTF8), *wxConvCurrent); filename = filename1; #endif ImgCell *tmp; if (m_fileSystem) // loading from zip tmp = new ImgCell(filename, false, m_fileSystem); #if wxCHECK_VERSION(2,9,0) else if (node->GetAttribute(wxT("del"), wxT("yes")) != wxT("no")) #else else if (node->GetPropVal(wxT("del"), wxT("yes")) != wxT("no")) #endif tmp = new ImgCell(filename, true, NULL); else tmp = new ImgCell(filename, false, NULL); #if wxCHECK_VERSION(2,9,0) if (node->GetAttribute(wxT("rect"), wxT("true")) == wxT("false")) tmp->DrawRectangle(false); #else if (node->GetPropVal(wxT("rect"), wxT("true")) == wxT("false")) tmp->DrawRectangle(false); #endif if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("slide"))
// parse_tag // // Assumes that starting < has already been parsed. TreeNode *TreeParser::ParseTag() { TreeNode& tag = *AllocNode(); bool closed = false; int c; tag.mbIsControl = false; tag.mbIsText = false; c = NextRequired(); if (isspace(c)) do { c = NextRequired(); } while(isspace(c)); if (c=='?' || c=='!') { tag.mbIsText = true; tag.mbIsControl = true; tag.mName = "<"; tag.mName += c; int bracket_count = 1; do { c = NextRequired(); tag.mName += c; if (c == '<') ++bracket_count; else if (c == '>') --bracket_count; } while(bracket_count); return &tag; } else if (c == '/') { tag.mName += c; c = NextRequired(); } do { tag.mName += tolower(c); c = NextRequired(); } while(istagchar(c)); if (tag.mName[0] == '/') closed = true; // backwards compatibility std::string::size_type pos = 0; if (closed) pos = 1; if (!tag.mName.compare(pos, 2, "w:")) tag.mName.replace(pos, 2, "lina:"); while(c != '>') { if (c == '/' || c=='?') { closed = true; c = NextRequired(); } else if (istagchar(c)) { tag.mAttribs.push_back(TreeAttribute()); TreeAttribute& att = tag.mAttribs.back(); do { att.mName += tolower(c); c = NextRequired(); } while(istagchar(c)); while(isspace(c)) c = NextRequired(); att.mbNoValue = true; if (c == '=') { att.mbNoValue = false; do { c = NextRequired(); } while(isspace(c)); if (c == '"') { c = NextRequired(); while(c != '"') { att.mValue += c; c = NextRequired(); } c = NextRequired(); } else { do { att.mValue += c; c = NextRequired(); } while(istagchar(c)); } } } else if (isspace(c)) { c = NextRequired(); } else unexpected(c); } if (!closed) { c = NextRequired(); for(;;) { TreeNode *p; if (c == '<') { p = ParseTag(); if (p && !p->mName.empty() && p->mName[0] == '/') { if ((std::string("/") + tag.mName) != p->mName) error("closing tag <%s> doesn't match opening tag <%s> on line %d", p->mName.c_str(), tag.mName.c_str(), tag.mLineno); break; } c = NextRequired(); } else { p = ParseInline(c); } if (p) tag.mChildren.push_back(p); } } // Check for a macro or include and whisk it away if so. if (tag.mName == "lina:macro") { const TreeAttribute *a = tag.Attrib("name"); if (!a) error("macro definition must have NAME attribute"); mpDocument->mMacros[a->mValue] = &tag; return NULL; } else if (tag.mName == "lina:include") { const TreeAttribute *a = tag.Attrib("file"); if (!a) error("<lina:include> must specify FILE"); PushFile(a->mValue.c_str()); return NULL; } return &tag; }
/* * Add this directory to the list of data to be printed for a directory and * decide whether to tell the recursion processor whether to continue * recursing or not. */ static Dtype ls_direntproc (void *callerdat, const char *dir, const char *repos, const char *update_dir, List *entries) { Dtype retval; Node *p; /* Due to the way we called start_recursion() from ls_proc() with a single * argument at a time, we can assume that if we don't yet have a parent * directory in DIRS then this directory should be processed. */ if (strcmp (dir, ".")) { /* Search for our parent directory. */ char *parent; parent = xmalloc (strlen (update_dir) - strlen (dir) + 1); strncpy (parent, update_dir, strlen (update_dir) - strlen (dir)); parent[strlen (update_dir) - strlen (dir)] = '\0'; strip_trailing_slashes (parent); p = findnode (callerdat, parent); } else p = NULL; if (p) { /* Push this dir onto our parent directory's listing. */ Node *n = getnode(); if (entries_format) n->data = Xasprintf ("D/%s////\n", dir); else if (long_format) { struct long_format_data *out = xmalloc (sizeof (struct long_format_data)); out->header = xstrdup ("d--- "); out->time = gmformat_time_t (unix_time_stamp (repos)); out->footer = Xasprintf ("%12s%s%s", "", show_dead_revs ? " " : "", dir); n->data = out; n->delproc = long_format_data_delproc; } else n->data = Xasprintf ("%s\n", dir); addnode (p->data, n); } if (!p || recurse) { /* Create a new list for this directory. */ p = getnode (); p->key = xstrdup (strcmp (update_dir, ".") ? update_dir : ""); p->data = getlist (); p->delproc = ls_delproc; addnode (callerdat, p); /* Create a local directory and mark it as needing deletion. This is * the behavior the recursion processor relies upon, a la update & * checkout. */ if (!isdir (dir)) { int nonbranch; if (show_tag == NULL && show_date == NULL) { ParseTag (&show_tag, &show_date, &nonbranch); set_tag = true; } if (!created_dir) created_dir = xstrdup (update_dir); make_directory (dir); Create_Admin (dir, update_dir, repos, show_tag, show_date, nonbranch, 0, 0); Subdir_Register (entries, NULL, dir); } /* Tell do_recursion to keep going. */ retval = R_PROCESS; } else retval = R_SKIP_ALL; return retval; }
void GenericXMLParser::DoParse(String theTag, Anything &tag) { StartTrace(GenericXMLParser.DoParse); int c, lookahead; Anything &tagbody = tag; // now just append, allow for different things like tagbody = tag["body"] String reply; while ((c = Get()) != 0 && c != EOF) { switch (c) { case '<': Store(tagbody, reply); lookahead = Peek(); switch (lookahead) { case '!': Store(tagbody, reply); Store(tagbody, ParseCommentCdataOrDtd()); break; case '/': { Get(); String tagname = ParseName(); c = Peek(); if ('>' == c && tagname == theTag) { Get(); return; // done //reply.Append("</").Append(tagname).Append(char(c)); } else { // a potential syntax error... reply.Append("</").Append(tagname); String msg("Unexpected character <x"); msg.AppendAsHex((unsigned char)c).Append('>'); msg.Append(" or mismatched tag: ").Append(tagname); msg.Append(" expected: ").Append(theTag); Error(msg); } break; } case '?': { Store(tagbody, ParseXmlOrProcessingInstruction()); break; } default: if (IsValidNameChar(lookahead)) { String tagname; Anything subTag; Anything attrs; bool hasbody = ParseTag(tagname, attrs); subTag[tagname] = attrs; if (hasbody) { DoParse(tagname, subTag); } Store(tagbody, subTag); //if (hasbody) //Store (ProcessTag(tagname,attributes)); //else //Store(RenderTagAsLiteral(tagname,attributes)); } else { // it cannot be a tag, so just append the '<' reply << (char)c; } } break; case '\x0D':// normalize line feeds if ('\x0A' == Peek()) { Get(); } c = '\x0A' ; // Fall Through... default: reply << ((char)c); } } Store(tagbody, reply); }