M
[deliverable/binutils-gdb.git] / binutils / resrc.c
index 64c6c787ea6dd93dd6c40b53405add17cb75ba95..9ba3c11780726be0a30dcb3a5e1e0610b8089377 100644 (file)
@@ -1,5 +1,5 @@
 /* resrc.c -- read and write Windows rc files.
-   Copyright 1997 Free Software Foundation, Inc.
+   Copyright 1997, 1998 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
 
    This file is part of GNU Binutils.
@@ -19,7 +19,7 @@
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  */
 
-/* This file contains function that read and write Windows rc files.
+/* This file contains functions that read and write Windows rc files.
    These are text files that represent resources.  */
 
 #include "bfd.h"
 #include <ctype.h>
 #include <sys/stat.h>
 
+#if defined (_WIN32) && ! defined (__CYGWIN32__)
+#define popen _popen
+#define pclose _pclose
+#endif
+
 /* The default preprocessor.  */
 
 #define DEFAULT_PREPROCESSOR "gcc -E -xc-header -DRC_INVOKED"
@@ -142,7 +147,8 @@ read_rc_file (filename, preprocessor, preprocargs, language)
 
   cpp_pipe = popen (cmd, FOPEN_RT);
   if (cpp_pipe == NULL)
-    fatal ("can't popen `%s': %s", cmd, strerror (errno));
+    fatal (_("can't popen `%s': %s"), cmd, strerror (errno));
+  free (cmd);
 
   xatexit (close_pipe);
 
@@ -154,7 +160,7 @@ read_rc_file (filename, preprocessor, preprocargs, language)
   yyparse ();
 
   if (pclose (cpp_pipe) != 0)
-    fprintf (stderr, "%s: warning: preprocessor failed\n", program_name);
+    fprintf (stderr, _("%s: warning: preprocessor failed\n"), program_name);
   cpp_pipe = NULL;
 
   if (fontdirs != NULL)
@@ -199,7 +205,7 @@ static void
 unexpected_eof (msg)
      const char *msg;
 {
-  fatal ("%s: unexpected EOF", msg);
+  fatal (_("%s: unexpected EOF"), msg);
 }
 
 /* Read a 16 bit word from a file.  The data is assumed to be little
@@ -256,7 +262,7 @@ get_data (e, p, c, msg)
   if (got == c)
     return;
 
-  fatal ("%s: read of %lu returned %lu", msg, c, got);
+  fatal (_("%s: read of %lu returned %lu"), msg, c, got);
 }
 \f
 /* Define an accelerator resource.  */
