ReactOS 0.4.15-dev-7968-g24a56f8
typelib.c File Reference
#include "config.h"
#include "wine/port.h"
#include "wine/wpp.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include "windef.h"
#include "winbase.h"
#include "widl.h"
#include "utils.h"
#include "parser.h"
#include "header.h"
#include "typelib.h"
#include "widltypes.h"
#include "typelib_struct.h"
#include "typetree.h"
Include dependency graph for typelib.c:

Go to the source code of this file.

Classes

struct  oatype
 

Macros

#define NTYPES   (sizeof(oatypes)/sizeof(oatypes[0]))
 
#define KWP(p)   ((const struct oatype *)(p))
 

Functions

static int kw_cmp_func (const void *s1, const void *s2)
 
static unsigned short builtin_vt (const type_t *t)
 
static int match (const char *n, const char *m)
 
unsigned short get_type_vt (type_t *t)
 
static void tlb_read (int fd, void *buf, int count)
 
static void tlb_lseek (int fd, off_t offset)
 
static void msft_read_guid (int fd, MSFT_SegDir *segdir, int offset, GUID *guid)
 
static void read_msft_importlib (importlib_t *importlib, int fd)
 
static int open_typelib (const char *name)
 
static void read_importlib (importlib_t *importlib)
 
void add_importlib (const char *name, typelib_t *typelib)
 

Variables

static const struct oatype oatypes []
 

Macro Definition Documentation

◆ KWP

#define KWP (   p)    ((const struct oatype *)(p))

Definition at line 75 of file typelib.c.

◆ NTYPES

#define NTYPES   (sizeof(oatypes)/sizeof(oatypes[0]))

Definition at line 74 of file typelib.c.

Function Documentation

◆ add_importlib()

void add_importlib ( const char name,
typelib_t typelib 
)

Definition at line 391 of file typelib.c.

393{
395
396 if(!typelib) return;
397
398 LIST_FOR_EACH_ENTRY( importlib, &typelib->importlibs, importlib_t, entry )
399 if(!strcmp(name, importlib->name))
400 return;
401
402 chat("add_importlib: %s\n", name);
403
404 importlib = xmalloc(sizeof(*importlib));
405 memset( importlib, 0, sizeof(*importlib) );
406 importlib->name = xstrdup(name);
407
408 read_importlib(importlib);
409 list_add_head( &typelib->importlibs, &importlib->entry );
410}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static ITypeLib * typelib
Definition: apps.c:108
char * xstrdup(const char *s)
Definition: uimain.c:768
void * xmalloc(int size)
Definition: uimain.c:747
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
uint32_t entry
Definition: isohybrid.c:63
importlib("stdole2.tlb")
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define memset(x, y, z)
Definition: compat.h:39
static void read_importlib(importlib_t *importlib)
Definition: typelib.c:352
void chat(const char *s,...)
Definition: utils.c:131
Definition: name.c:39

◆ builtin_vt()

static unsigned short builtin_vt ( const type_t t)
static

Definition at line 82 of file typelib.c.

