wintab32: Remove unneeded cast.
[wine] / tools / widl / proxy.c
1 /*
2  * IDL Compiler
3  *
4  * Copyright 2002 Ove Kaaven
5  * Copyright 2004 Mike McCormack
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #include <string.h>
31 #include <assert.h>
32 #include <ctype.h>
33 #include <signal.h>
34
35 #include "widl.h"
36 #include "utils.h"
37 #include "parser.h"
38 #include "header.h"
39 #include "typegen.h"
40
41 #define END_OF_LIST(list)       \
42   do {                          \
43     if (list) {                 \
44       while (NEXT_LINK(list))   \
45         list = NEXT_LINK(list); \
46     }                           \
47   } while(0)
48
49 static FILE* proxy;
50 static int indent = 0;
51
52 /* FIXME: support generation of stubless proxies */
53
54 static void print_proxy( const char *format, ... )
55 {
56   va_list va;
57   va_start( va, format );
58   print( proxy, indent, format, va );
59   va_end( va );
60 }
61
62 static void write_stubdescproto(void)
63 {
64   print_proxy( "static const MIDL_STUB_DESC Object_StubDesc;\n");
65   print_proxy( "\n");
66 }
67
68 static void write_stubdesc(int expr_eval_routines)
69 {
70   print_proxy( "static const MIDL_STUB_DESC Object_StubDesc =\n{\n");
71   indent++;
72   print_proxy( "0,\n");
73   print_proxy( "NdrOleAllocate,\n");
74   print_proxy( "NdrOleFree,\n");
75   print_proxy( "{0}, 0, 0, %s, 0,\n", expr_eval_routines ? "ExprEvalRoutines" : "0");
76   print_proxy( "__MIDL_TypeFormatString.Format,\n");
77   print_proxy( "1, /* -error bounds_check flag */\n");
78   print_proxy( "0x10001, /* Ndr library version */\n");
79   print_proxy( "0,\n");
80   print_proxy( "0x50100a4, /* MIDL Version 5.1.164 */\n");
81   print_proxy( "0,\n");
82   print_proxy("%s,\n", list_empty(&user_type_list) ? "0" : "UserMarshalRoutines");
83   print_proxy( "0,  /* notify & notify_flag routine table */\n");
84   print_proxy( "1,  /* Flags */\n");
85   print_proxy( "0,  /* Reserved3 */\n");
86   print_proxy( "0,  /* Reserved4 */\n");
87   print_proxy( "0   /* Reserved5 */\n");
88   indent--;
89   print_proxy( "};\n");
90   print_proxy( "\n");
91 }
92
93 static void init_proxy(ifref_list_t *ifaces)
94 {
95   if (proxy) return;
96   if(!(proxy = fopen(proxy_name, "w")))
97     error("Could not open %s for output\n", proxy_name);
98   print_proxy( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
99   print_proxy( "\n");
100   print_proxy( "#ifndef __REDQ_RPCPROXY_H_VERSION__\n");
101   print_proxy( "#define __REQUIRED_RPCPROXY_H_VERSION__ 440\n");
102   print_proxy( "#endif /* __REDQ_RPCPROXY_H_VERSION__ */\n");
103   print_proxy( "\n");
104   print_proxy( "#define __midl_proxy\n");
105   print_proxy( "#include \"objbase.h\"\n");
106   print_proxy( "#include \"rpcproxy.h\"\n");
107   print_proxy( "#ifndef __RPCPROXY_H_VERSION__\n");
108   print_proxy( "#error This code needs a newer version of rpcproxy.h\n");
109   print_proxy( "#endif /* __RPCPROXY_H_VERSION__ */\n");
110   print_proxy( "\n");
111   print_proxy( "#include \"%s\"\n", header_name);
112   print_proxy( "\n");
113   write_formatstringsdecl(proxy, indent, ifaces, need_proxy);
114   write_stubdescproto();
115 }
116
117 static void clear_output_vars( const var_list_t *args )
118 {
119   const var_t *arg;
120
121   if (!args) return;
122   LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
123   {
124     if (is_attr(arg->attrs, ATTR_OUT) && !is_attr(arg->attrs, ATTR_IN)) {
125       print_proxy( "if(%s)\n", arg->name );
126       indent++;
127       print_proxy( "MIDL_memset( %s, 0, sizeof( *%s ));\n", arg->name, arg->name );
128       indent--;
129     }
130   }
131 }
132
133 int is_var_ptr(const var_t *v)
134 {
135   return is_ptr(v->type);
136 }
137
138 int cant_be_null(const var_t *v)
139 {
140   /* Search backwards for the most recent pointer attribute.  */
141   const attr_list_t *attrs = v->attrs;
142   const type_t *type = v->type;
143
144   if (! attrs && type)
145   {
146     attrs = type->attrs;
147     type = type->ref;
148   }
149
150   while (attrs)
151   {
152     int t = get_attrv(attrs, ATTR_POINTERTYPE);
153
154     if (t == RPC_FC_FP || t == RPC_FC_OP || t == RPC_FC_UP)
155       return 0;
156
157     if (t == RPC_FC_RP)
158       return 1;
159
160     if (type)
161     {
162       attrs = type->attrs;
163       type = type->ref;
164     }
165     else
166       attrs = NULL;
167   }
168
169   return 1;                             /* Default is RPC_FC_RP.  */
170 }
171
172 static void proxy_check_pointers( const var_list_t *args )
173 {
174   const var_t *arg;
175
176   if (!args) return;
177   LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
178   {
179     if (is_var_ptr(arg) && cant_be_null(arg)) {
180         print_proxy( "if(!%s)\n", arg->name );
181         indent++;
182         print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
183         indent--;
184     }
185   }
186 }
187
188 static void free_variable( const var_t *arg )
189 {
190   unsigned int type_offset = arg->type->typestring_offset;
191   expr_t *iid;
192   type_t *type = arg->type;
193   expr_t *size = get_size_is_expr(type, arg->name);
194
195   if (size)
196   {
197     print_proxy( "_StubMsg.MaxCount = " );
198     write_expr(proxy, size, 0);
199     fprintf(proxy, ";\n\n");
200     print_proxy( "NdrClearOutParameters( &_StubMsg, ");
201     fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
202     fprintf(proxy, "(void*)%s );\n", arg->name );
203     return;
204   }
205
206   switch( type->type )
207   {
208   case RPC_FC_BYTE:
209   case RPC_FC_CHAR:
210   case RPC_FC_WCHAR:
211   case RPC_FC_SHORT:
212   case RPC_FC_USHORT:
213   case RPC_FC_ENUM16:
214   case RPC_FC_LONG:
215   case RPC_FC_ULONG:
216   case RPC_FC_ENUM32:
217   case RPC_FC_STRUCT:
218     break;
219
220   case RPC_FC_FP:
221   case RPC_FC_IP:
222     iid = get_attrp( arg->attrs, ATTR_IIDIS );
223     if( iid )
224     {
225       print_proxy( "_StubMsg.MaxCount = (unsigned long) " );
226       write_expr(proxy, iid, 1);
227       print_proxy( ";\n\n" );
228     }
229     print_proxy( "NdrClearOutParameters( &_StubMsg, ");
230     fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
231     fprintf(proxy, "(void*)%s );\n", arg->name );
232     break;
233
234   default:
235     print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
236   }
237 }
238
239 static void proxy_free_variables( var_list_t *args )
240 {
241   const var_t *arg;
242
243   if (!args) return;
244   LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
245     if (is_attr(arg->attrs, ATTR_OUT))
246     {
247       free_variable( arg );
248       fprintf(proxy, "\n");
249     }
250 }
251
252 static void gen_proxy(type_t *iface, const func_t *cur, int idx,
253                       unsigned int proc_offset)
254 {
255   var_t *def = cur->def;
256   int has_ret = !is_void(def->type);
257   int has_full_pointer = is_full_pointer_function(cur);
258
259   indent = 0;
260   write_type_decl_left(proxy, def->type);
261   print_proxy( " STDMETHODCALLTYPE %s_", iface->name);
262   write_name(proxy, def);
263   print_proxy( "_Proxy(\n");
264   write_args(proxy, cur->args, iface->name, 1, TRUE);
265   print_proxy( ")\n");
266   print_proxy( "{\n");
267   indent ++;
268   /* local variables */
269   if (has_ret) {
270     print_proxy( "" );
271     write_type_decl_left(proxy, def->type);
272     print_proxy( " _RetVal;\n");
273   }
274   print_proxy( "RPC_MESSAGE _RpcMessage;\n" );
275   print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n" );
276   if (has_ret) {
277     if (decl_indirect(def->type))
278       print_proxy("void *_p_%s = &%s;\n",
279                  "_RetVal", "_RetVal");
280   }
281   print_proxy( "\n");
282
283   if (has_full_pointer)
284     write_full_pointer_init(proxy, indent, cur, FALSE);
285
286   /* FIXME: trace */
287   clear_output_vars( cur->args );
288
289   print_proxy( "RpcTryExcept\n" );
290   print_proxy( "{\n" );
291   indent++;
292   print_proxy( "NdrProxyInitialize(This, &_RpcMessage, &_StubMsg, &Object_StubDesc, %d);\n", idx);
293   proxy_check_pointers( cur->args );
294
295   print_proxy( "RpcTryFinally\n" );
296   print_proxy( "{\n" );
297   indent++;
298
299   write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_BUFFERSIZE);
300
301   print_proxy( "NdrProxyGetBuffer(This, &_StubMsg);\n" );
302
303   write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_MARSHAL);
304
305   print_proxy( "NdrProxySendReceive(This, &_StubMsg);\n" );
306   fprintf(proxy, "\n");
307   print_proxy( "_StubMsg.BufferStart = _RpcMessage.Buffer;\n" );
308   print_proxy( "_StubMsg.BufferEnd   = _StubMsg.BufferStart + _RpcMessage.BufferLength;\n\n" );
309
310   print_proxy("if ((_RpcMessage.DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
311   indent++;
312   print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
313   indent--;
314   fprintf(proxy, "\n");
315
316   write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_UNMARSHAL);
317
318   if (has_ret)
319   {
320       if (decl_indirect(def->type))
321           print_proxy("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal");
322       else if (is_ptr(def->type) || is_array(def->type))
323           print_proxy("%s = 0;\n", "_RetVal");
324       write_remoting_arguments(proxy, indent, cur, PASS_RETURN, PHASE_UNMARSHAL);
325   }
326
327   indent--;
328   print_proxy( "}\n");
329   print_proxy( "RpcFinally\n" );
330   print_proxy( "{\n" );
331   indent++;
332   if (has_full_pointer)
333     write_full_pointer_free(proxy, indent, cur);
334   print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" );
335   indent--;
336   print_proxy( "}\n");
337   print_proxy( "RpcEndFinally\n" );
338   indent--;
339   print_proxy( "}\n" );
340   print_proxy( "RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
341   print_proxy( "{\n" );
342   if (has_ret) {
343     indent++;
344     proxy_free_variables( cur->args );
345     print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
346     indent--;
347   }
348   print_proxy( "}\n" );
349   print_proxy( "RpcEndExcept\n" );
350
351   if (has_ret) {
352     print_proxy( "return _RetVal;\n" );
353   }
354   indent--;
355   print_proxy( "}\n");
356   print_proxy( "\n");
357 }
358
359 static void gen_stub(type_t *iface, const func_t *cur, const char *cas,
360                      unsigned int proc_offset)
361 {
362   var_t *def = cur->def;
363   const var_t *arg;
364   int has_ret = !is_void(def->type);
365   int has_full_pointer = is_full_pointer_function(cur);
366
367   indent = 0;
368   print_proxy( "void __RPC_STUB %s_", iface->name);
369   write_name(proxy, def);
370   print_proxy( "_Stub(\n");
371   indent++;
372   print_proxy( "IRpcStubBuffer* This,\n");
373   print_proxy( "IRpcChannelBuffer *_pRpcChannelBuffer,\n");
374   print_proxy( "PRPC_MESSAGE _pRpcMessage,\n");
375   print_proxy( "DWORD* _pdwStubPhase)\n");
376   indent--;
377   print_proxy( "{\n");
378   indent++;
379   print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface->name, iface->name);
380   print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n");
381   declare_stub_args( proxy, indent, cur );
382   fprintf(proxy, "\n");
383
384   /* FIXME: trace */
385
386   print_proxy("NdrStubInitialize(_pRpcMessage, &_StubMsg, &Object_StubDesc, _pRpcChannelBuffer);\n");
387   fprintf(proxy, "\n");
388
389   write_parameters_init(proxy, indent, cur);
390
391   print_proxy("RpcTryFinally\n");
392   print_proxy("{\n");
393   indent++;
394   if (has_full_pointer)
395     write_full_pointer_init(proxy, indent, cur, TRUE);
396   print_proxy("if ((_pRpcMessage->DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
397   indent++;
398   print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
399   indent--;
400   fprintf(proxy, "\n");
401
402   write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_UNMARSHAL);
403   fprintf(proxy, "\n");
404
405   assign_stub_out_args( proxy, indent, cur );
406
407   print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
408   fprintf(proxy, "\n");
409   print_proxy("");
410   if (has_ret) fprintf(proxy, "_RetVal = ");
411   if (cas) fprintf(proxy, "%s_%s_Stub", iface->name, cas);
412   else
413   {
414       fprintf(proxy, "_This->lpVtbl->");
415       write_name(proxy, def);
416   }
417   fprintf(proxy, "(_This");
418
419   if (cur->args)
420   {
421       LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
422       {
423           fprintf(proxy, ", ");
424           if (arg->type->declarray)
425               fprintf(proxy, "*");
426           write_name(proxy, arg);
427       }
428   }
429   fprintf(proxy, ");\n");
430   fprintf(proxy, "\n");
431   print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
432   fprintf(proxy, "\n");
433
434   write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_BUFFERSIZE);
435
436   print_proxy("NdrStubGetBuffer(This, _pRpcChannelBuffer, &_StubMsg);\n");
437
438   write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_MARSHAL);
439   fprintf(proxy, "\n");
440
441   if (has_ret)
442       print_phase_basetype(proxy, indent, PHASE_MARSHAL, PASS_RETURN, def, "_RetVal");
443
444   indent--;
445   print_proxy("}\n");
446   print_proxy("RpcFinally\n");
447   print_proxy("{\n");
448
449   write_remoting_arguments(proxy, indent+1, cur, PASS_OUT, PHASE_FREE);
450
451   if (has_full_pointer)
452     write_full_pointer_free(proxy, indent, cur);
453
454   print_proxy("}\n");
455   print_proxy("RpcEndFinally\n");
456
457   print_proxy("_pRpcMessage->BufferLength = _StubMsg.Buffer - (unsigned char *)_pRpcMessage->Buffer;\n");
458   indent--;
459
460   print_proxy("}\n");
461   print_proxy("\n");
462 }
463
464 static int write_proxy_methods(type_t *iface)
465 {
466   const func_t *cur;
467   int i = 0;
468
469   if (iface->ref) i = write_proxy_methods(iface->ref);
470   if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) {
471     var_t *def = cur->def;
472     if (!is_callas(def->attrs)) {
473       if (i) fprintf(proxy, ",\n");
474       print_proxy( "%s_", iface->name);
475       write_name(proxy, def);
476       fprintf(proxy, "_Proxy");
477       i++;
478     }
479   }
480   return i;
481 }
482
483 static int write_stub_methods(type_t *iface)
484 {
485   const func_t *cur;
486   int i = 0;
487
488   if (iface->ref) i = write_stub_methods(iface->ref);
489   else return i; /* skip IUnknown */
490
491   if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) {
492     var_t *def = cur->def;
493     if (!is_local(def->attrs)) {
494       if (i) fprintf(proxy,",\n");
495       print_proxy( "%s_", iface->name);
496       write_name(proxy, def);
497       fprintf(proxy, "_Stub");
498       i++;
499     }
500   }
501   return i;
502 }
503
504 static void write_proxy(type_t *iface, unsigned int *proc_offset)
505 {
506   int midx = -1, stubs;
507   const func_t *cur;
508
509   if (!iface->funcs) return;
510
511   /* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
512
513   fprintf(proxy, "/*****************************************************************************\n");
514   fprintf(proxy, " * %s interface\n", iface->name);
515   fprintf(proxy, " */\n");
516   LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
517   {
518     const var_t *def = cur->def;
519     if (!is_local(def->attrs)) {
520       const var_t *cas = is_callas(def->attrs);
521       const char *cname = cas ? cas->name : NULL;
522       int idx = cur->idx;
523       if (cname) {
524           const func_t *m;
525           LIST_FOR_EACH_ENTRY( m, iface->funcs, const func_t, entry )
526               if (!strcmp(m->def->name, cname))
527               {
528                   idx = m->idx;
529                   break;
530               }
531       }
532       gen_proxy(iface, cur, idx, *proc_offset);
533       gen_stub(iface, cur, cname, *proc_offset);
534       *proc_offset += get_size_procformatstring_func( cur );
535       if (midx == -1) midx = idx;
536       else if (midx != idx) error("method index mismatch in write_proxy\n");
537       midx++;
538     }
539   }
540
541   /* proxy vtable */
542   print_proxy( "static const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", midx, iface->name);
543   print_proxy( "{\n");
544   indent++;
545   print_proxy( "{\n", iface->name);
546   indent++;
547   print_proxy( "&IID_%s,\n", iface->name);
548   indent--;
549   print_proxy( "},\n");
550   print_proxy( "{\n");
551   indent++;
552   write_proxy_methods(iface);
553   fprintf(proxy, "\n");
554   indent--;
555   print_proxy( "}\n");
556   indent--;
557   print_proxy( "};\n");
558   fprintf(proxy, "\n\n");
559
560   /* stub vtable */
561   print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface->name);
562   print_proxy( "{\n");
563   indent++;
564   stubs = write_stub_methods(iface);
565   fprintf(proxy, "\n");
566   indent--;
567   fprintf(proxy, "};\n");
568   print_proxy( "\n");
569   print_proxy( "static const CInterfaceStubVtbl _%sStubVtbl =\n", iface->name);
570   print_proxy( "{\n");
571   indent++;
572   print_proxy( "{\n");
573   indent++;
574   print_proxy( "&IID_%s,\n", iface->name);
575   print_proxy( "0,\n");
576   print_proxy( "%d,\n", stubs+3);
577   print_proxy( "&%s_table[-3],\n", iface->name);
578   indent--;
579   print_proxy( "},\n", iface->name);
580   print_proxy( "{\n");
581   indent++;
582   print_proxy( "CStdStubBuffer_METHODS\n");
583   indent--;
584   print_proxy( "}\n");
585   indent--;
586   print_proxy( "};\n");
587   print_proxy( "\n");
588 }
589
590 static int does_any_iface(const ifref_list_t *ifaces, type_pred_t pred)
591 {
592   ifref_t *ir;
593
594   if (ifaces)
595     LIST_FOR_EACH_ENTRY(ir, ifaces, ifref_t, entry)
596       if (pred(ir->iface))
597         return TRUE;
598
599   return FALSE;
600 }
601
602 int need_proxy(const type_t *iface)
603 {
604   return is_object(iface->attrs) && !is_local(iface->attrs);
605 }
606
607 int need_stub(const type_t *iface)
608 {
609   return !is_object(iface->attrs) && !is_local(iface->attrs);
610 }
611
612 int need_proxy_file(const ifref_list_t *ifaces)
613 {
614   return does_any_iface(ifaces, need_proxy);
615 }
616
617 int need_stub_files(const ifref_list_t *ifaces)
618 {
619   return does_any_iface(ifaces, need_stub);
620 }
621
622 void write_proxies(ifref_list_t *ifaces)
623 {
624   ifref_t *cur;
625   int expr_eval_routines;
626   char *file_id = proxy_token;
627   int c;
628   unsigned int proc_offset = 0;
629
630   if (!do_proxies) return;
631   if (do_everything && !need_proxy_file(ifaces)) return;
632
633   init_proxy(ifaces);
634   if(!proxy) return;
635
636   if (ifaces)
637       LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
638           if (need_proxy(cur->iface))
639               write_proxy(cur->iface, &proc_offset);
640
641   expr_eval_routines = write_expr_eval_routines(proxy, proxy_token);
642   if (expr_eval_routines)
643       write_expr_eval_routine_list(proxy, proxy_token);
644   write_user_quad_list(proxy);
645   write_stubdesc(expr_eval_routines);
646
647   print_proxy( "#if !defined(__RPC_WIN32__)\n");
648   print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
649   print_proxy( "#endif\n");
650   print_proxy( "\n");
651   write_procformatstring(proxy, ifaces, need_proxy);
652   write_typeformatstring(proxy, ifaces, need_proxy);
653
654   fprintf(proxy, "static const CInterfaceProxyVtbl* const _%s_ProxyVtblList[] =\n", file_id);
655   fprintf(proxy, "{\n");
656   if (ifaces)
657       LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
658           if(cur->iface->ref && cur->iface->funcs && need_proxy(cur->iface))
659               fprintf(proxy, "    (const CInterfaceProxyVtbl*)&_%sProxyVtbl,\n", cur->iface->name);
660
661   fprintf(proxy, "    0\n");
662   fprintf(proxy, "};\n");
663   fprintf(proxy, "\n");
664
665   fprintf(proxy, "static const CInterfaceStubVtbl* const _%s_StubVtblList[] =\n", file_id);
666   fprintf(proxy, "{\n");
667   if (ifaces)
668       LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
669           if(cur->iface->ref && cur->iface->funcs && need_proxy(cur->iface))
670               fprintf(proxy, "    (const CInterfaceStubVtbl*)&_%sStubVtbl,\n", cur->iface->name);
671   fprintf(proxy, "    0\n");
672   fprintf(proxy, "};\n");
673   fprintf(proxy, "\n");
674
675   fprintf(proxy, "static PCInterfaceName const _%s_InterfaceNamesList[] =\n", file_id);
676   fprintf(proxy, "{\n");
677   if (ifaces)
678       LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
679           if(cur->iface->ref && cur->iface->funcs && need_proxy(cur->iface))
680               fprintf(proxy, "    \"%s\",\n", cur->iface->name);
681   fprintf(proxy, "    0\n");
682   fprintf(proxy, "};\n");
683   fprintf(proxy, "\n");
684
685   fprintf(proxy, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_%s, pIID, n)\n", file_id, file_id);
686   fprintf(proxy, "\n");
687   fprintf(proxy, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id);
688   fprintf(proxy, "{\n");
689   c = 0;
690   if (ifaces)
691       LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
692           if(cur->iface->ref && cur->iface->funcs && need_proxy(cur->iface))
693           {
694               fprintf(proxy, "    if (!_%s_CHECK_IID(%d))\n", file_id, c);
695               fprintf(proxy, "    {\n");
696               fprintf(proxy, "        *pIndex = %d;\n", c);
697               fprintf(proxy, "        return 1;\n");
698               fprintf(proxy, "    }\n");
699               c++;
700           }
701   fprintf(proxy, "    return 0;\n");
702   fprintf(proxy, "}\n");
703   fprintf(proxy, "\n");
704
705   fprintf(proxy, "const ExtendedProxyFileInfo %s_ProxyFileInfo =\n", file_id);
706   fprintf(proxy, "{\n");
707   fprintf(proxy, "    (const PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id);
708   fprintf(proxy, "    (const PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id);
709   fprintf(proxy, "    _%s_InterfaceNamesList,\n", file_id);
710   fprintf(proxy, "    0,\n");
711   fprintf(proxy, "    &_%s_IID_Lookup,\n", file_id);
712   fprintf(proxy, "    %d,\n", c);
713   fprintf(proxy, "    1,\n");
714   fprintf(proxy, "    0,\n");
715   fprintf(proxy, "    0,\n");
716   fprintf(proxy, "    0,\n");
717   fprintf(proxy, "    0\n");
718   fprintf(proxy, "};\n");
719
720   fclose(proxy);
721 }