r3867 - in branches/beast-mingw: . sfi



Author: stw
Date: 2006-08-24 15:30:59 -0400 (Thu, 24 Aug 2006)
New Revision: 3867

Modified:
   branches/beast-mingw/ChangeLog.win32
   branches/beast-mingw/WIN32todo
   branches/beast-mingw/sfi/sficomport.c
   branches/beast-mingw/sfi/sficomwire.c
   branches/beast-mingw/sfi/sfidl-corec.cc
   branches/beast-mingw/sfi/sfidl-corecxx.cc
   branches/beast-mingw/sfi/sfidl-hostc.cc
   branches/beast-mingw/sfi/sfifilecrawler.c
   branches/beast-mingw/sfi/sfistore.c
   branches/beast-mingw/sfi/sfitime.c
   branches/beast-mingw/sfi/testsfi.c
Log:
Thu Aug 24 20:24:17 2006  Stefan Westerfeld  <stefan space twc de>

	* sfi/sficomport.c:
	* sfi/sficomwire.c: I didn't port these two yet, thus there is lots of
	code which I just disabled with #if 0... -

	* sfi/sfidl-hostc.cc:
	* sfi/sfidl-corec.cc: Use g_strescape to escape the filenames printed
	as #line directives (otherwise, the compiler will complain about paths
	like "E:\msys\1.0\home\stefan\foo.idl", trying to interpret \m and so
	forth as special characters)

	* sfi/sfidl-corecxx.cc: Escape path names for gdk-pixbuf-csource call,
	so that paths with \ are possible.

	* sfi/sfifilecrawler.c: On windows, both '/' and '\' can be directory
	separators; modified the code so that accepts both, when searching for
	the "next directory separator".

	* sfi/sfifilecrawler.c: Use GDir / g_dir_* functions instead of
	directly relying on dirent.h. That way, things work (before, the beast
	crashed within the filecrawler on startup).

	* sfi/sfistore.c: No symlinks on windows, so defined S_ISLNK(x) to
	false. Added required stdio.h #include.

	* sfi/sfitime.c: Get rid of gettimeofday() and use
	g_get_current_time() instead.

	* sfi/testsfi.c: Add missing fcntl.h #include for windows pipes.


Modified: branches/beast-mingw/ChangeLog.win32
===================================================================
--- branches/beast-mingw/ChangeLog.win32	2006-08-24 19:01:22 UTC (rev 3866)
+++ branches/beast-mingw/ChangeLog.win32	2006-08-24 19:30:59 UTC (rev 3867)
@@ -1,3 +1,34 @@
+Thu Aug 24 20:24:17 2006  Stefan Westerfeld  <stefan space twc de>
+
+	* sfi/sficomport.c:
+	* sfi/sficomwire.c: I didn't port these two yet, thus there is lots of
+	code which I just disabled with #if 0... -
+
+	* sfi/sfidl-hostc.cc:
+	* sfi/sfidl-corec.cc: Use g_strescape to escape the filenames printed
+	as #line directives (otherwise, the compiler will complain about paths
+	like "E:\msys\1.0\home\stefan\foo.idl", trying to interpret \m and so
+	forth as special characters)
+
+	* sfi/sfidl-corecxx.cc: Escape path names for gdk-pixbuf-csource call,
+	so that paths with \ are possible.
+
+	* sfi/sfifilecrawler.c: On windows, both '/' and '\' can be directory
+	separators; modified the code so that accepts both, when searching for
+	the "next directory separator".
+
+	* sfi/sfifilecrawler.c: Use GDir / g_dir_* functions instead of
+	directly relying on dirent.h. That way, things work (before, the beast
+	crashed within the filecrawler on startup).
+
+	* sfi/sfistore.c: No symlinks on windows, so defined S_ISLNK(x) to
+	false. Added required stdio.h #include.
+
+	* sfi/sfitime.c: Get rid of gettimeofday() and use
+	g_get_current_time() instead.
+
+	* sfi/testsfi.c: Add missing fcntl.h #include for windows pipes.
+
 Thu Aug 24 19:45:54 2006  Stefan Westerfeld  <stefan space twc de>
 
 	* birnet/birnetcore.h: Provide fake definitions for those errno's that

Modified: branches/beast-mingw/WIN32todo
===================================================================
--- branches/beast-mingw/WIN32todo	2006-08-24 19:01:22 UTC (rev 3866)
+++ branches/beast-mingw/WIN32todo	2006-08-24 19:30:59 UTC (rev 3867)
@@ -1 +1,3 @@
 - lazy cond/mutex/rec_mutex initializers should be eager
