Changeset 13518


Ignore:
Timestamp:
2006-12-15T12:19:11+13:00 (16 years ago)
Author:
mdewsnip
Message:

Running this on a big-endian machine would fail to read little-endian CDS/ISIS files. I've assumed most (all?) CDS/ISIS files are little-endian, and added code to convert the values into the right endianness on big-endian machines.

Location:
trunk/gsdl/packages/isis-gdl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/packages/isis-gdl/Compat.h

    r6127 r13518  
    104104#define MoveMemory memmove
    105105#define ZeroMemory(p,size) memset(p,0,size)
     106
     107
     108inline void fix_endianness(short int& x)
     109{
     110#if !defined(LITTLE_ENDIAN)
     111  if (x < 0) {
     112    unsigned short int ux = (unsigned short int) x;
     113    x = (ux>>8) |
     114        (ux<<8);
     115  }
     116  else {
     117    x = (x>>8) |
     118        (x<<8);
     119  }
     120#endif
     121}
     122
     123inline void fix_endianness(long int& x)
     124{
     125#if !defined(LITTLE_ENDIAN)
     126  if (x < 0) {
     127    unsigned long ux = (unsigned long) x;
     128    x = (ux>>24) |
     129      ((ux<<8) & 0x00FF0000) |
     130      ((ux>>8) & 0x0000FF00) |
     131      (ux<<24);
     132  }
     133  else {
     134    x = (x>>24) |
     135      ((x<<8) & 0x00FF0000) |
     136      ((x>>8) & 0x0000FF00) |
     137      (x<<24);
     138  }
     139#endif
     140}
  • trunk/gsdl/packages/isis-gdl/MFFile.h

    r6127 r13518  
    250250 
    251251//////////////////////////////
    252  
     252
    253253inline void MfFile::ReadMfHdr()
    254254//  Reads the master file header record
     
    257257   TRACE(_T("\nsizeof(SMfHeader)=%d"), sizeof(SMfHeader));
    258258   ::MoveMemory(&mfh_, buf_, sizeof(SMfHeader));
     259
     260   fix_endianness(mfh_.ctlmfn_);
     261   fix_endianness(mfh_.nxtmfn_);
     262   fix_endianness(mfh_.nxtmfb_);
     263   fix_endianness(mfh_.nxtmfp_);
     264   fix_endianness(mfh_.mftype_);
     265   fix_endianness(mfh_.reccnt_);
     266   fix_endianness(mfh_.mfcxx1_);
     267   fix_endianness(mfh_.mfcxx2_);
     268   fix_endianness(mfh_.mfcxx3_);
    259269}
    260270 
     
    279289   ReadBlk(buf_, 1L);
    280290   ::MoveMemory(&h, buf_, sizeof(SMfHeader));
     291
     292   fix_endianness(h.ctlmfn_);
     293   fix_endianness(h.nxtmfn_);
     294   fix_endianness(h.nxtmfb_);
     295   fix_endianness(h.nxtmfp_);
     296   fix_endianness(h.mftype_);
     297   fix_endianness(h.reccnt_);
     298   fix_endianness(h.mfcxx1_);
     299   fix_endianness(h.mfcxx2_);
     300   fix_endianness(h.mfcxx3_);
    281301}
    282302 
  • trunk/gsdl/packages/isis-gdl/Master.cpp

    r7135 r13518  
    161161        s.read((char *) &leader_directory.status_, sizeof(ISIS_INT));
    162162
     163        fix_endianness(leader_directory.mfn_);
     164        fix_endianness(leader_directory.mfrl_);
     165        fix_endianness(leader_directory.mfbwb_);
     166        fix_endianness(leader_directory.mfbwp_);
     167        fix_endianness(leader_directory.base_);
     168        fix_endianness(leader_directory.nvf_);
     169        fix_endianness(leader_directory.status_);
     170
    163171        if (!leader_directory.dir_.empty())
    164172            leader_directory.dir_.clear();
     
    174182                DirEntry de;
    175183                s.read((char *) &de, GetDirEntrySize());
     184                fix_endianness(de.tag_);
     185                fix_endianness(de.pos_);
     186                fix_endianness(de.len_);
    176187                // Don't check integrity of directory entries here
    177188                leader_directory.dir_.push_back(de);
     
    714725    leader_directory_.mfn_  = *(reinterpret_cast<ISIS_LONG*>((char *) record_.c_str()));
    715726    leader_directory_.mfrl_ = *(reinterpret_cast<ISIS_INT*> ((char *)(record_.c_str()+sizeof(ISIS_LONG))));
     727    fix_endianness(leader_directory_.mfn_);
     728    fix_endianness(leader_directory_.mfrl_);
    716729    if (leader_directory_.mfrl_ < 0) leader_directory_.mfrl_ = -leader_directory_.mfrl_;    // mfrl can be negative!!!!
    717730
  • trunk/gsdl/packages/isis-gdl/XRFFile.cpp

    r12714 r13518  
    151151void XrfFile::UnPack(void)
    152152{
     153   fix_endianness(xrf_->xrfpos_);
     154
    153155   xrfa_->xrfpos_ = xrf_->xrfpos_;
    154156   if (xrfa_->xrfpos_ < 0)
     
    163165   {
    164166      long j = xrf_->xrftiv_[i];             // Packed value
     167      fix_endianness(j);
    165168      bool b = (j < 0);
    166169      if (b)
Note: See TracChangeset for help on using the changeset viewer.