win32: Support autolaunching dbus daemon
[platform/upstream/glib.git] / gio / glib-compile-resources.c
index f677cb5..31e5624 100644 (file)
@@ -30,6 +30,9 @@
 #include <stdio.h>
 #include <locale.h>
 #include <errno.h>
+#ifdef G_OS_WIN32
+#include <io.h>
+#endif
 #ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
 #endif
@@ -73,7 +76,7 @@ typedef struct
   GString *string;  /* non-NULL when accepting text */
 } ParseState;
 
-static gchar *sourcedir = NULL;
+static gchar **sourcedirs = NULL;
 static gchar *xmllint = NULL;
 static gchar *gdk_pixbuf_pixdata = NULL;
 
@@ -174,6 +177,28 @@ get_parent (GHashTable *table,
   return parent;
 }
 
+static gchar *
+find_file (const gchar *filename)
+{
+  guint i;
+  gchar *real_file;
+  gboolean exists;
+
+  if (g_path_is_absolute (filename))
+    return g_strdup (filename);
+
+  /* search all the sourcedirs for the correct files in order */
+  for (i = 0; sourcedirs[i] != NULL; i++)
+    {
+       real_file = g_build_filename (sourcedirs[i], filename, NULL);
+       exists = g_file_test (real_file, G_FILE_TEST_EXISTS);
+       if (exists)
+         return real_file;
+       g_free (real_file);
+    }
+    return NULL;
+}
+
 static void
 end_element (GMarkupParseContext  *context,
             const gchar          *element_name,
@@ -217,10 +242,28 @@ end_element (GMarkupParseContext  *context,
 
       data = g_new0 (FileData, 1);
 
-      if (sourcedir != NULL)
-       real_file = g_build_filename (sourcedir, file, NULL);
+      if (sourcedirs != NULL)
+        {
+         real_file = find_file (file);
+         if (real_file == NULL)
+           {
+               g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                            _("Failed to locate '%s' in any source directory"), file);
+               return;
+           }
+       }
       else
-       real_file = g_strdup (file);
+        {
+         gboolean exists;
+         exists = g_file_test (file, G_FILE_TEST_EXISTS);
+         if (!exists)
+           {
+             g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                          _("Failed to locate '%s' in current directory"), file);
+             return;
+           }
+         real_file = g_strdup (file);
+       }
 
       data->filename = g_strdup (real_file);
       if (!state->collect_data)
@@ -244,7 +287,7 @@ end_element (GMarkupParseContext  *context,
               else
                 {
                   g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
-                               _("Unknown proprocessing options \"%s\""), options[i]);
+                               _("Unknown processing option \"%s\""), options[i]);
                   g_strfreev (options);
                   goto cleanup;
                 }
@@ -273,7 +316,6 @@ end_element (GMarkupParseContext  *context,
               argc = 0;
               argv[argc++] = (gchar *) xmllint;
               argv[argc++] = "--nonet";
-              argv[argc++] = "--noent";
               argv[argc++] = "--noblanks";
               argv[argc++] = "--output";
               argv[argc++] = tmp_file;
@@ -302,13 +344,19 @@ end_element (GMarkupParseContext  *context,
               real_file = g_strdup (tmp_file);
             }
 
-          if (to_pixdata && gdk_pixbuf_pixdata == NULL)
-           g_printerr ("GDK_PIXBUF_PIXDATA not set and gdk-pixbuf-pixdata not found in path; skipping to-pixdata preprocessing.\n");
-          if (to_pixdata && gdk_pixbuf_pixdata != NULL)
+          if (to_pixdata)
             {
               gchar *argv[4];
               int status, fd, argc;
 
+              if (gdk_pixbuf_pixdata == NULL)
+                {
+                  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                                       "to-pixbuf preprocessing requested but GDK_PIXBUF_PIXDATA "
+                                       "not set and gdk-pixbuf-pixdata not found in path");
+                  goto cleanup;
+                }
+
               tmp_file2 = g_strdup ("resource-XXXXXXXX");
               if ((fd = g_mkstemp (tmp_file2)) == -1)
                 {
@@ -342,7 +390,7 @@ end_element (GMarkupParseContext  *context,
               if (!WIFEXITED (status) || WEXITSTATUS (status) != 0)
                 {
                   g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                      _("Error processing input file with xmllint"));
+                                      _("Error processing input file with to-pixdata"));
                   goto cleanup;
                 }
 #endif
@@ -563,7 +611,7 @@ main (int argc, char **argv)
   GOptionContext *context;
   GOptionEntry entries[] = {
     { "target", 0, 0, G_OPTION_ARG_FILENAME, &target, N_("name of the output file"), N_("FILE") },
-    { "sourcedir", 0, 0, G_OPTION_ARG_FILENAME, &sourcedir, N_("The directory where files are to be read from (default to current directory)"), N_("DIRECTORY") },
+    { "sourcedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &sourcedirs, N_("The directories where files are to be read from (default to current directory)"), N_("DIRECTORY") },
     { "generate", 0, 0, G_OPTION_ARG_NONE, &generate_automatic, N_("Generate output in the format selected for by the target filename extension"), NULL },
     { "generate-header", 0, 0, G_OPTION_ARG_NONE, &generate_header, N_("Generate source header"), NULL },
     { "generate-source", 0, 0, G_OPTION_ARG_NONE, &generate_source, N_("Generate sourcecode used to link in the resource file into your code"), NULL },
@@ -620,9 +668,6 @@ main (int argc, char **argv)
 
   srcfile = argv[1];
 
-  if (sourcedir == NULL)
-    sourcedir = "";
-
   xmllint = g_strdup (g_getenv ("XMLLINT"));
   if (xmllint == NULL)
     xmllint = g_find_program_in_path ("xmllint");