83{
84 const char *kw = t->name;
85 struct oatype key;
86 const struct oatype *kwp;
87 key.kw = kw;
88#ifdef KW_BSEARCH
89 kwp = bsearch(&key, oatypes, NTYPES, sizeof(oatypes[0]), kw_cmp_func);
90#else
91 {
92 unsigned int i;
93 for (kwp=NULL, i=0; i < NTYPES; i++)
94 if (!kw_cmp_func(&key, &oatypes[i])) {
95 kwp = &oatypes[i];
96 break;
97 }
98 }
99#endif
100 if (kwp) {
101 return kwp->vt;
102 }
103 if (is_string_type (t->attrs, t))
104 {
105 const type_t *elem_type;
106 if (is_array(t))
107 elem_type = type_array_get_element(t);
108 else
109 elem_type = type_pointer_get_ref(t);
110 if (type_get_type(elem_type) == TYPE_BASIC)
111 {
112 switch (type_basic_get_type(elem_type))
113 {
114 case TYPE_BASIC_CHAR: return VT_LPSTR;
115 case TYPE_BASIC_WCHAR: return VT_LPWSTR;
116 default: break;
117 }
118 }
119 }
120 return 0;
121}
#define NULL
Definition: types.h:112
@ VT_LPSTR
Definition: compat.h:2324
@ VT_LPWSTR
Definition: compat.h:2325
GLdouble GLdouble t
Definition: gl.h:2047
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static int is_string_type(const attr_list_t *attrs, const type_t *type)
Definition: header.h:94
static int is_array(const type_t *t)
Definition: header.h:64
static int kw_cmp_func(const void *s1, const void *s2)
Definition: typelib.c:77
static const struct oatype oatypes[]
#define NTYPES
Definition: typelib.c:74
Definition: copy.c:22
Definition: typelib.c:59
unsigned short vt
Definition: typelib.c:61
const char * kw
Definition: typelib.c:60
#define bsearch
static enum type_type type_get_type(const type_t *type)
Definition: typetree.h:68
static enum type_basic_type type_basic_get_type(const type_t *type)
Definition: typetree.h:73
static type_t * type_array_get_element(const type_t *type)
Definition: typetree.h:253
static type_t * type_pointer_get_ref(const type_t *type)
Definition: typetree.h:292
@ TYPE_BASIC
Definition: widltypes.h:403
@ TYPE_BASIC_CHAR
Definition: widltypes.h:270
@ TYPE_BASIC_WCHAR
Definition: widltypes.h:273

Referenced by get_type_vt().

◆ get_type_vt()

unsigned short get_type_vt ( type_t t)

Definition at line 129 of file typelib.c.

130{
131 unsigned short vt;
132
133 chat("get_type_vt: %p type->name %s\n", t, t->name);
134 if (t->name) {
135 vt = builtin_vt(t);
136 if (vt) return vt;
137 }
138
139 if (type_is_alias(t) && is_attr(t->attrs, ATTR_PUBLIC))
140 return VT_USERDEFINED;
141
142 switch (type_get_type(t)) {
143 case TYPE_BASIC:
144 switch (type_basic_get_type(t)) {
145 case TYPE_BASIC_BYTE:
146 return VT_UI1;
147 case TYPE_BASIC_CHAR:
148 case TYPE_BASIC_INT8:
149 if (type_basic_get_sign(t) > 0)
150 return VT_UI1;
151 else
152 return VT_I1;
153 case TYPE_BASIC_WCHAR:
154 return VT_I2; /* mktyplib seems to parse wchar_t as short */
155 case TYPE_BASIC_INT16:
156 if (type_basic_get_sign(t) > 0)
157 return VT_UI2;
158 else
159 return VT_I2;
160 case TYPE_BASIC_INT:
161 if (type_basic_get_sign(t) > 0)
162 return VT_UINT;
163 else
164 return VT_INT;
165 case TYPE_BASIC_INT32:
166 case TYPE_BASIC_LONG:
168 if (type_basic_get_sign(t) > 0)
169 return VT_UI4;
170 else
171 return VT_I4;
172 case TYPE_BASIC_INT64:
173 case TYPE_BASIC_HYPER:
174 if (type_basic_get_sign(t) > 0)
175 return VT_UI8;
176 else
177 return VT_I8;
179 if (pointer_size == 8)
180 {
181 if (type_basic_get_sign(t) > 0)
182 return VT_UI8;
183 else
184 return VT_I8;
185 }
186 else
187 {
188 if (type_basic_get_sign(t) > 0)
189 return VT_UI4;
190 else
191 return VT_I4;
192 }
193 case TYPE_BASIC_FLOAT:
194 return VT_R4;
196 return VT_R8;
198 error("handles can't be used in typelibs\n");
199 }
200 break;
201
202 case TYPE_POINTER:
203 return VT_PTR;
204
205 case TYPE_ARRAY:
207 {
208 if (match(type_array_get_element(t)->name, "SAFEARRAY"))
209 return VT_SAFEARRAY;
210 return VT_PTR;
211 }
212 else
213 return VT_CARRAY;
214
215 case TYPE_INTERFACE:
216 if(match(t->name, "IUnknown"))
217 return VT_UNKNOWN;
218 if(match(t->name, "IDispatch"))
219 return VT_DISPATCH;
220 return VT_USERDEFINED;
221
222 case TYPE_ENUM:
223 case TYPE_STRUCT:
224 case TYPE_COCLASS:
225 case TYPE_MODULE:
226 case TYPE_UNION:
228 return VT_USERDEFINED;
229
230 case TYPE_VOID:
231 return VT_VOID;
232
233 case TYPE_ALIAS:
234 /* aliases should be filtered out by the type_get_type call above */
235 assert(0);
236 break;
237
238 case TYPE_FUNCTION:
239 error("get_type_vt: functions not supported\n");
240 break;
241
242 case TYPE_BITFIELD:
243 error("get_type_vt: bitfields not supported\n");
244 break;
245 }
246 return 0;
247}
@ VT_UI8
Definition: compat.h:2315
@ VT_VOID
Definition: compat.h:2318
@ VT_INT
Definition: compat.h:2316
@ VT_R4
Definition: compat.h:2299
@ VT_UNKNOWN
Definition: compat.h:2308
@ VT_PTR
Definition: compat.h:2320
@ VT_UI2
Definition: compat.h:2312
@ VT_SAFEARRAY
Definition: compat.h:2321
@ VT_R8
Definition: compat.h:2300
@ VT_I8
Definition: compat.h:2314
@ VT_I1
Definition: compat.h:2310
@ VT_I4
Definition: compat.h:2298
@ VT_USERDEFINED
Definition: compat.h:2323
@ VT_I2
Definition: compat.h:2297
@ VT_UI4
Definition: compat.h:2313
@ VT_UINT
Definition: compat.h:2317
@ VT_CARRAY
Definition: compat.h:2322
@ VT_DISPATCH
Definition: compat.h:2304
@ VT_UI1
Definition: compat.h:2311
static REFPROPVARIANT PROPVAR_CHANGE_FLAGS VARTYPE vt
Definition: suminfo.c:86
#define assert(x)
Definition: debug.h:53
#define error(str)
Definition: mkdosfs.c:1605
int is_attr(const attr_list_t *list, enum attr_type t)
Definition: header.c:99
static unsigned short builtin_vt(const type_t *t)
Definition: typelib.c:82
Definition: match.c:28
static int type_array_is_decl_as_ptr(const type_t *type)
Definition: typetree.h:260
static int type_basic_get_sign(const type_t *type)
Definition: typetree.h:80
static int type_is_alias(const type_t *type)
Definition: typetree.h:274
unsigned int pointer_size
Definition: widl.c:158
@ TYPE_ENUM
Definition: widltypes.h:404
@ TYPE_BITFIELD
Definition: widltypes.h:415
@ TYPE_UNION
Definition: widltypes.h:407
@ TYPE_ALIAS
Definition: widltypes.h:408
@ TYPE_POINTER
Definition: widltypes.h:413
@ TYPE_VOID
Definition: widltypes.h:402
@ TYPE_ENCAPSULATED_UNION
Definition: widltypes.h:406
@ TYPE_COCLASS
Definition: widltypes.h:410
@ TYPE_STRUCT
Definition: widltypes.h:405
@ TYPE_MODULE
Definition: widltypes.h:409
@ TYPE_INTERFACE
Definition: widltypes.h:412
@ TYPE_ARRAY
Definition: widltypes.h:414
@ TYPE_FUNCTION
Definition: widltypes.h:411
@ ATTR_PUBLIC
Definition: widltypes.h:148
@ TYPE_BASIC_DOUBLE
Definition: widltypes.h:275
@ TYPE_BASIC_INT32
Definition: widltypes.h:265
@ TYPE_BASIC_ERROR_STATUS_T
Definition: widltypes.h:276
@ TYPE_BASIC_INT16
Definition: widltypes.h:264
@ TYPE_BASIC_HYPER
Definition: widltypes.h:271
@ TYPE_BASIC_HANDLE
Definition: widltypes.h:277
@ TYPE_BASIC_INT8
Definition: widltypes.h:263
@ TYPE_BASIC_INT3264
Definition: widltypes.h:268
@ TYPE_BASIC_LONG
Definition: widltypes.h:269
@ TYPE_BASIC_INT64
Definition: widltypes.h:266
@ TYPE_BASIC_BYTE
Definition: widltypes.h:272
@ TYPE_BASIC_INT
Definition: widltypes.h:267
@ TYPE_BASIC_FLOAT
Definition: widltypes.h:274

Referenced by add_typedef_typeinfo(), encode_type(), encode_var(), get_element_size(), write_args(), write_default_value(), and write_var_desc().

◆ kw_cmp_func()

static int kw_cmp_func ( const void s1,
const void s2 
)
static

Definition at line 77 of file typelib.c.

78{
79 return strcmp(KWP(s1)->kw, KWP(s2)->kw);
80}
struct S1 s1
struct S2 s2
#define KWP(p)
Definition: typelib.c:75

Referenced by builtin_vt().

◆ match()

static int match ( const char n,
const char m 
)
static

Definition at line 123 of file typelib.c.

124{
125 if (!n) return 0;
126 return !strcmp(n, m);
127}
GLdouble n
Definition: glext.h:7729
const GLfloat * m
Definition: glext.h:10848

◆ msft_read_guid()

static void msft_read_guid ( int  fd,
MSFT_SegDir segdir,
int  offset,
GUID guid 
)
static

Definition at line 276 of file typelib.c.

277{
279 tlb_read(fd, guid, sizeof(GUID));
280}
GLintptr offset
Definition: glext.h:5920
const GUID * guid
static int fd
Definition: io.c:51
static void tlb_read(int fd, void *buf, int count)
Definition: typelib.c:264
static void tlb_lseek(int fd, off_t offset)
Definition: typelib.c:270
MSFT_pSeg pGuidTab
Definition: typelib.h:105
INT offset
Definition: typelib.h:89

Referenced by read_msft_importlib().

◆ open_typelib()

static int open_typelib ( const char name)
static

Definition at line 338 of file typelib.c.

339{
340 char *file_name;
341 int fd;
342
344 if(!file_name)
345 return open(name, O_RDONLY | O_BINARY );
346
349 return fd;
350}
#define O_BINARY
Definition: acwin.h:109
#define O_RDONLY
Definition: acwin.h:108
#define open
Definition: acwin.h:95
#define free
Definition: debug_ros.c:5
static LPCWSTR file_name
Definition: protocol.c:147
char * wpp_find_include(const char *name, const char *parent_name)
Definition: preproc.c:509

Referenced by read_importlib().

◆ read_importlib()

static void read_importlib ( importlib_t importlib)
static

Definition at line 352 of file typelib.c.

353{
354 int fd;
355 INT magic;
356
357 fd = open_typelib(importlib->name);
358
359 /* widl extension: if importlib name has no .tlb extension, try using .tlb */
360 if(fd < 0) {
361 const char *p = strrchr(importlib->name, '.');
362 size_t len = p ? p - importlib->name : strlen(importlib->name);
363 if(strcmp(importlib->name + len, ".tlb")) {
364 char *tlb_name = xmalloc(len + 5);
365 memcpy(tlb_name, importlib->name, len);
366 strcpy(tlb_name + len, ".tlb");
367 fd = open_typelib(tlb_name);
368 free(tlb_name);
369 }
370 }
371
372 if(fd < 0)
373 error("Could not find importlib %s.\n", importlib->name);
374
375 tlb_read(fd, &magic, sizeof(magic));
376
377 switch(magic) {
378 case MSFT_MAGIC:
379 read_msft_importlib(importlib, fd);
380 break;
381 default:
382 error("Wrong or unsupported typelib magic %x\n", magic);
383 };
384
385 close(fd);
386}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define close
Definition: acwin.h:98
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
u32_t magic(void)
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
static void read_msft_importlib(importlib_t *importlib, int fd)
Definition: typelib.c:282
static int open_typelib(const char *name)
Definition: typelib.c:338
int32_t INT
Definition: typedefs.h:58
#define MSFT_MAGIC

Referenced by add_importlib().

◆ read_msft_importlib()

static void read_msft_importlib ( importlib_t importlib,
int  fd 
)
static

Definition at line 282 of file typelib.c.

