/* resrc.c -- read and write Windows rc files.
- Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007
+ Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2011
Free Software Foundation, Inc.
Written by Ian Lance Taylor, Cygnus Support.
Rewritten by Kai Tietz, Onevision.
if (pid == -1)
{
- fatal (_("%s %s: %s"), errmsg_fmt, errmsg_arg, strerror (errno));
+ fatal ("%s %s: %s", errmsg_fmt, errmsg_arg, strerror (errno));
return 1;
}
char *cmd;
const char *fnquotes = (filename_need_quotes (filename) ? "\"" : "");
+ if (filename == NULL)
+ filename = "-";
/* Setup the default resource import path taken from input file. */
- if (strchr (filename, '/') != NULL || strchr (filename, '\\') != NULL)
+ else if (strchr (filename, '/') != NULL || strchr (filename, '\\') != NULL)
{
- char *e, *c;
+ char *edit, *dir;
if (filename[0] == '/'
|| filename[0] == '\\'
|| filename[1] == ':')
- e = c = xstrdup (filename);
+ /* Absolute path. */
+ edit = dir = xstrdup (filename);
else
{
- e = c = xmalloc (strlen (filename) + 3);
- sprintf (c, "./%s", filename);
+ /* Relative path. */
+ edit = dir = xmalloc (strlen (filename) + 3);
+ sprintf (dir, "./%s", filename);
}
- e += strlen (c);
- while (e > c && (e[-1] != '\\' && e[-1] != '/'))
+
+ /* Walk dir backwards stopping at the first directory separator. */
+ edit += strlen (dir);
+ while (edit > dir && (edit[-1] != '\\' && edit[-1] != '/'))
{
- --e;
- e[0] = 0;
+ --edit;
+ edit[0] = 0;
}
+
/* Cut off trailing slash. */
- --e;
- e[0] = 0;
- while ((e = strchr (c, '\\')) != NULL)
- *e = '/';
+ --edit;
+ edit[0] = 0;
+
+ /* Convert all back slashes to forward slashes. */
+ while ((edit = strchr (dir, '\\')) != NULL)
+ *edit = '/';
- windres_add_include_dir (e);
+ windres_add_include_dir (dir);
}
istream_type = (use_temp_file) ? ISTREAM_FILE : ISTREAM_PIPE;
if (preprocargs == NULL)
preprocargs = "";
- if (filename == NULL)
- filename = "-";
if (preprocessor)
{
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. */
void
rcparse_warning (const char *msg)
{
- fprintf (stderr, _("%s:%d: %s\n"), rc_filename, rc_lineno, msg);
+ fprintf (stderr, "%s:%d: %s\n", rc_filename, rc_lineno, msg);
}
/* Die if we get an unexpected end of file. */
if (got == c)
return;
- fatal (_("%s: read of %lu returned %lu"), msg, (long) c, (long) got);
+ fatal (_("%s: read of %lu returned %lu"),
+ msg, (unsigned long) c, (unsigned long) got);
}
\f
/* Define an accelerator resource. */
/* Add string version info to a list of version information. */
rc_ver_info *
-append_ver_stringfileinfo (rc_ver_info *verinfo, const char *language,
- rc_ver_stringinfo *strings)
+append_ver_stringfileinfo (rc_ver_info *verinfo,
+ rc_ver_stringtable *stringtables)
{
rc_ver_info *vi, **pp;
vi = (rc_ver_info *) res_alloc (sizeof (rc_ver_info));
vi->next = NULL;
vi->type = VERINFO_STRING;
- unicode_from_ascii ((rc_uint_type *) NULL, &vi->u.string.language, language);
- vi->u.string.strings = strings;
+ vi->u.string.stringtables = stringtables;
for (pp = &verinfo; *pp != NULL; pp = &(*pp)->next)
;
return verinfo;
}
+rc_ver_stringtable *
+append_ver_stringtable (rc_ver_stringtable *stringtable,
+ const char *language,
+ rc_ver_stringinfo *strings)
+{
+ rc_ver_stringtable *vst, **pp;
+
+ vst = (rc_ver_stringtable *) res_alloc (sizeof (rc_ver_stringtable));
+ vst->next = NULL;
+ unicode_from_ascii ((rc_uint_type *) NULL, &vst->language, language);
+ vst->strings = strings;
+
+ for (pp = &stringtable; *pp != NULL; pp = &(*pp)->next)
+ ;
+ *pp = vst;
+
+ return stringtable;
+}
+
/* Add variable version info to a list of version information. */
rc_ver_info *
without the need to store it somewhere externally. */
void
-write_rc_file (const char *filename, const rc_res_directory *resources)
+write_rc_file (const char *filename, const rc_res_directory *res_dir)
{
FILE *e;
rc_uint_type language;
}
language = (rc_uint_type) ((bfd_signed_vma) -1);
- write_rc_directory (e, resources, (const rc_res_id *) NULL,
+ write_rc_directory (e, res_dir, (const rc_res_id *) NULL,
(const rc_res_id *) NULL, &language, 1);
}
{
if (k == 0)
plen = fprintf (e, "0x%lxL",
- (long) windres_get_32 (&wrtarget, data + i, length - i));
+ (unsigned long) windres_get_32 (&wrtarget, data + i, length - i));
else
plen = fprintf (e, " 0x%lxL",
- (long) windres_get_32 (&wrtarget, data + i, length - i)) - 1;
+ (unsigned long) windres_get_32 (&wrtarget, data + i, length - i)) - 1;
if (has_next || (i + 4) < length)
{
if (plen>0 && plen < 11)
{
if (stringtable->strings[i].length != 0)
{
- fprintf (e, " %lu, ", (long) offset + i);
+ fprintf (e, " %lu, ", (unsigned long) offset + i);
unicode_print_quoted (e, stringtable->strings[i].string,
stringtable->strings[i].length);
fprintf (e, "\n");
{
case VERINFO_STRING:
{
+ const rc_ver_stringtable *vst;
const rc_ver_stringinfo *vs;
fprintf (e, " BLOCK \"StringFileInfo\"\n");
fprintf (e, " BEGIN\n");
- fprintf (e, " BLOCK ");
- unicode_print_quoted (e, vi->u.string.language, -1);
- fprintf (e, "\n");
- fprintf (e, " BEGIN\n");
- for (vs = vi->u.string.strings; vs != NULL; vs = vs->next)
+ for (vst = vi->u.string.stringtables; vst != NULL; vst = vst->next)
{
- fprintf (e, " VALUE ");
- unicode_print_quoted (e, vs->key, -1);
- fprintf (e, ", ");
- unicode_print_quoted (e, vs->value, -1);
+ fprintf (e, " BLOCK ");
+ unicode_print_quoted (e, vst->language, -1);
+
fprintf (e, "\n");
- }
+ fprintf (e, " BEGIN\n");
+
+ for (vs = vst->strings; vs != NULL; vs = vs->next)
+ {
+ fprintf (e, " VALUE ");
+ unicode_print_quoted (e, vs->key, -1);
+ fprintf (e, ", ");
+ unicode_print_quoted (e, vs->value, -1);
+ fprintf (e, "\n");
+ }
- fprintf (e, " END\n");
+ fprintf (e, " END\n");
+ }
fprintf (e, " END\n");
break;
}