Back to index

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

#include <nsImportEncodeScan.h>

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

List of all members.

Public Member Functions

 nsImportEncodeScan ()
 ~nsImportEncodeScan ()
PRBool InitEncodeScan (PRBool appleSingleEncode, nsIFileSpec *pSpec, const char *pName, PRUint8 *pBuf, PRUint32 sz)
void CleanUpEncodeScan (void)
virtual PRBool Scan (PRBool *pDone)
void InitScan (nsIFileSpec *pSpec, PRUint8 *pBuf, PRUint32 sz)
PRBool OpenScan (nsIFileSpec *pSpec, PRUint32 bufSz=4096)
void CleanUpScan (void)

Protected Member Functions

void FillInEntries (int numEntries)
PRBool AddEntries (void)
void ShiftBuffer (void)
PRBool FillBufferFromFile (void)
virtual PRBool ScanBuffer (PRBool *pDone)

Protected Attributes

PRBool m_isAppleSingle
nsIFileSpecm_pInputFile
int m_encodeScanState
long m_resourceForkSize
long m_dataForkSize
nsCString m_useFileName
nsIFileSpecm_pFile
PRUint8m_pBuf
PRUint32 m_bufSz
PRUint32 m_bytesInBuf
PRUint32 m_pos
PRBool m_eof
PRBool m_allocated

Detailed Description

Definition at line 45 of file nsImportEncodeScan.h.


Constructor & Destructor Documentation

Definition at line 101 of file nsImportEncodeScan.cpp.


Member Function Documentation

Definition at line 219 of file nsImportEncodeScan.cpp.

{
#ifdef _MAC_IMPORT_CODE
       if (!g2000Secs) {
              g2000Secs = Get2000Secs();
              gGMTDelta = GetGmtDelta();
       }
       MemCpy( m_pBuf + m_bytesInBuf, (PC_S8) m_useFileName, m_useFileName.GetLength());
       m_bytesInBuf += m_useFileName.GetLength();              
       if (m_useFileName.GetLength() < 32) {
              int len = m_useFileName.GetLength();
              while (len < 32) {
                     *((P_S8)m_pBuf + m_bytesInBuf) = 0;
                     m_bytesInBuf++;
                     len++;
              }
       }
       
       Str255 comment;
       comment[0] = 0;
       OSErr err = FSpDTGetComment( m_inputFileLoc, comment);
       comment[0] = 200;
       MemCpy( m_pBuf + m_bytesInBuf, &(comment[1]), comment[0]);
       m_bytesInBuf += comment[0];
       
       long   dates[4];
       dates[0] = gCatInfoPB.hFileInfo.ioFlCrDat;
       dates[1] = gCatInfoPB.hFileInfo.ioFlMdDat;
       dates[2] = gCatInfoPB.hFileInfo.ioFlBkDat;
       dates[3] = 0x80000000;
       for (short i = 0; i < 3; i++) {
              dates[i] -= g2000Secs;
              dates[i] += gGMTDelta;
       }
       MemCpy( m_pBuf + m_bytesInBuf, dates, 16);
       m_bytesInBuf += 16;
       
       
       FInfo  fInfo = gCatInfoPB.hFileInfo.ioFlFndrInfo;
       FXInfo fxInfo = gCatInfoPB.hFileInfo.ioFlXFndrInfo;
       fInfo.fdFlags = 0;
       fInfo.fdLocation.h = 0;
       fInfo.fdLocation.v = 0;
       fInfo.fdFldr = 0;
       MemSet( &fxInfo, 0, sizeof( fxInfo));
       MemCpy( m_pBuf + m_bytesInBuf, &fInfo, 16);
       m_bytesInBuf += 16;
       MemCpy( m_pBuf + m_bytesInBuf, &fxInfo, 16);
       m_bytesInBuf += 16;
       
       
       dates[0] = 0;
       if ((gCatInfoPB.hFileInfo.ioFlAttrib & 1) != 0)
              dates[0] |= 1;
       MemCpy( m_pBuf + m_bytesInBuf, dates, 4);
       m_bytesInBuf += 4;
       
       
#endif
       return( PR_TRUE);
}

Here is the caller graph for this function:

Definition at line 138 of file nsImportEncodeScan.cpp.

Here is the caller graph for this function:

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 nsImportEncodeScan::FillInEntries ( int  numEntries) [protected]

Definition at line 147 of file nsImportEncodeScan.cpp.

