[Kstars-devel] KDE/kdeedu/kstars/kstars

Akarsh Simha akarshsimha at gmail.com
Thu Jun 11 09:06:16 CEST 2009


SVN commit 980107 by asimha:

+ Use the correct syntax of the byteswap macros defined in the
  standard include, byteswap.h

Many thanks to Mike Hore, who helped me find this mistake! This should
fix bug 195414 at least partially, although it still needs testing.

CCMAIL: kstars-devel at kde.org
CCBUG: 195414



 M  +6 -6      binfilehelper.cpp  
 M  +17 -17    data/tools/binfiletester.c  
 M  +16 -16    data/tools/nomadbinfiletester.c  
 M  +6 -6      data/tools/readnomadbindump.c  
 M  +18 -18    skycomponents/deepstarcomponent.cpp  
 M  +10 -10    skycomponents/starcomponent.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/binfilehelper.cpp #980106:980107
@@ -112,7 +112,7 @@
     preambleUpdated = true;    
     // Read the field descriptor table
     fread(&nfields, 2, 1, fileHandle);
-    if( byteswap ) bswap_16( nfields );
+    if( byteswap ) nfields = bswap_16( nfields );
     fields.clear();
     for(i = 0; i < nfields; ++i) {
         de = new dataElement;
@@ -120,7 +120,7 @@
             delete de;
             return ERR_FD_TRUNC;
         }
-        if( byteswap ) bswap_32( de->scale );
+        if( byteswap ) de->scale = bswap_32( de->scale );
         fields.append( de );
     }
 
@@ -135,7 +135,7 @@
 
     // Read the index table
     fread(&indexSize, 4, 1, fileHandle);
-    if( byteswap ) bswap_32( indexSize );
+    if( byteswap ) indexSize = bswap_32( indexSize );
 
     quint32 ID;
     quint32 offset;
@@ -156,7 +156,7 @@
             errorMessage.sprintf("Table truncated before expected! Read i = %d index entries so far", i);
             return ERR_INDEX_TRUNC;
         }
-        if( byteswap ) bswap_32( ID );
+        if( byteswap ) ID = bswap_32( ID );
         if(ID >= indexSize) {
             errorMessage.sprintf("ID %u is greater than the expected number of expected entries (%u)", ID, indexSize);
             return ERR_INDEX_BADID;
@@ -169,12 +169,12 @@
             errorMessage.sprintf("Table truncated before expected! Read i = %d index entries so far", i);
             return ERR_BADSEEK;
         }
-        if( byteswap ) bswap_32( offset );
+        if( byteswap ) offset = bswap_32( offset );
         if(!fread(&nrecs, 4, 1, fileHandle)) {
             errorMessage.sprintf("Table truncated before expected! Read i = %d index entries so far", i);
             return ERR_BADSEEK;
         }
