ReactOS 0.4.15-dev-8096-ga0eec98
register.c File Reference
#include "config.h"
#include "wine/port.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "widl.h"
#include "utils.h"
#include "parser.h"
#include "header.h"
#include "typegen.h"
#include "typelib.h"
Include dependency graph for register.c:

Go to the source code of this file.

Functions

static const charformat_uuid (const UUID *uuid)
 
static const charget_coclass_threading (const type_t *class)
 
static const type_tfind_ps_factory (const statement_list_t *stmts)
 
static void write_interface (const type_t *iface, const type_t *ps_factory)
 
static void write_interfaces (const statement_list_t *stmts, const type_t *ps_factory)
 
static void write_typelib_interface (const type_t *iface, const typelib_t *typelib)
 
static void write_typelib_interfaces (const typelib_t *typelib)
 
static int write_coclass (const type_t *class, const typelib_t *typelib)
 
static void write_coclasses (const statement_list_t *stmts, const typelib_t *typelib)
 
static int write_progid (const type_t *class)
 
static void write_progids (const statement_list_t *stmts)
 
void write_regscript (const statement_list_t *stmts)
 
void write_typelib_regscript (const statement_list_t *stmts)
 
void output_typelib_regscript (const typelib_t *typelib)
 

Variables

static int indent
 

Function Documentation

◆ find_ps_factory()

static const type_t * find_ps_factory ( const statement_list_t stmts)
static

Definition at line 67 of file register.c.

68{
69 const statement_t *stmt;
70
71 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
72 {
73 if (stmt->type == STMT_TYPE)
74 {
75 const type_t *type = stmt->u.type;
76 if (type_get_type(type) == TYPE_COCLASS && !strcmp( type->name, "PSFactoryBuffer" ))
77 return type;
78 }
79 }
80 return NULL;
81}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define NULL
Definition: types.h:112
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
uint32_t entry
Definition: isohybrid.c:63
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
statement_type_t type
Definition: parser.h:124
union _statement_t::@5034 u
static enum type_type type_get_type(const type_t *type)
Definition: typetree.h:68
@ TYPE_COCLASS
Definition: widltypes.h:410
@ STMT_TYPE
Definition: widltypes.h:242

Referenced by write_regscript().

◆ format_uuid()

static const char * format_uuid ( const UUID uuid)
static

Definition at line 43 of file register.c.

44{
45 static char buffer[40];
46 sprintf( buffer, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
47 uuid->Data1, uuid->Data2, uuid->Data3,
48 uuid->Data4[0], uuid->Data4[1], uuid->Data4[2], uuid->Data4[3],
49 uuid->Data4[4], uuid->Data4[5], uuid->Data4[6], uuid->Data4[7] );
50 return buffer;
51}
GLuint buffer
Definition: glext.h:5915
Definition: msctf.idl:550
#define sprintf(buf, format,...)
Definition: sprintf.c:55

Referenced by output_typelib_regscript(), write_coclass(), write_interface(), write_progid(), and write_typelib_interface().

◆ get_coclass_threading()

static const char * get_coclass_threading ( const type_t class)
static

Definition at line 53 of file register.c.

54{
55 static const char * const models[] =
56 {
57 NULL,
58 "Apartment", /* THREADING_APARTMENT */
59 "Neutral", /* THREADING_NEUTRAL */
60 "Single", /* THREADING_SINGLE */
61 "Free", /* THREADING_FREE */
62 "Both", /* THREADING_BOTH */
63 };
64 return models[get_attrv( class->attrs, ATTR_THREADING )];
65}
const WCHAR * class
Definition: main.c:68
unsigned int get_attrv(const attr_list_t *list, enum attr_type t)
Definition: header.c:115
@ ATTR_THREADING
Definition: widltypes.h:161

Referenced by write_coclass().

◆ output_typelib_regscript()

void output_typelib_regscript ( const typelib_t typelib)

Definition at line 304 of file register.c.

