2 * Generation of dll registration scripts
4 * Copyright 2010 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
40 static const char *format_uuid( const UUID
*uuid
)
42 static char buffer
[40];
43 sprintf( buffer
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
44 uuid
->Data1
, uuid
->Data2
, uuid
->Data3
,
45 uuid
->Data4
[0], uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3],
46 uuid
->Data4
[4], uuid
->Data4
[5], uuid
->Data4
[6], uuid
->Data4
[7] );
50 static int write_interface( const type_t
*iface
)
52 const UUID
*uuid
= get_attrp( iface
->attrs
, ATTR_UUID
);
54 if (!type_iface_get_inherit( iface
)) return 0;
55 if (!need_proxy( iface
)) return 0;
57 put_str( indent
, "ForceRemove '%s' = s '%s'\n", format_uuid( uuid
), iface
->name
);
58 put_str( indent
, "{\n" );
60 put_str( indent
, "NumMethods = s %u\n", count_methods( iface
));
61 put_str( indent
, "ProxyStubClsid32 = s '%%CLSID_PSFactoryBuffer%%'\n" );
63 put_str( indent
, "}\n" );
67 static int write_interfaces( const statement_list_t
*stmts
)
69 const statement_t
*stmt
;
72 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
74 if (stmt
->type
== STMT_LIBRARY
)
75 count
+= write_interfaces( stmt
->u
.lib
->stmts
);
76 else if (stmt
->type
== STMT_TYPE
&& type_get_type( stmt
->u
.type
) == TYPE_INTERFACE
)
77 count
+= write_interface( stmt
->u
.type
);
82 /* put a string into the resource file */
83 static inline void put_string( const char *str
)
87 unsigned char ch
= *str
++;
88 put_word( toupper(ch
) );
93 void write_regscript( const statement_list_t
*stmts
)
97 if (!do_regscript
) return;
98 if (do_everything
&& !need_proxy_file( stmts
)) return;
100 init_output_buffer();
102 put_str( indent
, "HKCR\n" );
103 put_str( indent
++, "{\n" );
105 put_str( indent
, "NoRemove Interface\n" );
106 put_str( indent
++, "{\n" );
107 count
= write_interfaces( stmts
);
108 put_str( --indent
, "}\n" );
112 put_str( indent
, "NoRemove CLSID\n" );
113 put_str( indent
++, "{\n" );
114 put_str( indent
, "ForceRemove '%%CLSID_PSFactoryBuffer%%' = s 'PSFactoryBuffer'\n" );
115 put_str( indent
++, "{\n" );
116 put_str( indent
, "InprocServer32 = s '%%MODULE%%' { val ThreadingModel = s 'Both' }\n" );
117 put_str( --indent
, "}\n" );
118 put_str( --indent
, "}\n" );
121 put_str( --indent
, "}\n" );
123 if (strendswith( regscript_name
, ".res" )) /* create a binary resource file */
125 unsigned char *data
= output_buffer
;
126 size_t data_size
= output_buffer_pos
;
127 size_t header_size
= 5 * sizeof(unsigned int) + 2 * sizeof(unsigned short);
129 header_size
+= (strlen(regscript_token
) + strlen("WINE_REGISTRY") + 2) * sizeof(unsigned short);
131 init_output_buffer();
133 put_dword( 0 ); /* ResSize */
134 put_dword( 32 ); /* HeaderSize */
135 put_word( 0xffff ); /* ResType */
137 put_word( 0xffff ); /* ResName */
139 put_dword( 0 ); /* DataVersion */
140 put_word( 0 ); /* Memory options */
141 put_word( 0 ); /* Language */
142 put_dword( 0 ); /* Version */
143 put_dword( 0 ); /* Characteristics */
145 put_dword( data_size
); /* ResSize */
146 put_dword( (header_size
+ 3) & ~3 ); /* HeaderSize */
147 put_string( "WINE_REGISTRY" ); /* ResType */
148 put_string( regscript_token
); /* ResName */
150 put_dword( 0 ); /* DataVersion */
151 put_word( 0 ); /* Memory options */
152 put_word( 0 ); /* Language */
153 put_dword( 0 ); /* Version */
154 put_dword( 0 ); /* Characteristics */
156 put_data( data
, data_size
);
159 flush_output_buffer( regscript_name
);
163 FILE *f
= fopen( regscript_name
, "w" );
164 if (!f
) error( "Could not open %s for output\n", regscript_name
);
165 if (fwrite( output_buffer
, output_buffer_pos
, 1, f
) != output_buffer_pos
)
166 error( "Failed to write to %s\n", regscript_name
);
168 error( "Failed to write to %s\n", regscript_name
);