+- use_fallbacks=1 in sfi_file_crawler? is that ok?
+- is using GTimeVal & friends a better option than using mingws gettimeofday()?

Modified: branches/beast-mingw/sfi/sficomport.c
===================================================================
--- branches/beast-mingw/sfi/sficomport.c	2006-08-24 19:01:22 UTC (rev 3866)
+++ branches/beast-mingw/sfi/sficomport.c	2006-08-24 19:30:59 UTC (rev 3867)
@@ -28,7 +28,9 @@
 #include <fcntl.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#if 0
 #include <sys/wait.h>
+#endif
 
 static BIRNET_MSG_TYPE_DEFINE (debug_comport, "comport", BIRNET_MSG_DEBUG, NULL);
 #define DEBUG(...)              birnet_debug (debug_comport, __VA_ARGS__)
@@ -56,6 +58,7 @@
 {
   if (fd >= 0)
     {
+#if 0
       glong r, d_long;
       do
 	d_long = fcntl (fd, F_GETFL);
@@ -66,6 +69,7 @@
       do
 	r = fcntl (fd, F_SETFL, d_long);
       while (r < 0 && errno == EINTR);
+#endif
     }
   return fd;
 }
@@ -200,6 +204,7 @@
 com_port_try_reap (SfiComPort *port,
                    gboolean    mayblock)
 {
+#if 0
   if (port->remote_pid && !port->reaped)
     {
       int status = 0;
@@ -218,6 +223,7 @@
       else if (ret < 0 && errno == EINTR && mayblock)
         com_port_try_reap (port, mayblock);
     }
+#endif
 }
 
 void
@@ -245,7 +251,9 @@
       !port->reaped &&
       !port->sigterm_sent)
     {
+#if 0
       if (kill (port->remote_pid, SIGTERM) >= 0)
+#endif
         port->sigterm_sent = TRUE;
       com_port_try_reap (port, FALSE);
     }
@@ -605,6 +613,8 @@
       
       if (blocking && !port->rvalues && port->pfd[0].fd >= 0)
         {
+	  g_printerr ("sfi_comport: blocking not ported\n");
+#if 0 /* use GIOChannels here */
           struct timeval tv = { 60, 0, };
           fd_set in_fds, out_fds, exp_fds;
           gint xfd;
@@ -627,6 +637,7 @@
           /* block only once so higher layers may handle signals */
           blocking = FALSE;
           goto loop_blocking;
+#endif
         }
     }
   MASS_DEBUG ("[%s: DONE receiving]", port->ident);
@@ -732,7 +743,9 @@
       !port->reaped &&
       !port->sigkill_sent)
     {
+#if 0 /* no SIGKILL */
       if (kill (port->remote_pid, SIGKILL) >= 0)
+#endif
         port->sigkill_sent = TRUE;
     }
   com_port_try_reap (port, TRUE);

Modified: branches/beast-mingw/sfi/sficomwire.c
===================================================================
--- branches/beast-mingw/sfi/sficomwire.c	2006-08-24 19:01:22 UTC (rev 3866)
+++ branches/beast-mingw/sfi/sficomwire.c	2006-08-24 19:30:59 UTC (rev 3867)
@@ -25,7 +25,6 @@
 #include <signal.h>
 #include <fcntl.h>
 #include <sys/time.h>
-#include <sys/resource.h>
 
 
 /* --- prototypes --- */
@@ -37,6 +36,7 @@
 static void
 nonblock_fd (gint fd)
 {
+#if 0
   if (fd >= 0)
     {
       glong r, d_long;
@@ -50,6 +50,7 @@
 	r = fcntl (fd, F_SETFL, d_long);
       while (r < 0 && errno == EINTR);
     }
+#endif
 }
 
 SfiComWire*
@@ -776,8 +777,10 @@
   if (wire->standard_error >= 0)
     close (wire->standard_error);
   wire->standard_error = -1;
+#if 0
   if (wire->remote_pid > 1 && terminate)
     kill (wire->remote_pid, SIGTERM);
+#endif
   wire->remote_pid = -1;
 }
 
@@ -830,6 +833,7 @@
 sfi_com_wire_select (SfiComWire *wire,
 		     guint       timeout)
 {
+#if 0
   fd_set rfds, wfds, efds;
   guint *fds, i, n, max_fd = 0;
   struct timeval tv;
@@ -861,6 +865,7 @@
   tv.tv_usec = (timeout % 1000) * 1000;
   tv.tv_sec = timeout / 1000;
   select (max_fd + 1, &rfds, &wfds, NULL, &tv);
+#endif
 }
 
 gchar*
