#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
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;
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,
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)
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;
}
argc = 0;
argv[argc++] = (gchar *) xmllint;
argv[argc++] = "--nonet";
- argv[argc++] = "--noent";
argv[argc++] = "--noblanks";
argv[argc++] = "--output";
argv[argc++] = tmp_file;
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)
{
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
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 },
srcfile = argv[1];
- if (sourcedir == NULL)
- sourcedir = "";
-
xmllint = g_strdup (g_getenv ("XMLLINT"));
if (xmllint == NULL)
xmllint = g_find_program_in_path ("xmllint");