From 13a88f8a4f56db668d6f62d295d1cb74ea170227 Mon Sep 17 00:00:00 2001
From: Joel Anderson <joelanderson333@gmail.com>
Date: Sat, 30 May 2020 19:24:53 -0400
Subject: [PATCH] fix windmc typedef bug

While a typedef can be specified in message files for the messages following
with the `MessageIdTypedef` directive, only the last typedef was honored by
windmc. This corrects this behavior, matching mc.exe functionality.
---
 binutils/mcparse.y | 1 +
 binutils/windmc.c  | 4 ++--
 binutils/windmc.h  | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/binutils/mcparse.y b/binutils/mcparse.y
index 0fbef9b470..a274eeee5a 100644
--- a/binutils/mcparse.y
+++ b/binutils/mcparse.y
@@ -181,6 +181,7 @@ message:
 	    cur_node->severity = mc_cur_severity;
 	    cur_node->id = ($1 & 0xffffUL);
 	    cur_node->vid = ($1 & 0xffffUL) | mc_sefa_val;
+	    cur_node->id_typecast = mcset_msg_id_typedef;
 	    mc_last_id = $1;
 	  }
 	  lang_entities
diff --git a/binutils/windmc.c b/binutils/windmc.c
index 0aae65071f..98bb3ad690 100644
--- a/binutils/windmc.c
+++ b/binutils/windmc.c
@@ -821,7 +821,7 @@ write_dbg (FILE *fp)
   while (h != NULL)
     {
       if (h->symbol)
-	write_dbg_define (fp, h->symbol, mcset_msg_id_typedef);
+	write_dbg_define (fp, h->symbol, h->id_typecast);
       h = h->next;
     }
   fprintf (fp, "  { (");
@@ -908,7 +908,7 @@ write_header (FILE *fp)
 	    fprintf (fp, "%s", s);
 	}
       if (h->symbol)
-	write_header_define (fp, h->symbol, h->vid, mcset_msg_id_typedef, h->sub);
+	write_header_define (fp, h->symbol, h->vid, h->id_typecast, h->sub);
       h = h->next;
     }
 }
diff --git a/binutils/windmc.h b/binutils/windmc.h
index 784ecc856a..5c74124f44 100644
--- a/binutils/windmc.h
+++ b/binutils/windmc.h
@@ -66,6 +66,7 @@ typedef struct mc_node
   unichar *symbol;
   rc_uint_type id;
   rc_uint_type vid;
+  unichar *id_typecast;
   mc_node_lang *sub;
 } mc_node;
 
-- 
2.17.1