@@ -269,7 +275,7 @@ define_accelerator (id, resinfo, data)
 {
   struct res_resource *r;
 
-  r = define_standard_resource (&resources, RT_ACCELERATORS, id,
+  r = define_standard_resource (&resources, RT_ACCELERATOR, id,
                                resinfo->language, 0);
   r->type = RES_TYPE_ACCELERATOR;
   r->u.acc = data;
@@ -298,10 +304,10 @@ define_bitmap (id, resinfo, filename)
   e = open_file_search (filename, FOPEN_RB, "bitmap file", &real_filename);
 
   if (stat (real_filename, &s) < 0)
-    fatal ("stat failed on bitmap file `%s': %s", real_filename,
+    fatal (_("stat failed on bitmap file `%s': %s"), real_filename,
           strerror (errno));
 
-  data = (unsigned char *) xmalloc (s.st_size - BITMAP_SKIP);
+  data = (unsigned char *) res_alloc (s.st_size - BITMAP_SKIP);
 
   for (i = 0; i < BITMAP_SKIP; i++)
     getc (e);
@@ -351,7 +357,7 @@ define_cursor (id, resinfo, filename)
   type = get_word (e, real_filename);
   count = get_word (e, real_filename);
   if (type != 2)
-    fatal ("cursor file `%s' does not contain cursor data", real_filename);
+    fatal (_("cursor file `%s' does not contain cursor data"), real_filename);
 
   /* Read in the icon directory entries.  */
 
@@ -383,14 +389,14 @@ define_cursor (id, resinfo, filename)
       struct cursor *c;
 
       if (fseek (e, icondirs[i].offset, SEEK_SET) != 0)
-       fatal ("%s: fseek to %lu failed: %s", real_filename,
+       fatal (_("%s: fseek to %lu failed: %s"), real_filename,
               icondirs[i].offset, strerror (errno));
 
-      data = (unsigned char *) xmalloc (icondirs[i].bytes);
+      data = (unsigned char *) res_alloc (icondirs[i].bytes);
 
       get_data (e, data, icondirs[i].bytes, real_filename);
 
-      c = (struct cursor *) xmalloc (sizeof *c);
+      c = (struct cursor *) res_alloc (sizeof *c);
       c->xhotspot = icondirs[i].u.cursor.xhotspot;
       c->yhotspot = icondirs[i].u.cursor.yhotspot;
       c->length = icondirs[i].bytes;
@@ -419,21 +425,24 @@ define_cursor (id, resinfo, filename)
     {
       struct group_cursor *cg;
 
-      /* These manipulations of icondirs into cg are copied from rcl.  */
-
-      cg = (struct group_cursor *) xmalloc (sizeof *cg);
+      cg = (struct group_cursor *) res_alloc (sizeof *cg);
       cg->next = NULL;
       cg->width = icondirs[i].width;
       cg->height = 2 * icondirs[i].height;
+
+      /* FIXME: What should these be set to?  */
       cg->planes = 1;
-      cg->bits = 4;
-      cg->bytes = icondirs[i].bytes + 8;
+      cg->bits = 1;
+
+      cg->bytes = icondirs[i].bytes + 4;
       cg->index = first_cursor + i + 1;
 
       *pp = cg;
       pp = &(*pp)->next;
     }
 
+  free (icondirs);
+
   r = define_standard_resource (&resources, RT_GROUP_CURSOR, id,
                                resinfo->language, 0);
   r->type = RES_TYPE_GROUP_CURSOR;
@@ -452,7 +461,7 @@ define_dialog (id, resinfo, dialog)
   struct dialog *copy;
   struct res_resource *r;
 
-  copy = (struct dialog *) xmalloc (sizeof *copy);
+  copy = (struct dialog *) res_alloc (sizeof *copy);
   *copy = *dialog;
 
   r = define_standard_resource (&resources, RT_DIALOG, id,
@@ -467,7 +476,7 @@ define_dialog (id, resinfo, dialog)
 
 struct dialog_control *
 define_control (text, id, x, y, width, height, class, style, exstyle)
-     char *text;
+     const char *text;
      unsigned long id;
      unsigned long x;
      unsigned long y;
@@ -479,7 +488,7 @@ define_control (text, id, x, y, width, height, class, style, exstyle)
 {
   struct dialog_control *n;
 
-  n = (struct dialog_control *) xmalloc (sizeof *n);
+  n = (struct dialog_control *) res_alloc (sizeof *n);
   n->next = NULL;
   n->id = id;
   n->style = style;
@@ -497,7 +506,6 @@ define_control (text, id, x, y, width, height, class, style, exstyle)
       n->text.named = 0;
       n->text.u.id = 0;
     }
-  free (text);
   n->data = NULL;
   n->help = 0;
 
@@ -517,18 +525,20 @@ define_font (id, resinfo, filename)
   struct stat s;
   unsigned char *data;
   struct res_resource *r;
-  struct fontdir *fd;
   long offset;
+  long fontdatalength;
+  unsigned char *fontdata;
+  struct fontdir *fd;
   const char *device, *face;
   struct fontdir **pp;
 
   e = open_file_search (filename, FOPEN_RB, "font file", &real_filename);
 
   if (stat (real_filename, &s) < 0)
-    fatal ("stat failed on bitmap file `%s': %s", real_filename,
+    fatal (_("stat failed on bitmap file `%s': %s"), real_filename,
           strerror (errno));
 
-  data = (unsigned char *) xmalloc (s.st_size);
+  data = (unsigned char *) res_alloc (s.st_size);
 
   get_data (e, data, s.st_size, real_filename);
 
@@ -568,15 +578,17 @@ define_font (id, resinfo, filename)
 
   ++fonts;
 
-  fd = (struct fontdir *) xmalloc (sizeof *fd);
+  fontdatalength = 58 + strlen (device) + strlen (face);
+  fontdata = (unsigned char *) res_alloc (fontdatalength);
+  memcpy (fontdata, data, 56);
+  strcpy ((char *) fontdata + 56, device);
+  strcpy ((char *) fontdata + 57 + strlen (device), face);
+
+  fd = (struct fontdir *) res_alloc (sizeof *fd);
   fd->next = NULL;
   fd->index = fonts;
-  fd->length = 58 + strlen (device) + strlen (face);
-  fd->data = (unsigned char *) xmalloc (fd->length);
-
-  memcpy (fd->data, data, 56);
-  strcpy ((char *) fd->data + 56, device);
-  strcpy ((char *) fd->data + 57 + strlen (device), face);
+  fd->length = fontdatalength;
+  fd->data = fontdata;
 
   for (pp = &fontdirs; *pp != NULL; pp = &(*pp)->next)
     ;
@@ -636,7 +648,7 @@ define_icon (id, resinfo, filename)
   type = get_word (e, real_filename);
   count = get_word (e, real_filename);
   if (type != 1)
-    fatal ("icon file `%s' does not contain icon data", real_filename);
+    fatal (_("icon file `%s' does not contain icon data"), real_filename);
 
   /* Read in the icon directory entries.  */
 
@@ -667,10 +679,10 @@ define_icon (id, resinfo, filename)
       struct res_id name;
 
       if (fseek (e, icondirs[i].offset, SEEK_SET) != 0)
-       fatal ("%s: fseek to %lu failed: %s", real_filename,
+       fatal (_("%s: fseek to %lu failed: %s"), real_filename,
               icondirs[i].offset, strerror (errno));
 
-      data = (unsigned char *) xmalloc (icondirs[i].bytes);
+      data = (unsigned char *) res_alloc (icondirs[i].bytes);
 
       get_data (e, data, icondirs[i].bytes, real_filename);
 
@@ -698,16 +710,21 @@ define_icon (id, resinfo, filename)
     {
       struct group_icon *cg;
 
-      /* FIXME: rcl sets planes and bits based on colors, rather than
-         just copying the values from the file.  */
+      /* For some reason, at least in some files the planes and bits
+         are zero.  We instead set them from the color.  This is
+         copied from rcl.  */
 
-      cg = (struct group_icon *) xmalloc (sizeof *cg);
+      cg = (struct group_icon *) res_alloc (sizeof *cg);
       cg->next = NULL;
       cg->width = icondirs[i].width;
       cg->height = icondirs[i].height;
       cg->colors = icondirs[i].colorcount;
-      cg->planes = icondirs[i].u.icon.planes;
-      cg->bits = icondirs[i].u.icon.bits;
+
+      cg->planes = 1;
+      cg->bits = 0;
+      while ((1 << cg->bits) < cg->colors)
+       ++cg->bits;
+
       cg->bytes = icondirs[i].bytes;
       cg->index = first_icon + i + 1;
 
@@ -715,6 +732,8 @@ define_icon (id, resinfo, filename)
       pp = &(*pp)->next;
     }
 
+  free (icondirs);
+
   r = define_standard_resource (&resources, RT_GROUP_ICON, id,
                                resinfo->language, 0);
   r->type = RES_TYPE_GROUP_ICON;
@@ -730,11 +749,16 @@ define_menu (id, resinfo, menuitems)
      const struct res_res_info *resinfo;
      struct menuitem *menuitems;
 {
+  struct menu *m;
   struct res_resource *r;
 
+  m = (struct menu *) res_alloc (sizeof *m);
+  m->items = menuitems;
+  m->help = 0;
+
   r = define_standard_resource (&resources, RT_MENU, id, resinfo->language, 0);
   r->type = RES_TYPE_MENU;
-  r->u.menu = menuitems;
+  r->u.menu = m;
   r->res_info = *resinfo;
 }
 
@@ -743,7 +767,7 @@ define_menu (id, resinfo, menuitems)
 
 struct menuitem *
 define_menuitem (text, menuid, type, state, help, menuitems)
-     char *text;
+     const char *text;
      int menuid;
      unsigned long type;
      unsigned long state;
@@ -752,12 +776,15 @@ define_menuitem (text, menuid, type, state, help, menuitems)
 {
   struct menuitem *mi;
 
-  mi = (struct menuitem *) xmalloc (sizeof *mi);
+  mi = (struct menuitem *) res_alloc (sizeof *mi);
   mi->next = NULL;
   mi->type = type;
   mi->state = state;
   mi->id = menuid;
-  mi->text = text;
+  if (text == NULL)
+    mi->text = NULL;
+  else
+    unicode_from_ascii ((int *) NULL, &mi->text, text);
   mi->help = help;
   mi->popup = menuitems;
   return mi;
@@ -781,10 +808,10 @@ define_messagetable (id, resinfo, filename)
                        &real_filename);
 
   if (stat (real_filename, &s) < 0)
-    fatal ("stat failed on bitmap file `%s': %s", real_filename,
+    fatal (_("stat failed on bitmap file `%s': %s"), real_filename,
           strerror (errno));
 
-  data = (unsigned char *) xmalloc (s.st_size);
+  data = (unsigned char *) res_alloc (s.st_size);
 
   get_data (e, data, s.st_size, real_filename);
 
@@ -806,7 +833,7 @@ void
 define_rcdata (id, resinfo, data)
      struct res_id id;
      const struct res_res_info *resinfo;
-     struct rcdata_data *data;
+     struct rcdata_item *data;
 {
   struct res_resource *r;
 
@@ -817,61 +844,42 @@ define_rcdata (id, resinfo, data)
   r->res_info = *resinfo;
 }
 
-/* Add an rcdata_item to an rcdata resource.  */
-
-struct rcdata_data *
-append_rcdata_item (data, item)
-     struct rcdata_data *data;
-     struct rcdata_item *item;
-{
-  if (data == NULL)
-    {
-      data = (struct rcdata_data *) xmalloc (sizeof *data);
-      data->first = item;
-      data->last = item;
-    }
-  else
-    {
-      data->last->next = item;
-      data->last = item;
-    }
-
-  return data;
-}
-
-/* Add a string to an rcdata resource.  */
+/* Create an rcdata item holding a string.  */
 
-struct rcdata_data *
-append_rcdata_string (data, string)
-     struct rcdata_data *data;
-     char *string;
+struct rcdata_item *
+define_rcdata_string (string, len)
+     const char *string;
+     unsigned long len;
 {
   struct rcdata_item *ri;
+  char *s;
 
-  ri = (struct rcdata_item *) xmalloc (sizeof *ri);
+  ri = (struct rcdata_item *) res_alloc (sizeof *ri);
   ri->next = NULL;
   ri->type = RCDATA_STRING;
-  ri->u.string = string;
+  ri->u.string.length = len;
+  s = (char *) res_alloc (len);
+  memcpy (s, string, len);
+  ri->u.string.s = s;
 
-  return append_rcdata_item (data, ri);
+  return ri;
 }
 
-/* Add a number to an rcdata resource.  */
+/* Create an rcdata item holding a number.  */
 
-struct rcdata_data *
-append_rcdata_number (data, val, dword)
-     struct rcdata_data *data;
+struct rcdata_item *
+define_rcdata_number (val, dword)
      unsigned long val;
      int dword;
 {
   struct rcdata_item *ri;
 
-  ri = (struct rcdata_item *) xmalloc (sizeof *ri);
+  ri = (struct rcdata_item *) res_alloc (sizeof *ri);
   ri->next = NULL;
   ri->type = dword ? RCDATA_DWORD : RCDATA_WORD;
   ri->u.word = val;
 
-  return append_rcdata_item (data, ri);
+  return ri;
 }
 
 /* Define a stringtable resource.  This is called for each string
@@ -881,13 +889,13 @@ void
 define_stringtable (resinfo, stringid, string)
      const struct res_res_info *resinfo;
      unsigned long stringid;
-     char *string;
+     const char *string;
 {
   struct res_id id;
   struct res_resource *r;
 
   id.named = 0;
-  id.u.id = stringid >> 4;
+  id.u.id = (stringid >> 4) + 1;
   r = define_standard_resource (&resources, RT_STRING, id,
                                resinfo->language, 1);
 
@@ -897,7 +905,7 @@ define_stringtable (resinfo, stringid, string)
 
       r->type = RES_TYPE_STRINGTABLE;
       r->u.stringtable = ((struct stringtable *)
-                         xmalloc (sizeof (struct stringtable)));
+                         res_alloc (sizeof (struct stringtable)));
       for (i = 0; i < 16; i++)
        {
          r->u.stringtable->strings[i].length = 0;
@@ -910,7 +918,6 @@ define_stringtable (resinfo, stringid, string)
   unicode_from_ascii (&r->u.stringtable->strings[stringid & 0xf].length,
                      &r->u.stringtable->strings[stringid & 0xf].string,
                      string);
-  free (string);
 }
 
 /* Define a user data resource where the data is in the rc file.  */
@@ -920,7 +927,7 @@ define_user_data (id, type, resinfo, data)
      struct res_id id;
      struct res_id type;
      const struct res_res_info *resinfo;
-     struct rcdata_data *data;
+     struct rcdata_item *data;
 {
   struct res_id ids[3];
   struct res_resource *r;
@@ -955,10 +962,10 @@ define_user_file (id, type, resinfo, filename)
   e = open_file_search (filename, FOPEN_RB, "font file", &real_filename);
 
   if (stat (real_filename, &s) < 0)
-    fatal ("stat failed on bitmap file `%s': %s", real_filename,
+    fatal (_("stat failed on bitmap file `%s': %s"), real_filename,
           strerror (errno));
 
-  data = (unsigned char *) xmalloc (s.st_size);
+  data = (unsigned char *) res_alloc (s.st_size);
 
   get_data (e, data, s.st_size, real_filename);
 
@@ -972,15 +979,12 @@ define_user_file (id, type, resinfo, filename)
 
   r = define_resource (&resources, 3, ids, 0);
   r->type = RES_TYPE_USERDATA;
-  r->u.userdata = ((struct rcdata_data *)
-                  xmalloc (sizeof (struct rcdata_data)));
-  r->u.userdata->first = ((struct rcdata_item *)
-                         xmalloc (sizeof (struct rcdata_item)));
-  r->u.userdata->last = r->u.userdata->first;
-  r->u.userdata->first->next = NULL;
-  r->u.userdata->first->type = RCDATA_BUFFER;
-  r->u.userdata->first->u.buffer.length = s.st_size;
-  r->u.userdata->first->u.buffer.data = data;
+  r->u.userdata = ((struct rcdata_item *)
+                  res_alloc (sizeof (struct rcdata_item)));
+  r->u.userdata->next = NULL;
+  r->u.userdata->type = RCDATA_BUFFER;
+  r->u.userdata->u.buffer.length = s.st_size;
+  r->u.userdata->u.buffer.data = data;
   r->res_info = *resinfo;
 }
 
@@ -998,7 +1002,7 @@ define_versioninfo (id, language, fixedverinfo, verinfo)
   r = define_standard_resource (&resources, RT_VERSION, id, language, 0);
   r->type = RES_TYPE_VERSIONINFO;
   r->u.versioninfo = ((struct versioninfo *)
-                     xmalloc (sizeof (struct versioninfo)));
+                     res_alloc (sizeof (struct versioninfo)));
   r->u.versioninfo->fixed = fixedverinfo;
   r->u.versioninfo->var = verinfo;
   r->res_info.language = language;
@@ -1009,17 +1013,15 @@ define_versioninfo (id, language, fixedverinfo, verinfo)
 struct ver_info *
 append_ver_stringfileinfo (verinfo, language, strings)
      struct ver_info *verinfo;
-     char *language;
+     const char *language;
      struct ver_stringinfo *strings;
 {
   struct ver_info *vi, **pp;
 
-  vi = (struct ver_info *) xmalloc (sizeof *vi);
+  vi = (struct ver_info *) res_alloc (sizeof *vi);
   vi->next = NULL;
   vi->type = VERINFO_STRING;
-  unicode_from_ascii ((unsigned short *) NULL, &vi->u.string.language,
-                     language);
-  free (language);
+  unicode_from_ascii ((int *) NULL, &vi->u.string.language, language);
   vi->u.string.strings = strings;
 
   for (pp = &verinfo; *pp != NULL; pp = &(*pp)->next)
@@ -1034,16 +1036,15 @@ append_ver_stringfileinfo (verinfo, language, strings)
 struct ver_info *
 append_ver_varfileinfo (verinfo, key, var)
      struct ver_info *verinfo;
-     char *key;
+     const char *key;
      struct ver_varinfo *var;
 {
   struct ver_info *vi, **pp;
 
-  vi = (struct ver_info *) xmalloc (sizeof *vi);
+  vi = (struct ver_info *) res_alloc (sizeof *vi);
   vi->next = NULL;
   vi->type = VERINFO_VAR;
-  unicode_from_ascii ((unsigned short *) NULL, &vi->u.var.key, key);
-  free (key);
+  unicode_from_ascii ((int *) NULL, &vi->u.var.key, key);
   vi->u.var.var = var;
 
   for (pp = &verinfo; *pp != NULL; pp = &(*pp)->next)
@@ -1058,17 +1059,15 @@ append_ver_varfileinfo (verinfo, key, var)
 struct ver_stringinfo *
 append_verval (strings, key, value)
      struct ver_stringinfo *strings;
-     char *key;
-     char *value;
+     const char *key;
+     const char *value;
 {
   struct ver_stringinfo *vs, **pp;
 
-  vs = (struct ver_stringinfo *) xmalloc (sizeof *vs);
+  vs = (struct ver_stringinfo *) res_alloc (sizeof *vs);
   vs->next = NULL;
-  unicode_from_ascii ((unsigned short *) NULL, &vs->key, key);
-  free (key);
-  unicode_from_ascii ((unsigned short *) NULL, &vs->value, value);
-  free (value);
+  unicode_from_ascii ((int *) NULL, &vs->key, key);
+  unicode_from_ascii ((int *) NULL, &vs->value, value);
 
   for (pp = &strings; *pp != NULL; pp = &(*pp)->next)
     ;
@@ -1087,7 +1086,7 @@ append_vertrans (var, language, charset)
 {
   struct ver_varinfo *vv, **pp;
 
-  vv = (struct ver_varinfo *) xmalloc (sizeof *vv);
+  vv = (struct ver_varinfo *) res_alloc (sizeof *vv);
   vv->next = NULL;
   vv->language = language;
   vv->charset = charset;
@@ -1121,8 +1120,10 @@ static void write_rc_dialog_control
   PARAMS ((FILE *, const struct dialog_control *));
 static void write_rc_fontdir PARAMS ((FILE *, const struct fontdir *));
 static void write_rc_group_icon PARAMS ((FILE *, const struct group_icon *));
-static void write_rc_menu PARAMS ((FILE *, const struct menuitem *, int, int));
-static void write_rc_rcdata PARAMS ((FILE *, const struct rcdata_data *, int));
+static void write_rc_menu PARAMS ((FILE *, const struct menu *, int));
+static void write_rc_menuitems
+  PARAMS ((FILE *, const struct menuitem *, int, int));
+static void write_rc_rcdata PARAMS ((FILE *, const struct rcdata_item *, int));
 static void write_rc_stringtable
   PARAMS ((FILE *, const struct res_id *, const struct stringtable *));
 static void write_rc_versioninfo PARAMS ((FILE *, const struct versioninfo *));
@@ -1166,7 +1167,7 @@ write_rc_file (filename, resources)
     {
       e = fopen (filename, FOPEN_WT);
       if (e == NULL)
-       fatal ("can't open `%s' for output: %s", filename, strerror (errno));
+       fatal (_("can't open `%s' for output: %s"), filename, strerror (errno));
     }
 
   language = -1;
@@ -1222,7 +1223,7 @@ write_rc_directory (e, rd, type, name, language, level)
          /* If we're at level 3, then this key represents a language.
             Use it to update the current language.  */
          if (! re->id.named
-             && re->id.u.id != *language
+             && re->id.u.id != (unsigned long) (unsigned int) *language
              && (re->id.u.id & 0xffff) == re->id.u.id)
            {
              fprintf (e, "LANGUAGE %lu, %lu\n",
@@ -1293,7 +1294,7 @@ write_rc_subdir (e, re, type, name, language, level)
            case RT_STRING: s = "stringtable"; break;
            case RT_FONTDIR: s = "fontdir"; break;
            case RT_FONT: s = "font"; break;
-           case RT_ACCELERATORS: s = "accelerators"; break;
+           case RT_ACCELERATOR: s = "accelerators"; break;
            case RT_RCDATA: s = "rcdata"; break;
            case RT_MESSAGETABLE: s = "messagetable"; break;
            case RT_GROUP_CURSOR: s = "group cursor"; break;
@@ -1363,7 +1364,7 @@ write_rc_resource (e, type, name, res, language)
 
     case RES_TYPE_ACCELERATOR:
       s = "ACCELERATOR";
-      rt = RT_ACCELERATORS;
+      rt = RT_ACCELERATOR;
       break;
 
     case RES_TYPE_BITMAP:
@@ -1451,7 +1452,7 @@ write_rc_resource (e, type, name, res, language)
 
   if (rt != 0
       && type != NULL
-      && (type->named || type->u.id != rt))
+      && (type->named || type->u.id != (unsigned long) rt))
     {
       fprintf (e, "// Unexpected resource type mismatch: ");
       res_id_print (e, *type, 1);
@@ -1565,7 +1566,7 @@ write_rc_resource (e, type, name, res, language)
       break;
 
     case RES_TYPE_MENU:
-      write_rc_menu (e, res->u.menu, menuex, 0);
+      write_rc_menu (e, res->u.menu, menuex);
       break;
 
     case RES_TYPE_RCDATA:
@@ -1690,15 +1691,21 @@ write_rc_dialog (e, dialog)
     fprintf (e, "STYLE 0x%lx\n", dialog->style);
   if (dialog->exstyle != 0)
     fprintf (e, "EXSTYLE 0x%lx\n", dialog->exstyle);
-  if (dialog->class.named || dialog->class.u.id != 0)
+  if ((dialog->class.named && dialog->class.u.n.length > 0)
+      || dialog->class.u.id != 0)
     {
       fprintf (e, "CLASS ");
       res_id_print (e, dialog->class, 0);
       fprintf (e, "\n");
     }
   if (dialog->caption != NULL)
-    fprintf (e, "CAPTION \"%s\"\n", dialog->caption);
-  if (dialog->menu.named || dialog->menu.u.id != 0)
+    {
+      fprintf (e, "CAPTION \"");
+      unicode_print (e, dialog->caption, -1);
+      fprintf (e, "\"\n");
+    }
+  if ((dialog->menu.named && dialog->menu.u.n.length > 0)
+      || dialog->menu.u.id != 0)
     {
       fprintf (e, "MENU ");
       res_id_print (e, dialog->menu, 0);
@@ -1706,7 +1713,9 @@ write_rc_dialog (e, dialog)
     }
   if (dialog->font != NULL)
     {
-      fprintf (e, "FONT %d, \"%s\"", dialog->pointsize, dialog->font);
+      fprintf (e, "FONT %d, \"", dialog->pointsize);
+      unicode_print (e, dialog->font, -1);
+      fprintf (e, "\"");
       if (dialog->ex != NULL
          && (dialog->ex->weight != 0 || dialog->ex->italic != 0))
        fprintf (e, ", %d, %d", dialog->ex->weight, dialog->ex->italic);
@@ -1778,8 +1787,9 @@ write_rc_dialog_control (e, control)
                || ci->style == (control->style & 0xff)))
          break;
     }
-
-  if (ci->name != NULL)
+  if (ci == NULL)
+    fprintf (e, "CONTROL");
+  else if (ci->name != NULL)
     fprintf (e, "%s", ci->name);
   else
     fprintf (e, "CONTROL");
@@ -1793,9 +1803,13 @@ write_rc_dialog_control (e, control)
 
   fprintf (e, " %d, ", control->id);
 
-  if (ci->name == NULL)
+  if (ci == NULL)
     {
+      if (control->class.named)
+       fprintf (e, "\"");
       res_id_print (e, control->class, 0);
+      if (control->class.named)
+       fprintf (e, "\"");
       fprintf (e, ", 0x%lx, ", control->style);
     }
 
@@ -1863,7 +1877,20 @@ write_rc_group_icon (e, group_icon)
 /* Write out a menu resource.  */
 
 static void
-write_rc_menu (e, menuitems, menuex, ind)
+write_rc_menu (e, menu, menuex)
+     FILE *e;
+     const struct menu *menu;
+     int menuex;
+{
+  if (menu->help != 0)
+    fprintf (e, "// Help ID: %lu\n", menu->help);
+  write_rc_menuitems (e, menu->items, menuex, 0);
+}
+
+/* Write out menuitems.  */
+
+static void
+write_rc_menuitems (e, menuitems, menuex, ind)
      FILE *e;
      const struct menuitem *menuitems;
      int menuex;
@@ -1896,7 +1923,11 @@ write_rc_menu (e, menuitems, menuex, ind)
       if (mi->text == NULL)
        fprintf (e, " \"\"");
       else
-       fprintf (e, " \"%s\"", mi->text);
+       {
+         fprintf (e, " \"");
+         unicode_print (e, mi->text, -1);
+         fprintf (e, "\"");
+       }
 
       if (! menuex)
        {
@@ -1937,7 +1968,7 @@ write_rc_menu (e, menuitems, menuex, ind)
       fprintf (e, "\n");
 
       if (mi->popup != NULL)
-       write_rc_menu (e, mi->popup, menuex, ind + 2);
+       write_rc_menuitems (e, mi->popup, menuex, ind + 2);
     }
 
   indent (e, ind);
@@ -1950,7 +1981,7 @@ write_rc_menu (e, menuitems, menuex, ind)
 static void
 write_rc_rcdata (e, rcdata, ind)
      FILE *e;
-     const struct rcdata_data *rcdata;
+     const struct rcdata_item *rcdata;
      int ind;
 {
   const struct rcdata_item *ri;
@@ -1958,7 +1989,7 @@ write_rc_rcdata (e, rcdata, ind)
   indent (e, ind);
   fprintf (e, "BEGIN\n");
 
-  for (ri = rcdata->first; ri != NULL; ri = ri->next)
+  for (ri = rcdata; ri != NULL; ri = ri->next)
     {
       if (ri->type == RCDATA_BUFFER && ri->u.buffer.length == 0)
        continue;
@@ -1979,12 +2010,26 @@ write_rc_rcdata (e, rcdata, ind)
          break;
 
        case RCDATA_STRING:
-         fprintf (e, "\"%s\"", ri->u.string);
-         break;
+         {
+           const char *s;
+           unsigned long i;
+
+           fprintf (e, "\"");
+           s = ri->u.string.s;
+           for (i = 0; i < ri->u.string.length; i++)
+             {
+               if (isprint ((unsigned char) *s))
+                 putc (*s, e);
+               else
+                 fprintf (e, "\\%03o", *s);
+             }
+           fprintf (e, "\"");
+           break;
+         }
 
        case RCDATA_WSTRING:
          fprintf (e, "L\"");
-         unicode_print (e, ri->u.wstring, -1);
+         unicode_print (e, ri->u.wstring.w, ri->u.wstring.length);
          fprintf (e, "\"");
          break;
 
@@ -2009,7 +2054,7 @@ write_rc_rcdata (e, rcdata, ind)
                else
                  {
                    fprintf (e, ",\n");
-                   indent (e, ind);
+                   indent (e, ind + 2);
                  }
                fprintf (e, "%luL", l);
              }
@@ -2024,7 +2069,7 @@ write_rc_rcdata (e, rcdata, ind)
                else
                  {
                    fprintf (e, ",\n");
-                   indent (e, ind);
+                   indent (e, ind + 2);
                  }
                fprintf (e, "%d", i);
                i += 2;
@@ -2037,7 +2082,7 @@ write_rc_rcdata (e, rcdata, ind)
                else
                  {
                    fprintf (e, ",\n");
-                   indent (e, ind);
+                   indent (e, ind + 2);
                  }
                if ((ri->u.buffer.data[i] & 0x7f) == ri->u.buffer.data[i]
                    && isprint (ri->u.buffer.data[i]))
@@ -2071,7 +2116,7 @@ write_rc_stringtable (e, name, stringtable)
   int i;
 
   if (name != NULL && ! name->named)
-    offset = name->u.id << 4;
+    offset = (name->u.id - 1) << 4;
   else
     {
       fprintf (e, "// %s string table name\n",
This page took 0.034199 seconds and 4 git commands to generate.