[Kst] getdata patch

Matthew D Truch matt at truch.net
Tue Jan 10 19:50:06 CET 2006


On Fri, Jan 06, 2006 at 05:49:05PM -0500, Barth Netterfield wrote:
> 
> OK.  Lets stick with evolutionary changes as things have been going.

So, back to my original question, then.  Comments on the patch (coding
style/direction/worthiness/etc.)  I've attached it again for your
convenience.  

-- 
"I think better with a glass of beer in front of me; two heads are better than one!"
--------------------------
Matthew Truch
Department of Physics
Brown University
matt at truch.net
http://matt.truch.net/
-------------- next part --------------
Index: kst/kst/datasources/dirfile/getdata.h
===================================================================
--- kst/kst/datasources/dirfile/getdata.h	(revision 494990)
+++ kst/kst/datasources/dirfile/getdata.h	(working copy)
@@ -75,4 +75,14 @@
 #endif
 struct FormatType *GetFormat(const char *filedir, int *error_code);
 
+/***************************************************************************/
+/*                                                                         */
+/*    Close all open file descriptors for a given dirfile                  */
+/*                                                                         */
+/***************************************************************************/
+#ifdef __cplusplus
+extern "C"
 #endif
+int GetDataClose(const char *filename_in, int *error_code);
+
+#endif
Index: kst/kst/datasources/dirfile/getdata.c
===================================================================
--- kst/kst/datasources/dirfile/getdata.c	(revision 494990)
+++ kst/kst/datasources/dirfile/getdata.c	(working copy)
@@ -1850,5 +1850,49 @@
 
   return GetSPF(field_name, F, error_code);
 }
+
+/***************************************************************************/
+/*                                                                         */
+/*    Close all the open file descriptors for raw fields in a dirfile      */
+/*    Returns the number of files closed and sets error_code as appropriate*/
+/*                                                                         */
+/***************************************************************************/
+int GetDataClose(const char *filename_in, int *error_code) {
+  struct FormatType *F;
+  char filename[MAX_FILENAME_LENGTH+1];
+  int i;
+  int n_closed;
+
+  *error_code = GD_E_OK;
+  n_closed = 0;
+
+  if (first_time) {
+    Formats.n = 0;
+    Formats.F = NULL;
+    first_time = 0;
+    return n_closed;
+  }
+  
+  strncpy(filename, filename_in, MAX_FILENAME_LENGTH);
+  if (filename[strlen(filename)-1]=='/') filename[strlen(filename)-1]='\0';
+  F = GetFormat(filename, error_code);
+  if (*error_code!=GD_E_OK) {
+    return n_closed;
+  }
+  
+  if (!F || F->n_raw==0) {
+    *error_code = GD_E_FORMAT;
+    return n_closed;
+  }
+
+  for (i = 0; i < F->n_raw; i++) {
+    if (close(F->rawEntries[i].fp) == 0)
+      n_closed++;
+    F->rawEntries[i].fp = -1;
+  }
+  
+  return n_closed;
+}
+
 /* vim: ts=2 sw=2 et
 */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kst/attachments/20060110/523f76f6/attachment.pgp 


More information about the Kst mailing list