Back to index

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

#include <ImportOutFile.h>

Collaboration diagram for ImportOutFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ImportOutFile ()
 ImportOutFile (nsIFileSpec *pFile, PRUint8 *pBuf, PRUint32 sz)
 ~ImportOutFile ()
PRBool InitOutFile (nsIFileSpec *pFile, PRUint32 bufSz=4096)
void InitOutFile (nsIFileSpec *pFile, PRUint8 *pBuf, PRUint32 sz)
PRBool WriteData (const PRUint8 *pSrc, PRUint32 len)
PRBool WriteByte (PRUint8 byte)
PRBool WriteStr (const char *pStr)
PRBool WriteU8NullTerm (const PRUint8 *pSrc, PRBool includeNull)
PRBool WriteEol (void)
PRBool Done (void)
PRBool SetMarker (int markerID)
void ClearMarker (int markerID)
PRBool WriteStrAtMarker (int markerID, const char *pStr)
PRBool Set8bitTranslator (nsImportTranslator *pTrans)
PRBool End8bitTranslation (PRBool *pEngaged, nsCString &useCharset, nsCString &encoding)

Protected Member Functions

PRBool Flush (void)

Protected Attributes

nsIFileSpecm_pFile
PRUint8m_pBuf
PRUint32 m_bufSz
PRUint32 m_pos
PRBool m_ownsFileAndBuffer
PRUint32 m_markers [kMaxMarkers]
nsImportTranslatorm_pTrans
PRBool m_engaged
PRBool m_supports8to7
ImportOutFilem_pTransOut
PRUint8m_pTransBuf

Detailed Description

Definition at line 47 of file ImportOutFile.h.


Constructor & Destructor Documentation

Definition at line 56 of file ImportOutFile.cpp.

Here is the caller graph for this function:

ImportOutFile::ImportOutFile ( nsIFileSpec pFile,
PRUint8 pBuf,
PRUint32  sz 
)

Definition at line 68 of file ImportOutFile.cpp.

Here is the call graph for this function:

Definition at line 77 of file ImportOutFile.cpp.