{
#ifdef _MAC_IMPORT_CODE
       int           len = m_useFileName.GetLength();
       if (len < 32)
              len = 32;
       long   entry[3];
       long   fileOffset = 26 + (12 * numEntries);
       entry[0] = 3;
       entry[1] = fileOffset;
       entry[2] = m_useFileName.GetLength();
       fileOffset += len;
       MemCpy( m_pBuf + m_bytesInBuf, entry, 12);
       m_bytesInBuf += 12;         
       
       
       Str255 comment;
       comment[0] = 0;
       OSErr err = FSpDTGetComment( m_inputFileLoc, comment);
       if (comment[0] > 200)
              comment[0] = 200;
       entry[0] = 4;
       entry[1] = fileOffset;
       entry[2] = comment[0];
       fileOffset += 200;
       MemCpy( m_pBuf + m_bytesInBuf, entry, 12);
       m_bytesInBuf += 12;         
       
       
       entry[0] = 8;
       entry[1] = fileOffset;
       entry[2] = 16;
       fileOffset += 16;
       MemCpy( m_pBuf + m_bytesInBuf, entry, 12);
       m_bytesInBuf += 12;         
       
       entry[0] = 9;
       entry[1] = fileOffset;
       entry[2] = 32;
       fileOffset += 32;
       MemCpy( m_pBuf + m_bytesInBuf, entry, 12);
       m_bytesInBuf += 12;         

       
       entry[0] = 10;
       entry[1] = fileOffset;
       entry[2] = 4;
       fileOffset += 4;
       MemCpy( m_pBuf + m_bytesInBuf, entry, 12);
       m_bytesInBuf += 12;
       
       if (m_resourceForkSize) {
              entry[0] = 2;
              entry[1] = fileOffset;
              entry[2] = m_resourceForkSize;
              fileOffset += m_resourceForkSize;
              MemCpy( m_pBuf + m_bytesInBuf, entry, 12);
              m_bytesInBuf += 12;         
       }
       
       if (m_dataForkSize) {
              entry[0] = 1;
              entry[1] = fileOffset;
              entry[2] = m_dataForkSize;
              fileOffset += m_dataForkSize;
              MemCpy( m_pBuf + m_bytesInBuf, entry, 12);
              m_bytesInBuf += 12;
       }
       
#endif        
}

Here is the caller graph for this function:

PRBool nsImportEncodeScan::InitEncodeScan ( PRBool  appleSingleEncode,
nsIFileSpec pSpec,
const char *  pName,
PRUint8 pBuf,
PRUint32  sz 
)

Definition at line 106 of file nsImportEncodeScan.cpp.

{
       CleanUpEncodeScan();
       m_isAppleSingle = appleSingleEncode;
       m_encodeScanState = kBeginAppleSingle;
       m_pInputFile = fileLoc;
       NS_IF_ADDREF( m_pInputFile);
       m_useFileName = pName;
       m_pBuf = pBuf;
       m_bufSz = sz;
       if (!m_isAppleSingle) {
              PRBool open = PR_FALSE;
              nsresult rv = m_pInputFile->IsStreamOpen( &open);
              if (NS_FAILED( rv) || !open) {
                     rv = m_pInputFile->OpenStreamForReading();
                     if (NS_FAILED( rv))
                            return( PR_FALSE);
              }

              InitScan( m_pInputFile, pBuf, sz);
       }
       else {
       #ifdef _MAC_IMPORT_CODE
              // Fill in the file sizes
              m_resourceForkSize = fileLoc.GetMacFileSize( UFileLocation::eResourceFork);
              m_dataForkSize = fileLoc.GetMacFileSize( UFileLocation::eDataFork);
       #endif
       }

       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);
}
PRBool nsImportEncodeScan::Scan ( PRBool pDone) [virtual]

Reimplemented from nsImportScanFile.

Definition at line 281 of file nsImportEncodeScan.cpp.

