[Kst] extragear/graphics/kst/kst/datasources/dirfile

Matthew D Truch matt at truch.net
Wed Nov 16 03:37:48 CET 2005


SVN commit 480677 by truch:

Apply the patch to fix the 'getdata borked' bug for now.  

BUG: 116461


 M  +19 -23    getdata.c  
 M  +1 -0      getdata_struct.h  


--- trunk/extragear/graphics/kst/kst/datasources/dirfile/getdata.c #480676:480677
@@ -287,13 +287,15 @@
 /*                                                                         */
 /***************************************************************************/
 struct FormatType *GetFormat(const char *filedir, int *error_code) {
-  int i_format;
+  int i_format, i;
+  struct stat statbuf;
   FILE *fp;
   char format_file[MAX_FILENAME_LENGTH+6];
   char instring[MAX_LINE_LENGTH];
   struct FormatType *F;
   char in_cols[MAX_IN_COLS][MAX_LINE_LENGTH];
   int n_cols;
+  char raw_data_filename[MAX_FILENAME_LENGTH+FIELD_LENGTH+2];
 
   /** first check to see if we have already read it **/
   for (i_format=0; i_format<Formats.n; i_format++) {
@@ -312,7 +314,7 @@
   F = Formats.F+Formats.n-1;
 
   /***** open the format file (if there is one) ******/
-  sprintf(format_file,"%s/format", filedir);
+  snprintf(format_file, MAX_FILENAME_LENGTH+6, "%s/format", filedir);
   fp = fopen(format_file, "r");
   if (fp == NULL) {
     *error_code = GD_E_OPEN_FORMAT;
@@ -406,6 +408,15 @@
   }
   /** Now sort the lists */
   if (F->n_raw > 1) {
+    for (i=0; i<F->n_raw; i++) {
+      snprintf(raw_data_filename, MAX_FILENAME_LENGTH+FIELD_LENGTH+2, 
+          "%s/%s", filedir, F->rawEntries[i].field);
+      if (stat(raw_data_filename, &statbuf) >=0) {
+        F->first_field = F->rawEntries[i];
+        break;
+      }
+    }
+
     qsort(F->rawEntries, F->n_raw, sizeof(struct RawEntryType),
         RawCmp);
   }
@@ -891,7 +902,8 @@
 
   /** open the file (and cache the fp) if it hasn't been opened yet. */
   if (R->fp <0) {
-    sprintf(datafilename, "%s/%s", F->FileDirName, field_code);
+    snprintf(datafilename, MAX_FILENAME_LENGTH+FIELD_LENGTH + 1, 
+        "%s/%s", F->FileDirName, field_code);
     R->fp = open(datafilename, O_RDONLY);
     if (R->fp<0) {
       *n_read = 0;
@@ -1682,9 +1694,6 @@
   char raw_data_filename[MAX_FILENAME_LENGTH+FIELD_LENGTH+2];
   struct stat statbuf;
   int nf;
-  char field_buf[80];
-  const char *field;
-  int i;
 
   *error_code = GD_E_OK;
 
@@ -1706,28 +1715,15 @@
     return(0);
   }
 
-  if (in_field == NULL) {
-    /* check for first valid raw field */
-    for (i=0; i<F->n_raw; i++) {
-      sprintf(raw_data_filename,"%s/%s", filename, F->rawEntries[i].field);
-      if (stat(raw_data_filename, &statbuf) >=0) {
-        strncpy(field_buf, F->rawEntries[i].field, 79);
-        i = F->n_raw;
-      }
-    }
-    field = field_buf;
-  } else {
-    field = in_field;
-  }
-
-  sprintf(raw_data_filename,"%s/%s", filename, field);
+  /* load the first valid raw field */
+  snprintf(raw_data_filename, MAX_FILENAME_LENGTH+FIELD_LENGTH+2, 
+      "%s/%s", filename, F->first_field.field);
   if (stat(raw_data_filename, &statbuf) < 0) {
     return(0);
   }
 
   nf = statbuf.st_size/
-    (F->rawEntries[0].size*F->rawEntries[0].samples_per_frame);
-
+    (F->first_field.size*F->first_field.samples_per_frame);
   nf += F->frame_offset;
 
   nf -= 2;
--- trunk/extragear/graphics/kst/kst/datasources/dirfile/getdata_struct.h #480676:480677
@@ -69,6 +69,7 @@
 struct FormatType {
   char FileDirName[MAX_FILENAME_LENGTH];
   int frame_offset;
+  struct RawEntryType first_field;
   struct RawEntryType *rawEntries;
   int n_raw;
   struct LincomEntryType *lincomEntries;


More information about the Kst mailing list