quartz: Increase min_lag.
[wine.git] / tools / widl / register.c
blob61870ea1349caee636b03d29eb30c0eb5479af93
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 #include <string.h>
30 #include <ctype.h>
32 #include "widl.h"
33 #include "utils.h"
34 #include "parser.h"
35 #include "header.h"
36 #include "typegen.h"
38 static int indent;
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] );
47 return buffer;
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;
56 if (!uuid) return 0;
57 put_str( indent, "ForceRemove '%s' = s '%s'\n", format_uuid( uuid ), iface->name );
58 put_str( indent, "{\n" );
59 indent++;
60 put_str( indent, "NumMethods = s %u\n", count_methods( iface ));
61 put_str( indent, "ProxyStubClsid32 = s '%%CLSID_PSFactoryBuffer%%'\n" );
62 indent--;
63 put_str( indent, "}\n" );
64 return 1;
67 static int write_interfaces( const statement_list_t *stmts )
69 const statement_t *stmt;
70 int count = 0;
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 );
79 return count;
82 /* put a string into the resource file */
83 static inline void put_string( const char *str )
85 while (*str)
87 unsigned char ch = *str++;
88 put_word( toupper(ch) );
90 put_word( 0 );
93 void write_regscript( const statement_list_t *stmts )
95 int count;
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" );
110 if (count)
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 */
136 put_word( 0x0000 );
137 put_word( 0xffff ); /* ResName */
138 put_word( 0x0000 );
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 */
149 align_output( 4 );
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 );
157 free( data );
158 align_output( 4 );
159 flush_output_buffer( regscript_name );
161 else
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 );
167 if (fclose( f ))
168 error( "Failed to write to %s\n", regscript_name );