-        if( byteswap ) bswap_32( nrecs );
+        if( byteswap ) nrecs = bswap_32( nrecs );
         if(prev_offset != 0 && prev_nrecs != (-prev_offset + offset)/recordSize) { 
             errorMessage.sprintf("Expected %u  = (%X - %x) / %x records, but found %u, in index entry %u", 
                                     (offset - prev_offset) / recordSize, offset, prev_offset, recordSize, prev_nrecs, i - 1);
--- trunk/KDE/kdeedu/kstars/kstars/data/tools/binfiletester.c #980106:980107
@@ -57,14 +57,14 @@
  * Does byteswapping for starData structures
  */
 void bswap_stardata( starData *stardata ) {
-    bswap_32( stardata->RA );
-    bswap_32( stardata->Dec );
-    bswap_32( stardata->dRA );
-    bswap_32( stardata->dDec );
-    bswap_32( stardata->parallax );
-    bswap_32( stardata->HD );
-    bswap_16( stardata->mag );
-    bswap_16( stardata->bv_index );
+    stardata->RA = bswap_32( stardata->RA );
+    stardata->Dec = bswap_32( stardata->Dec );
+    stardata->dRA = bswap_32( stardata->dRA );
+    stardata->dDec = bswap_32( stardata->dDec );
+    stardata->parallax = bswap_32( stardata->parallax );
+    stardata->HD = bswap_32( stardata->HD );
+    stardata->mag = bswap_16( stardata->mag );
+    stardata->bv_index = bswap_16( stardata->bv_index );
 }
 
 int verifyIndexValidity(FILE *f) {
@@ -91,7 +91,7 @@
             +nerr;
             break;
         }
-        if( byteswap ) bswap_32( trixel );
+        if( byteswap ) trixel = bswap_32( trixel );
         if(trixel >= ntrixels) {
             fprintf(stderr, "Trixel number %u is greater than the expected number of trixels %u\n", trixel, ntrixels);
             ++nerr;
@@ -103,9 +103,9 @@
 	  ++nerr;
         }
         fread(&offset, 4, 1, f);
-        if( byteswap ) bswap_32( offset );
+        if( byteswap ) offset = bswap_32( offset );
         fread(&nrecs, 4, 1, f);
-        if( byteswap ) bswap_32( nrecs );
+        if( byteswap ) nrecs = bswap_32( nrecs );
         if( prev_offset != 0 && prev_nrecs != (-prev_offset + offset)/sizeof(starData) ) { 
             fprintf( stderr, "Expected %u  = (%X - %x) / %d records, but found %u, in trixel %d\n", 
                      (offset - prev_offset) / sizeof( starData ), offset, prev_offset, sizeof( starData ), nrecs, trixel);
@@ -219,15 +219,15 @@
     offset = index_offset + trixel * INDEX_ENTRY_SIZE; // CAUTION: Change if the size of each entry in the index table changes
     fseek(f, offset, SEEK_SET);
     fread(&trix, 4, 1, f);
-    if( byteswap ) bswap_32( trix );
+    if( byteswap ) trix = bswap_32( trix );
     if(trix != trixel) {
         fprintf(stderr, "ERROR: Something fishy in the index. I guessed that %d would be here, but instead I find %d. Aborting.\n", trixel, trix);
         return;
     }
     fread(&offset, 4, 1, f);
-    if( byteswap ) bswap_32( offset );
+    if( byteswap ) offset = bswap_32( offset );
     fread(&nrecs, 4, 1, f);
-    if( byteswap ) bswap_32( nrecs );
+    if( byteswap ) nrecs = bswap_32( nrecs );
 
     if(fseek(f, offset, SEEK_SET)) {
         fprintf(stderr, "ERROR: Could not seek to position %X in the file. The file is either truncated or the indexes are bogus.\n", offset);
@@ -297,17 +297,17 @@
     fread(&version_no, 1, 1, f);
     fprintf( stdout, "File version number: %d\n", version_no );
     fread(&nfields, 2, 1, f);
-    if( byteswap ) bswap_16( nfields );
+    if( byteswap ) nfields = bswap_16( nfields );
     fprintf( stdout, "%d fields reported\n", nfields );
 
     for(i = 0; i < nfields; ++i) {
         fread(&(de[i]), sizeof(struct dataElement), 1, f);
-        if( byteswap ) bswap_32( de->scale );
+        if( byteswap ) de->scale = bswap_32( de->scale );
         displayDataElementDescription(&(de[i]));
     }
 
     fread(&ntrixels, 4, 1, f);
-    if( byteswap ) bswap_32( ntrixels );
+    if( byteswap ) ntrixels = bswap_32( ntrixels );
     fprintf( stdout, "Number of trixels reported = %d\n", ntrixels );
 
     return 1;
--- trunk/KDE/kdeedu/kstars/kstars/data/tools/nomadbinfiletester.c #980106:980107
@@ -26,7 +26,7 @@
 #include <math.h>
 #include <sys/types.h>
 #include <string.h>
-#include "byteswap.h"
+#include <byteswap.h>
 
 
 /*
@@ -52,12 +52,12 @@
  * Does byteswapping for deepStarData structures
  */
 void bswap_stardata( deepStarData *stardata ) {
-    bswap_32( stardata->RA );
-    bswap_32( stardata->Dec );
-    bswap_16( stardata->dRA );
-    bswap_16( stardata->dDec );
-    bswap_16( stardata->B );
-    bswap_16( stardata->V );
+    stardata->RA=bswap_32( stardata->RA );
+    stardata->Dec=bswap_32( stardata->Dec );
+    stardata->dRA=bswap_16( stardata->dRA );
+    stardata->dDec=bswap_16( stardata->dDec );
+    stardata->B=bswap_16( stardata->B );
+    stardata->V=bswap_16( stardata->V );
 }
 
 
@@ -85,7 +85,7 @@
             +nerr;
             break;
         }
-        if( byteswap ) bswap_32( trixel );
+        if( byteswap ) trixel=bswap_32( trixel );
         if(trixel >= ntrixels) {
             fprintf(stderr, "Trixel number %u is greater than the expected number of trixels %u\n", trixel, ntrixels);
             ++nerr;
@@ -97,9 +97,9 @@
             ++nerr;
         }
         fread(&offset, 4, 1, f);
-        if( byteswap ) bswap_32( offset );
+        if( byteswap ) offset = bswap_32( offset );
         fread(&nrecs, 4, 1, f);
-        if( byteswap ) bswap_32( nrecs );
+        if( byteswap ) nrecs = bswap_32( nrecs );
         if( prev_offset != 0 && prev_nrecs != (-prev_offset + offset)/sizeof(deepStarData) ) { 
             fprintf( stderr, "Expected %u  = (%X - %x) / 16 records, but found %u, in trixel %d\n", 
                      (offset - prev_offset) / 16, offset, prev_offset, nrecs, trixel );
@@ -220,15 +220,15 @@
     offset = index_offset + id * 8; // CAUTION: Change if the size of each entry in the index table changes
     fseek(f, offset, SEEK_SET);
     fread(&trix, 4, 1, f);
-    if( byteswap ) bswap_32( trix );
+    if( byteswap ) trix = bswap_32( trix );
     if(trix != id) {
         fprintf(stderr, "ERROR: Something fishy in the index. I guessed that %d would be here, but instead I find %d. Aborting.\n", id, trix);
         return;
     }
     fread(&offset, 4, 1, f);
-    if( byteswap ) bswap_32( offset );
+    if( byteswap ) offset = bswap_32( offset );
     fread(&nrecs, 4, 1, f);
-    if( byteswap ) bswap_32( nrecs );
+    if( byteswap ) nrecs = bswap_32( nrecs );
 
     if(fseek(f, offset, SEEK_SET)) {
         fprintf(stderr, "ERROR: Could not seek to position %X in the file. The file is either truncated or the indexes are bogus.\n", offset);
@@ -293,17 +293,17 @@
     fprintf( stdout, "Version number: %d\n", version_no );
 
     fread(&nfields, 2, 1, f);
-    if( byteswap ) bswap_16( nfields );
+    if( byteswap ) nfields = bswap_16( nfields );
     fprintf( stdout, "%d fields reported\n", nfields );
 
     for(i = 0; i < nfields; ++i) {
         fread(&(de[i]), sizeof(struct dataElement), 1, f);
-        if( byteswap ) bswap_32( de->scale );
+        if( byteswap ) de->scale = bswap_32( de->scale );
         displayDataElementDescription(&(de[i]));
     }
 
     fread(&ntrixels, 4, 1, f);
-    if( byteswap ) bswap_32( ntrixels );
+    if( byteswap ) ntrixels = bswap_32( ntrixels );
     fprintf( stdout, "Number of trixels reported = %d\n", ntrixels );
 
     return 1;
--- trunk/KDE/kdeedu/kstars/kstars/data/tools/readnomadbindump.c #980106:980107
@@ -45,12 +45,12 @@
  * Does byteswapping for deepStarData structures
  */
 void bswap_stardata( deepStarData *stardata ) {
-    bswap_32( stardata->RA );
-    bswap_32( stardata->Dec );
-    bswap_16( stardata->dRA );
-    bswap_16( stardata->dDec );
-    bswap_16( stardata->B );
-    bswap_16( stardata->V );
+    stardata->RA = bswap_32( stardata->RA );
+    stardata->Dec = bswap_32( stardata->Dec );
+    stardata->dRA = bswap_16( stardata->dRA );
+    stardata->dDec = bswap_16( stardata->dDec );
+    stardata->B = bswap_16( stardata->B );
+    stardata->V = bswap_16( stardata->V );
 }
 
 int main(int argc, char *argv[]) {
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepstarcomponent.cpp #980106:980107
@@ -77,11 +77,11 @@
 
     fread( &faintmag, 2, 1, dataFile );
     if( starReader.getByteSwap() )
-        bswap_16( faintmag );
+        faintmag = bswap_16( faintmag );
     fread( &htm_level, 1, 1, dataFile );
     fread( &t_MSpT, 2, 1, dataFile ); // Unused
     if( starReader.getByteSwap() )
-        bswap_16( faintmag );
+        faintmag = bswap_16( faintmag );
 
 
     // TODO: Read the multiplying factor from the dataFile
@@ -336,7 +336,7 @@
         quint8 htm_level;
         fread( &faintmag, 2, 1, starReader.getFileHandle() );
         if( starReader.getByteSwap() )
-            bswap_16( faintmag );
+            faintmag = bswap_16( faintmag );
         if( starReader.guessRecordSize() == 16 )
             m_FaintMagnitude = faintmag / 1000.0;
         else
@@ -353,7 +353,7 @@
         meshLevel = htm_level;
         fread( &MSpT, 2, 1, starReader.getFileHandle() );
         if( starReader.getByteSwap() )
-            bswap_16( MSpT );
+            MSpT = bswap_16( MSpT );
         fileOpened = true;
         kDebug() << "  Sky Mesh Size: " << m_skyMesh->size();
         for (long int i = 0; i < m_skyMesh->size(); i++) {
@@ -431,23 +431,23 @@
 }
 
 void DeepStarComponent::byteSwap( deepStarData *stardata ) {
-    bswap_32( stardata->RA );
-    bswap_32( stardata->Dec );
-    bswap_16( stardata->dRA );
-    bswap_16( stardata->dDec );
-    bswap_16( stardata->B );
-    bswap_16( stardata->V );
+    stardata->RA = bswap_32( stardata->RA );
+    stardata->Dec = bswap_32( stardata->Dec );
+    stardata->dRA = bswap_16( stardata->dRA );
+    stardata->dDec = bswap_16( stardata->dDec );
+    stardata->B = bswap_16( stardata->B );
+    stardata->V = bswap_16( stardata->V );
 }
 
 void DeepStarComponent::byteSwap( starData *stardata ) {
-    bswap_32( stardata->RA );
-    bswap_32( stardata->Dec );
-    bswap_32( stardata->dRA );
-    bswap_32( stardata->dDec );
-    bswap_32( stardata->parallax );
-    bswap_32( stardata->HD );
-    bswap_16( stardata->mag );
-    bswap_16( stardata->bv_index );
+    stardata->RA = bswap_32( stardata->RA );
+    stardata->Dec = bswap_32( stardata->Dec );
+    stardata->dRA = bswap_32( stardata->dRA );
+    stardata->dDec = bswap_32( stardata->dDec );
+    stardata->parallax = bswap_32( stardata->parallax );
+    stardata->HD = bswap_32( stardata->HD );
+    stardata->mag = bswap_16( stardata->mag );
+    stardata->bv_index = bswap_16( stardata->bv_index );
 }
 
 bool DeepStarComponent::verifySBLIntegrity() {
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.cpp #980106:980107
@@ -458,11 +458,11 @@
 
     fread( &faintmag, 2, 1, dataFile );
     if( swapBytes )
-        bswap_16( faintmag );
+        faintmag = bswap_16( faintmag );
     fread( &htm_level, 1, 1, dataFile );
     fread( &t_MSpT, 2, 1, dataFile ); // Unused
     if( swapBytes )
-        bswap_16( faintmag );
+        faintmag = bswap_16( faintmag );
 
 
     if( faintmag / 100.0 > m_FaintMagnitude )
@@ -653,14 +653,14 @@
 }
 
 void StarComponent::byteSwap( starData *stardata ) {
-    bswap_32( stardata->RA );
-    bswap_32( stardata->Dec );
-    bswap_32( stardata->dRA );
-    bswap_32( stardata->dDec );
-    bswap_32( stardata->parallax );
-    bswap_32( stardata->HD );
-    bswap_16( stardata->mag );
-    bswap_16( stardata->bv_index );
+    stardata->RA = bswap_32( stardata->RA );
+    stardata->Dec = bswap_32( stardata->Dec );
+    stardata->dRA = bswap_32( stardata->dRA );
+    stardata->dDec = bswap_32( stardata->dDec );
+    stardata->parallax = bswap_32( stardata->parallax );
+    stardata->HD = bswap_32( stardata->HD );
+    stardata->mag = bswap_16( stardata->mag );
+    stardata->bv_index = bswap_16( stardata->bv_index );
 }
 /*
 void StarComponent::printDebugInfo() {


More information about the Kstars-devel mailing list