Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsImportScanFileLines Class Reference

#include <nsImportScanFile.h>

Inheritance diagram for nsImportScanFileLines:
Inheritance graph
[legend]
Collaboration diagram for nsImportScanFileLines:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsImportScanFileLines ()
void ResetLineScan (void)
virtual PRBool ProcessLine (PRUint8 *, PRUint32, PRBool *)
void InitScan (nsIFileSpec *pSpec, PRUint8 *pBuf, PRUint32 sz)
PRBool OpenScan (nsIFileSpec *pSpec, PRUint32 bufSz=4096)
void CleanUpScan (void)
virtual PRBool Scan (PRBool *pDone)

Protected Member Functions

virtual PRBool ScanBuffer (PRBool *pDone)
void ShiftBuffer (void)
PRBool FillBufferFromFile (void)

Protected Attributes

PRBool m_needEol
nsIFileSpecm_pFile
PRUint8m_pBuf
PRUint32 m_bufSz
PRUint32 m_bytesInBuf
PRUint32 m_pos
PRBool m_eof
PRBool m_allocated

Detailed Description

Definition at line 71 of file nsImportScanFile.h.


Constructor & Destructor Documentation

Definition at line 73 of file nsImportScanFile.h.


Member Function Documentation

Definition at line 106 of file nsImportScanFile.cpp.

{
       NS_IF_RELEASE( m_pFile);
       m_pFile = nsnull;
       if (m_allocated) {
              if (m_pBuf)
                     delete [] m_pBuf;
              m_pBuf = NULL;
       }
}

Here is the caller graph for this function:

PRBool nsImportScanFile::FillBufferFromFile ( void  ) [protected, inherited]

Definition at line 137 of file nsImportScanFile.cpp.