{
       nsresult      rv;

       *pDone = PR_FALSE;
       if (m_isAppleSingle) {
              // Stuff the buffer with things needed to encode the file...
              // then just allow UScanFile to handle each fork, but be careful
              // when handling eof.
              switch( m_encodeScanState) {
                     case kBeginAppleSingle: {
                            #ifdef _MAC_IMPORT_CODE
                            OSErr err = GetCatInfoNoName( m_inputFileLoc.GetVRefNum(), m_inputFileLoc.GetParID(), m_inputFileLoc.GetFileNamePtr(), &gCatInfoPB);
                            if (err != noErr)
                                   return( FALSE);
                            #endif
                            m_eof = PR_FALSE;
                            m_pos = 0;
                            memcpy( m_pBuf, gAppleSingleHeader, kAppleSingleHeaderSize);
                            m_bytesInBuf = kAppleSingleHeaderSize;
                            int numEntries = 5;
                            if (m_dataForkSize)
                                   numEntries++;
                            if (m_resourceForkSize)
                                   numEntries++;
                            memcpy( m_pBuf + m_bytesInBuf, &numEntries, sizeof( numEntries));
                            m_bytesInBuf += sizeof( numEntries);
                            FillInEntries( numEntries);
                            m_encodeScanState = kAddEntries;
                            return( ScanBuffer( pDone));
                     }
                     break;
                     
                     case kBeginDataFork: {
                            if (!m_dataForkSize) {
                                   m_encodeScanState = kDoneWithFile;
                                   return( PR_TRUE);
                            }
                            // Initialize the scan of the data fork...
                            PRBool open = PR_FALSE;
                            rv = m_pInputFile->IsStreamOpen( &open);
                            if (!open)
                                   rv = m_pInputFile->OpenStreamForReading();
                            if (NS_FAILED( rv))
                                   return( PR_FALSE);   
                            m_encodeScanState = kScanningDataFork;
                            return( PR_TRUE);
                     }
                     break;
                     
                     case kScanningDataFork: {
                            PRBool result = FillBufferFromFile();
                            if (!result)
                                   return( PR_FALSE);
                            if (m_eof) {
                                   m_eof = PR_FALSE;
                                   result = ScanBuffer( pDone);
                                   if (!result)
                                          return( PR_FALSE);
                                   m_pInputFile->CloseStream();
                                   m_encodeScanState = kDoneWithFile;
                                   return( PR_TRUE);
                            }
                            else
                                   return( ScanBuffer( pDone));
                     }
                     break;
                     
                     case kScanningRsrcFork: {
                            PRBool result = FillBufferFromFile();
                            if (!result)
                                   return( PR_FALSE);
                            if (m_eof) {
                                   m_eof = PR_FALSE;
                                   result = ScanBuffer( pDone);
                                   if (!result)
                                          return( PR_FALSE);
                                   m_pInputFile->CloseStream();
                                   m_encodeScanState = kBeginDataFork;
                                   return( PR_TRUE);
                            }
                            else
                                   return( ScanBuffer( pDone));
                     }
                     break;
                     
                     case kBeginResourceFork: {
                            if (!m_resourceForkSize) {
                                   m_encodeScanState = kBeginDataFork;
                                   return( PR_TRUE);
                            }
                            /*
                            // FIXME: Open the resource fork on the Mac!!!
                            m_fH = UFile::OpenRsrcFileRead( m_inputFileLoc);
                            if (m_fH == TR_FILE_ERROR)
                                   return( FALSE);      
                            */
                            m_encodeScanState = kScanningRsrcFork;
                            return( PR_TRUE);
                     }
                     break;
                     
                     case kAddEntries: {
                            ShiftBuffer();
                            if (!AddEntries())
                                   return( PR_FALSE);
                            m_encodeScanState = kBeginResourceFork;
                            return( ScanBuffer( pDone));
                     }
                     break;
                     
                     case kDoneWithFile: {
                            ShiftBuffer();
                            m_eof = PR_TRUE;
                            if (!ScanBuffer( pDone))
                                   return( PR_FALSE);
                            *pDone = PR_TRUE;
                            return( PR_TRUE);
                     }
                     break;
              }
              
       }
       else
              return( nsImportScanFile::Scan( pDone));
              
       return( PR_FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsImportScanFile::ScanBuffer ( PRBool pDone) [protected, virtual, inherited]

Reimplemented in nsImportScanFileLines, and nsImportMimeEncode.

Definition at line 189 of file nsImportScanFile.cpp.

{
       return( PR_TRUE);
}

Here is the caller 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.

Definition at line 64 of file nsImportEncodeScan.h.

Definition at line 62 of file nsImportEncodeScan.h.

PRBool nsImportScanFile::m_eof [protected, inherited]

Definition at line 67 of file nsImportScanFile.h.

Definition at line 60 of file nsImportEncodeScan.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.

Definition at line 61 of file nsImportEncodeScan.h.

PRUint32 nsImportScanFile::m_pos [protected, inherited]

Definition at line 66 of file nsImportScanFile.h.

Definition at line 63 of file nsImportEncodeScan.h.

Definition at line 65 of file nsImportEncodeScan.h.


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