@@ -922,10 +927,11 @@
 unset_cloexec (gint fd)
 {
   gint r;
-  
+#if 0 
   do
     r = fcntl (fd, F_SETFD, 0 /* FD_CLOEXEC */);
   while (r < 0 && errno == EINTR);
+#endif
 }
 
 typedef struct {
@@ -942,8 +948,10 @@
     unset_cloexec (cdata->keepexec1);
   if (cdata->keepexec2)
     unset_cloexec (cdata->keepexec2);
+#if 0
   /* drop scheduling priorities if we have any */
   setpriority (PRIO_PROCESS, getpid(), 0);
+#endif
 }
 
 gchar*

Modified: branches/beast-mingw/sfi/sfidl-corec.cc
===================================================================
--- branches/beast-mingw/sfi/sfidl-corec.cc	2006-08-24 19:01:22 UTC (rev 3866)
+++ branches/beast-mingw/sfi/sfidl-corec.cc	2006-08-24 19:30:59 UTC (rev 3867)
@@ -855,7 +855,11 @@
             for (vector<Param>::const_iterator pi = rdef.contents.begin(); pi != rdef.contents.end(); pi++, f++)
               {
                 if (generateIdlLineNumbers)
-                  printf ("#line %u \"%s\"\n", pi->line, parser.fileName().c_str());
+		  {
+		    char *esc_filename = g_strescape (parser.fileName().c_str(), NULL);
+		    printf ("#line %u \"%s\"\n", pi->line, esc_filename);
+		    g_free (esc_filename);
+		  }
                 printf ("  %s_field[%d] = %s;\n", name.c_str(), f, construct_pspec (*pi).c_str());
               }
           }

Modified: branches/beast-mingw/sfi/sfidl-corecxx.cc
===================================================================
--- branches/beast-mingw/sfi/sfidl-corecxx.cc	2006-08-24 19:01:22 UTC (rev 3866)
+++ branches/beast-mingw/sfi/sfidl-corecxx.cc	2006-08-24 19:30:59 UTC (rev 3867)
@@ -1366,7 +1366,8 @@
         gint estatus = 0;
         GError *error = NULL;
         gchar *out, *err = NULL;
-        string cmd = string() + "gdk-pixbuf-csource " + "--name=local_pixstream " + ii->file;
+	gchar *escaped_image_filename = g_strescape (ii->file.c_str(), "");
+        string cmd = string() + "gdk-pixbuf-csource " + "--name=local_pixstream " + escaped_image_filename;
         g_spawn_command_line_sync (cmd.c_str(), &out, &err, &estatus, &error);
         if (err && *err)
           g_printerr ("gdk-pixbuf-csource: %s", err);
@@ -1374,7 +1375,7 @@
           {
             if (error)
               g_printerr ("failed to convert image file \"%s\" with gdk-pixbuf-csource%c %s",
-                          ii->file.c_str(), error ? ':' : ' ', error->message);
+                          escaped_image_filename, error ? ':' : ' ', error->message);
             exit (estatus & 255 ? estatus : 1);
           }
         g_clear_error (&error);

Modified: branches/beast-mingw/sfi/sfidl-hostc.cc
===================================================================
--- branches/beast-mingw/sfi/sfidl-hostc.cc	2006-08-24 19:01:22 UTC (rev 3866)
+++ branches/beast-mingw/sfi/sfidl-hostc.cc	2006-08-24 19:30:59 UTC (rev 3867)
@@ -104,8 +104,10 @@
 
 	  for (vector<Param>::const_iterator pi = rdef.contents.begin(); pi != rdef.contents.end(); pi++, f++)
 	    {
-	      printf("#line %u \"%s\"\n", pi->line, parser.fileName().c_str());
+	      gchar *esc_filename = g_strescape (parser.fileName().c_str(), NULL);
+	      printf ("#line %u \"%s\"\n", pi->line, esc_filename);
 	      printf("  %s_field[%d] = %s;\n", name.c_str(), f, makeParamSpec (*pi).c_str());
+	      g_free (esc_filename);
 	    }
 	}
       if (parser.isSequence (*ti))
@@ -114,8 +116,10 @@
 
 	  string name = makeLowerName (sdef.name);
 
