Bug 92112 - bitfield selection for getdata
Summary: bitfield selection for getdata
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: Slackware Linux
: NOR wishlist
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-26 05:53 UTC by D. V. Wiebe
Modified: 2004-10-26 18:21 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description D. V. Wiebe 2004-10-26 05:53:06 UTC
Version:           1.0.0_devel (using KDE KDE 3.3.1)
Installed from:    Slackware Packages
Compiler:          gcc (GCC) 3.3.4 
OS:                Linux

As an extension to the BIT derived type, it would be nice to be able to have a derived getdata type that would retrieve a bitfield range from another field.  So, I could extract a 3 bit number starting at bit 5 of an input field by specifying

3_BIT_NUMBER     BITFIELD input_field 5 3

or something similar to the format file.  Currently I'm implementing this through a combination of BIT and LINCOM derived fields.

Similar to C's bitfield struct.
Comment 1 Netterfield 2004-10-26 18:21:30 UTC
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;
 };