Add note to check that all changes have been pushed before creating the source tarballs
[binutils-gdb.git] / binutils / resrc.c
index b4edba992fca9de49a73d9eac83d3dd225922500..3ea9813d8bd08d99e98ea72040fb75e456ee069f 100644 (file)
@@ -1,5 +1,5 @@
 /* resrc.c -- read and write Windows rc files.
-   Copyright (C) 1997-2015 Free Software Foundation, Inc.
+   Copyright (C) 1997-2023 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
    Rewritten by Kai Tietz, Onevision.
 
@@ -75,7 +75,8 @@
 
 /* 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.  */
@@ -200,8 +201,8 @@ run_cmd (char *cmd, const char *redir)
   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;
@@ -215,7 +216,7 @@ run_cmd (char *cmd, const char *redir)
       i++;
 
   i++;
-  argv = alloca (sizeof (char *) * (i + 3));
+  argv = xmalloc (sizeof (char *) * (i + 3));
   i = 0;
   s = cmd;
 
@@ -266,6 +267,7 @@ run_cmd (char *cmd, const char *redir)
 
   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);
@@ -314,7 +316,7 @@ open_input_stream (char *cmd)
     {
       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);
@@ -377,17 +379,13 @@ static FILE *
 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)
@@ -409,10 +407,16 @@ look_for_default (char *cmd, const char *prefix, int end_prefix,
        }
     }
 
-  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);
@@ -489,10 +493,9 @@ read_rc_file (const char *filename, const char *preprocessor,
     {
       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
@@ -673,7 +676,7 @@ get_long (FILE *e, const char *msg)
 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)
@@ -2275,7 +2278,7 @@ write_rc_resource (FILE *e, const rc_res_id *type,
            default:
     res_id_print (e, *type, 0);
              break;
-       
+
            PRINT_RT_NAME(RT_MANIFEST);
            PRINT_RT_NAME(RT_ANICURSOR);
            PRINT_RT_NAME(RT_ANIICON);
@@ -2777,7 +2780,7 @@ write_rc_toolbar (FILE *e, const rc_toolbar *tb)
     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;
   }
@@ -2840,6 +2843,10 @@ write_rc_menuitems (FILE *e, const rc_menuitem *menuitems, int menuex,
            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
        {
@@ -2892,7 +2899,7 @@ test_rc_datablock_text (rc_uint_type length, const bfd_byte *data)
   int has_nl;
   rc_uint_type c;
   rc_uint_type i;
-  
+
   if (length <= 1)
     return 0;
 
@@ -3029,7 +3036,7 @@ write_rc_datablock (FILE *e, rc_uint_type length, const bfd_byte *data, int has_
              if (i < length)
                fprintf (e, "\n");
            }
-          
+
          if (i == 0)
              {
              indent (e, 2);
@@ -3052,7 +3059,7 @@ write_rc_datablock (FILE *e, rc_uint_type length, const bfd_byte *data, int has_
              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')
@@ -3090,9 +3097,9 @@ write_rc_datablock (FILE *e, rc_uint_type length, const bfd_byte *data, int has_
                  {
          rc_uint_type k;
          rc_uint_type comment_start;
-         
+
          comment_start = i;
-         
+
          if (! first)
            indent (e, 2);