-	  printf("#line %u \"%s\"\n", sdef.content.line, parser.fileName().c_str());
+	  gchar *esc_filename = g_strescape (parser.fileName().c_str(), NULL);
+	  printf("#line %u \"%s\"\n", sdef.content.line, esc_filename);
 	  printf("  %s_content = %s;\n", name.c_str(), makeParamSpec (sdef.content).c_str());
+	  g_free (esc_filename);
 	}
     }
   printf("}\n");

Modified: branches/beast-mingw/sfi/sfifilecrawler.c
===================================================================
--- branches/beast-mingw/sfi/sfifilecrawler.c	2006-08-24 19:01:22 UTC (rev 3866)
+++ branches/beast-mingw/sfi/sfifilecrawler.c	2006-08-24 19:30:59 UTC (rev 3867)
@@ -20,8 +20,7 @@
 #include "sfiprimitives.h"
 #include "topconfig.h"
 #include <string.h>
-#include <sys/types.h>
-#include <dirent.h>
+#include <sys/stat.h>
 
 #define INCREMENTAL_RESULTS 1
 
@@ -174,7 +173,7 @@
   if (strchr (file_pattern, '?') || strchr (file_pattern, '*'))
     {
       gchar *s = g_strconcat (base_dir, G_DIR_SEPARATOR_S, NULL);
-      self->dhandle = opendir (s);
+      self->dhandle = g_dir_open (s, 0, NULL);
       g_free (s);
       if (self->dhandle)
 	{
@@ -200,16 +199,17 @@
 static void	/* self->accu is implicit in/out arg */
 file_crawler_crawl_readdir (SfiFileCrawler *self)
 {
-  DIR *dd = self->dhandle;
-  struct dirent *d_entry = readdir (dd);
-  
-  if (d_entry)
+  /* FIXME:stw: either this function is by design only supposed to be called
+   * with self->dhandle != NULL, or my win32 changes need fixing
+   */
+  g_return_if_fail (self->dhandle != NULL);
+
+  const gchar *filename = g_dir_read_name (self->dhandle);
+  if (filename)
     {
-      if (!(d_entry->d_name[0] == '.' && d_entry->d_name[1] == 0) &&
-	  !(d_entry->d_name[0] == '.' && d_entry->d_name[1] == '.' && d_entry->d_name[2] == 0) &&
-	  g_pattern_match_string (self->pspec, d_entry->d_name))
+      if (g_pattern_match_string (self->pspec, filename))
 	{
-	  gchar *str = g_strconcat (self->base_dir, G_DIR_SEPARATOR_S, d_entry->d_name, NULL);
+	  gchar *str = g_strconcat (self->base_dir, G_DIR_SEPARATOR_S, filename, NULL);
 	  if (self->ftest && !g_file_test_all (str, self->ftest))
 	    g_free (str);
 	  else
@@ -222,12 +222,29 @@
       self->pspec = NULL;
       g_free (self->base_dir);
       self->base_dir = NULL;
-      closedir (dd);
+      g_dir_close (self->dhandle);
       self->dhandle = NULL;
       self->ftest = 0;
     }
 }
 
+/* On unix, it is equivalent with strchr (path, '/').
+ *
+ * On windows, it takes into account that both, '/' and '\' are
+ * valid directory separators.
+ */
+static gchar*
+find_next_dir_separator (gchar *path)
+{
+  while (*path && !G_IS_DIR_SEPARATOR (*path))
+    path++;
+
+  if (*path)
+    return path;
+  else
+    return NULL;
+}
+
 static void
 file_crawler_queue_abs_file_path (SfiFileCrawler *self,
 				  const gchar    *path_pattern,
@@ -240,7 +257,7 @@
   freeme = p = g_strdup (path_pattern);
   
   /* seperate root */
-  sep = strchr (p, G_DIR_SEPARATOR);
+  sep = find_next_dir_separator (p);
   g_return_if_fail (sep != NULL);	/* absolute paths must have a seperator */
   *sep++ = 0;
   
@@ -258,12 +275,12 @@
   self->dlist = sfi_ring_prepend (self->dlist, g_strdup (p));
   
   /* compress multiple dir seperators */
-  while (*sep == G_DIR_SEPARATOR)
+  while (G_IS_DIR_SEPARATOR (*sep))
     sep++;
   
   /* add remaining segments to queue */
   p = sep;
-  sep = strchr (p, G_DIR_SEPARATOR);
+  sep = find_next_dir_separator (p);
   while (sep)
     {
       *sep++ = 0;
@@ -272,7 +289,7 @@
       while (*sep == G_DIR_SEPARATOR)
 	sep++;
       p = sep;
-      sep = strchr (p, G_DIR_SEPARATOR);
+      sep = find_next_dir_separator (p);
     }
   
   /* final segment */
@@ -345,7 +362,7 @@
   gchar *home, *user = NULL;
   if (rpath[0] != '~')
     return cwd ? g_strconcat (cwd, G_DIR_SEPARATOR_S, rpath, NULL) : NULL;
-  dir = strchr (rpath + 1, G_DIR_SEPARATOR);
+  dir = find_next_dir_separator (rpath + 1);
   if (dir && dir > rpath + 1)
     user = g_strndup (rpath + 1, dir - rpath - 1);
   else if (!dir && rpath[1])
@@ -510,7 +527,7 @@
           struct stat st;
           if (stat (str, &st) < 0)      /* guard against existance */
             {
-              if (mkdir (str, 0755) < 0)
+              if (mkdir (str) < 0)
                 break;
             }
         }
@@ -602,7 +619,9 @@
   return birnet_file_check (file, buffer);
 }
 
+#if 0
 #include <pwd.h>
+#endif
 
 static gchar*
 get_user_home (const gchar *user,
@@ -626,6 +645,7 @@
         return g_strdup (p->pw_dir);
     }
 #endif
+  use_fallbacks = 1;
   if (!user)
     return g_strdup (g_get_home_dir ());
   return use_fallbacks ? g_strdup (g_get_home_dir ()) : NULL;

Modified: branches/beast-mingw/sfi/sfistore.c
===================================================================
--- branches/beast-mingw/sfi/sfistore.c	2006-08-24 19:01:22 UTC (rev 3866)
+++ branches/beast-mingw/sfi/sfistore.c	2006-08-24 19:30:59 UTC (rev 3867)
@@ -24,6 +24,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <stdio.h> /* SEEK_SET */
 #include <string.h>
 #include <errno.h>
 
@@ -404,6 +405,10 @@
   return rstore;
 }
 
+#ifdef WIN32
+#define S_ISLNK(x) false
+#endif
+
 SfiRStore*
 sfi_rstore_new_open (const gchar *fname)
 {

Modified: branches/beast-mingw/sfi/sfitime.c
===================================================================
--- branches/beast-mingw/sfi/sfitime.c	2006-08-24 19:01:22 UTC (rev 3866)
+++ branches/beast-mingw/sfi/sfitime.c	2006-08-24 19:30:59 UTC (rev 3867)
@@ -48,18 +48,21 @@
 _sfi_init_time (void)
 {
   static gboolean initialized = FALSE;
-  struct timeval tv = { 0, };
+  GTimeVal tv = { 0, };
   time_t t;
   gint error;
 
   g_assert (initialized++ == FALSE);
 
   tzset ();
-  error = gettimeofday (&tv, NULL);
+  g_get_current_time (&tv);
+#if 0
   if (error)
     g_error ("gettimeofday() failed: %s", g_strerror (errno));
+#endif
   t = tv.tv_sec + tv.tv_usec / 1000000;
 
+#if 0
   /* we need to find out the timezone offset relative to GMT here */
 #if 0
   { /* aparently FreeBSD/BSD4.3 doesn't have an extern long timezone; set by
@@ -74,9 +77,12 @@
      */
     struct tm tmdata;
     localtime_r (&t, &tmdata);
+#if 0
     gmt_diff = -tmdata.tm_gmtoff;
+#endif
   }
 #endif
+#endif
 
   gmt_diff *= SFI_USEC_FACTOR;
 }
@@ -96,10 +102,10 @@
 SfiTime
 sfi_time_system (void)
 {
-  struct timeval tv;
+  GTimeVal tv;
   SfiTime ustime;
 
-  gettimeofday (&tv, NULL);
+  g_get_current_time (&tv);
   ustime = tv.tv_sec;
   ustime = ustime * SFI_USEC_FACTOR + tv.tv_usec;
 

Modified: branches/beast-mingw/sfi/testsfi.c
===================================================================
--- branches/beast-mingw/sfi/testsfi.c	2006-08-24 19:01:22 UTC (rev 3866)
+++ branches/beast-mingw/sfi/testsfi.c	2006-08-24 19:30:59 UTC (rev 3867)
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <signal.h>	/* G_BREAKPOINT() */
+#include <fcntl.h>      /* pipe() on win32 */
 
 
 /* provide IDL type initializers */




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]