{
       if (m_ownsFileAndBuffer) {
              Flush();
              if (m_pBuf)
                     delete [] m_pBuf;
       }
       
       NS_IF_RELEASE( m_pFile);

       if (m_pTrans)
              delete m_pTrans;
       if (m_pTransOut)
              delete m_pTransOut;
       if (m_pTransBuf)
              delete m_pTransBuf;
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 296 of file ImportOutFile.cpp.

{
       if (markerID < kMaxMarkers)
              m_markers[markerID] = 0;
}

Definition at line 60 of file ImportOutFile.h.

{return( Flush());}

Here is the call graph for this function:

PRBool ImportOutFile::End8bitTranslation ( PRBool pEngaged,
nsCString useCharset,
nsCString encoding 
)

Definition at line 108 of file ImportOutFile.cpp.

{
       if (!m_pTrans)
              return( PR_FALSE);


       PRBool bResult = Flush();
       if (m_supports8to7 && m_pTransOut) {
              if (bResult)
                     bResult = m_pTrans->FinishConvertToFile( m_pTransOut);
              if (bResult)
                     bResult = Flush();
       }

       if (m_supports8to7) {
              m_pTrans->GetCharset( useCharset);
              m_pTrans->GetEncoding( encoding);
       }
       else
              useCharset.Truncate();
       *pEngaged = m_engaged;
       delete m_pTrans;
       m_pTrans = nsnull;
       if (m_pTransOut)
              delete m_pTransOut;
       m_pTransOut = nsnull;
       if (m_pTransBuf)
              delete m_pTransBuf;
       m_pTransBuf = nsnull;

       return( bResult);
}

Here is the call graph for this function:

PRBool ImportOutFile::Flush ( void  ) [protected]

Definition at line 182 of file ImportOutFile.cpp.

{
       if (!m_pos)
              return( PR_TRUE);

       PRUint32      transLen;
       PRBool        duddleyDoWrite = PR_FALSE;

       // handle translations if appropriate
       if (m_pTrans) {
              if (m_engaged && m_supports8to7) {
                     // Markers can get confused by this crap!!!
                     // TLR: FIXME: Need to update the markers based on
                     // the difference between the translated len and untranslated len

                     if (!m_pTrans->ConvertToFile(  m_pBuf, m_pos, m_pTransOut, &transLen))
                            return( PR_FALSE);
                     if (!m_pTransOut->Flush())
                            return( PR_FALSE);
                     // now update our buffer...
                     if (transLen < m_pos) {
                            memcpy( m_pBuf, m_pBuf + transLen, m_pos - transLen);
                     }
                     m_pos -= transLen;
              }
              else if (m_engaged) {
                     // does not actually support translation!
                     duddleyDoWrite = PR_TRUE;
              }
              else {
                     // should we engage?
                     PRUint8 *     pChar = m_pBuf;
                     PRUint32      len = m_pos;
                     while (len) {
                            if (!ImportCharSet::IsUSAscii( *pChar))
                                   break;
                            pChar++;
                            len--;
                     }
                     if (len) {
                            m_engaged = PR_TRUE;
                            if (m_supports8to7) {
                                   // allocate our translation output buffer and file...
                                   m_pTransBuf = new PRUint8[m_bufSz];
                                   m_pTransOut = new ImportOutFile( m_pFile, m_pTransBuf, m_bufSz);
                                   return( Flush());
                            }
                            else
                                   duddleyDoWrite = PR_TRUE;
                     }
                     else {
                            duddleyDoWrite = PR_TRUE;
                     }
              }
       }
       else
              duddleyDoWrite = PR_TRUE;

       if (duddleyDoWrite) {
              PRInt32 written = 0;
              nsresult rv = m_pFile->Write( (const char *)m_pBuf, (PRInt32)m_pos, &written);
              if (NS_FAILED( rv) || ((PRUint32)written != m_pos))
                     return( PR_FALSE);
              m_pos = 0;
       }
       
       return( PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool ImportOutFile::InitOutFile ( nsIFileSpec pFile,
PRUint32  bufSz = 4096 
)

Definition at line 141 of file ImportOutFile.cpp.

{
       if (!bufSz)
              bufSz = 32 * 1024;   
       if (!m_pBuf) {
              m_pBuf = new PRUint8[ bufSz];
       }
       
       // m_fH = UFile::CreateFile( oFile, kMacNoCreator, kMacTextFile);
       PRBool open = PR_FALSE;
       nsresult rv = pSpec->IsStreamOpen( &open);
       if (NS_FAILED( rv) || !open) {
              rv = pSpec->OpenStreamForWriting();
              if (NS_FAILED( rv)) {
                     IMPORT_LOG0( "Couldn't create outfile\n");
                     delete [] m_pBuf;
                     m_pBuf = nsnull;
                     return( PR_FALSE);
              }
       }
       m_pFile = pSpec;
       NS_ADDREF( m_pFile);
       m_ownsFileAndBuffer = PR_TRUE;
       m_pos = 0;
       m_bufSz = bufSz;

       return( PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ImportOutFile::InitOutFile ( nsIFileSpec pFile,
PRUint8 pBuf,
PRUint32  sz 
)

Definition at line 170 of file ImportOutFile.cpp.

Definition at line 95 of file ImportOutFile.cpp.

{
       if (!Flush())
              return( PR_FALSE);

       m_engaged = PR_FALSE;
       m_pTrans = pTrans;
       m_supports8to7 = pTrans->Supports8bitEncoding();


       return( PR_TRUE);
}

Here is the call graph for this function:

Definition at line 274 of file ImportOutFile.cpp.

{
       if (!Flush()) {
              return( PR_FALSE);
       }

       if (markerID < kMaxMarkers) {
              PRInt32 pos = 0;
              nsresult rv;
              if (m_pFile) {
                     rv = m_pFile->Tell( &pos);
                     if (NS_FAILED( rv)) {
                            IMPORT_LOG0( "*** Error, Tell failed on output stream\n");
                            return( PR_FALSE);
                     }
              }
              m_markers[markerID] = (PRUint32)pos + m_pos;
       }

       return( PR_TRUE);
}

Here is the call graph for this function:

Definition at line 112 of file ImportOutFile.h.

                                                    {
       if (m_pos == m_bufSz) {
              if (!Flush())
                     return( PR_FALSE);
       }
       *(m_pBuf + m_pos) = byte;
       m_pos++;
       return( PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool ImportOutFile::WriteData ( const PRUint8 pSrc,
PRUint32  len 
) [inline]

Definition at line 92 of file ImportOutFile.h.

                                                                          {
       while ((len + m_pos) > m_bufSz) {
              if ((m_bufSz - m_pos)) {
                     memcpy( m_pBuf + m_pos, pSrc, m_bufSz - m_pos);
                     len -= (m_bufSz - m_pos);
                     pSrc += (m_bufSz - m_pos);
                     m_pos = m_bufSz;
              }
              if (!Flush())
                     return( PR_FALSE);
       }
       
       if (len) {
              memcpy( m_pBuf + m_pos, pSrc, len);
              m_pos += len;
       }

       return( PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 59 of file ImportOutFile.h.

{ return( WriteStr( "\x0D\x0A")); }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool ImportOutFile::WriteStr ( const char *  pStr) [inline]

Definition at line 57 of file ImportOutFile.h.

{return( WriteU8NullTerm( (const PRUint8 *) pStr, PR_FALSE)); }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool ImportOutFile::WriteStrAtMarker ( int  markerID,
const char *  pStr 
)

Definition at line 302 of file ImportOutFile.cpp.

{
       if (markerID >= kMaxMarkers)
              return( PR_FALSE);

       if (!Flush())
              return( PR_FALSE);
       nsresult      rv;
       PRInt32              pos;
       rv = m_pFile->Tell( &pos);
       if (NS_FAILED( rv))
              return( PR_FALSE);
       rv = m_pFile->Seek( (PRInt32) m_markers[markerID]);
       if (NS_FAILED( rv))
              return( PR_FALSE);
       PRInt32 written;
       rv = m_pFile->Write( pStr, strlen( pStr), &written);
       if (NS_FAILED( rv))
              return( PR_FALSE);

       rv = m_pFile->Seek( pos);
       if (NS_FAILED( rv))
              return( PR_FALSE);

       return( PR_TRUE);
}

Here is the call graph for this function:

PRBool ImportOutFile::WriteU8NullTerm ( const PRUint8 pSrc,
PRBool  includeNull 
)

Definition at line 251 of file ImportOutFile.cpp.

{
       while (*pSrc) {
              if (m_pos >= m_bufSz) {
                     if (!Flush())
                            return( PR_FALSE);
              }
              *(m_pBuf + m_pos) = *pSrc;
              m_pos++;
              pSrc++;
       }
       if (includeNull) {
              if (m_pos >= m_bufSz) {
                     if (!Flush())
                            return( PR_FALSE);
              }
              *(m_pBuf + m_pos) = 0;
              m_pos++;
       }

       return( PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 77 of file ImportOutFile.h.

Definition at line 86 of file ImportOutFile.h.

Definition at line 82 of file ImportOutFile.h.

Definition at line 79 of file ImportOutFile.h.

Definition at line 76 of file ImportOutFile.h.

Definition at line 75 of file ImportOutFile.h.

Definition at line 78 of file ImportOutFile.h.

Definition at line 85 of file ImportOutFile.h.

Definition at line 89 of file ImportOutFile.h.

Definition at line 88 of file ImportOutFile.h.

Definition at line 87 of file ImportOutFile.h.


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