283{
285 MSFT_SegDir segdir;
286 int *typeinfo_offs;
287 int i;
288
289 importlib->allocated = 0;
290
291 tlb_lseek(fd, 0);
292 tlb_read(fd, &header, sizeof(header));
293
294 importlib->version = header.version;
295
296 typeinfo_offs = xmalloc(header.nrtypeinfos*sizeof(INT));
297 tlb_read(fd, typeinfo_offs, header.nrtypeinfos*sizeof(INT));
298 tlb_read(fd, &segdir, sizeof(segdir));
299
300 msft_read_guid(fd, &segdir, header.posguid, &importlib->guid);
301
302 importlib->ntypeinfos = header.nrtypeinfos;
303 importlib->importinfos = xmalloc(importlib->ntypeinfos*sizeof(importinfo_t));
304
305 for(i=0; i < importlib->ntypeinfos; i++) {
307 MSFT_NameIntro nameintro;
308 int len;
309
310 tlb_lseek(fd, sizeof(MSFT_Header) + header.nrtypeinfos*sizeof(INT) + sizeof(MSFT_SegDir)
311 + typeinfo_offs[i]);
312 tlb_read(fd, &base, sizeof(base));
313
314 importlib->importinfos[i].importlib = importlib;
315 importlib->importinfos[i].flags = (base.typekind&0xf)<<24;
316 importlib->importinfos[i].offset = -1;
317 importlib->importinfos[i].id = i;
318
319 if(base.posguid != -1) {
320 importlib->importinfos[i].flags |= MSFT_IMPINFO_OFFSET_IS_GUID;
321 msft_read_guid(fd, &segdir, base.posguid, &importlib->importinfos[i].guid);
322 }
323 else memset( &importlib->importinfos[i].guid, 0, sizeof(importlib->importinfos[i].guid));
324
325 tlb_lseek(fd, segdir.pNametab.offset + base.NameOffset);
326 tlb_read(fd, &nameintro, sizeof(nameintro));
327
328 len = nameintro.namelen & 0xff;
329
330 importlib->importinfos[i].name = xmalloc(len+1);
331 tlb_read(fd, importlib->importinfos[i].name, len);
332 importlib->importinfos[i].name[len] = 0;
333 }
334
335 free(typeinfo_offs);
336}
#define MSFT_IMPINFO_OFFSET_IS_GUID
Definition: typelib.h:174
static void msft_read_guid(int fd, MSFT_SegDir *segdir, int offset, GUID *guid)
Definition: typelib.c:276
MSFT_pSeg pNametab
Definition: typelib.h:109

Referenced by read_importlib().

◆ tlb_lseek()

static void tlb_lseek ( int  fd,
off_t  offset 
)
static

Definition at line 270 of file typelib.c.

271{
272 if(lseek(fd, offset, SEEK_SET) == -1)
273 error("lseek failed\n");
274}
#define SEEK_SET
Definition: jmemansi.c:26
#define lseek
Definition: syshdrs.h:47

Referenced by msft_read_guid(), and read_msft_importlib().

◆ tlb_read()

static void tlb_read ( int  fd,
void buf,
int  count 
)
static

Definition at line 264 of file typelib.c.

265{
266 if(read(fd, buf, count) < count)
267 error("error while reading importlib.\n");
268}
#define read
Definition: acwin.h:96
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751

Referenced by msft_read_guid(), read_importlib(), and read_msft_importlib().

Variable Documentation

◆ oatypes

const struct oatype oatypes[]
static
Initial value:
= {
{"BSTR", VT_BSTR},
{"CURRENCY", VT_CY},
{"DATE", VT_DATE},
{"DECIMAL", VT_DECIMAL},
{"HRESULT", VT_HRESULT},
{"LPSTR", VT_LPSTR},
{"LPWSTR", VT_LPWSTR},
{"SCODE", VT_ERROR},
{"VARIANT", VT_VARIANT},
{"VARIANT_BOOL", VT_BOOL}
}
@ VT_BSTR
Definition: compat.h:2303
@ VT_DECIMAL
Definition: compat.h:2309
@ VT_ERROR
Definition: compat.h:2305
@ VT_CY
Definition: compat.h:2301
@ VT_VARIANT
Definition: compat.h:2307
@ VT_HRESULT
Definition: compat.h:2319
@ VT_DATE
Definition: compat.h:2302
@ VT_BOOL
Definition: compat.h:2306

Referenced by builtin_vt().