{
       PRBool eof = PR_FALSE;
       nsresult rv = m_pFile->Eof( &eof);
       if (eof) {
              return( PR_FALSE);
       }

       // Fill up a buffer and scan it
       ShiftBuffer();

       // Read in some more bytes
       PRUint32      cnt = m_bufSz - m_bytesInBuf;
       // To distinguish from disk errors
       // Check first for end of file?
       // Set a done flag if true...
       PRInt32 read;
       char *pBuf = (char *)m_pBuf;
       pBuf += m_bytesInBuf;
       rv = m_pFile->Read( &pBuf, (PRInt32) cnt, &read);

       if (NS_FAILED( rv))
              return( PR_FALSE);
       eof = PR_FALSE;
       rv = m_pFile->Eof( &eof);
       if (eof)
              m_eof = PR_TRUE;

       m_bytesInBuf += cnt;
       return( PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsImportScanFile::InitScan ( nsIFileSpec pSpec,
PRUint8 pBuf,
PRUint32  sz 
) [inherited]

Definition at line 96 of file nsImportScanFile.cpp.

{
       m_pFile = pSpec;
       NS_IF_ADDREF( pSpec);
       m_pBuf = pBuf;
       m_bufSz = sz;
       m_bytesInBuf = 0;
       m_pos = 0;
}

Here is the caller graph for this function:

PRBool nsImportScanFile::OpenScan ( nsIFileSpec pSpec,
PRUint32  bufSz = 4096 
) [inherited]

Definition at line 68 of file nsImportScanFile.cpp.

{
       if (!bufSz)
              bufSz = 32 * 1024;
       if (!m_pBuf) {
              m_pBuf = new PRUint8[bufSz];
       }
       
       PRBool open = PR_FALSE;
       nsresult rv = pSpec->IsStreamOpen( &open);
       if (NS_FAILED( rv) || !open) {
              rv = pSpec->OpenStreamForReading();
              if (NS_FAILED( rv)) {
                     delete [] m_pBuf;
                     m_pBuf = nsnull;
                     return( PR_FALSE);
              }
       }
       m_pFile = pSpec;
       NS_IF_ADDREF( m_pFile);
       m_allocated = PR_TRUE;
       m_bytesInBuf = 0;
       m_pos = 0;
       m_bufSz = bufSz;
       return( PR_TRUE);
}
virtual PRBool nsImportScanFileLines::ProcessLine ( PRUint8 ,
PRUint32  ,
PRBool  
) [inline, virtual]

Definition at line 77 of file nsImportScanFile.h.

{return( PR_TRUE);}

Here is the caller graph for this function:

Definition at line 75 of file nsImportScanFile.h.

PRBool nsImportScanFile::Scan ( PRBool pDone) [virtual, inherited]

Reimplemented in nsImportEncodeScan.

Definition at line 169 of file nsImportScanFile.cpp.

{
       PRBool eof = PR_FALSE;
       m_pFile->Eof( &eof);

       if (eof) {
              if (m_pos < m_bytesInBuf) {
                     ScanBuffer( pDone);
              }
              *pDone = PR_TRUE;
              return( PR_TRUE);
       }

       // Fill up a buffer and scan it
       if (!FillBufferFromFile())
              return( PR_FALSE);

       return( ScanBuffer( pDone));
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsImportScanFileLines::ScanBuffer ( PRBool pDone) [protected, virtual]

Reimplemented from nsImportScanFile.

Definition at line 195 of file nsImportScanFile.cpp.

{
       // m_pos, m_bytesInBuf, m_eof, m_pBuf are relevant

       PRUint32             pos = m_pos;
       PRUint32             max = m_bytesInBuf;
       PRUint8 *            pChar = m_pBuf + pos;
       PRUint32             startPos;
       
       while (pos < max) {
              if (m_needEol) {
                     // Find the next eol...
                     while ((pos < max) && (*pChar != ImportCharSet::cCRChar) && (*pChar != ImportCharSet::cLinefeedChar)) {
                            pos++;
                            pChar++;
                     }
                     m_pos = pos;
                     if (pos < max)
                            m_needEol = PR_FALSE;
                     if (pos == max) // need more buffer for an end of line
                            break;
              }
              // Skip past any eol characters
              while ((pos < max) && ((*pChar == ImportCharSet::cCRChar) || (*pChar == ImportCharSet::cLinefeedChar))) {
                     pos++;
                     pChar++;
              }
              m_pos = pos;
              if (pos == max)
                     break;
              // Make sure we can find either the eof or the 
              // next end of line
              startPos = pos;
              while ((pos < max) && (*pChar != ImportCharSet::cCRChar) && (*pChar != ImportCharSet::cLinefeedChar)) {
                     pos++;
                     pChar++;
              }
              
              // Is line too big for our buffer?
              if ((pos == max) && !m_eof) {
                     if (!m_pos) { // line too big for our buffer
                            m_pos = pos;
                            m_needEol = PR_TRUE;
                     }
                     break;
              }
              
              if (!ProcessLine( m_pBuf + startPos, pos - startPos, pDone)) {
                     return( PR_FALSE);
              }
              m_pos = pos;
       }

       return( PR_TRUE);
}

Here is the call graph for this function:

void nsImportScanFile::ShiftBuffer ( void  ) [protected, inherited]

Definition at line 117 of file nsImportScanFile.cpp.

{
       PRUint8 *     pTop;
       PRUint8 *     pCurrent;

       if (m_pos < m_bytesInBuf) {
              pTop = m_pBuf;
              pCurrent = pTop + m_pos;
              PRUint32             cnt = m_bytesInBuf - m_pos;
              while (cnt) {
                     *pTop = *pCurrent;
                     pTop++; pCurrent++;
                     cnt--;
              }
       }

       m_bytesInBuf -= m_pos;
       m_pos = 0;
}

Here is the caller graph for this function:


Member Data Documentation

PRBool nsImportScanFile::m_allocated [protected, inherited]

Definition at line 68 of file nsImportScanFile.h.

PRUint32 nsImportScanFile::m_bufSz [protected, inherited]

Definition at line 64 of file nsImportScanFile.h.

PRUint32 nsImportScanFile::m_bytesInBuf [protected, inherited]

Definition at line 65 of file nsImportScanFile.h.

PRBool nsImportScanFile::m_eof [protected, inherited]

Definition at line 67 of file nsImportScanFile.h.

Definition at line 82 of file nsImportScanFile.h.

PRUint8* nsImportScanFile::m_pBuf [protected, inherited]

Definition at line 63 of file nsImportScanFile.h.

nsIFileSpec* nsImportScanFile::m_pFile [protected, inherited]

Definition at line 62 of file nsImportScanFile.h.

PRUint32 nsImportScanFile::m_pos [protected, inherited]

Definition at line 66 of file nsImportScanFile.h.


The documentation for this class was generated from the following files: