From 8d03a0b285eb282b80d512ac9c28523cb464c209 Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Sun, 10 Jan 2016 15:59:19 +0800
Subject: widl: Write SLTG blocks according to the index order.

Now multiple types can be correctly parsed and displayed by oleview.
---
 tools/widl/write_sltg.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/tools/widl/write_sltg.c b/tools/widl/write_sltg.c
index 04c6123..4b86bf9 100644
--- a/tools/widl/write_sltg.c
+++ b/tools/widl/write_sltg.c
@@ -291,9 +291,20 @@ static void add_block(struct sltg_typelib *sltg, void *data, int size, const cha
     block->length = size;
     block->data = data;
     block->index_string = add_index(&sltg->index, name);
-    block->next = sltg->blocks;
+    block->next = NULL;
+
+    if (sltg->blocks)
+    {
+        struct sltg_block *blocks = sltg->blocks;
+
+        while (blocks->next)
+            blocks = blocks->next;
+
+        blocks->next = block;
+    }
+    else
+        sltg->blocks = block;
 
-    sltg->blocks = block;
     sltg->n_file_blocks++;
 }
 
@@ -378,7 +389,7 @@ static void sltg_add_typeinfo(struct sltg_typelib *sltg, void *data, int size, c
     {
         struct sltg_block *typeinfo = sltg->typeinfo;
 
-        while (typeinfo && typeinfo->next)
+        while (typeinfo->next)
             typeinfo = typeinfo->next;
 
         typeinfo->next = block;
@@ -1084,12 +1095,12 @@ int create_sltg_typelib(typelib_t *typelib)
     init_name_table(&sltg);
     init_library(&sltg);
 
-    add_library_block(&sltg);
-
     if (typelib->stmts)
         LIST_FOR_EACH_ENTRY(stmt, typelib->stmts, const statement_t, entry)
             add_statement(&sltg, stmt);
 
+    add_library_block(&sltg);
+
     save_all_changes(&sltg);
 
     return 1;
-- 
2.6.4

