- Support multiple interfaces per idl file.
[reactos.git] / reactos / tools / widl / server.c
1 /*
2 * IDL Compiler
3 *
4 * Copyright 2005 Eric Kohl
5 *
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.
10 *
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.
15 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "config.h"
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28 #include <string.h>
29 #include <assert.h>
30 #include <ctype.h>
31 #include <signal.h>
32
33 #include "widl.h"
34 #include "utils.h"
35 #include "parser.h"
36 #include "header.h"
37
38 #define END_OF_LIST(list) \
39 do { \
40 if (list) { \
41 while (NEXT_LINK(list)) \
42 list = NEXT_LINK(list); \
43 } \
44 } while(0)
45
46 static FILE* server;
47 static int indent = 0;
48
49
50 static int print_server(const char *format, ...)
51 {
52 va_list va;
53 int i, r;
54
55 va_start(va, format);
56 for (i = 0; i < indent; i++)
57 fprintf(server, " ");
58 r = vfprintf(server, format, va);
59 va_end(va);
60 return r;
61 }
62
63
64 static void write_procformatstring(type_t *iface)
65 {
66 func_t *func = iface->funcs;
67 var_t *var;
68
69 print_server("static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =\n");
70 print_server("{\n");
71 indent++;
72 print_server("0,\n");
73 print_server("{\n");
74 indent++;
75
76 while (NEXT_LINK(func)) func = NEXT_LINK(func);
77 while (func)
78 {
79 /* emit argument data */
80 if (func->args)
81 {
82 var = func->args;
83 while (NEXT_LINK(var)) var = NEXT_LINK(var);
84 while (var)
85 {
86 switch(var->type->type)
87 {
88 case RPC_FC_BYTE:
89 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
90 print_server("0x%02x, /* FC_BYTE */\n", var->type->type);
91 break;
92 case RPC_FC_CHAR:
93 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
94 print_server("0x%02x, /* FC_CHAR */\n", var->type->type);
95 break;
96 case RPC_FC_WCHAR:
97 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
98 print_server("0x%02x, /* FC_WCHAR */\n", var->type->type);
99 break;
100 case RPC_FC_USHORT:
101 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
102 print_server("0x%02x, /* FC_USHORT */\n", var->type->type);
103 break;
104 case RPC_FC_SHORT:
105 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
106 print_server("0x%02x, /* FC_SHORT */\n", var->type->type);
107 break;
108 case RPC_FC_ULONG:
109 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
110 print_server("0x%02x, /* FC_ULONG */\n", var->type->type);
111 break;
112 case RPC_FC_LONG:
113 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
114 print_server("0x%02x, /* FC_LONG */\n", var->type->type);
115 break;
116 case RPC_FC_HYPER:
117 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
118 print_server("0x%02x, /* FC_HYPER */\n", var->type->type);
119 break;
120 case RPC_FC_IGNORE:
121 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
122 print_server("0x%02x, /* FC_IGNORE */\n", var->type->type);
123 break;
124 case RPC_FC_SMALL:
125 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
126 print_server("0x%02x, /* FC_SMALL */\n", RPC_FC_SMALL);
127 break;
128 case RPC_FC_FLOAT:
129 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
130 print_server("0x%02x, /* FC_FLOAT */\n", RPC_FC_FLOAT);
131 break;
132 case RPC_FC_DOUBLE:
133 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
134 print_server("0x%02x, /* FC_DOUBLE */\n", RPC_FC_DOUBLE);
135 break;
136 default:
137 error("Unknown/unsupported type\n");
138 }
139
140 var = PREV_LINK(var);
141 }
142 }
143
144 /* emit return value data */
145 var = func->def;
146 if (is_void(var->type, NULL))
147 {
148 print_server("0x5b, /* FC_END */\n");
149 print_server("0x5c, /* FC_PAD */\n");
150 }
151 else
152 {
153 switch(var->type->type)
154 {
155 case RPC_FC_BYTE:
156 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
157 print_server("0x%02x, /* FC_BYTE */\n", var->type->type);
158 break;
159 case RPC_FC_CHAR:
160 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
161 print_server("0x%02x, /* FC_CHAR */\n", var->type->type);
162 break;
163 case RPC_FC_WCHAR:
164 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
165 print_server("0x%02x, /* FC_WCHAR */\n", var->type->type);
166 break;
167 case RPC_FC_USHORT:
168 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
169 print_server("0x%02x, /* FC_USHORT */\n", var->type->type);
170 break;
171 case RPC_FC_SHORT:
172 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
173 print_server("0x%02x, /* FC_SHORT */\n", var->type->type);
174 break;
175 case RPC_FC_ULONG:
176 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
177 print_server("0x%02x, /* FC_ULONG */\n", var->type->type);
178 break;
179 case RPC_FC_LONG:
180 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
181 print_server("0x%02x, /* FC_LONG */\n", var->type->type);
182 break;
183 case RPC_FC_HYPER:
184 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
185 print_server("0x%02x, /* FC_HYPER */\n", var->type->type);
186 break;
187 case RPC_FC_SMALL:
188 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
189 print_server("0x%02x, /* FC_SMALL */\n", RPC_FC_SMALL);
190 break;
191 case RPC_FC_FLOAT:
192 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
193 print_server("0x%02x, /* FC_FLOAT */\n", RPC_FC_FLOAT);
194 break;
195 case RPC_FC_DOUBLE:
196 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
197 print_server("0x%02x, /* FC_DOUBLE */\n", RPC_FC_DOUBLE);
198 break;
199 default:
200 error("Unknown/unsupported type\n");
201 }
202 }
203
204 func = PREV_LINK(func);
205 }
206
207 print_server("0x0\n");
208 indent--;
209 print_server("}\n");
210 indent--;
211 print_server("};\n");
212 print_server("\n");
213 }
214
215
216 static void write_typeformatstring(void)
217 {
218 print_server("static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =\n");
219 print_server("{\n");
220 indent++;
221 print_server("0,\n");
222 print_server("{\n");
223 indent++;
224 print_server("NdrFcShort(0x0),\n");
225 print_server("0x0\n");
226 indent--;
227 print_server("}\n");
228 indent--;
229 print_server("};\n");
230 print_server("\n");
231 }
232
233
234 unsigned int get_required_buffer_size(type_t *type)
235 {
236 switch(type->type)
237 {
238 case RPC_FC_BYTE:
239 case RPC_FC_SMALL:
240 case RPC_FC_CHAR:
241 case RPC_FC_WCHAR:
242 case RPC_FC_USHORT:
243 case RPC_FC_SHORT:
244 case RPC_FC_ULONG:
245 case RPC_FC_LONG:
246 case RPC_FC_FLOAT:
247 return 4;
248
249 case RPC_FC_HYPER:
250 case RPC_FC_DOUBLE:
251 return 8;
252
253 case RPC_FC_IGNORE:
254 return 0;
255
256 default:
257 error("Unknown/unsupported type: %s\n", type->name);
258 }
259 }
260
261
262 static void unmarshall_arguments(func_t *func)
263 {
264 unsigned int alignment;
265 unsigned int size;
266 unsigned int last_size = 0;
267 var_t *var;
268
269 if (!func->args)
270 return;
271
272 var = func->args;
273 while (NEXT_LINK(var)) var = NEXT_LINK(var);
274 while (var)
275 {
276 alignment = 0;
277 switch (var->type->type)
278 {
279 case RPC_FC_BYTE:
280 case RPC_FC_CHAR:
281 case RPC_FC_SMALL:
282 size = 1;
283 alignment = 0;
284 break;
285
286 case RPC_FC_WCHAR:
287 case RPC_FC_USHORT:
288 case RPC_FC_SHORT:
289 size = 2;
290 if (last_size != 0 && last_size < 2)
291 alignment = (2 - last_size);
292 break;
293
294 case RPC_FC_ULONG:
295 case RPC_FC_LONG:
296 case RPC_FC_FLOAT:
297 size = 4;
298 if (last_size != 0 && last_size < 4)
299 alignment = (4 - last_size);
300 break;
301
302 case RPC_FC_HYPER:
303 case RPC_FC_DOUBLE:
304 size = 8;
305 if (last_size != 0 && last_size < 4)
306 alignment = (4 - last_size);
307 break;
308
309 case RPC_FC_IGNORE:
310 size = 0;
311 break;
312
313 default:
314 error("Unknown/unsupported type!");
315 }
316
317 if (size != 0)
318 {
319 if (alignment != 0)
320 print_server("_StubMsg.Buffer += %u;\n", alignment);
321
322 print_server("");
323 write_name(server, var);
324 fprintf(server, " = *((");
325 write_type(server, var->type, var, var->tname);
326 fprintf(server, " __RPC_FAR*)_StubMsg.Buffer)++;\n");
327 fprintf(server, "\n");
328
329 last_size = size;
330 }
331
332 var = PREV_LINK(var);
333 }
334 }
335
336
337 static void write_function_stubs(type_t *iface)
338 {
339 int explicit_handle = is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE);
340 func_t *func = iface->funcs;
341 var_t *var;
342 var_t* explicit_handle_var;
343 unsigned int proc_offset = 0;
344
345 while (NEXT_LINK(func)) func = NEXT_LINK(func);
346 while (func)
347 {
348 var_t *def = func->def;
349
350 /* check for a defined binding handle */
351 explicit_handle_var = get_explicit_handle_var(func);
352 if (explicit_handle)
353 {
354 if (!explicit_handle_var)
355 {
356 error("%s() does not define an explicit binding handle!\n", def->name);
357 return;
358 }
359 }
360 else
361 {
362 if (explicit_handle_var)
363 {
364 error("%s() must not define a binding handle!\n", def->name);
365 return;
366 }
367 }
368
369 write_type(server, def->type, def, def->tname);
370 fprintf(server, " __RPC_STUB\n");
371 fprintf(server, "%s_", iface->name);
372 write_name(server, def);
373 fprintf(server, "(\n");
374 indent++;
375 print_server("PRPC_MESSAGE _pRpcMessage)\n");
376 indent--;
377
378 /* write the functions body */
379 fprintf(server, "{\n");
380 indent++;
381
382 /* declare return value '_RetVal' */
383 if (!is_void(def->type, NULL))
384 {
385 print_server("");
386 write_type(server, def->type, def, def->tname);
387 fprintf(server, " _RetVal;\n");
388 }
389
390 /* declare arguments */
391 if (func->args)
392 {
393 var = func->args;
394 while (NEXT_LINK(var)) var = NEXT_LINK(var);
395 while (var)
396 {
397 print_server("");
398 write_type(server, var->type, var, var->tname);
399 fprintf(server, " ");
400 write_name(server, var);
401 fprintf(server, ";\n");
402
403 var = PREV_LINK(var);
404 }
405 }
406
407 print_server("MIDL_STUB_MESSAGE _StubMsg;\n");
408 print_server("RPC_STATUS _Status;\n");
409 fprintf(server, "\n");
410
411
412 print_server("((void)(_Status));\n");
413 print_server("NdrServerInitializeNew(\n");
414 indent++;
415 print_server("_pRpcMessage,\n");
416 print_server("&_StubMsg,\n");
417 print_server("&%s_StubDesc);\n", iface->name);
418 indent--;
419 fprintf(server, "\n");
420
421 if (explicit_handle)
422 {
423 print_server("%s = _pRpcMessage->Handle;\n", explicit_handle_var->name);
424 fprintf(server, "\n");
425 }
426
427 print_server("RpcTryFinally\n");
428 print_server("{\n");
429 indent++;
430 print_server("RpcTryExcept\n");
431 print_server("{\n");
432 indent++;
433
434 if (func->args)
435 {
436 print_server("if ((_pRpcMessage->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)\n");
437 indent++;
438 print_server("NdrConvert(\n");
439 indent++;
440 print_server("(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
441 print_server("(PFORMAT_STRING)&__MIDL_ProcFormatString.Format[%u]);\n", proc_offset);
442 indent -= 2;
443 fprintf(server, "\n");
444
445 unmarshall_arguments(func);
446 }
447
448 print_server("if (_StubMsg.Buffer > _StubMsg.BufferEnd)\n");
449 print_server("{\n");
450 indent++;
451 print_server("RpcRaiseException(RPC_X_BAD_STUB_DATA);\n");
452 indent--;
453 print_server("}\n");
454 indent--;
455 print_server("}\n");
456 print_server("RpcExcept(RPC_BAD_STUB_DATA_EXCEPTION_FILTER)\n");
457 print_server("{\n");
458 indent++;
459 print_server("RpcRaiseException(RPC_X_BAD_STUB_DATA);\n");
460 indent--;
461 print_server("}\n");
462 print_server("RpcEndExcept\n");
463 fprintf(server, "\n");
464
465
466 /* Call the real server function */
467 if (!is_void(def->type, NULL))
468 print_server("_RetVal = ");
469 else
470 print_server("");
471 write_name(server, def);
472
473 if (func->args)
474 {
475 int first_arg = 1;
476
477 fprintf(server, "(\n");
478 indent++;
479 var = func->args;
480 while (NEXT_LINK(var)) var = NEXT_LINK(var);
481 while (var)
482 {
483 if (first_arg)
484 first_arg = 0;
485 else
486 fprintf(server, ",\n");
487 print_server("");
488 write_name(server, var);
489 var = PREV_LINK(var);
490 }
491 fprintf(server, ");\n");
492 indent--;
493 }
494 else
495 {
496 fprintf(server, "();\n");
497 }
498
499 /* marshall the return value */
500 if (!is_void(def->type, NULL))
501 {
502 fprintf(server, "\n");
503 print_server("_StubMsg.BufferLength = %uU;\n", get_required_buffer_size(def->type));
504 print_server("_pRpcMessage->BufferLength = _StubMsg.BufferLength;\n");
505 fprintf(server, "\n");
506 print_server("_Status = I_RpcGetBuffer(_pRpcMessage);\n");
507 print_server("if (_Status)\n");
508 indent++;
509 print_server("RpcRaiseException(_Status);\n");
510 indent--;
511 fprintf(server, "\n");
512 print_server("_StubMsg.Buffer = (unsigned char __RPC_FAR *)_pRpcMessage->Buffer;\n");
513 fprintf(server, "\n");
514
515 print_server("*((");
516 write_type(server, def->type, def, def->tname);
517 fprintf(server, " __RPC_FAR *)_StubMsg.Buffer)++ = _RetVal;\n");
518 }
519
520 indent--;
521 print_server("}\n");
522 print_server("RpcFinally\n");
523 print_server("{\n");
524 print_server("}\n");
525 print_server("RpcEndFinally\n");
526
527 /* calculate buffer length */
528 fprintf(server, "\n");
529 print_server("_pRpcMessage->BufferLength =\n");
530 indent++;
531 print_server("(unsigned int)((long)_StubMsg.Buffer - (long)_pRpcMessage->Buffer);\n");
532 indent--;
533 indent--;
534 fprintf(server, "}\n");
535 fprintf(server, "\n");
536
537 /* update proc_offset */
538 if (func->args)
539 {
540 var = func->args;
541 while (NEXT_LINK(var)) var = NEXT_LINK(var);
542 while (var)
543 {
544 proc_offset += 2; /* FIXME */
545 var = PREV_LINK(var);
546 }
547 }
548 proc_offset += 2; /* FIXME */
549
550 func = PREV_LINK(func);
551 }
552 }
553
554
555 static void write_dispatchtable(type_t *iface)
556 {
557 unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION);
558 unsigned long method_count = 0;
559 func_t *cur = iface->funcs;
560
561 print_server("static RPC_DISPATCH_FUNCTION %s_table[] =\n", iface->name);
562 print_server("{\n");
563 indent++;
564 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
565 while (cur)
566 {
567 var_t *def = cur->def;
568
569 print_server("%s_", iface->name);
570 write_name(server, def);
571 fprintf(server, ",\n");
572
573 method_count++;
574 cur = PREV_LINK(cur);
575 }
576 print_server("0\n");
577 indent--;
578 print_server("};\n");
579 print_server("RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable =\n", iface->name, LOWORD(ver), HIWORD(ver));
580 print_server("{\n");
581 indent++;
582 print_server("%u,\n", method_count);
583 print_server("%s_table\n", iface->name);
584 indent--;
585 print_server("};\n");
586 fprintf(server, "\n");
587 }
588
589
590 static void write_stubdescdecl(type_t *iface)
591 {
592 print_server("extern const MIDL_STUB_DESC %s_StubDesc;\n", iface->name);
593 fprintf(server, "\n");
594 }
595
596
597 static void write_stubdescriptor(type_t *iface)
598 {
599 print_server("static const MIDL_STUB_DESC %s_StubDesc =\n", iface->name);
600 print_server("{\n");
601 indent++;
602 print_server("(void __RPC_FAR *)& %s___RpcServerInterface,\n", iface->name);
603 print_server("MIDL_user_allocate,\n");
604 print_server("MIDL_user_free,\n");
605 print_server("0,\n");
606 print_server("0,\n");
607 print_server("0,\n");
608 print_server("0,\n");
609 print_server("0,\n");
610 print_server("__MIDL_TypeFormatString.Format,\n");
611 print_server("1, /* -error bounds_check flag */\n");
612 print_server("0x10001, /* Ndr library version */\n");
613 print_server("0,\n");
614 print_server("0x50100a4, /* MIDL Version 5.1.164 */\n");
615 print_server("0,\n");
616 print_server("0,\n");
617 print_server("0, /* notify & notify_flag routine table */\n");
618 print_server("1, /* Flags */\n");
619 print_server("0, /* Reserved3 */\n");
620 print_server("0, /* Reserved4 */\n");
621 print_server("0 /* Reserved5 */\n");
622 indent--;
623 print_server("};\n");
624 fprintf(server, "\n");
625 }
626
627
628 static void write_serverinterfacedecl(type_t *iface)
629 {
630 unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION);
631 UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
632
633 print_server("extern RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable;\n", iface->name, LOWORD(ver), HIWORD(ver));
634 fprintf(server, "\n");
635 print_server("static const RPC_SERVER_INTERFACE %s___RpcServerInterface =\n", iface->name );
636 print_server("{\n");
637 indent++;
638 print_server("sizeof(RPC_SERVER_INTERFACE),\n");
639 print_server("{{0x%08lx,0x%04x,0x%04x,{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x}},{%d,%d}},\n",
640 uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0], uuid->Data4[1],
641 uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5], uuid->Data4[6],
642 uuid->Data4[7], LOWORD(ver), HIWORD(ver));
643 print_server("{{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},\n"); /* FIXME */
644 print_server("&%s_v%d_%d_DispatchTable,\n", iface->name, LOWORD(ver), HIWORD(ver));
645 print_server("0,\n");
646 print_server("0,\n");
647 print_server("0,\n");
648 print_server("0,\n");
649 print_server("0,\n");
650 indent--;
651 print_server("};\n");
652 print_server("RPC_IF_HANDLE %s_v%d_%d_s_ifspec = (RPC_IF_HANDLE)& %s___RpcServerInterface;\n",
653 iface->name, LOWORD(ver), HIWORD(ver), iface->name);
654 fprintf(server, "\n");
655 }
656
657 static void write_formatdesc( const char *str )
658 {
659 print_server("typedef struct _MIDL_%s_FORMAT_STRING\n", str );
660 print_server("{\n");
661 indent++;
662 print_server("short Pad;\n");
663 print_server("unsigned char Format[%s_FORMAT_STRING_SIZE];\n", str);
664 indent--;
665 print_server("} MIDL_%s_FORMAT_STRING;\n", str);
666 print_server("\n");
667 }
668
669
670 static void write_formatstringsdecl(type_t *iface)
671 {
672 func_t *func;
673 var_t *var;
674 int byte_count = 1;
675
676 print_server("#define TYPE_FORMAT_STRING_SIZE %d\n", 3); /* FIXME */
677
678 /* determine the proc format string size */
679 func = iface->funcs;
680 while (NEXT_LINK(func)) func = NEXT_LINK(func);
681 while (func)
682 {
683 /* argument list size */
684 if (func->args)
685 {
686 var = func->args;
687 while (NEXT_LINK(var)) var = NEXT_LINK(var);
688 while (var)
689 {
690 byte_count += 2; /* FIXME: determine real size */
691 var = PREV_LINK(var);
692 }
693 }
694
695 /* return value size */
696 byte_count += 2; /* FIXME: determine real size */
697 func = PREV_LINK(func);
698 }
699 print_server("#define PROC_FORMAT_STRING_SIZE %d\n", byte_count);
700
701 fprintf(server, "\n");
702 write_formatdesc("TYPE");
703 write_formatdesc("PROC");
704 fprintf(server, "\n");
705 print_server("extern const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
706 print_server("extern const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
707 print_server("\n");
708 }
709
710
711 static void init_server(void)
712 {
713 if (server)
714 return;
715 if (!(server = fopen(server_name, "w")))
716 error("Could not open %s for output\n", server_name);
717
718 print_server("/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", WIDL_FULLVERSION, input_name);
719 print_server("#include<string.h>\n");
720 fprintf(server, "\n");
721 print_server("#include\"%s\"\n", header_name);
722 fprintf(server, "\n");
723 }
724
725
726 void write_server(ifref_t *ifaces)
727 {
728 ifref_t *iface = ifaces;
729
730 if (!do_server)
731 return;
732 if (!iface)
733 return;
734 END_OF_LIST(iface);
735
736 init_server();
737 if (!server)
738 return;
739
740 while (iface)
741 {
742 fprintf(server, "/*****************************************************************************\n");
743 fprintf(server, " * %s interface\n", iface->iface->name);
744 fprintf(server, " */\n");
745 fprintf(server, "\n");
746
747 write_formatstringsdecl(iface->iface);
748 write_serverinterfacedecl(iface->iface);
749 write_stubdescdecl(iface->iface);
750
751 write_function_stubs(iface->iface);
752
753 write_stubdescriptor(iface->iface);
754 write_dispatchtable(iface->iface);
755
756 print_server("#if !defined(__RPC_WIN32__)\n");
757 print_server("#error Invalid build platform for this stub.\n");
758 print_server("#endif\n");
759 fprintf(server, "\n");
760
761 write_procformatstring(iface->iface);
762 write_typeformatstring();
763
764 fprintf(server, "\n");
765
766 iface = PREV_LINK(iface);
767 }
768
769 fclose(server);
770 }