Store interfaces, structs, coclasses and modules that are to be
written into a typelib in a list.

diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index 55c7862..86b22e1 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -713,7 +713,9 @@
 						  $$->type = get_struct_type( $4 );
 						  $$->fields = $4;
 						  $$->defined = TRUE;
-						}
+                                                  if(in_typelib)
+                                                      add_struct($$);
+                                                }
 	;
 
 type:	  tVOID					{ $$ = make_tref(NULL, make_type(0, NULL)); }
diff --git a/tools/widl/typelib.c b/tools/widl/typelib.c
index d2e0926..e9a28ce 100644
--- a/tools/widl/typelib.c
+++ b/tools/widl/typelib.c
@@ -35,7 +35,6 @@
 #include "typelib.h"
 
 int in_typelib = 0;
-static FILE* typelib;
 
 /* Copied from wtypes.h. Not included directly because that would create a
  * circular dependency (after all, wtypes.h is generated by widl...) */
@@ -91,6 +90,7 @@
     VT_ILLEGALMASKED = 0xfff,
     VT_TYPEMASK = 0xfff
 };
+static typelib_t *typelib;
 
 /* List of oleauto types that should be recognized by name.
  * (most of) these seem to be intrinsic types in mktyplib. */
@@ -217,52 +217,84 @@
 
 void start_typelib(char *name, attr_t *attrs)
 {
-  in_typelib++;
-  if (!do_everything && !typelib_only) return;
-  if(!(typelib = fopen(typelib_name, "wb")))
-    error("Could not open %s for output\n", typelib_name);
+    in_typelib++;
+    if (!do_everything && !typelib_only) return;
+
+    typelib = xmalloc(sizeof(*typelib));
+    typelib->name = xstrdup(name);
+    typelib->filename = xstrdup(typelib_name);
+    typelib->attrs = attrs;
 }
 
 void end_typelib(void)
 {
-  if (typelib) fclose(typelib);
-  in_typelib--;
+    in_typelib--;
+    if (!typelib) return;
+
+/*    create_msft_typelib(typelib);*/
+    return;
 }
 
 void add_interface(type_t *iface)
 {
-  if (!typelib) return;
+    typelib_entry_t *entry;
+    if (!typelib) return;
 
-  /* FIXME: add interface and dependent types to typelib */
-  printf("add interface: %s\n", iface->name);
+    chat("add interface: %s\n", iface->name);
+    entry = xmalloc(sizeof(*entry));
+    entry->kind = TKIND_INTERFACE;
+    entry->u.interface = iface;
+    LINK(entry, typelib->entry);
+    typelib->entry = entry;
 }
 
 void add_coclass(class_t *cls)
 {
-  ifref_t *lcur = cls->ifaces;
-  ifref_t *cur;
+    ifref_t *lcur = cls->ifaces;
+    ifref_t *cur;
+    typelib_entry_t *entry;
 
-  if (lcur) {
-    while (NEXT_LINK(lcur)) lcur = NEXT_LINK(lcur);
-  }
+    if (lcur) {
+        while (NEXT_LINK(lcur)) lcur = NEXT_LINK(lcur);
+    }
 
-  if (!typelib) return;
+    if (!typelib) return;
 
-  /* install interfaces the coclass depends on */
-  cur = lcur;
-  while (cur) {
-    add_interface(cur->iface);
-    cur = PREV_LINK(cur);
-  }
-
-  /* FIXME: add coclass to typelib */
-  printf("add coclass: %s\n", cls->name);
+    /* install interfaces the coclass depends on */
+    cur = lcur;
+    while (cur) {
+        add_interface(cur->iface);
+        cur = PREV_LINK(cur);
+    }
+    entry = xmalloc(sizeof(*entry));
+    entry->kind = TKIND_COCLASS;
+    entry->u.class = cls;
+    LINK(entry, typelib->entry);
+    typelib->entry = entry;
 }
 
 void add_module(type_t *module)
 {
-  if (!typelib) return;
+    typelib_entry_t *entry;
+    if (!typelib) return;
 
-  /* FIXME: add module to typelib */
-  printf("add module: %s\n", module->name);
+    chat("add module: %s\n", module->name);
+    entry = xmalloc(sizeof(*entry));
+    entry->kind = TKIND_MODULE;
+    entry->u.module = module;
+    LINK(entry, typelib->entry);
+    typelib->entry = entry;
+}
+
+void add_struct(type_t *structure)
+{
+     typelib_entry_t *entry;
+     if (!typelib) return;
+
+     chat("add struct: %s\n", structure->name);
+     entry = xmalloc(sizeof(*entry));
+     entry->kind = TKIND_RECORD;
+     entry->u.structure = structure;
+     LINK(entry, typelib->entry);
+     typelib->entry = entry;
 }
diff --git a/tools/widl/typelib.h b/tools/widl/typelib.h
index dd1e1cf..fe173b4 100644
--- a/tools/widl/typelib.h
+++ b/tools/widl/typelib.h
@@ -27,5 +27,6 @@
 extern void add_interface(type_t *iface);
 extern void add_coclass(class_t *cls);
 extern void add_module(type_t *module);
+extern void add_struct(type_t *structure);
 
 #endif
diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h
index c6c8ab9..4918b4e 100644
--- a/tools/widl/widltypes.h
+++ b/tools/widl/widltypes.h
@@ -45,6 +45,8 @@
 typedef struct _func_t func_t;
 typedef struct _ifref_t ifref_t;
 typedef struct _class_t class_t;
+typedef struct _typelib_entry_t typelib_entry_t;
+typedef struct _typelib_t typelib_t;
 
 #define DECL_LINK(type) \
   type *l_next; \
@@ -126,6 +128,19 @@
     EXPR_COND,
 };
 
+enum type_kind
+{
+    TKIND_ENUM = 0,
+    TKIND_RECORD,
+    TKIND_MODULE,
+    TKIND_INTERFACE,
+    TKIND_DISPATCH,
+    TKIND_COCLASS,
+    TKIND_ALIAS,
+    TKIND_UNION,
+    TKIND_MAX
+};
+   
 struct _attr_t {
   enum attr_type type;
   union {
@@ -214,4 +229,22 @@
   DECL_LINK(class_t)
 };
 
+struct _typelib_entry_t {
+    enum type_kind kind;
+    union {
+        class_t *class;
+        type_t *interface;
+        type_t *module;
+        type_t *structure;
+    } u;
+    DECL_LINK(typelib_entry_t)
+};
+
+struct _typelib_t {
+    char *name;
+    char *filename;
+    attr_t *attrs;
+    typelib_entry_t *entry;
+};
+
 #endif