This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
return cpp_pipe;
}
-/* look for the preprocessor program */
+/* Determine if FILENAME contains special characters that
+ can cause problems unless the entire filename is quoted. */
+
+static int
+filename_need_quotes (const char *filename)
+{
+ if (filename == NULL || (filename[0] == '-' && filename[1] == 0))
+ return 0;
+
+ while (*filename != 0)
+ {
+ switch (*filename)
+ {
+ case '&':
+ case ' ':
+ case '<':
+ case '>':
+ case '|':
+ case '%':
+ return 1;
+ }
+ ++filename;
+ }
+ return 0;
+}
+
+/* Look for the preprocessor program. */
static FILE *
look_for_default (char *cmd, const char *prefix, int end_prefix,
char *space;
int found;
struct stat s;
+ const char *fnquotes = (filename_need_quotes (filename) ? "\"" : "");
strcpy (cmd, prefix);
strcpy (cmd, prefix);
- sprintf (cmd + end_prefix, "%s %s %s",
- DEFAULT_PREPROCESSOR, preprocargs, filename);
+ sprintf (cmd + end_prefix, "%s %s %s%s%s",
+ DEFAULT_PREPROCESSOR, preprocargs, fnquotes, filename, fnquotes);
if (verbose)
fprintf (stderr, _("Using `%s'\n"), cmd);
const char *preprocargs, int language, int use_temp_file)
{
char *cmd;
+ const char *fnquotes = (filename_need_quotes (filename) ? "\"" : "");
+
+ if (filename == NULL)
+ filename = "-";
+ /* Setup the default resource import path taken from input file. */
+ else if (strchr (filename, '/') != NULL || strchr (filename, '\\') != NULL)
+ {
+ char *edit, *dir;
+
+ if (filename[0] == '/'
+ || filename[0] == '\\'
+ || filename[1] == ':')
+ /* Absolute path. */
+ edit = dir = xstrdup (filename);
+ else
+ {
+ /* Relative path. */
+ edit = dir = xmalloc (strlen (filename) + 3);
+ sprintf (dir, "./%s", filename);
+ }
+
+ /* Walk dir backwards stopping at the first directory separator. */
+ edit += strlen (dir);
+ while (edit > dir && (edit[-1] != '\\' && edit[-1] != '/'))
+ {
+ --edit;
+ edit[0] = 0;
+ }
+
+ /* Cut off trailing slash. */
+ --edit;
+ edit[0] = 0;
+
+ /* Convert all back slashes to forward slashes. */
+ while ((edit = strchr (dir, '\\')) != NULL)
+ *edit = '/';
+
+ windres_add_include_dir (dir);
+ }
istream_type = (use_temp_file) ? ISTREAM_FILE : ISTREAM_PIPE;
if (preprocargs == NULL)
preprocargs = "";
- if (filename == NULL)
- filename = "-";
if (preprocessor)
{
cmd = xmalloc (strlen (preprocessor)
+ strlen (preprocargs)
+ strlen (filename)
+ + strlen (fnquotes) * 2
+ 10);
- sprintf (cmd, "%s %s %s", preprocessor, preprocargs, filename);
+ sprintf (cmd, "%s %s %s%s%s", preprocessor, preprocargs,
+ fnquotes, filename, fnquotes);
cpp_pipe = open_input_stream (cmd);
}
+ strlen (preprocessor)
+ strlen (preprocargs)
+ strlen (filename)
+ + strlen (fnquotes) * 2
#ifdef HAVE_EXECUTABLE_SUFFIX
+ strlen (EXECUTABLE_SUFFIX)
#endif
else
{
if (cpp_pipe != NULL)
- pclose (cpp_pipe);
+ {
+ int err;
+ err = pclose (cpp_pipe);
+ /* We are reading from a pipe, therefore we don't
+ know if cpp failed or succeeded until pclose. */
+ if (err != 0 || errno == ECHILD)
+ {
+ /* Since this is also run via xatexit, safeguard. */
+ cpp_pipe = NULL;
+ cpp_temp_file = NULL;
+ fatal (_("preprocessing failed."));
+ }
+ }
}
/* Since this is also run via xatexit, safeguard. */