305{
306 const UUID *typelib_uuid = get_attrp( typelib->attrs, ATTR_UUID );
307 const char *descr = get_attrp( typelib->attrs, ATTR_HELPSTRING );
308 const expr_t *lcid_expr = get_attrp( typelib->attrs, ATTR_LIBLCID );
309 unsigned int version = get_attrv( typelib->attrs, ATTR_VERSION );
310 unsigned int flags = 0;
311 char id_part[12] = "";
312#ifndef __REACTOS__
313 char *resname = typelib_name;
314#endif
315 expr_t *expr;
316
317 if (is_attr( typelib->attrs, ATTR_RESTRICTED )) flags |= 1; /* LIBFLAG_FRESTRICTED */
318 if (is_attr( typelib->attrs, ATTR_CONTROL )) flags |= 2; /* LIBFLAG_FCONTROL */
319 if (is_attr( typelib->attrs, ATTR_HIDDEN )) flags |= 4; /* LIBFLAG_FHIDDEN */
320
321 put_str( indent, "HKCR\n" );
322 put_str( indent++, "{\n" );
323
324 put_str( indent, "NoRemove Typelib\n" );
325 put_str( indent++, "{\n" );
326 put_str( indent, "NoRemove '%s'\n", format_uuid( typelib_uuid ));
327 put_str( indent++, "{\n" );
328 put_str( indent, "'%u.%u' = s '%s'\n",
330 put_str( indent++, "{\n" );
331 expr = get_attrp( typelib->attrs, ATTR_ID );
332#ifdef __REACTOS__
333 if (expr)
334 sprintf(id_part, "\\%d", expr->cval);
335#else
336 if (expr)
337 {
338 sprintf(id_part, "\\%d", expr->cval);
339 resname = xmalloc( strlen(typelib_name) + 20 );
340 sprintf(resname, "%s\\%d", typelib_name, expr->cval);
341 }
342#endif
343 put_str( indent, "'%x' { %s = s '%%MODULE%%%s' }\n",
344 lcid_expr ? lcid_expr->cval : 0, pointer_size == 8 ? "win64" : "win32", id_part );
345 put_str( indent, "FLAGS = s '%u'\n", flags );
346 put_str( --indent, "}\n" );
347 put_str( --indent, "}\n" );
348 put_str( --indent, "}\n" );
349
350 put_str( indent, "NoRemove Interface\n" );
351 put_str( indent++, "{\n" );
353 put_str( --indent, "}\n" );
354
355 put_str( indent, "NoRemove CLSID\n" );
356 put_str( indent++, "{\n" );
358 put_str( --indent, "}\n" );
359
360 write_progids( typelib->stmts );
361 put_str( --indent, "}\n" );
362#ifdef __REACTOS__
363 add_output_to_resources( "WINE_REGISTRY", typelib_name );
364#else
365 add_output_to_resources( "WINE_REGISTRY", resname );
366#endif
367}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static ITypeLib * typelib
Definition: apps.c:108
void * xmalloc(int size)
Definition: uimain.c:747
#define ATTR_HIDDEN
Definition: fat.h:160
static const WCHAR version[]
Definition: asmname.c:66
GLbitfield flags
Definition: glext.h:7161
const char * descr
Definition: boot.c:45
int is_attr(const attr_list_t *list, enum attr_type t)
Definition: header.c:99
void * get_attrp(const attr_list_t *list, enum attr_type t)
Definition: header.c:107
static void write_coclasses(const statement_list_t *stmts, const typelib_t *typelib)
Definition: register.c:181
static void write_progids(const statement_list_t *stmts)
Definition: register.c:223
static int indent
Definition: register.c:41
static void write_typelib_interfaces(const typelib_t *typelib)
Definition: register.c:140
static const char * format_uuid(const UUID *uuid)
Definition: register.c:43
void add_output_to_resources(const char *type, const char *name)
Definition: utils.c:307
void put_str(int indent, const char *format,...)
Definition: utils.c:423
#define MINORVERSION(version)
Definition: utils.h:76
#define MAJORVERSION(version)
Definition: utils.h:75
int cval
Definition: widltypes.h:319
Definition: query.h:87
char * typelib_name
Definition: widl.c:139
unsigned int pointer_size
Definition: widl.c:158
@ ATTR_UUID
Definition: widltypes.h:166
@ ATTR_VERSION
Definition: widltypes.h:169
@ ATTR_CONTROL
Definition: widltypes.h:86
@ ATTR_LIBLCID
Definition: widltypes.h:122
@ ATTR_RESTRICTED
Definition: widltypes.h:153
@ ATTR_ID
Definition: widltypes.h:112
@ ATTR_HELPSTRING
Definition: widltypes.h:108

Referenced by save_all_changes().

◆ write_coclass()

static int write_coclass ( const type_t class,
const typelib_t typelib 
)
static

Definition at line 151 of file register.c.

152{
153 const UUID *uuid = get_attrp( class->attrs, ATTR_UUID );
154 const char *descr = get_attrp( class->attrs, ATTR_HELPSTRING );
155 const char *progid = get_attrp( class->attrs, ATTR_PROGID );
156 const char *vi_progid = get_attrp( class->attrs, ATTR_VIPROGID );
157 const char *threading = get_coclass_threading( class );
158 unsigned int version = get_attrv( class->attrs, ATTR_VERSION );
159
160 if (!uuid) return 0;
161 if (typelib && !threading && !progid) return 0;
162 if (!descr) descr = class->name;
163
164 put_str( indent, "'%s' = s '%s'\n", format_uuid( uuid ), descr );
165 put_str( indent++, "{\n" );
166 if (threading) put_str( indent, "InprocServer32 = s '%%MODULE%%' { val ThreadingModel = s '%s' }\n",
167 threading );
168 if (progid) put_str( indent, "ProgId = s '%s'\n", progid );
169 if (typelib)
170 {
171 const UUID *typelib_uuid = get_attrp( typelib->attrs, ATTR_UUID );
172 put_str( indent, "TypeLib = s '%s'\n", format_uuid( typelib_uuid ));
173 if (!version) version = get_attrv( typelib->attrs, ATTR_VERSION );
174 }
175 if (version) put_str( indent, "Version = s '%u.%u'\n", MAJORVERSION(version), MINORVERSION(version) );
176 if (vi_progid) put_str( indent, "VersionIndependentProgId = s '%s'\n", vi_progid );
177 put_str( --indent, "}\n" );
178 return 1;
179}
#define progid(str)
Definition: exdisp.idl:31
#define vi_progid(str)
Definition: exdisp.idl:32
#define threading(model)
Definition: exdisp.idl:30
static const char * get_coclass_threading(const type_t *class)
Definition: register.c:53
@ ATTR_VIPROGID
Definition: widltypes.h:170
@ ATTR_PROGID
Definition: widltypes.h:143

Referenced by write_coclasses().

◆ write_coclasses()

static void write_coclasses ( const statement_list_t stmts,
const typelib_t typelib 
)
static

Definition at line 181 of file register.c.

182{
183 const statement_t *stmt;
184
185 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
186 {
187 if (stmt->type == STMT_TYPE)
188 {
189 const type_t *type = stmt->u.type;
191 }
192 }
193}
static int write_coclass(const type_t *class, const typelib_t *typelib)
Definition: register.c:151

Referenced by output_typelib_regscript(), and write_regscript().

◆ write_interface()

static void write_interface ( const type_t iface,
const type_t ps_factory 
)
static

Definition at line 83 of file register.c.

84{
85 const UUID *uuid = get_attrp( iface->attrs, ATTR_UUID );
86 const UUID *ps_uuid = get_attrp( ps_factory->attrs, ATTR_UUID );
87
88 if (!uuid) return;
89 if (!is_object( iface )) return;
90 if (!type_iface_get_inherit(iface)) /* special case for IUnknown */
91 {
92 put_str( indent, "'%s' = s '%s'\n", format_uuid( uuid ), iface->name );
93 return;
94 }
95 if (is_local( iface->attrs )) return;
96 put_str( indent, "'%s' = s '%s'\n", format_uuid( uuid ), iface->name );
97 put_str( indent, "{\n" );
98 indent++;
99 put_str( indent, "NumMethods = s %u\n", count_methods( iface ));
100 put_str( indent, "ProxyStubClsid32 = s '%s'\n", format_uuid( ps_uuid ));
101 indent--;
102 put_str( indent, "}\n" );
103}
int count_methods(const type_t *iface)
Definition: proxy.c:465
int is_local(const attr_list_t *a)
Definition: header.c:938
int is_object(const type_t *iface)
Definition: header.c:928
attr_list_t * attrs
Definition: widltypes.h:422
const char * name
Definition: widltypes.h:419
static type_t * type_iface_get_inherit(const type_t *type)
Definition: typetree.h:158

Referenced by write_interfaces().

◆ write_interfaces()

static void write_interfaces ( const statement_list_t stmts,
const type_t ps_factory 
)
static

Definition at line 105 of file register.c.

106{
107 const statement_t *stmt;
108
109 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
110 {
111 if (stmt->type == STMT_TYPE && type_get_type( stmt->u.type ) == TYPE_INTERFACE)
112 write_interface( stmt->u.type, ps_factory );
113 }
114}
static void write_interface(const type_t *iface, const type_t *ps_factory)
Definition: register.c:83
@ TYPE_INTERFACE
Definition: widltypes.h:412

Referenced by write_regscript().

◆ write_progid()

static int write_progid ( const type_t class)
static

Definition at line 195 of file register.c.

196{
197 const UUID *uuid = get_attrp( class->attrs, ATTR_UUID );
198 const char *descr = get_attrp( class->attrs, ATTR_HELPSTRING );
199 const char *progid = get_attrp( class->attrs, ATTR_PROGID );
200 const char *vi_progid = get_attrp( class->attrs, ATTR_VIPROGID );
201
202 if (!uuid) return 0;
203 if (!descr) descr = class->name;
204
205 if (progid)
206 {
207 put_str( indent, "'%s' = s '%s'\n", progid, descr );
208 put_str( indent++, "{\n" );
209 put_str( indent, "CLSID = s '%s'\n", format_uuid( uuid ) );
210 put_str( --indent, "}\n" );
211 }
212 if (vi_progid)
213 {
214 put_str( indent, "'%s' = s '%s'\n", vi_progid, descr );
215 put_str( indent++, "{\n" );
216 put_str( indent, "CLSID = s '%s'\n", format_uuid( uuid ) );
217 if (progid && strcmp( progid, vi_progid )) put_str( indent, "CurVer = s '%s'\n", progid );
218 put_str( --indent, "}\n" );
219 }
220 return 1;
221}

Referenced by write_progids().

◆ write_progids()

static void write_progids ( const statement_list_t stmts)
static

Definition at line 223 of file register.c.

224{
225 const statement_t *stmt;
226
227 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
228 {
229 if (stmt->type == STMT_TYPE)
230 {
231 const type_t *type = stmt->u.type;
233 }
234 }
235}
static int write_progid(const type_t *class)
Definition: register.c:195

Referenced by output_typelib_regscript(), and write_regscript().

◆ write_regscript()

void write_regscript ( const statement_list_t stmts)

Definition at line 237 of file register.c.

238{
239 const type_t *ps_factory;
240
241 if (!do_regscript) return;
242 if (do_everything && !need_proxy_file( stmts )) return;
243
245
246 put_str( indent, "HKCR\n" );
247 put_str( indent++, "{\n" );
248
249 put_str( indent, "NoRemove Interface\n" );
250 put_str( indent++, "{\n" );
251 ps_factory = find_ps_factory( stmts );
252 if (ps_factory) write_interfaces( stmts, ps_factory );
253 put_str( --indent, "}\n" );
254
255 put_str( indent, "NoRemove CLSID\n" );
256 put_str( indent++, "{\n" );
257 write_coclasses( stmts, NULL );
258 put_str( --indent, "}\n" );
259
260 write_progids( stmts );
261 put_str( --indent, "}\n" );
262
263 if (strendswith( regscript_name, ".res" )) /* create a binary resource file */
264 {
265 add_output_to_resources( "WINE_REGISTRY", regscript_token );
267 }
268 else
269 {
270 FILE *f = fopen( regscript_name, "w" );
271 if (!f) error( "Could not open %s for output\n", regscript_name );
273 error( "Failed to write to %s\n", regscript_name );
274 if (fclose( f ))
275 error( "Failed to write to %s\n", regscript_name );
276 }
277}
GLfloat f
Definition: glext.h:7540
int need_proxy_file(const statement_list_t *stmts)
Definition: proxy.c:809
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define error(str)
Definition: mkdosfs.c:1605
static const type_t * find_ps_factory(const statement_list_t *stmts)
Definition: register.c:67
static void write_interfaces(const statement_list_t *stmts, const type_t *ps_factory)
Definition: register.c:105
size_t output_buffer_pos
Definition: utils.c:253
void flush_output_resources(const char *name)
Definition: utils.c:341
int strendswith(const char *str, const char *end)
Definition: utils.c:238
void init_output_buffer(void)
Definition: utils.c:272
int do_regscript
Definition: widl.c:122
int do_everything
Definition: widl.c:114
char * regscript_name
Definition: widl.c:147
char * regscript_token
Definition: widl.c:148

◆ write_typelib_interface()

static void write_typelib_interface ( const type_t iface,
const typelib_t typelib 
)
static

Definition at line 116 of file register.c.

117{
118 const UUID *typelib_uuid = get_attrp( typelib->attrs, ATTR_UUID );
119 const UUID *uuid = get_attrp( iface->attrs, ATTR_UUID );
120 unsigned int version = get_attrv( typelib->attrs, ATTR_VERSION );
121
122 if (!uuid) return;
123 if (!is_object( iface )) return;
124 if (!is_attr( iface->attrs, ATTR_OLEAUTOMATION ) && !is_attr( iface->attrs, ATTR_DISPINTERFACE ))
125 return;
126 put_str( indent, "'%s' = s '%s'\n", format_uuid( uuid ), iface->name );
127 put_str( indent, "{\n" );
128 indent++;
129 put_str( indent, "ProxyStubClsid = s '{00020424-0000-0000-C000-000000000046}'\n" );
130 put_str( indent, "ProxyStubClsid32 = s '{00020424-0000-0000-C000-000000000046}'\n" );
131 if (version)
132 put_str( indent, "TypeLib = s '%s' { val Version = s '%u.%u' }\n",
134 else
135 put_str( indent, "TypeLib = s '%s'", format_uuid( typelib_uuid ));
136 indent--;
137 put_str( indent, "}\n" );
138}
@ ATTR_OLEAUTOMATION
Definition: widltypes.h:135
@ ATTR_DISPINTERFACE
Definition: widltypes.h:94

Referenced by write_typelib_interfaces().

◆ write_typelib_interfaces()

static void write_typelib_interfaces ( const typelib_t typelib)
static

Definition at line 140 of file register.c.

141{
142 const statement_t *stmt;
143
144 if (typelib->stmts) LIST_FOR_EACH_ENTRY( stmt, typelib->stmts, const statement_t, entry )
145 {
146 if (stmt->type == STMT_TYPE && type_get_type( stmt->u.type ) == TYPE_INTERFACE)
148 }
149}
static void write_typelib_interface(const type_t *iface, const typelib_t *typelib)
Definition: register.c:116

Referenced by output_typelib_regscript().

◆ write_typelib_regscript()

void write_typelib_regscript ( const statement_list_t stmts)

Definition at line 280 of file register.c.

281{
282 const statement_t *stmt;
283 unsigned int count = 0;
284
285 if (!do_typelib) return;
286 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
287 {
288 if (stmt->type != STMT_LIBRARY) continue;
289 if (count && !strendswith( typelib_name, ".res" ))
290 error( "Cannot store multiple typelibs into %s\n", typelib_name );
291 else
292 {
293 if (do_old_typelib)
294 create_sltg_typelib( stmt->u.lib );
295 else
296 create_msft_typelib( stmt->u.lib );
297 }
298 count++;
299 }
301}
GLuint GLuint GLsizei count
Definition: gl.h:1545
int create_msft_typelib(typelib_t *typelib)
Definition: write_msft.c:2657
int create_sltg_typelib(typelib_t *typelib)
Definition: write_sltg.c:1831
typelib_t * lib
Definition: widltypes.h:540
int do_typelib
Definition: widl.c:117
int do_old_typelib
Definition: widl.c:118
@ STMT_LIBRARY
Definition: widltypes.h:240

Variable Documentation

◆ indent