void HTMLParser :: blockLevelTag( TElementShared aParent, bool aInsideForm ) { if ( isPTag() ) { pTag( aParent ); return; } if ( isListTag() ) { listTag( aParent ); skipTag(); return; } if ( isPreTag() ) { preTag( aParent ); return; } if ( isBodyStyleTag() ) { bodyStyleTag( aParent ); return; } if ( isFormTag() ) { if ( aInsideForm ) { // Not allowed here cout << "blockLevel: Illegal tag found. Skipping...\n"; skipTag(); return; } else { bodyStyleTag( aParent, true ); return; } } if ( isEmptyBlockTag() ) { emptyElementTag( aParent ); return; } if ( isTableTag() ) { tableTag( aParent ); return; } }
void HTMLParser :: headTag( TElementShared aParent ) { cout << "head tag found\n"; // Add to parent TElementShared element = mDocument->createElement( "head" ); aParent->appendChild( element ); bool insideHead = true; while ( insideHead ) { getTag(); if ( isStartTag() ) { if ( isTitleTag() || isStyleTag() || isScriptTag() ) { normalHeadTag( element ); continue; } if ( isIsIndexTag() || isBaseTag() || isMetaTag() || isLinkTag() ) { emptyElementTag( element ); continue; } if ( isCommentTag() ) { commentTag( element ); continue; } // Not a known tag cout << "headTag: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } else { if ( isHeadTag() ) { cout << "head closing tag found\n"; // End the while loop insideHead = false; } else { cout << "headTag: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } } } }
void HTMLParser :: htmlTag() { cout << "html tag found\n"; // Add to DOM tree TElementShared element = mDocument->createElement( "html" ); mDocument->appendChild( element ); bool insideHtml = true; while ( insideHtml ) { getTag(); if ( isStartTag() ) { if ( isHeadTag() ) { headTag( element ); continue; } if ( isBodyTag() ) { bodyStyleTag( element ); continue; } if ( isCommentTag() ) { commentTag( element ); continue; } cout << "htmlTag: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } else { if ( !mTag.compare( "html" ) ) { cout << "html closing tag found\n"; insideHtml = false; } else { cout << "htmlTag: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } } } }
void HTMLParser :: normalHeadTag( TElementShared aParent ) { cout << mTag << " tag found\n"; // Save the tag name string tag = mTag; // Add to parent TElementShared element = mDocument->createElement( tag ); aParent->appendChild( element ); bool insideHeadLevel = true; string data; while ( insideHeadLevel ) { data += getText(); getTag(); if ( !isStartTag() ) { if ( !mTag.compare( tag ) ) { cout << mTag << " closing tag found\n"; insideHeadLevel = false; } else { cout << "normalHead: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } } else { if ( isCommentTag() ) { commentTag( element ); continue; } cout << "normalHead: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } } TTextShared text = mDocument->createText( data ); element->appendChild( text ); cout << "Text is: " << data << endl; }
int sfccLex(parseUnion * lvalp, ParserControl * parm) { int i, rc; char *next; for (;;) { next = nextTag(parm->xmb); if (next == NULL) { return 0; } // fprintf(stderr,"--- token: %.32s\n",next); //usefull for debugging if (parm->xmb->eTagFound) { parm->xmb->eTagFound = 0; return parm->xmb->etag; } if (*next == '/') { for (i = 0; i < TAGS_NITEMS; i++) { if (nextEquals(next + 1, tags[i].tag, tags[i].tagLen) == 1) { skipTag(parm->xmb); return tags[i].etag; } } } else { if (strncmp(parm->xmb->cur, "<!--", 4) == 0) { parm->xmb->cur = strstr(parm->xmb->cur, "-->") + 3; continue; } for (i = 0; i < TAGS_NITEMS; i++) { if (nextEquals(next, tags[i].tag, tags[i].tagLen) == 1) { // printf("+++ %d\n",i); rc=tags[i].process(lvalp, parm); return rc; } } } break; } return 0; }
void HTMLParser :: startParsing( TDocumentShared aDocument ) { mDocument = aDocument; bool insideDoc = true; try { if ( mContent.size() == 0 ) { throw ReadException(); } while ( insideDoc ) { getTag(); if ( isDocTypeTag() ) { doctypeTag(); continue; } if ( isHtmlTag() ) { htmlTag(); // Last tag, quit the loop insideDoc = false; continue; } cout << "startParsing: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } } catch ( ReadException r ) { cout << "Unexpected end of file..\n"; cout << "Returning partial tree\n"; } }
void HTMLParser :: textLevelTag( TElementShared aParent, bool aConserveSpaces, bool aInsideAnchor ) { if ( isFontStyleTag() || isPhraseTag() || isFontTag() ) { normalTextTag( aParent, aConserveSpaces, aInsideAnchor ); return; } if ( isFormFieldTag() ) { formFieldTag( aParent, aConserveSpaces ); return; } if ( isAnchorTag() ) { if ( aInsideAnchor ) { // Not allowed here cout << "textLevel: Illegal tag found. Skipping...\n"; skipTag(); return; } else { normalTextTag( aParent, aConserveSpaces, true ); return; } } if ( isEmptyTextTag() ) { emptyElementTag( aParent ); return; } if ( isAppletTag() ) { appletTag( aParent, aConserveSpaces, aInsideAnchor ); return; } if ( isMapTag() ) { mapTag( aParent ); return; } }
int Tune::play(char* trackName) { if (isPlaying()) return 1; // Exit if track not found if (!track.open(trackName, O_READ)) { sd.errorHalt("Track not found !"); return 3; } playState = playback; // Reset decode time & bitrate from previous playback writeSCI(SCI_DECODE_TIME, 0); delay(100); skipTag(); // Skip ID3v2 tag if there's one feed(); // Feed VS1011e attachInterrupt(0, feed, RISING); // Let the interrupt handle the rest of the process return 0; }
void Html::extractCode(OutBuffer *buf) { //printf("Html::extractCode()\n"); dbuf = buf; // save for other routines buf->reserve(end - p); inCode = 0; while (1) { //printf("p = %p, *p = x%x\n", p, *p); switch (*p) { #if 0 // strings are not recognized outside of tags case '"': case '\'': skipString(); continue; #endif case '<': if (p[1] == '!' && isCommentStart()) { // Comments start with <!-- scanComment(); } else if(p[1] == '!' && isCDATAStart()) { scanCDATA(); } else if (p[1] == '/' && istagstart(*skipWhite(p + 2))) skipTag(); else if (istagstart(*skipWhite(p + 1))) skipTag(); else goto Ldefault; continue; case 0: case 0x1a: break; // end of file case '&': if (inCode) { // Translate character entity into ascii for D parser int c; c = charEntity(); buf->writeUTF8(c); } else p++; continue; case '\r': if (p[1] == '\n') goto Ldefault; case '\n': linnum++; // Always extract new lines, so that D lexer counts the // lines right. buf->writeByte(*p); p++; continue; default: Ldefault: if (inCode) buf->writeByte(*p); p++; continue; } break; } buf->writeByte(0); // ending sentinel //printf("D code is: '%s'\n", (char *)buf->data); }
void HTMLParser :: preTag( TElementShared aParent ) { cout << "pre tag found\n"; // Add to parent TElementShared element = mDocument->createElement( "pre" ); aParent->appendChild( element ); bool insidePre = true; string attribute; while ( insidePre ) { string data = getString( true ); switch ( mStringType ) { case ATTR : { attribute = data; if ( mAttrNoValue ) { element->setAttribute( attribute, "" ); attribute = ""; } break; } case ATTRVALUE : { if ( attribute.compare( "" ) ) { // Attribute has a name // I'll declare it legal element->setAttribute( attribute, data ); attribute = ""; } break; } case TAG : { if ( !isStartTag() ) { if ( isPreTag() ) { cout << "pre closing tag found\n"; insidePre = false; continue; } cout << "pre: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } else { if ( isFontStylePreTag() || isPhraseTag() ) { normalTextTag( element, true ); continue; } if ( isFormFieldTag() ) { formFieldTag( element, true ); continue; } if ( isAnchorTag() ) { normalTextTag( element, true, true ); continue; } if ( isAppletTag() ) { appletTag( element, true ); continue; } if ( isEmptyTextPreTag() ) { emptyElementTag( element ); continue; } if ( isMapTag() ) { mapTag( element ); continue; } if ( isCommentTag() ) { commentTag( element ); continue; } // Not a known tag cout << "pre: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } break; } case TEXT : { if ( data.compare( " " ) && data.compare( "" ) ) { cout << "Text is:" << endl << data << endl; TTextShared text = mDocument->createText( data ); element->appendChild( text ); } break; } } } }
int sfccLex(parseUnion * lvalp, ParserControl * parm) { int i, rc; char *next; char *nextSection ; for (;;) { if(parm->econ) { if(parm->econ->asynRCntl.escanInfo.getnew == 1 ){ nextSection = getNextSection(parm->econ) ; if(nextSection != NULL) { parm->xmb->base = nextSection ; parm->xmb->cur = nextSection ; parm->xmb->last = nextSection + (parm->econ->asynRCntl.escanInfo.sectlen) ; } else { printf(" sfccLex --- section is NULL !!!!!!!!!!!!!!!!! \n") ; } } } next = nextTag(parm->xmb); if (next == NULL) { return 0; } // fprintf(stderr,"--- token: %.32s\n",next); //usefull for debugging if (parm->xmb->eTagFound) { parm->xmb->eTagFound = 0; return parm->xmb->etag; } if (*next == '/') { for (i = 0; i < TAGS_NITEMS; i++) { if (nextEquals(next + 1, tags[i].tag, tags[i].tagLen) == 1) { skipTag(parm->xmb); return tags[i].etag; } } } else { if (strncmp(parm->xmb->cur, "<!--", 4) == 0) { parm->xmb->cur = strstr(parm->xmb->cur, "-->") + 3; continue; } else if (strncmp(parm->xmb->cur, "<EC>", 4) == 0) { parm->econ->asynRCntl.escanInfo.getnew = 1 ; parm->econ->asynRCntl.escanInfo.parsestate = PARSTATE_STARTED ; continue; } for (i = 0; i < TAGS_NITEMS; i++) { if (nextEquals(next, tags[i].tag, tags[i].tagLen) == 1) { // printf("+++ %d\n",i); rc=tags[i].process(lvalp, parm); return rc; } } } break; } return 0; }
void Html::skipTag() { enum TagState // what parsing state we're in { TStagstart, // start of tag name TStag, // in a tag name TSrest, // following tag name }; enum TagState state = TStagstart; int inot; unsigned char *tagstart = NULL; int taglen = 0; p++; inot = 0; if (*p == '/') { inot = 1; p++; } while (1) { switch (*p) { case '>': // found end of tag p++; break; case '"': case '\'': state = TSrest; skipString(); continue; case '<': if (p[1] == '!' && isCommentStart()) { // Comments start with <!-- scanComment(); } else if (p[1] == '/' && istagstart(*skipWhite(p + 2))) { error("nested tag"); skipTag(); } else if (istagstart(*skipWhite(p + 1))) { error("nested tag"); skipTag(); } // Treat comments as if they were whitespace state = TSrest; continue; case 0: case 0x1a: error("end of file before end of tag"); break; // end of file case '\r': if (p[1] == '\n') goto Ldefault; case '\n': linnum++; // Always extract new lines, so that code lexer counts the // lines right. dbuf->writeByte(*p); state = TSrest; // end of tag p++; continue; case ' ': case '\t': case '\f': case '\v': if (state == TStagstart) { p++; continue; } default: Ldefault: switch (state) { case TStagstart: // start of tag name assert(istagstart(*p)); state = TStag; tagstart = p; taglen = 0; break; case TStag: if (istag(*p)) { // Continuing tag name taglen++; } else { // End of tag name state = TSrest; } break; case TSrest: break; } p++; continue; } break; } // See if we parsed a <code> or </code> tag if (taglen && memicmp((char *) tagstart, (char *) "CODE", taglen) == 0 && *(p - 2) != '/') // ignore "<code />" (XHTML) { if (inot) { inCode--; if (inCode < 0) inCode = 0; // ignore extra </code>'s } else inCode++; } }
void HTMLParser :: flowLevelTag( TElementShared aParent ) { cout << mTag << " tag found\n"; // Save the tag name string tag = mTag; // Add to parent TElementShared element = mDocument->createElement( mTag ); aParent->appendChild( element ); bool insideFlow = true; string attribute; while ( insideFlow ) { // Warning: more possible than a tag only string data = getString(); switch ( mStringType ) { case ATTR : { attribute = data; if ( mAttrNoValue ) { element->setAttribute( attribute, "" ); attribute = ""; } break; } case ATTRVALUE : { if ( attribute.compare( "" ) ) { // Attribute has a name // I'll declare it legal element->setAttribute( attribute, data ); attribute = ""; } break; } case TAG : { if ( isStartTag() ) { if ( isBlockLevelTag() ) { blockLevelTag( element ); continue; } if ( isTextLevelTag() ) { textLevelTag( element ); continue; } if ( !mTag.compare( tag ) ) { cout << mTag << " closed implicitly\n"; // End the while loop insideFlow = false; backPedal(); continue; } // Not a known tag cout << "flowLevel: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } else { if ( !mTag.compare( tag ) ) { cout << mTag << " closing tag found\n"; // End the while loop insideFlow = false; continue; } if ( isListTag() ) { cout << mTag << " closed implicitly\n"; // End the while loop insideFlow = false; backPedal(); continue; } cout << "flowLevel: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } break; } case TEXT : { if ( data.compare( " " ) && data.compare( "" ) ) { cout << "Text is:" << endl << data << endl; TTextShared text = mDocument->createText( data ); element->appendChild( text ); } break; } } } }
void HTMLParser :: adressTag( TElementShared aParent ) { cout << "adress tag found\n"; // Add to parent TElementShared element = mDocument->createElement( "adress" ); aParent->appendChild( element ); bool insideAdress = true; string attribute; while ( insideAdress ) { string data = getString(); switch ( mStringType ) { case ATTR : { attribute = data; if ( mAttrNoValue ) { element->setAttribute( attribute, "" ); attribute = ""; } break; } case ATTRVALUE : { if ( attribute.compare( "" ) ) { // Attribute has a name // I'll declare it legal element->setAttribute( attribute, data ); attribute = ""; } break; } case TAG : { if ( isStartTag() ) { if ( isPTag() ) { pTag( element ); continue; } if ( isTextLevelTag() ) { textLevelTag( element ); continue; } if ( isCommentTag() ) { commentTag( element ); continue; } // Not a known tag cout << "adress: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } else { if ( !mTag.compare( "adress" ) ) { cout << mTag << "closing tag found\n"; // End the while loop insideAdress = false; } else { cout << "adress: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } } break; } case TEXT : { if ( data.compare( " " ) && data.compare( "" ) ) { cout << "Text is:" << endl << data << endl; TTextShared text = mDocument->createText( data ); element->appendChild( text ); } break; } } } }
void HTMLParser :: pTag( TElementShared aParent ) { cout << "p tag found\n"; // Add to parent TElementShared element = mDocument->createElement( "p" ); aParent->appendChild( element ); bool insideP = true; string attribute; while ( insideP ) { string data = getString(); switch ( mStringType ) { case ATTR : { attribute = data; if ( mAttrNoValue ) { element->setAttribute( attribute, "" ); attribute = ""; } break; } case ATTRVALUE : { if ( attribute.compare( "" ) ) { // Attribute has a name // I'll declare it legal element->setAttribute( attribute, data ); attribute = ""; } break; } case TAG : { if ( !isStartTag() ) { if ( isPTag() ) { cout << "p closing tag found\n"; insideP = false; continue; } if ( isAdressTag() || isBodyStyleTag() || isFormTag() || isListTag() ) { cout << "p closed implicitly\n"; insideP = false; backPedal(); continue; } cout << "p: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } else { if ( isBlockLevelTag() || isHeadingTag() || isLITag() ) { cout << "p closed implicitly\n"; insideP = false; backPedal(); continue; } if ( isTextLevelTag() ) { textLevelTag( element ); continue; } if ( isCommentTag() ) { commentTag( element ); continue; } // Not a known tag cout << "p: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } break; } case TEXT : { if ( data.compare( " " ) && data.compare( "" ) ) { cout << "Text is:" << endl << data << endl; TTextShared text = mDocument->createText( data ); element->appendChild( text ); } break; } } } }
void HTMLParser :: normalTextTag( TElementShared aParent, bool aConserveSpaces, bool aInsideAnchor ) { cout << mTag << " tag found\n"; // Save the tag name string tag = mTag; // Add to parent TElementShared element = mDocument->createElement( mTag ); aParent->appendChild( element ); bool insideNormalText = true; string text; string attribute; while ( insideNormalText ) { string data = getString( aConserveSpaces ); switch ( mStringType ) { case ATTR : { attribute = data; if ( mAttrNoValue ) { element->setAttribute( attribute, "" ); attribute = ""; } break; } case ATTRVALUE : { if ( attribute.compare( "" ) ) { // Attribute has a name // I'll declare it legal element->setAttribute( attribute, data ); attribute = ""; } break; } case TAG : { if ( !isStartTag() ) { if ( !mTag.compare( tag ) ) { cout << tag << " closing tag found\n"; insideNormalText = false; continue; } cout << "normalText: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } else { if ( isTextLevelTag() ) { textLevelTag( element, aConserveSpaces, aInsideAnchor ); continue; } if ( isCommentTag() ) { commentTag( element ); continue; } // Not a known tag cout << "normalText: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } break; } case TEXT : { if ( ( data.compare( " " ) && data.compare( "" ) ) || ( aConserveSpaces && data.compare( "" ) ) ) { cout << "Text is:" << endl << data << endl; TTextShared text = mDocument->createText( data ); element->appendChild( text ); } break; } } } }
void HTMLParser :: mapTag( TElementShared aParent ) { cout << "map tag found\n"; // Add to parent TElementShared element = mDocument->createElement( "map" ); aParent->appendChild( element ); bool insideMap = true; string attribute; while ( insideMap ) { string data = getString(); switch ( mStringType ) { case ATTR : { attribute = data; if ( mAttrNoValue ) { element->setAttribute( attribute, "" ); attribute = ""; } break; } case ATTRVALUE : { if ( attribute.compare( "" ) ) { // Attribute has a name // I'll declare it legal element->setAttribute( attribute, data ); attribute = ""; } break; } case TAG : { if ( isStartTag() ) { if ( isAreaTag() ) { emptyElementTag( element ); continue; } if ( isCommentTag() ) { commentTag( element ); continue; } // Not a known tag cout << "map: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } else { if ( isMapTag() ) { cout << "map closing tag found\n"; // End the while loop insideMap = false; } else { cout << "map: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } } break; } case TEXT : { if ( ( data.compare( " " ) && data.compare( "" ) ) ) { cout << "Text found in illegal place. Skipping...\n"; } break; } } } }
void HTMLParser :: listTag( TElementShared aParent ) { cout << mTag << " tag found\n"; // Save the tag name string tag = mTag; // To check if this list can have list items or not bool listItem = false; if ( isULTag() || isOLTag() ) { listItem = true; } // Add to parent TElementShared element = mDocument->createElement( mTag ); aParent->appendChild( element ); bool insideList = true; string attribute; while ( insideList ) { // Warning: more possible than a tag only string data = getString(); switch ( mStringType ) { case ATTR : { attribute = data; if ( mAttrNoValue ) { element->setAttribute( attribute, "" ); attribute = ""; } break; } case ATTRVALUE : { if ( attribute.compare( "" ) ) { // Attribute has a name // I'll declare it legal element->setAttribute( attribute, data ); attribute = ""; } break; } case TAG : { if ( isStartTag() ) { if ( ( isLITag() && listItem ) || ( isDDTag() && !listItem ) ) { flowLevelTag( element ); continue; } if ( isDTTag() && !listItem ) { textLevelTag( element ); continue; } if ( isCommentTag() ) { commentTag( element ); continue; } // Not a known tag cout << "list: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } else { if ( !mTag.compare( tag ) ) { cout << mTag << " closing tag found\n"; // End the while loop insideList = false; } else { cout << "list: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } } break; } case TEXT : { if ( data.compare( " " ) && data.compare( "" ) ) { cout << "Text found in illegal place. Skipping...\n"; } break; } } } }
void HTMLParser :: trTag( TElementShared aParent ) { cout << "tr tag found\n"; // Add to parent TElementShared element = mDocument->createElement( "tr" ); aParent->appendChild( element ); bool insideTr = true; string attribute; while ( insideTr ) { // Warning: more possible than a tag only string data = getString(); switch ( mStringType ) { case ATTR : { attribute = data; if ( mAttrNoValue ) { element->setAttribute( attribute, "" ); attribute = ""; } break; } case ATTRVALUE : { if ( attribute.compare( "" ) ) { // Attribute has a name // I'll declare it legal element->setAttribute( attribute, data ); attribute = ""; } break; } case TAG : { if ( isStartTag() ) { if ( isThTag() || isTdTag() ) { bodyStyleTag( element ); continue; } if ( isCommentTag() ) { commentTag( element ); continue; } // Not a known tag cout << "tr: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } else { if ( isTrTag() ) { cout << "tr closing tag found\n"; // End the while loop insideTr = false; } else { cout << "tr: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } } break; } case TEXT : { if ( data.compare( " " ) && data.compare( "" ) ) { cout << "Text found in illegal place. Skipping...\n"; } break; } } } }