generalize fstreams to our own input streams, this is the first part of a change to allow XUL from streams

This commit is contained in:
scc%netscape.com 1999-04-06 20:39:11 +00:00
parent 2c01f2f95c
commit a767ccc633
10 changed files with 42 additions and 58 deletions

View File

@ -123,7 +123,7 @@ class nsIParser : public nsISupports {
******************************************************************************************/
virtual PRBool EnableParser(PRBool aState) = 0;
virtual nsresult Parse(nsIURL* aURL,nsIStreamObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE) = 0;
virtual nsresult Parse(fstream& aStream,PRBool aEnableVerify=PR_FALSE) = 0;
virtual nsresult Parse(nsIInputStream& aStream, PRBool aEnableVerify=PR_FALSE) = 0;
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall) = 0;
//virtual PRBool IsValid(nsString& aSourceBuffer,const nsString& aContentTypeaLastCall) = 0;

View File

@ -603,7 +603,7 @@ nsresult nsParser::Parse(nsIURL* aURL,nsIStreamObserver* aListener,PRBool aVerif
* @param aStream is the i/o source
* @return error code -- 0 if ok, non-zero if error.
*/
nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){
nsresult nsParser::Parse(nsIInputStream& aStream,PRBool aVerifyEnabled){
mDTDVerification=aVerifyEnabled;
nsresult result=NS_ERROR_OUT_OF_MEMORY;
@ -638,7 +638,8 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){
nsParser::gHackMetaCharset = "";
// XXX end of meta tag charset hack
CParserContext* pc=new CParserContext(new nsScanner(theUnknownFilename,aStream, charset, charsetSource,PR_FALSE),&aStream,0);
nsInputStream input(&aStream);
CParserContext* pc=new CParserContext(new nsScanner(theUnknownFilename, input, charset, charsetSource,PR_FALSE),&aStream,0);
if(pc) {
PushContext(*pc);
pc->mSourceType=kHTMLTextContentType;

View File

@ -161,7 +161,7 @@ friend class CTokenHandler;
* @param aStream is the i/o source
* @return TRUE if all went well -- FALSE otherwise
*/
virtual nsresult Parse(fstream& aStream,PRBool aEnableVerify=PR_FALSE);
virtual nsresult Parse(nsIInputStream& aStream,PRBool aEnableVerify=PR_FALSE);
/**
* @update gess5/11/98

View File

@ -24,6 +24,7 @@
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetAlias.h"
#include "nsFileSpec.h"
const char* kBadHTMLText="<H3>Oops...</H3>You just tried to read a non-existent document: <BR>";
@ -53,7 +54,7 @@ nsScanner::nsScanner(nsString& anHTMLString, const nsString& aCharset, nsCharset
mOwnsStream=PR_FALSE;
mOffset=0;
mMarkPos=-1;
mFileStream=0;
mInputStream=0;
mUnicodeDecoder = 0;
mCharset = "";
mCharsetSource = kCharsetUninitialized;
@ -77,18 +78,9 @@ nsScanner::nsScanner(nsString& aFilename,PRBool aCreateStream, const nsString& a
mMarkPos=-1;
mTotalRead=0;
mOwnsStream=aCreateStream;
mFileStream=0;
mInputStream=0;
if(aCreateStream) {
char buffer[513];
aFilename.ToCString(buffer,sizeof(buffer)-1);
#if defined(HAVE_IOS_BINARY) || !defined(XP_UNIX)
/* XXX: HAVE_IOS_BINARY needs to be set for mac & win */
mFileStream=new fstream(buffer,ios::in|ios::binary);
#elif defined(HAVE_IOS_BIN)
mFileStream=new fstream(buffer,ios::in|ios::bin);
#else
mFileStream=new fstream(buffer,ios::in);
#endif
mInputStream = new nsInputFileStream(nsFileSpec(aFilename));
} //if
mUnicodeDecoder = 0;
mCharset = "";
@ -106,7 +98,7 @@ nsScanner::nsScanner(nsString& aFilename,PRBool aCreateStream, const nsString& a
* @param aFilename --
* @return
*/
nsScanner::nsScanner(nsString& aFilename,fstream& aStream,const nsString& aCharset, nsCharsetSource aSource, PRBool assumeOwnership) :
nsScanner::nsScanner(nsString& aFilename,nsInputStream& aStream,const nsString& aCharset, nsCharsetSource aSource, PRBool assumeOwnership) :
mBuffer(""), mFilename(aFilename)
{
mIncremental=PR_TRUE;
@ -114,7 +106,7 @@ nsScanner::nsScanner(nsString& aFilename,fstream& aStream,const nsString& aChars
mMarkPos=-1;
mTotalRead=0;
mOwnsStream=assumeOwnership;
mFileStream=&aStream;
mInputStream=&aStream;
mUnicodeDecoder = 0;
mCharset = "";
mCharsetSource = kCharsetUninitialized;
@ -185,12 +177,12 @@ nsresult nsScanner::SetDocumentCharset(const nsString& aCharset , nsCharsetSourc
* @return
*/
nsScanner::~nsScanner() {
if(mFileStream) {
mFileStream->close();
if(mInputStream) {
mInputStream->close();
if(mOwnsStream)
delete mFileStream;
delete mInputStream;
}
mFileStream=0;
mInputStream=0;
NS_IF_RELEASE(mUnicodeDecoder);
}
@ -285,7 +277,7 @@ PRBool nsScanner::Append(const PRUnichar* aBuffer, PRUint32 aLen){
nsresult nsScanner::FillBuffer(void) {
nsresult result=NS_OK;
if(!mFileStream) {
if(!mInputStream) {
//This is DEBUG code!!!!!! XXX DEBUG XXX
//If you're here, it means someone tried to load a
//non-existent document. So as a favor, we emit a
@ -301,9 +293,8 @@ nsresult nsScanner::FillBuffer(void) {
char buf[kBufsize+1];
buf[kBufsize]=0;
if(mFileStream) {
mFileStream->read(buf,kBufsize);
numread=mFileStream->gcount();
if(mInputStream) {
numread = mInputStream->read(buf, kBufsize);
if (0 == numread) {
return kEOF;
}

View File

@ -36,7 +36,7 @@
#include "nsIParser.h"
#include "prtypes.h"
#include "nsIUnicodeDecoder.h"
#include <fstream.h>
#include "nsFileStream.h"
typedef enum {
@ -86,7 +86,7 @@ class nsScanner {
* @param aMode represents the parser mode (nav, other)
* @return
*/
nsScanner(nsString& aFilename,fstream& aStream, const nsString& aCharset, nsCharsetSource aSource,PRBool assumeOwnership=PR_TRUE);
nsScanner(nsString& aFilename, nsInputStream& aStream, const nsString& aCharset, nsCharsetSource aSource,PRBool assumeOwnership=PR_TRUE);
~nsScanner();
@ -304,7 +304,7 @@ class nsScanner {
*/
nsresult FillBuffer(void);
fstream* mFileStream;
nsInputStream* mInputStream;
nsString mBuffer;
nsString mFilename;
PRUint32 mOffset;

View File

@ -123,7 +123,7 @@ class nsIParser : public nsISupports {
******************************************************************************************/
virtual PRBool EnableParser(PRBool aState) = 0;
virtual nsresult Parse(nsIURL* aURL,nsIStreamObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE) = 0;
virtual nsresult Parse(fstream& aStream,PRBool aEnableVerify=PR_FALSE) = 0;
virtual nsresult Parse(nsIInputStream& aStream, PRBool aEnableVerify=PR_FALSE) = 0;
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall) = 0;
//virtual PRBool IsValid(nsString& aSourceBuffer,const nsString& aContentTypeaLastCall) = 0;

View File

@ -603,7 +603,7 @@ nsresult nsParser::Parse(nsIURL* aURL,nsIStreamObserver* aListener,PRBool aVerif
* @param aStream is the i/o source
* @return error code -- 0 if ok, non-zero if error.
*/
nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){
nsresult nsParser::Parse(nsIInputStream& aStream,PRBool aVerifyEnabled){
mDTDVerification=aVerifyEnabled;
nsresult result=NS_ERROR_OUT_OF_MEMORY;
@ -638,7 +638,8 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){
nsParser::gHackMetaCharset = "";
// XXX end of meta tag charset hack
CParserContext* pc=new CParserContext(new nsScanner(theUnknownFilename,aStream, charset, charsetSource,PR_FALSE),&aStream,0);
nsInputStream input(&aStream);
CParserContext* pc=new CParserContext(new nsScanner(theUnknownFilename, input, charset, charsetSource,PR_FALSE),&aStream,0);
if(pc) {
PushContext(*pc);
pc->mSourceType=kHTMLTextContentType;

View File

@ -161,7 +161,7 @@ friend class CTokenHandler;
* @param aStream is the i/o source
* @return TRUE if all went well -- FALSE otherwise
*/
virtual nsresult Parse(fstream& aStream,PRBool aEnableVerify=PR_FALSE);
virtual nsresult Parse(nsIInputStream& aStream,PRBool aEnableVerify=PR_FALSE);
/**
* @update gess5/11/98

View File

@ -24,6 +24,7 @@
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetAlias.h"
#include "nsFileSpec.h"
const char* kBadHTMLText="<H3>Oops...</H3>You just tried to read a non-existent document: <BR>";
@ -53,7 +54,7 @@ nsScanner::nsScanner(nsString& anHTMLString, const nsString& aCharset, nsCharset
mOwnsStream=PR_FALSE;
mOffset=0;
mMarkPos=-1;
mFileStream=0;
mInputStream=0;
mUnicodeDecoder = 0;
mCharset = "";
mCharsetSource = kCharsetUninitialized;
@ -77,18 +78,9 @@ nsScanner::nsScanner(nsString& aFilename,PRBool aCreateStream, const nsString& a
mMarkPos=-1;
mTotalRead=0;
mOwnsStream=aCreateStream;
mFileStream=0;
mInputStream=0;
if(aCreateStream) {
char buffer[513];
aFilename.ToCString(buffer,sizeof(buffer)-1);
#if defined(HAVE_IOS_BINARY) || !defined(XP_UNIX)
/* XXX: HAVE_IOS_BINARY needs to be set for mac & win */
mFileStream=new fstream(buffer,ios::in|ios::binary);
#elif defined(HAVE_IOS_BIN)
mFileStream=new fstream(buffer,ios::in|ios::bin);
#else
mFileStream=new fstream(buffer,ios::in);
#endif
mInputStream = new nsInputFileStream(nsFileSpec(aFilename));
} //if
mUnicodeDecoder = 0;
mCharset = "";
@ -106,7 +98,7 @@ nsScanner::nsScanner(nsString& aFilename,PRBool aCreateStream, const nsString& a
* @param aFilename --
* @return
*/
nsScanner::nsScanner(nsString& aFilename,fstream& aStream,const nsString& aCharset, nsCharsetSource aSource, PRBool assumeOwnership) :
nsScanner::nsScanner(nsString& aFilename,nsInputStream& aStream,const nsString& aCharset, nsCharsetSource aSource, PRBool assumeOwnership) :
mBuffer(""), mFilename(aFilename)
{
mIncremental=PR_TRUE;
@ -114,7 +106,7 @@ nsScanner::nsScanner(nsString& aFilename,fstream& aStream,const nsString& aChars
mMarkPos=-1;
mTotalRead=0;
mOwnsStream=assumeOwnership;
mFileStream=&aStream;
mInputStream=&aStream;
mUnicodeDecoder = 0;
mCharset = "";
mCharsetSource = kCharsetUninitialized;
@ -185,12 +177,12 @@ nsresult nsScanner::SetDocumentCharset(const nsString& aCharset , nsCharsetSourc
* @return
*/
nsScanner::~nsScanner() {
if(mFileStream) {
mFileStream->close();
if(mInputStream) {
mInputStream->close();
if(mOwnsStream)
delete mFileStream;
delete mInputStream;
}
mFileStream=0;
mInputStream=0;
NS_IF_RELEASE(mUnicodeDecoder);
}
@ -285,7 +277,7 @@ PRBool nsScanner::Append(const PRUnichar* aBuffer, PRUint32 aLen){
nsresult nsScanner::FillBuffer(void) {
nsresult result=NS_OK;
if(!mFileStream) {
if(!mInputStream) {
//This is DEBUG code!!!!!! XXX DEBUG XXX
//If you're here, it means someone tried to load a
//non-existent document. So as a favor, we emit a
@ -301,9 +293,8 @@ nsresult nsScanner::FillBuffer(void) {
char buf[kBufsize+1];
buf[kBufsize]=0;
if(mFileStream) {
mFileStream->read(buf,kBufsize);
numread=mFileStream->gcount();
if(mInputStream) {
numread = mInputStream->read(buf, kBufsize);
if (0 == numread) {
return kEOF;
}

View File

@ -36,7 +36,7 @@
#include "nsIParser.h"
#include "prtypes.h"
#include "nsIUnicodeDecoder.h"
#include <fstream.h>
#include "nsFileStream.h"
typedef enum {
@ -86,7 +86,7 @@ class nsScanner {
* @param aMode represents the parser mode (nav, other)
* @return
*/
nsScanner(nsString& aFilename,fstream& aStream, const nsString& aCharset, nsCharsetSource aSource,PRBool assumeOwnership=PR_TRUE);
nsScanner(nsString& aFilename, nsInputStream& aStream, const nsString& aCharset, nsCharsetSource aSource,PRBool assumeOwnership=PR_TRUE);
~nsScanner();
@ -304,7 +304,7 @@ class nsScanner {
*/
nsresult FillBuffer(void);
fstream* mFileStream;
nsInputStream* mInputStream;
nsString mBuffer;
nsString mFilename;
PRUint32 mOffset;