/* resrc.c -- read and write Windows rc files.
- Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 1997-2023 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Cygnus Support.
Rewritten by Kai Tietz, Onevision.
/* The default preprocessor. */
-#define DEFAULT_PREPROCESSOR "gcc -E -xc -DRC_INVOKED"
+#define DEFAULT_PREPROCESSOR_CMD "gcc"
+#define DEFAULT_PREPROCESSOR_ARGS "-E -xc -DRC_INVOKED"
/* We read the directory entries in a cursor or icon file into
instances of this structure. */
int pid, wait_status, retcode;
int i;
const char **argv;
- char *errmsg_fmt, *errmsg_arg;
- char *temp_base = choose_temp_base ();
+ char *errmsg_fmt = NULL, *errmsg_arg = NULL;
+ char *temp_base = make_temp_file (NULL);
int in_quote;
char sep;
int redir_handle = -1;
i++;
i++;
- argv = alloca (sizeof (char *) * (i + 3));
+ argv = xmalloc (sizeof (char *) * (i + 3));
i = 0;
s = cmd;
pid = pexecute (argv[0], (char * const *) argv, program_name, temp_base,
&errmsg_fmt, &errmsg_arg, PEXECUTE_ONE | PEXECUTE_SEARCH);
+ free (argv);
/* Restore stdout to its previous setting. */
dup2 (stdout_save, STDOUT_FILENO);
{
char *fileprefix;
- fileprefix = choose_temp_base ();
+ fileprefix = make_temp_file (NULL);
cpp_temp_file = (char *) xmalloc (strlen (fileprefix) + 5);
sprintf (cpp_temp_file, "%s.irc", fileprefix);
free (fileprefix);
if (run_cmd (cmd, cpp_temp_file))
fatal (_("can't execute `%s': %s"), cmd, strerror (errno));
- cpp_pipe = fopen (cpp_temp_file, FOPEN_RT);;
+ cpp_pipe = fopen (cpp_temp_file, FOPEN_RT);
if (cpp_pipe == NULL)
fatal (_("can't open temporary file `%s': %s"),
cpp_temp_file, strerror (errno));
look_for_default (char *cmd, const char *prefix, int end_prefix,
const char *preprocargs, const char *filename)
{
- char *space;
int found;
struct stat s;
const char *fnquotes = (filename_need_quotes (filename) ? "\"" : "");
strcpy (cmd, prefix);
- sprintf (cmd + end_prefix, "%s", DEFAULT_PREPROCESSOR);
- space = strchr (cmd + end_prefix, ' ');
- if (space)
- *space = 0;
+ sprintf (cmd + end_prefix, "%s", DEFAULT_PREPROCESSOR_CMD);
if (
#if defined (__DJGPP__) || defined (__CYGWIN__) || defined (_WIN32)
}
}
- strcpy (cmd, prefix);
+ if (filename_need_quotes (cmd))
+ {
+ char *cmd_copy = xmalloc (strlen (cmd));
+ strcpy (cmd_copy, cmd);
+ sprintf (cmd, "\"%s\"", cmd_copy);
+ free (cmd_copy);
+ }
- sprintf (cmd + end_prefix, "%s %s %s%s%s",
- DEFAULT_PREPROCESSOR, preprocargs, fnquotes, filename, fnquotes);
+ sprintf (cmd + strlen (cmd), " %s %s %s%s%s",
+ DEFAULT_PREPROCESSOR_ARGS, preprocargs, fnquotes, filename, fnquotes);
if (verbose)
fprintf (stderr, _("Using `%s'\n"), cmd);
{
char *dash, *slash, *cp;
- preprocessor = DEFAULT_PREPROCESSOR;
-
cmd = xmalloc (strlen (program_name)
- + strlen (preprocessor)
+ + strlen (DEFAULT_PREPROCESSOR_CMD)
+ + strlen (DEFAULT_PREPROCESSOR_ARGS)
+ strlen (preprocargs)
+ strlen (filename)
+ strlen (fnquotes) * 2
static void
get_data (FILE *e, bfd_byte *p, rc_uint_type c, const char *msg)
{
- rc_uint_type got; // $$$d
+ rc_uint_type got; /* $$$d */
got = (rc_uint_type) fread (p, 1, c, e);
if (got == c)
default:
res_id_print (e, *type, 0);
break;
-
+
PRINT_RT_NAME(RT_MANIFEST);
PRINT_RT_NAME(RT_ANICURSOR);
PRINT_RT_NAME(RT_ANIICON);
indent (e, 2);
if (it->id.u.id == 0)
fprintf (e, "SEPARATOR\n");
- else
+ else
fprintf (e, "BUTTON %d\n", (int) it->id.u.id);
it = it->next;
}
fprintf (e, ", MENUBARBREAK");
if ((mi->type & MENUITEM_MENUBREAK) != 0)
fprintf (e, ", MENUBREAK");
+ if ((mi->type & MENUITEM_OWNERDRAW) != 0)
+ fprintf (e, ", OWNERDRAW");
+ if ((mi->type & MENUITEM_BITMAP) != 0)
+ fprintf (e, ", BITMAP");
}
else
{
int has_nl;
rc_uint_type c;
rc_uint_type i;
-
+
if (length <= 1)
return 0;
{
int has_error = 0;
const struct bin_messagetable *mt;
+
fprintf (e, "BEGIN\n");
write_rc_datablock (e, length, data, 0, 0, 0);
if (length < BIN_MESSAGETABLE_SIZE)
has_error = 1;
else
- do {
- rc_uint_type m, i;
- mt = (const struct bin_messagetable *) data;
- m = windres_get_32 (&wrtarget, mt->cblocks, length);
- if (length < (BIN_MESSAGETABLE_SIZE + m * BIN_MESSAGETABLE_BLOCK_SIZE))
- {
- has_error = 1;
- break;
- }
- for (i = 0; i < m; i++)
- {
- rc_uint_type low, high, offset;
- const struct bin_messagetable_item *mti;
+ do
+ {
+ rc_uint_type m, i;
+
+ mt = (const struct bin_messagetable *) data;
+ m = windres_get_32 (&wrtarget, mt->cblocks, length);
+
+ if (length < (BIN_MESSAGETABLE_SIZE + m * BIN_MESSAGETABLE_BLOCK_SIZE))
+ {
+ has_error = 1;
+ break;
+ }
+ for (i = 0; i < m; i++)
+ {
+ rc_uint_type low, high, offset;
+ const struct bin_messagetable_item *mti;
+
+ low = windres_get_32 (&wrtarget, mt->items[i].lowid, 4);
+ high = windres_get_32 (&wrtarget, mt->items[i].highid, 4);
+ offset = windres_get_32 (&wrtarget, mt->items[i].offset, 4);
+
+ while (low <= high)
+ {
+ rc_uint_type elen, flags;
+ if ((offset + BIN_MESSAGETABLE_ITEM_SIZE) > length)
+ {
+ has_error = 1;
+ break;
+ }
+ mti = (const struct bin_messagetable_item *) &data[offset];
+ elen = windres_get_16 (&wrtarget, mti->length, 2);
+ flags = windres_get_16 (&wrtarget, mti->flags, 2);
+ if ((offset + elen) > length)
+ {
+ has_error = 1;
+ break;
+ }
+ wr_printcomment (e, "MessageId = 0x%x", low);
+ wr_printcomment (e, "");
+
+ if ((flags & MESSAGE_RESOURCE_UNICODE) == MESSAGE_RESOURCE_UNICODE)
+ {
+ /* PR 17512: file: 5c3232dc. */
+ if (elen > BIN_MESSAGETABLE_ITEM_SIZE * 2)
+ unicode_print (e, (const unichar *) mti->data,
+ (elen - BIN_MESSAGETABLE_ITEM_SIZE) / 2);
+ }
+ else
+ {
+ if (elen > BIN_MESSAGETABLE_ITEM_SIZE)
+ ascii_print (e, (const char *) mti->data,
+ (elen - BIN_MESSAGETABLE_ITEM_SIZE));
+ }
+
+ wr_printcomment (e,"");
+ ++low;
+ offset += elen;
+ }
+ }
+ }
+ while (0);
- low = windres_get_32 (&wrtarget, mt->items[i].lowid, 4);
- high = windres_get_32 (&wrtarget, mt->items[i].highid, 4);
- offset = windres_get_32 (&wrtarget, mt->items[i].offset, 4);
- while (low <= high)
- {
- rc_uint_type elen, flags;
- if ((offset + BIN_MESSAGETABLE_ITEM_SIZE) > length)
- {
- has_error = 1;
- break;
- }
- mti = (const struct bin_messagetable_item *) &data[offset];
- elen = windres_get_16 (&wrtarget, mti->length, 2);
- flags = windres_get_16 (&wrtarget, mti->flags, 2);
- if ((offset + elen) > length)
- {
- has_error = 1;
- break;
- }
- wr_printcomment (e, "MessageId = 0x%x", low);
- wr_printcomment (e, "");
- if ((flags & MESSAGE_RESOURCE_UNICODE) == MESSAGE_RESOURCE_UNICODE)
- unicode_print (e, (const unichar *) mti->data,
- (elen - BIN_MESSAGETABLE_ITEM_SIZE) / 2);
- else
- ascii_print (e, (const char *) mti->data,
- (elen - BIN_MESSAGETABLE_ITEM_SIZE));
- wr_printcomment (e,"");
- ++low;
- offset += elen;
- }
- }
- } while (0);
if (has_error)
wr_printcomment (e, "Illegal data");
wr_print_flush (e);
fprintf (e, "BEGIN\n");
if (show_comment == -1)
- {
+ {
if (test_rc_datablock_text(length, data))
{
rc_uint_type i, c;
;
if (i < length && data[i] == '\n')
++i, ++c;
- ascii_print (e, (const char *) &data[i - c], c);
+ ascii_print(e, (const char *) &data[i - c], c);
fprintf (e, "\"");
if (i < length)
fprintf (e, "\n");
}
-
+
if (i == 0)
{
indent (e, 2);
u = (const unichar *) &data[i];
indent (e, 2);
fprintf (e, "L\"");
-
+
for (c = 0; i < length && c < 160 && u[c] != '\n'; c++, i += 2)
;
if (i < length && u[c] == '\n')
{
rc_uint_type k;
rc_uint_type comment_start;
-
+
comment_start = i;
-
+
if (! first)
indent (e, 2);