fixed a dozen new parser bugs

git-svn-id: svn://10.0.0.236/trunk@17861 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rickg%netscape.com
1999-01-15 19:29:35 +00:00
parent bcae14f76c
commit 2884211b1d
48 changed files with 248 additions and 310 deletions

View File

@@ -9,7 +9,7 @@
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
@@ -321,7 +321,7 @@ CNavDTD::CNavDTD() : nsIDTD(){
mLineNumber=1;
nsCRT::zero(mTokenHandlers,sizeof(mTokenHandlers));
mHasOpenBody=PR_FALSE;
mHasOpenHead=PR_FALSE;
mHasOpenHead=0;
mHasOpenForm=PR_FALSE;
mHasOpenMap=PR_FALSE;
mAllowUnknownTags=PR_FALSE;
@@ -464,29 +464,31 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParse
* @param aParser is the parser object that's driving this process
* @return error code (almost always 0)
*/
nsresult CNavDTD::BuildModel(nsIParser* aParser) {
nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
nsHTMLTokenizer* theTokenizer=(nsHTMLTokenizer*)GetTokenizer();
nsITokenRecycler* theRecycler=GetTokenRecycler();
if(aTokenizer) {
nsITokenizer* oldTokenizer=mTokenizer;
mTokenizer=aTokenizer;
nsITokenRecycler* theRecycler=aTokenizer->GetTokenRecycler();
//nsresult result2=NS_ERROR_HTMLPARSER_BLOCK;
if(theTokenizer) {
while(NS_OK==result){
CToken* theToken=theTokenizer->PopToken();
CToken* theToken=mTokenizer->PopToken();
if(theToken) {
result=HandleToken(theToken,aParser);
if(NS_SUCCEEDED(result)) {
theRecycler->RecycleToken(theToken);
}
else if(NS_ERROR_HTMLPARSER_BLOCK!=result){
theTokenizer->PushTokenFront(theToken);
mTokenizer->PushTokenFront(theToken);
}
// theRootDTD->Verify(kEmptyString,aParser);
}
else break;
}
}//while
mTokenizer=oldTokenizer;
}
else result=NS_ERROR_HTMLPARSER_BADTOKENIZER;
return result;
}
@@ -723,9 +725,9 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI
//Sick as it sounds, I have to make sure the body has been
//opened before other tags can be added to the content sink...
static eHTMLTags gBodyBlockers[]={eHTMLTag_body,eHTMLTag_frameset,eHTMLTag_head,eHTMLTag_map};
static eHTMLTags gBodyBlockers[]={eHTMLTag_body,eHTMLTag_frameset,eHTMLTag_map};
PRInt32 theBodyBlocker=GetTopmostIndexOf(gBodyBlockers,sizeof(gBodyBlockers)/sizeof(eHTMLTag_unknown));
if(kNotFound==theBodyBlocker) {
if((kNotFound==theBodyBlocker) && (!mHasOpenHead)){
if(CanPropagate(eHTMLTag_body,aChildTag)) {
mHasOpenBody=PR_TRUE;
CStartToken theToken(eHTMLTag_body); //open the body container...
@@ -736,11 +738,17 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI
eHTMLTags theParentTag=mBodyContext->Last();
PRBool theCanContainResult=CanContain(theParentTag,aChildTag);
eHTMLTags theTarget=FindAutoCloseTargetForStartTag(aChildTag,mBodyContext->mTags);
if(eHTMLTag_unknown!=theTarget){
result=CloseContainersTo(theTarget,PR_TRUE);
theParentTag=mBodyContext->Last();
theCanContainResult=CanContain(theParentTag,aChildTag);
// Ok Genius answer this:
// If the parent can contain the child, why would it be necessary
// to find an autoclose target?
if(!theCanContainResult) {
eHTMLTags theTarget=FindAutoCloseTargetForStartTag(aChildTag,mBodyContext->mTags);
if(eHTMLTag_unknown!=theTarget){
result=CloseContainersTo(theTarget,PR_TRUE);
theParentTag=mBodyContext->Last();
theCanContainResult=CanContain(theParentTag,aChildTag);
}
}
if(PR_FALSE==theCanContainResult){
@@ -769,7 +777,7 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI
if(mBodyContext->mOpenStyles) {
CloseTransientStyles(aChildTag);
}
}
}
result=OpenContainer(aNode,PR_TRUE);
}
else { //we're writing a leaf...
@@ -813,13 +821,11 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
case eHTMLTag_title:
{
PRBool headOpen=mHasOpenHead;
if(!headOpen)
result=OpenHead(attrNode);
result=OpenHead(attrNode);
if(NS_OK==result) {
result=CollectSkippedContent(attrNode,theAttrCount);
mSink->SetTitle(attrNode.GetSkippedContent());
if((NS_OK==result) && (!headOpen))
if(NS_OK==result)
result=CloseHead(attrNode);
}
}
@@ -833,9 +839,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
case eHTMLTag_style:
{
PRBool headOpen=mHasOpenHead;
if(!headOpen)
result=OpenHead(attrNode);
result=OpenHead(attrNode);
if(NS_OK==result) {
PRInt32 theCount;
CollectSkippedContent(attrNode,theCount);
@@ -1046,6 +1050,7 @@ nsresult CNavDTD::HandleScriptToken(nsCParserNode& aNode) {
// We're in the HEAD, but don't bother to open it.
if(NS_OK==result) {
CollectSkippedContent(aNode,attrCount);
CloseHead(aNode);
result=AddLeaf(aNode);
}//if
}//if
@@ -1255,22 +1260,25 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
*/
PRBool CNavDTD::CanPropagate(eHTMLTags aParentTag,eHTMLTags aChildTag) const {
PRBool result=PR_FALSE;
PRBool parentCanContain=CanContain(aParentTag,aChildTag);
if(IsContainer(aChildTag)){
if(nsHTMLElement::IsBlockParent(aParentTag) || (gHTMLElements[aParentTag].GetSpecialChildren())) {
while(eHTMLTag_unknown!=aChildTag) {
if(CanContain(aParentTag,aChildTag)){
if(parentCanContain){
result=PR_TRUE;
break;
}//if
CTagList* theTagList=gHTMLElements[aChildTag].GetRootTags();
aChildTag=theTagList->mTags[0];
parentCanContain=CanContain(aParentTag,aChildTag);
}//while
}//if
}//if
else if(nsHTMLElement::IsTextTag(aChildTag)){
result=PR_TRUE;
}
else result=parentCanContain;
return result;
}
@@ -1322,7 +1330,7 @@ PRBool CNavDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild) const {
default:
if(FindTagInSet(aChild,gFormElementTags,sizeof(gFormElementTags)/sizeof(eHTMLTag_unknown)))
result=!HasOpenContainer(eHTMLTag_form);
result=PR_TRUE;
else result=FindTagInSet(aChild,gWhitespaceTags,sizeof(gWhitespaceTags)/sizeof(eHTMLTag_unknown));
}
break;
@@ -1880,10 +1888,12 @@ nsresult CNavDTD::CloseHTML(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::OpenHead(const nsIParserNode& aNode){
mBodyContext->Push(eHTMLTag_head);
nsresult result=mSink->OpenHead(aNode);
mHasOpenHead=PR_TRUE;
return result;
//mBodyContext->Push(eHTMLTag_head);
if(!mHasOpenHead++) {
nsresult result=mSink->OpenHead(aNode);
}
return NS_OK;
}
/**
@@ -1895,10 +1905,11 @@ nsresult CNavDTD::OpenHead(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::CloseHead(const nsIParserNode& aNode){
nsresult result=mSink->CloseHead(aNode);
mBodyContext->Pop();
mHasOpenHead=PR_FALSE;
return result;
if(0==--mHasOpenHead){
nsresult result=mSink->CloseHead(aNode);
}
//mBodyContext->Pop();
return NS_OK;
}
/**
@@ -2117,7 +2128,7 @@ CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){
break;
case eHTMLTag_head:
result=OpenHead(aNode); //open the head...
// result=OpenHead(aNode); //open the head...
break;
default:
@@ -2160,7 +2171,7 @@ CNavDTD::CloseContainer(const nsIParserNode& aNode,eHTMLTags aTag,
break;
case eHTMLTag_head:
result=CloseHead(aNode);
//result=CloseHead(aNode);
break;
case eHTMLTag_body:
@@ -2310,24 +2321,13 @@ nsresult CNavDTD::AddHeadLeaf(const nsIParserNode& aNode){
return result;
}
PRBool headOpen=mHasOpenHead;
if(!headOpen)
result=OpenHead(aNode);
result=OpenHead(aNode);
if(NS_OK==result) {
result=AddLeaf(aNode);
// XXX If the return value tells us to block, go
// ahead and close the tag out anyway, since its
// contents will be consumed.
if (NS_SUCCEEDED(result)) {
nsresult rv = CloseHead(aNode);
// XXX Only send along a failure. If the close
// succeeded we still may need to indicate that the
// parser has blocked (i.e. return the result of
// the AddLeaf.
if (rv != NS_OK) {
result = rv;
}
}
CloseHead(aNode);
}
return result;
}

View File

@@ -200,7 +200,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
* The parser uses a code sandwich to wrap the parsing process. Before
@@ -529,7 +529,7 @@ protected:
PRBool mAllowUnknownTags;
PRBool mHasOpenForm;
PRBool mHasOpenMap;
PRBool mHasOpenHead;
PRInt32 mHasOpenHead;
PRBool mHasOpenBody;
PRBool mHadBodyOrFrameset;
nsString mFilename;

View File

@@ -9,7 +9,7 @@
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
@@ -58,6 +58,7 @@ CParserContext::CParserContext(nsScanner* aScanner,void* aKey,nsIStreamObserver*
mTransferBufferSize=eTransferBufferSize;
mParserEnabled=PR_TRUE;
mStreamListenerState=eNone;
mMultipart=PR_TRUE;
}

View File

@@ -67,6 +67,7 @@ public:
PRUint32 mTransferBufferSize;
PRBool mParserEnabled;
eStreamState mStreamListenerState; //this is really only here for debug purposes.
PRBool mMultipart;
// nsDeque mTokenDeque;
};

View File

@@ -281,7 +281,7 @@ NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFilename,PRInt32 aLevel,nsIPars
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP CRtfDTD::BuildModel(nsIParser* aParser) {
NS_IMETHODIMP CRtfDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
return result;
}

View File

@@ -212,7 +212,7 @@ class CRtfDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
* The parser uses a code sandwich to wrap the parsing process. Before

View File

@@ -536,6 +536,7 @@ PRBool CDTDDebug::Verify(nsIDTD * aDTD, nsIParser * aParser, int aContextStackP
// write the true URL at the top of the file.
if (debugFile) {
// dump the html source into the newly created file.
PRofstream ps;
ps.attach(debugFile);
if (theParser)

View File

@@ -260,7 +260,7 @@ static nsHTMLElement gHTMLElements[] = {
{eHTMLTag_i, &gRootTags, 0, 0, kBPIPIC},
{eHTMLTag_iframe, &gRootTags, 0, 0, kAll},
{eHTMLTag_ilayer, &gRootTags, 0, 0, kBPIP},
{eHTMLTag_ilayer, &gRootTags, 0, 0, kAll},
{eHTMLTag_img, &gRootTags, 0, 0, kBPIP},
{eHTMLTag_input, &gRootTags, 0, 0, kBPIP}, //NOT DONE!!!
{eHTMLTag_ins, &gRootTags, 0, 0, kAll, &gInBody, 0},
@@ -359,6 +359,7 @@ public:
for(index=0;index<max;index++){
gHTMLElements[gStyleTags[index]].mSelfContained=PR_TRUE;
}
gHTMLElements[eHTMLTag_a].mSelfContained=PR_FALSE;
gHTMLElements[eHTMLTag_frameset].mSelfContained=PR_TRUE;
gHTMLElements[eHTMLTag_ol].mSelfContained=PR_TRUE;
gHTMLElements[eHTMLTag_ul].mSelfContained=PR_TRUE;

View File

@@ -199,6 +199,10 @@ PRInt32 nsHTMLTokenizer::GetCount(void) {
return mTokenDeque.GetSize();
}
CToken* nsHTMLTokenizer::GetTokenAt(PRInt32 anIndex){
return (CToken*)mTokenDeque.ObjectAt(anIndex);
}
/**
* This method repeatedly called by the tokenizer.
* Each time, we determine the kind of token were about to

View File

@@ -61,6 +61,7 @@ public:
virtual CToken* PushToken(CToken* theToken);
virtual CToken* PopToken(void);
virtual CToken* PeekToken(void);
virtual CToken* GetTokenAt(PRInt32 anIndex);
virtual PRInt32 GetCount(void);
protected:

View File

@@ -253,7 +253,7 @@ nsresult CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
* @return
*/
void CStartToken::DebugDumpSource(ostream& out) {
char buffer[200];
char buffer[1000];
mTextValue.ToCString(buffer,sizeof(buffer)-1);
out << "<" << buffer;
if(!mAttributed)
@@ -380,7 +380,7 @@ PRInt32 CEndToken::GetTokenType(void) {
* @return
*/
void CEndToken::DebugDumpSource(ostream& out) {
char buffer[200];
char buffer[1000];
mTextValue.ToCString(buffer,sizeof(buffer)-1);
out << "</" << buffer << ">";
}
@@ -987,7 +987,7 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
* @return
*/
void CAttributeToken::DebugDumpSource(ostream& out) {
char buffer[200];
static char buffer[1000];
mTextKey.ToCString(buffer,sizeof(buffer)-1);
out << " " << buffer;
if(mTextValue.Length()){

View File

@@ -115,7 +115,7 @@ class nsIDTD : public nsISupports {
* @param anErrorCode - contains error code resulting from parse process
* @return
*/
NS_IMETHOD BuildModel(nsIParser* aParser)=0;
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer)=0;
/**
* Called during model building phase of parse process. Each token created during
@@ -138,6 +138,7 @@ class nsIDTD : public nsISupports {
*/
virtual nsITokenizer* GetTokenizer(void)=0;
virtual nsITokenRecycler* GetTokenRecycler(void)=0;
/**

View File

@@ -165,6 +165,7 @@ class nsIParser : public nsISupports {
#define NS_ERROR_HTMLPARSER_BADURL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1005)
#define NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1006)
#define NS_ERROR_HTMLPARSER_INTERRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1007)
#define NS_ERROR_HTMLPARSER_BADTOKENIZER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1008)
/**
* Return codes for parsing routines.

View File

@@ -61,6 +61,7 @@ public:
virtual CToken* PopToken(void)=0;
virtual CToken* PeekToken(void)=0;
virtual PRInt32 GetCount(void)=0;
virtual CToken* GetTokenAt(PRInt32 anIndex)=0;
};

View File

@@ -164,7 +164,7 @@ nsParser::~nsParser() {
}
NS_IF_RELEASE(mObserver);
NS_RELEASE(mSink);
NS_IF_RELEASE(mSink);
//don't forget to add code here to delete
//what may be several contexts...
@@ -565,15 +565,15 @@ nsresult nsParser::Parse(nsIURL* aURL,nsIStreamObserver* aListener,PRBool aVerif
nsresult result=kBadURL;
mDTDVerification=aVerifyEnabled;
mMultipart=PR_TRUE;
if(aURL) {
const char* spec;
nsresult rv = aURL->GetSpec(&spec);
if (rv != NS_OK) return rv;
nsAutoString theName(spec);
CParserContext* cp=new CParserContext(new nsScanner(theName,PR_FALSE),aURL,aListener);
if(cp) {
PushContext(*cp);
CParserContext* pc=new CParserContext(new nsScanner(theName,PR_FALSE),aURL,aListener);
if(pc) {
pc->mMultipart=PR_TRUE;
PushContext(*pc);
result=NS_OK;
}
}
@@ -598,8 +598,8 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){
PushContext(*pc);
pc->mSourceType="text/html";
pc->mStreamListenerState=eOnStart;
pc->mMultipart=PR_FALSE;
mParserContext->mScanner->Eof();
mMultipart=PR_FALSE;
result=ResumeParse();
pc=PopContext();
delete pc;
@@ -634,12 +634,11 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,PRBool anHTMLString,PRBool aVer
CParserContext* pc=new CParserContext(new nsScanner(aSourceBuffer),&aSourceBuffer,0);
if(pc) {
nsIDTD* thePrevDTD=(mParserContext) ? mParserContext->mDTD: 0;
PushContext(*pc);
pc->mStreamListenerState=eOnStart;
pc->mMultipart=PR_FALSE;
if(PR_TRUE==anHTMLString)
pc->mSourceType="text/html";
mMultipart=PR_FALSE;
result=ResumeParse();
// mParserContext->mDTD=0;
pc=PopContext();
@@ -672,7 +671,7 @@ nsresult nsParser::ResumeParse(nsIDTD* aDefaultDTD) {
result=Tokenize();
result=BuildModel();
if((!mMultipart) || ((eOnStop==mParserContext->mStreamListenerState) && (NS_OK==result))){
if((!mParserContext->mMultipart) || ((eOnStop==mParserContext->mStreamListenerState) && (NS_OK==result))){
DidBuildModel(mStreamStatus);
}
else {
@@ -707,6 +706,7 @@ nsresult nsParser::BuildModel() {
//Get the root DTD for use in model building...
CParserContext* theRootContext=mParserContext;
nsITokenizer* theTokenizer=mParserContext->mDTD->GetTokenizer();
while(theRootContext->mPrevContext) {
theRootContext=theRootContext->mPrevContext;
}
@@ -714,7 +714,7 @@ nsresult nsParser::BuildModel() {
nsIDTD* theRootDTD=theRootContext->mDTD;
nsresult result=NS_OK;
if(theRootDTD) {
result=theRootDTD->BuildModel(this);
result=theRootDTD->BuildModel(this,theTokenizer);
}
return result;
@@ -958,52 +958,23 @@ nsresult nsParser::Tokenize(){
*/
PRBool nsParser::DidTokenize(){
PRBool result=PR_TRUE;
{
fstream out("c:/temp/tokens.out",ios::trunc);
DebugDumpSource(out);
}
return result;
}
/**
* This debug routine is used to cause the tokenizer to
* iterate its token list, asking each token to dump its
* contents to the given output stream.
*
* @update gess 3/25/98
* @param
* @return
*/
void nsParser::DebugDumpTokens(ostream& out) {
/*
nsDequeIterator b=mParserContext->mTokenDeque.Begin();
nsDequeIterator e=mParserContext->mTokenDeque.End();
void nsParser::DebugDumpSource(ostream& aStream) {
PRInt32 theIndex=-1;
nsITokenizer* theTokenizer=mParserContext->mDTD->GetTokenizer();
CToken* theToken;
while(b!=e) {
theToken=(CToken*)(b++);
theToken->DebugDumpToken(out);
while(theToken=theTokenizer->GetTokenAt(++theIndex)) {
// theToken->DebugDumpToken(out);
theToken->DebugDumpSource(aStream);
}
*/
}
/**
* This debug routine is used to cause the tokenizer to
* iterate its token list, asking each token to dump its
* contents to the given output stream.
*
* @update gess 3/25/98
* @param
* @return
*/
void nsParser::DebugDumpSource(ostream& out) {
/*
nsDequeIterator b=mParserContext->mTokenDeque.Begin();
nsDequeIterator e=mParserContext->mTokenDeque.End();
CToken* theToken;
while(b!=e) {
theToken=(CToken*)(b++);
theToken->DebugDumpSource(out);
}
*/
}

View File

@@ -181,17 +181,7 @@ friend class CTokenHandler;
*/
virtual nsresult ResumeParse(nsIDTD* mDefaultDTD=0);
/**
* This debug routine is used to cause the tokenizer to
* iterate its token list, asking each token to dump its
* contents to the given output stream.
*
* @update gess 3/25/98
* @param
* @return
*/
void DebugDumpSource(ostream& out);
void DebugDumpSource(ostream& anOutput);
//*********************************************
// These methods are callback methods used by
@@ -268,18 +258,6 @@ private:
* @return TRUE if all went well
*/
PRBool DidTokenize();
/**
* This debug routine is used to cause the tokenizer to
* iterate its token list, asking each token to dump its
* contents to the given output stream.
*
* @update gess 3/25/98
* @param
* @return
*/
void DebugDumpTokens(ostream& out);
/**
* This method is used as a backstop to compute the kind of content
@@ -312,7 +290,6 @@ protected:
PRBool mDTDVerification;
nsString mCommand;
PRInt32 mStreamStatus;
PRBool mMultipart;
};

View File

@@ -226,7 +226,7 @@ NS_IMETHODIMP CValidDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,n
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP CValidDTD::BuildModel(nsIParser* aParser) {
NS_IMETHODIMP CValidDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
return result;
}

View File

@@ -131,7 +131,7 @@ class CValidDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
* The parser uses a code sandwich to wrap the parsing process. Before

View File

@@ -306,27 +306,31 @@ NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotify
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser) {
NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
nsHTMLTokenizer* theTokenizer=(nsHTMLTokenizer*)GetTokenizer();
nsITokenRecycler* theRecycler=GetTokenRecycler();
if(theTokenizer) {
if(aTokenizer) {
nsITokenizer* oldTokenizer=mTokenizer;
mTokenizer=aTokenizer;
nsITokenRecycler* theRecycler=mTokenizer->GetTokenRecycler();
while(NS_OK==result){
CToken* theToken=theTokenizer->PopToken();
CToken* theToken=mTokenizer->PopToken();
if(theToken) {
result=HandleToken(theToken,aParser);
if(NS_SUCCEEDED(result)) {
theRecycler->RecycleToken(theToken);
}
else if(NS_ERROR_HTMLPARSER_BLOCK!=result){
theTokenizer->PushTokenFront(theToken);
mTokenizer->PushTokenFront(theToken);
}
// theRootDTD->Verify(kEmptyString,aParser);
}
else break;
}
}//while
mTokenizer=oldTokenizer;
}
else result=NS_ERROR_HTMLPARSER_BADTOKENIZER;
return result;
}

View File

@@ -121,7 +121,7 @@ class CViewSourceHTML: public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
* The parser uses a code sandwich to wrap the parsing process. Before

View File

@@ -251,30 +251,35 @@ NS_IMETHODIMP CWellFormedDTD::WillBuildModel(nsString& aFilename,PRBool aNotifyS
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP CWellFormedDTD::BuildModel(nsIParser* aParser) {
NS_IMETHODIMP CWellFormedDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
nsHTMLTokenizer* theTokenizer=(nsHTMLTokenizer*)GetTokenizer();
nsITokenRecycler* theRecycler=GetTokenRecycler();
if(theTokenizer) {
if(aTokenizer) {
nsITokenizer* oldTokenizer=mTokenizer;
mTokenizer=aTokenizer;
nsITokenRecycler* theRecycler=aTokenizer->GetTokenRecycler();
while(NS_OK==result){
CToken* theToken=theTokenizer->PopToken();
CToken* theToken=mTokenizer->PopToken();
if(theToken) {
result=HandleToken(theToken,aParser);
if(NS_SUCCEEDED(result)) {
theRecycler->RecycleToken(theToken);
}
else if(NS_ERROR_HTMLPARSER_BLOCK!=result){
theTokenizer->PushTokenFront(theToken);
mTokenizer->PushTokenFront(theToken);
}
// theRootDTD->Verify(kEmptyString,aParser);
}
else break;
}
}//while
mTokenizer=oldTokenizer;
}
else result=NS_ERROR_HTMLPARSER_BADTOKENIZER;
return result;
}
/**
*
* @update gess5/18/98

View File

@@ -119,7 +119,7 @@ class CWellFormedDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
* The parser uses a code sandwich to wrap the parsing process. Before

View File

@@ -439,7 +439,7 @@ nsresult nsXIFDTD::WillBuildModel(nsString& aFileName,PRBool aNotifySink,nsIPars
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP nsXIFDTD::BuildModel(nsIParser* aParser) {
NS_IMETHODIMP nsXIFDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
return result;
}

View File

@@ -174,7 +174,7 @@ class nsXIFDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
*

View File

@@ -9,7 +9,7 @@
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
@@ -321,7 +321,7 @@ CNavDTD::CNavDTD() : nsIDTD(){
mLineNumber=1;
nsCRT::zero(mTokenHandlers,sizeof(mTokenHandlers));
mHasOpenBody=PR_FALSE;
mHasOpenHead=PR_FALSE;
mHasOpenHead=0;
mHasOpenForm=PR_FALSE;
mHasOpenMap=PR_FALSE;
mAllowUnknownTags=PR_FALSE;
@@ -464,29 +464,31 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParse
* @param aParser is the parser object that's driving this process
* @return error code (almost always 0)
*/
nsresult CNavDTD::BuildModel(nsIParser* aParser) {
nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
nsHTMLTokenizer* theTokenizer=(nsHTMLTokenizer*)GetTokenizer();
nsITokenRecycler* theRecycler=GetTokenRecycler();
if(aTokenizer) {
nsITokenizer* oldTokenizer=mTokenizer;
mTokenizer=aTokenizer;
nsITokenRecycler* theRecycler=aTokenizer->GetTokenRecycler();
//nsresult result2=NS_ERROR_HTMLPARSER_BLOCK;
if(theTokenizer) {
while(NS_OK==result){
CToken* theToken=theTokenizer->PopToken();
CToken* theToken=mTokenizer->PopToken();
if(theToken) {
result=HandleToken(theToken,aParser);
if(NS_SUCCEEDED(result)) {
theRecycler->RecycleToken(theToken);
}
else if(NS_ERROR_HTMLPARSER_BLOCK!=result){
theTokenizer->PushTokenFront(theToken);
mTokenizer->PushTokenFront(theToken);
}
// theRootDTD->Verify(kEmptyString,aParser);
}
else break;
}
}//while
mTokenizer=oldTokenizer;
}
else result=NS_ERROR_HTMLPARSER_BADTOKENIZER;
return result;
}
@@ -723,9 +725,9 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI
//Sick as it sounds, I have to make sure the body has been
//opened before other tags can be added to the content sink...
static eHTMLTags gBodyBlockers[]={eHTMLTag_body,eHTMLTag_frameset,eHTMLTag_head,eHTMLTag_map};
static eHTMLTags gBodyBlockers[]={eHTMLTag_body,eHTMLTag_frameset,eHTMLTag_map};
PRInt32 theBodyBlocker=GetTopmostIndexOf(gBodyBlockers,sizeof(gBodyBlockers)/sizeof(eHTMLTag_unknown));
if(kNotFound==theBodyBlocker) {
if((kNotFound==theBodyBlocker) && (!mHasOpenHead)){
if(CanPropagate(eHTMLTag_body,aChildTag)) {
mHasOpenBody=PR_TRUE;
CStartToken theToken(eHTMLTag_body); //open the body container...
@@ -736,11 +738,17 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI
eHTMLTags theParentTag=mBodyContext->Last();
PRBool theCanContainResult=CanContain(theParentTag,aChildTag);
eHTMLTags theTarget=FindAutoCloseTargetForStartTag(aChildTag,mBodyContext->mTags);
if(eHTMLTag_unknown!=theTarget){
result=CloseContainersTo(theTarget,PR_TRUE);
theParentTag=mBodyContext->Last();
theCanContainResult=CanContain(theParentTag,aChildTag);
// Ok Genius answer this:
// If the parent can contain the child, why would it be necessary
// to find an autoclose target?
if(!theCanContainResult) {
eHTMLTags theTarget=FindAutoCloseTargetForStartTag(aChildTag,mBodyContext->mTags);
if(eHTMLTag_unknown!=theTarget){
result=CloseContainersTo(theTarget,PR_TRUE);
theParentTag=mBodyContext->Last();
theCanContainResult=CanContain(theParentTag,aChildTag);
}
}
if(PR_FALSE==theCanContainResult){
@@ -769,7 +777,7 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI
if(mBodyContext->mOpenStyles) {
CloseTransientStyles(aChildTag);
}
}
}
result=OpenContainer(aNode,PR_TRUE);
}
else { //we're writing a leaf...
@@ -813,13 +821,11 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
case eHTMLTag_title:
{
PRBool headOpen=mHasOpenHead;
if(!headOpen)
result=OpenHead(attrNode);
result=OpenHead(attrNode);
if(NS_OK==result) {
result=CollectSkippedContent(attrNode,theAttrCount);
mSink->SetTitle(attrNode.GetSkippedContent());
if((NS_OK==result) && (!headOpen))
if(NS_OK==result)
result=CloseHead(attrNode);
}
}
@@ -833,9 +839,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
case eHTMLTag_style:
{
PRBool headOpen=mHasOpenHead;
if(!headOpen)
result=OpenHead(attrNode);
result=OpenHead(attrNode);
if(NS_OK==result) {
PRInt32 theCount;
CollectSkippedContent(attrNode,theCount);
@@ -1046,6 +1050,7 @@ nsresult CNavDTD::HandleScriptToken(nsCParserNode& aNode) {
// We're in the HEAD, but don't bother to open it.
if(NS_OK==result) {
CollectSkippedContent(aNode,attrCount);
CloseHead(aNode);
result=AddLeaf(aNode);
}//if
}//if
@@ -1255,22 +1260,25 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
*/
PRBool CNavDTD::CanPropagate(eHTMLTags aParentTag,eHTMLTags aChildTag) const {
PRBool result=PR_FALSE;
PRBool parentCanContain=CanContain(aParentTag,aChildTag);
if(IsContainer(aChildTag)){
if(nsHTMLElement::IsBlockParent(aParentTag) || (gHTMLElements[aParentTag].GetSpecialChildren())) {
while(eHTMLTag_unknown!=aChildTag) {
if(CanContain(aParentTag,aChildTag)){
if(parentCanContain){
result=PR_TRUE;
break;
}//if
CTagList* theTagList=gHTMLElements[aChildTag].GetRootTags();
aChildTag=theTagList->mTags[0];
parentCanContain=CanContain(aParentTag,aChildTag);
}//while
}//if
}//if
else if(nsHTMLElement::IsTextTag(aChildTag)){
result=PR_TRUE;
}
else result=parentCanContain;
return result;
}
@@ -1322,7 +1330,7 @@ PRBool CNavDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild) const {
default:
if(FindTagInSet(aChild,gFormElementTags,sizeof(gFormElementTags)/sizeof(eHTMLTag_unknown)))
result=!HasOpenContainer(eHTMLTag_form);
result=PR_TRUE;
else result=FindTagInSet(aChild,gWhitespaceTags,sizeof(gWhitespaceTags)/sizeof(eHTMLTag_unknown));
}
break;
@@ -1880,10 +1888,12 @@ nsresult CNavDTD::CloseHTML(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::OpenHead(const nsIParserNode& aNode){
mBodyContext->Push(eHTMLTag_head);
nsresult result=mSink->OpenHead(aNode);
mHasOpenHead=PR_TRUE;
return result;
//mBodyContext->Push(eHTMLTag_head);
if(!mHasOpenHead++) {
nsresult result=mSink->OpenHead(aNode);
}
return NS_OK;
}
/**
@@ -1895,10 +1905,11 @@ nsresult CNavDTD::OpenHead(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::CloseHead(const nsIParserNode& aNode){
nsresult result=mSink->CloseHead(aNode);
mBodyContext->Pop();
mHasOpenHead=PR_FALSE;
return result;
if(0==--mHasOpenHead){
nsresult result=mSink->CloseHead(aNode);
}
//mBodyContext->Pop();
return NS_OK;
}
/**
@@ -2117,7 +2128,7 @@ CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){
break;
case eHTMLTag_head:
result=OpenHead(aNode); //open the head...
// result=OpenHead(aNode); //open the head...
break;
default:
@@ -2160,7 +2171,7 @@ CNavDTD::CloseContainer(const nsIParserNode& aNode,eHTMLTags aTag,
break;
case eHTMLTag_head:
result=CloseHead(aNode);
//result=CloseHead(aNode);
break;
case eHTMLTag_body:
@@ -2310,24 +2321,13 @@ nsresult CNavDTD::AddHeadLeaf(const nsIParserNode& aNode){
return result;
}
PRBool headOpen=mHasOpenHead;
if(!headOpen)
result=OpenHead(aNode);
result=OpenHead(aNode);
if(NS_OK==result) {
result=AddLeaf(aNode);
// XXX If the return value tells us to block, go
// ahead and close the tag out anyway, since its
// contents will be consumed.
if (NS_SUCCEEDED(result)) {
nsresult rv = CloseHead(aNode);
// XXX Only send along a failure. If the close
// succeeded we still may need to indicate that the
// parser has blocked (i.e. return the result of
// the AddLeaf.
if (rv != NS_OK) {
result = rv;
}
}
CloseHead(aNode);
}
return result;
}

View File

@@ -200,7 +200,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
* The parser uses a code sandwich to wrap the parsing process. Before
@@ -529,7 +529,7 @@ protected:
PRBool mAllowUnknownTags;
PRBool mHasOpenForm;
PRBool mHasOpenMap;
PRBool mHasOpenHead;
PRInt32 mHasOpenHead;
PRBool mHasOpenBody;
PRBool mHadBodyOrFrameset;
nsString mFilename;

View File

@@ -9,7 +9,7 @@
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
@@ -58,6 +58,7 @@ CParserContext::CParserContext(nsScanner* aScanner,void* aKey,nsIStreamObserver*
mTransferBufferSize=eTransferBufferSize;
mParserEnabled=PR_TRUE;
mStreamListenerState=eNone;
mMultipart=PR_TRUE;
}

View File

@@ -67,6 +67,7 @@ public:
PRUint32 mTransferBufferSize;
PRBool mParserEnabled;
eStreamState mStreamListenerState; //this is really only here for debug purposes.
PRBool mMultipart;
// nsDeque mTokenDeque;
};

View File

@@ -281,7 +281,7 @@ NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFilename,PRInt32 aLevel,nsIPars
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP CRtfDTD::BuildModel(nsIParser* aParser) {
NS_IMETHODIMP CRtfDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
return result;
}

View File

@@ -212,7 +212,7 @@ class CRtfDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
* The parser uses a code sandwich to wrap the parsing process. Before

View File

@@ -536,6 +536,7 @@ PRBool CDTDDebug::Verify(nsIDTD * aDTD, nsIParser * aParser, int aContextStackP
// write the true URL at the top of the file.
if (debugFile) {
// dump the html source into the newly created file.
PRofstream ps;
ps.attach(debugFile);
if (theParser)

View File

@@ -260,7 +260,7 @@ static nsHTMLElement gHTMLElements[] = {
{eHTMLTag_i, &gRootTags, 0, 0, kBPIPIC},
{eHTMLTag_iframe, &gRootTags, 0, 0, kAll},
{eHTMLTag_ilayer, &gRootTags, 0, 0, kBPIP},
{eHTMLTag_ilayer, &gRootTags, 0, 0, kAll},
{eHTMLTag_img, &gRootTags, 0, 0, kBPIP},
{eHTMLTag_input, &gRootTags, 0, 0, kBPIP}, //NOT DONE!!!
{eHTMLTag_ins, &gRootTags, 0, 0, kAll, &gInBody, 0},
@@ -359,6 +359,7 @@ public:
for(index=0;index<max;index++){
gHTMLElements[gStyleTags[index]].mSelfContained=PR_TRUE;
}
gHTMLElements[eHTMLTag_a].mSelfContained=PR_FALSE;
gHTMLElements[eHTMLTag_frameset].mSelfContained=PR_TRUE;
gHTMLElements[eHTMLTag_ol].mSelfContained=PR_TRUE;
gHTMLElements[eHTMLTag_ul].mSelfContained=PR_TRUE;

View File

@@ -199,6 +199,10 @@ PRInt32 nsHTMLTokenizer::GetCount(void) {
return mTokenDeque.GetSize();
}
CToken* nsHTMLTokenizer::GetTokenAt(PRInt32 anIndex){
return (CToken*)mTokenDeque.ObjectAt(anIndex);
}
/**
* This method repeatedly called by the tokenizer.
* Each time, we determine the kind of token were about to

View File

@@ -61,6 +61,7 @@ public:
virtual CToken* PushToken(CToken* theToken);
virtual CToken* PopToken(void);
virtual CToken* PeekToken(void);
virtual CToken* GetTokenAt(PRInt32 anIndex);
virtual PRInt32 GetCount(void);
protected:

View File

@@ -253,7 +253,7 @@ nsresult CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
* @return
*/
void CStartToken::DebugDumpSource(ostream& out) {
char buffer[200];
char buffer[1000];
mTextValue.ToCString(buffer,sizeof(buffer)-1);
out << "<" << buffer;
if(!mAttributed)
@@ -380,7 +380,7 @@ PRInt32 CEndToken::GetTokenType(void) {
* @return
*/
void CEndToken::DebugDumpSource(ostream& out) {
char buffer[200];
char buffer[1000];
mTextValue.ToCString(buffer,sizeof(buffer)-1);
out << "</" << buffer << ">";
}
@@ -987,7 +987,7 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
* @return
*/
void CAttributeToken::DebugDumpSource(ostream& out) {
char buffer[200];
static char buffer[1000];
mTextKey.ToCString(buffer,sizeof(buffer)-1);
out << " " << buffer;
if(mTextValue.Length()){

View File

@@ -115,7 +115,7 @@ class nsIDTD : public nsISupports {
* @param anErrorCode - contains error code resulting from parse process
* @return
*/
NS_IMETHOD BuildModel(nsIParser* aParser)=0;
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer)=0;
/**
* Called during model building phase of parse process. Each token created during
@@ -138,6 +138,7 @@ class nsIDTD : public nsISupports {
*/
virtual nsITokenizer* GetTokenizer(void)=0;
virtual nsITokenRecycler* GetTokenRecycler(void)=0;
/**

View File

@@ -165,6 +165,7 @@ class nsIParser : public nsISupports {
#define NS_ERROR_HTMLPARSER_BADURL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1005)
#define NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1006)
#define NS_ERROR_HTMLPARSER_INTERRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1007)
#define NS_ERROR_HTMLPARSER_BADTOKENIZER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1008)
/**
* Return codes for parsing routines.

View File

@@ -61,6 +61,7 @@ public:
virtual CToken* PopToken(void)=0;
virtual CToken* PeekToken(void)=0;
virtual PRInt32 GetCount(void)=0;
virtual CToken* GetTokenAt(PRInt32 anIndex)=0;
};

View File

@@ -164,7 +164,7 @@ nsParser::~nsParser() {
}
NS_IF_RELEASE(mObserver);
NS_RELEASE(mSink);
NS_IF_RELEASE(mSink);
//don't forget to add code here to delete
//what may be several contexts...
@@ -565,15 +565,15 @@ nsresult nsParser::Parse(nsIURL* aURL,nsIStreamObserver* aListener,PRBool aVerif
nsresult result=kBadURL;
mDTDVerification=aVerifyEnabled;
mMultipart=PR_TRUE;
if(aURL) {
const char* spec;
nsresult rv = aURL->GetSpec(&spec);
if (rv != NS_OK) return rv;
nsAutoString theName(spec);
CParserContext* cp=new CParserContext(new nsScanner(theName,PR_FALSE),aURL,aListener);
if(cp) {
PushContext(*cp);
CParserContext* pc=new CParserContext(new nsScanner(theName,PR_FALSE),aURL,aListener);
if(pc) {
pc->mMultipart=PR_TRUE;
PushContext(*pc);
result=NS_OK;
}
}
@@ -598,8 +598,8 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){
PushContext(*pc);
pc->mSourceType="text/html";
pc->mStreamListenerState=eOnStart;
pc->mMultipart=PR_FALSE;
mParserContext->mScanner->Eof();
mMultipart=PR_FALSE;
result=ResumeParse();
pc=PopContext();
delete pc;
@@ -634,12 +634,11 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,PRBool anHTMLString,PRBool aVer
CParserContext* pc=new CParserContext(new nsScanner(aSourceBuffer),&aSourceBuffer,0);
if(pc) {
nsIDTD* thePrevDTD=(mParserContext) ? mParserContext->mDTD: 0;
PushContext(*pc);
pc->mStreamListenerState=eOnStart;
pc->mMultipart=PR_FALSE;
if(PR_TRUE==anHTMLString)
pc->mSourceType="text/html";
mMultipart=PR_FALSE;
result=ResumeParse();
// mParserContext->mDTD=0;
pc=PopContext();
@@ -672,7 +671,7 @@ nsresult nsParser::ResumeParse(nsIDTD* aDefaultDTD) {
result=Tokenize();
result=BuildModel();
if((!mMultipart) || ((eOnStop==mParserContext->mStreamListenerState) && (NS_OK==result))){
if((!mParserContext->mMultipart) || ((eOnStop==mParserContext->mStreamListenerState) && (NS_OK==result))){
DidBuildModel(mStreamStatus);
}
else {
@@ -707,6 +706,7 @@ nsresult nsParser::BuildModel() {
//Get the root DTD for use in model building...
CParserContext* theRootContext=mParserContext;
nsITokenizer* theTokenizer=mParserContext->mDTD->GetTokenizer();
while(theRootContext->mPrevContext) {
theRootContext=theRootContext->mPrevContext;
}
@@ -714,7 +714,7 @@ nsresult nsParser::BuildModel() {
nsIDTD* theRootDTD=theRootContext->mDTD;
nsresult result=NS_OK;
if(theRootDTD) {
result=theRootDTD->BuildModel(this);
result=theRootDTD->BuildModel(this,theTokenizer);
}
return result;
@@ -958,52 +958,23 @@ nsresult nsParser::Tokenize(){
*/
PRBool nsParser::DidTokenize(){
PRBool result=PR_TRUE;
{
fstream out("c:/temp/tokens.out",ios::trunc);
DebugDumpSource(out);
}
return result;
}
/**
* This debug routine is used to cause the tokenizer to
* iterate its token list, asking each token to dump its
* contents to the given output stream.
*
* @update gess 3/25/98
* @param
* @return
*/
void nsParser::DebugDumpTokens(ostream& out) {
/*
nsDequeIterator b=mParserContext->mTokenDeque.Begin();
nsDequeIterator e=mParserContext->mTokenDeque.End();
void nsParser::DebugDumpSource(ostream& aStream) {
PRInt32 theIndex=-1;
nsITokenizer* theTokenizer=mParserContext->mDTD->GetTokenizer();
CToken* theToken;
while(b!=e) {
theToken=(CToken*)(b++);
theToken->DebugDumpToken(out);
while(theToken=theTokenizer->GetTokenAt(++theIndex)) {
// theToken->DebugDumpToken(out);
theToken->DebugDumpSource(aStream);
}
*/
}
/**
* This debug routine is used to cause the tokenizer to
* iterate its token list, asking each token to dump its
* contents to the given output stream.
*
* @update gess 3/25/98
* @param
* @return
*/
void nsParser::DebugDumpSource(ostream& out) {
/*
nsDequeIterator b=mParserContext->mTokenDeque.Begin();
nsDequeIterator e=mParserContext->mTokenDeque.End();
CToken* theToken;
while(b!=e) {
theToken=(CToken*)(b++);
theToken->DebugDumpSource(out);
}
*/
}

View File

@@ -181,17 +181,7 @@ friend class CTokenHandler;
*/
virtual nsresult ResumeParse(nsIDTD* mDefaultDTD=0);
/**
* This debug routine is used to cause the tokenizer to
* iterate its token list, asking each token to dump its
* contents to the given output stream.
*
* @update gess 3/25/98
* @param
* @return
*/
void DebugDumpSource(ostream& out);
void DebugDumpSource(ostream& anOutput);
//*********************************************
// These methods are callback methods used by
@@ -268,18 +258,6 @@ private:
* @return TRUE if all went well
*/
PRBool DidTokenize();
/**
* This debug routine is used to cause the tokenizer to
* iterate its token list, asking each token to dump its
* contents to the given output stream.
*
* @update gess 3/25/98
* @param
* @return
*/
void DebugDumpTokens(ostream& out);
/**
* This method is used as a backstop to compute the kind of content
@@ -312,7 +290,6 @@ protected:
PRBool mDTDVerification;
nsString mCommand;
PRInt32 mStreamStatus;
PRBool mMultipart;
};

View File

@@ -226,7 +226,7 @@ NS_IMETHODIMP CValidDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,n
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP CValidDTD::BuildModel(nsIParser* aParser) {
NS_IMETHODIMP CValidDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
return result;
}

View File

@@ -131,7 +131,7 @@ class CValidDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
* The parser uses a code sandwich to wrap the parsing process. Before

View File

@@ -306,27 +306,31 @@ NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotify
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser) {
NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
nsHTMLTokenizer* theTokenizer=(nsHTMLTokenizer*)GetTokenizer();
nsITokenRecycler* theRecycler=GetTokenRecycler();
if(theTokenizer) {
if(aTokenizer) {
nsITokenizer* oldTokenizer=mTokenizer;
mTokenizer=aTokenizer;
nsITokenRecycler* theRecycler=mTokenizer->GetTokenRecycler();
while(NS_OK==result){
CToken* theToken=theTokenizer->PopToken();
CToken* theToken=mTokenizer->PopToken();
if(theToken) {
result=HandleToken(theToken,aParser);
if(NS_SUCCEEDED(result)) {
theRecycler->RecycleToken(theToken);
}
else if(NS_ERROR_HTMLPARSER_BLOCK!=result){
theTokenizer->PushTokenFront(theToken);
mTokenizer->PushTokenFront(theToken);
}
// theRootDTD->Verify(kEmptyString,aParser);
}
else break;
}
}//while
mTokenizer=oldTokenizer;
}
else result=NS_ERROR_HTMLPARSER_BADTOKENIZER;
return result;
}

View File

@@ -121,7 +121,7 @@ class CViewSourceHTML: public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
* The parser uses a code sandwich to wrap the parsing process. Before

View File

@@ -251,30 +251,35 @@ NS_IMETHODIMP CWellFormedDTD::WillBuildModel(nsString& aFilename,PRBool aNotifyS
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP CWellFormedDTD::BuildModel(nsIParser* aParser) {
NS_IMETHODIMP CWellFormedDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
nsHTMLTokenizer* theTokenizer=(nsHTMLTokenizer*)GetTokenizer();
nsITokenRecycler* theRecycler=GetTokenRecycler();
if(theTokenizer) {
if(aTokenizer) {
nsITokenizer* oldTokenizer=mTokenizer;
mTokenizer=aTokenizer;
nsITokenRecycler* theRecycler=aTokenizer->GetTokenRecycler();
while(NS_OK==result){
CToken* theToken=theTokenizer->PopToken();
CToken* theToken=mTokenizer->PopToken();
if(theToken) {
result=HandleToken(theToken,aParser);
if(NS_SUCCEEDED(result)) {
theRecycler->RecycleToken(theToken);
}
else if(NS_ERROR_HTMLPARSER_BLOCK!=result){
theTokenizer->PushTokenFront(theToken);
mTokenizer->PushTokenFront(theToken);
}
// theRootDTD->Verify(kEmptyString,aParser);
}
else break;
}
}//while
mTokenizer=oldTokenizer;
}
else result=NS_ERROR_HTMLPARSER_BADTOKENIZER;
return result;
}
/**
*
* @update gess5/18/98

View File

@@ -119,7 +119,7 @@ class CWellFormedDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
* The parser uses a code sandwich to wrap the parsing process. Before

View File

@@ -439,7 +439,7 @@ nsresult nsXIFDTD::WillBuildModel(nsString& aFileName,PRBool aNotifySink,nsIPars
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP nsXIFDTD::BuildModel(nsIParser* aParser) {
NS_IMETHODIMP nsXIFDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer) {
nsresult result=NS_OK;
return result;
}

View File

@@ -174,7 +174,7 @@ class nsXIFDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHOD BuildModel(nsIParser* aParser);
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);
/**
*