[Kst] [Bug 92112] bitfield selection for getdata

netterfield at astro.utoronto.ca netterfield at astro.utoronto.ca
Tue Oct 26 18:21:32 CEST 2004


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
        
http://bugs.kde.org/show_bug.cgi?id=92112        
netterfield astro utoronto ca changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From netterfield astro utoronto ca  2004-10-26 18:21 -------
CVS commit by netterfield: 

FEATURE: 92112

Feature added as requested.  The 'number of bits' field is optional.


  M +22 -5     getdata.c   1.17
  M +1 -0      getdata_struct.h   1.3


--- kdeextragear-2/kst/kst/datasources/dirfile/getdata.c  #1.16:1.17
 @ -190,11 +190,24  @ static void ParseMplex(char in_cols[15][
 /***************************************************************************/
 static void ParseBit(char in_cols[15][MAX_LINE_LENGTH],
+                     int n_cols,
                      struct BitEntryType *B,
                      int *error_code) {
+  int error = 0;
+  
   strcpy(B->field, in_cols[0]); /* field */
   strncpy(B->raw_field, in_cols[2], FIELD_LENGTH); /* field */
 
   B->bitnum=atoi(in_cols[3]);
-  if ((B->bitnum<0) || B->bitnum>31) {
+  if (n_cols>4) {
+    B->numbits=atoi(in_cols[4]);
+  } else {
+    B->numbits=1;
+  }
+  
+  if (B->numbits<1) error = 1;
+  if (B->bitnum<0) error = 1;
+  if (B->bitnum + B->numbits - 1 > 31) error = 1;
+  
+  if (error) {
     *error_code=GD_E_FORMAT;
     return;
 @ -329,5 +342,5  @ struct FormatType *GetFormat(const char 
         realloc(F->bitEntries,
                 F->n_bit*sizeof(struct BitEntryType));
-      ParseBit(in_cols, F->bitEntries+F->n_bit - 1,
+      ParseBit(in_cols, n_cols, F->bitEntries+F->n_bit - 1,
                   error_code); 
     } else {
 @ -1028,4 +1041,5  @ static int DoIfBit(struct FormatType *F,
   int spf;
   int ns;
+  int mask;
 
   /******* binary search for the field *******/
 @ -1059,6 +1073,9  @ static int DoIfBit(struct FormatType *F,
   }
 
+  if (B->numbits==32) mask = 0xffffffff;
+  else mask = (int)(pow(2,B->numbits)-0.9999);
+  
   for (i=0; i<*n_read; i++) {
-    tmpbuf[i] = (tmpbuf[i]>>B->bitnum) & 0x0001;
+    tmpbuf[i] = (tmpbuf[i]>>B->bitnum) & mask;
   }
 

--- kdeextragear-2/kst/kst/datasources/dirfile/getdata_struct.h  #1.2:1.3
 @ -58,4 +58,5  @ struct BitEntryType {
   char raw_field[FIELD_LENGTH+1];
   int bitnum;
+  int numbits;
 };



More information about the Kst mailing list