- Server stubs are void functions.
[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 fprintf(server, "void __RPC_STUB\n");
370 fprintf(server, "%s_", iface->name);
371 write_name(server, def);
372 fprintf(server, "(\n");
373 indent++;
374 print_server("PRPC_MESSAGE _pRpcMessage)\n");
375 indent--;
376
377 /* write the functions body */
378 fprintf(server, "{\n");
379 indent++;
380
381 /* declare return value '_RetVal' */
382 if (!is_void(def->type, NULL))
383 {
384 print_server("");
385 write_type(server, def->type, def, def->tname);
386 fprintf(server, " _RetVal;\n");
387 }
388
389 /* declare arguments */
390 if (func->args)
391 {
392 var = func->args;
393 while (NEXT_LINK(var)) var = NEXT_LINK(var);
394 while (var)
395 {
396 print_server("");
397 write_type(server, var->type, var, var->tname);
398 fprintf(server, " ");
399 write_name(server, var);
400 fprintf(server, ";\n");
401
402 var = PREV_LINK(var);
403 }
404 }
405
406 print_server("MIDL_STUB_MESSAGE _StubMsg;\n");
407 print_server("RPC_STATUS _Status;\n");
408 fprintf(server, "\n");
409
410
411 print_server("((void)(_Status));\n");
412 print_server("NdrServerInitializeNew(\n");
413 indent++;
414 print_server("_pRpcMessage,\n");
415 print_server("&_StubMsg,\n");
416 print_server("&%s_StubDesc);\n", iface->name);
417 indent--;
418 fprintf(server, "\n");
419
420 if (explicit_handle)
421 {
422 print_server("%s = _pRpcMessage->Handle;\n", explicit_handle_var->name);
423 fprintf(server, "\n");
424 }
425
426 print_server("RpcTryFinally\n");
427 print_server("{\n");
428 indent++;
429 print_server("RpcTryExcept\n");
430 print_server("{\n");
431 indent++;
432
433 if (func->args)
434 {
435 print_server("if ((_pRpcMessage->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)\n");
436 indent++;
437 print_server("NdrConvert(\n");
438 indent++;
439 print_server("(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
440 print_server("(PFORMAT_STRING)&__MIDL_ProcFormatString.Format[%u]);\n", proc_offset);
441 indent -= 2;
442 fprintf(server, "\n");
443
444 unmarshall_arguments(func);
445 }
446
447 print_server("if (_StubMsg.Buffer > _StubMsg.BufferEnd)\n");
448 print_server("{\n");
449 indent++;
450 print_server("RpcRaiseException(RPC_X_BAD_STUB_DATA);\n");
451 indent--;
452 print_server("}\n");
453 indent--;
454 print_server("}\n");
455 print_server("RpcExcept(RPC_BAD_STUB_DATA_EXCEPTION_FILTER)\n");
456 print_server("{\n");
457 indent++;
458 print_server("RpcRaiseException(RPC_X_BAD_STUB_DATA);\n");
459 indent--;
460 print_server("}\n");
461 print_server("RpcEndExcept\n");
462 fprintf(server, "\n");
463
464
465 /* Call the real server function */
466 if (!is_void(def->type, NULL))
467 print_server("_RetVal = ");
468 else
469 print_server("");
470 write_name(server, def);
471
472 if (func->args)
473 {
474 int first_arg = 1;
475
476 fprintf(server, "(\n");
477 indent++;
478 var = func->args;
479 while (NEXT_LINK(var)) var = NEXT_LINK(var);
480 while (var)
481 {
482 if (first_arg)
483 first_arg = 0;
484 else
485 fprintf(server, ",\n");
486 print_server("");
487 write_name(server, var);
488 var = PREV_LINK(var);
489 }
490 fprintf(server, ");\n");
491 indent--;
492 }
493 else
494 {
495 fprintf(server, "();\n");
496 }
497
498 /* marshall the return value */
499 if (!is_void(def->type, NULL))
500 {
501 fprintf(server, "\n");
502 print_server("_StubMsg.BufferLength = %uU;\n", get_required_buffer_size(def->type));
503 print_server("_pRpcMessage->BufferLength = _StubMsg.BufferLength;\n");
504 fprintf(server, "\n");
505 print_server("_Status = I_RpcGetBuffer(_pRpcMessage);\n");
506 print_server("if (_Status)\n");
507 indent++;
508 print_server("RpcRaiseException(_Status);\n");
509 indent--;
510 fprintf(server, "\n");
511 print_server("_StubMsg.Buffer = (unsigned char __RPC_FAR *)_pRpcMessage->Buffer;\n");
512 fprintf(server, "\n");
513
514 print_server("*((");
515 write_type(server, def->type, def, def->tname);
516 fprintf(server, " __RPC_FAR *)_StubMsg.Buffer)++ = _RetVal;\n");
517 }
518
519 indent--;
520 print_server("}\n");
521 print_server("RpcFinally\n");
522 print_server("{\n");
523 print_server("}\n");
524 print_server("RpcEndFinally\n");
525
526 /* calculate buffer length */
527 fprintf(server, "\n");
528 print_server("_pRpcMessage->BufferLength =\n");
529 indent++;
530 print_server("(unsigned int)((long)_StubMsg.Buffer - (long)_pRpcMessage->Buffer);\n");
531 indent--;
532 indent--;
533 fprintf(server, "}\n");
534 fprintf(server, "\n");
535
536 /* update proc_offset */
537 if (func->args)
538 {
539 var = func->args;
540 while (NEXT_LINK(var)) var = NEXT_LINK(var);
541 while (var)
542 {
543 proc_offset += 2; /* FIXME */
544 var = PREV_LINK(var);
545 }
546 }
547 proc_offset += 2; /* FIXME */
548
549 func = PREV_LINK(func);
550 }
551 }
552
553
554 static void write_dispatchtable(type_t *iface)
555 {
556 unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION);
557 unsigned long method_count = 0;
558 func_t *cur = iface->funcs;
559
560 print_server("static RPC_DISPATCH_FUNCTION %s_table[] =\n", iface->name);
561 print_server("{\n");
562 indent++;
563 while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
564 while (cur)
565 {
566 var_t *def = cur->def;
567
568 print_server("%s_", iface->name);
569 write_name(server, def);
570 fprintf(server, ",\n");
571
572 method_count++;
573 cur = PREV_LINK(cur);
574 }
575 print_server("0\n");
576 indent--;
577 print_server("};\n");
578 print_server("RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable =\n", iface->name, LOWORD(ver), HIWORD(ver));
579 print_server("{\n");
580 indent++;
581 print_server("%u,\n", method_count);
582 print_server("%s_table\n", iface->name);
583 indent--;
584 print_server("};\n");
585 fprintf(server, "\n");
586 }
587
588
589 static void write_stubdescdecl(type_t *iface)
590 {
591 print_server("extern const MIDL_STUB_DESC %s_StubDesc;\n", iface->name);
592 fprintf(server, "\n");
593 }
594
595
596 static void write_stubdescriptor(type_t *iface)
597 {
598 print_server("static const MIDL_STUB_DESC %s_StubDesc =\n", iface->name);
599 print_server("{\n");
600 indent++;
601 print_server("(void __RPC_FAR *)& %s___RpcServerInterface,\n", iface->name);
602 print_server("MIDL_user_allocate,\n");
603 print_server("MIDL_user_free,\n");
604 print_server("{NULL},\n");
605 print_server("0,\n");
606 print_server("0,\n");
607 print_server("0,\n");
608 print_server("0,\n");
609 print_server("__MIDL_TypeFormatString.Format,\n");
610 print_server("1, /* -error bounds_check flag */\n");
611 print_server("0x10001, /* Ndr library version */\n");
612 print_server("0,\n");
613 print_server("0x50100a4, /* MIDL Version 5.1.164 */\n");
614 print_server("0,\n");
615 print_server("0,\n");
616 print_server("0, /* notify & notify_flag routine table */\n");
617 print_server("1, /* Flags */\n");
618 print_server("0, /* Reserved3 */\n");
619 print_server("0, /* Reserved4 */\n");
620 print_server("0 /* Reserved5 */\n");
621 indent--;
622 print_server("};\n");
623 fprintf(server, "\n");
624 }
625
626
627 static void write_serverinterfacedecl(type_t *iface)
628 {
629 unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION);
630 UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
631
632 print_server("extern RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable;\n", iface->name, LOWORD(ver), HIWORD(ver));
633 fprintf(server, "\n");
634 print_server("static const RPC_SERVER_INTERFACE %s___RpcServerInterface =\n", iface->name );
635 print_server("{\n");
636 indent++;
637 print_server("sizeof(RPC_SERVER_INTERFACE),\n");
638 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",
639 uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0], uuid->Data4[1],
640 uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5], uuid->Data4[6],
641 uuid->Data4[7], LOWORD(ver), HIWORD(ver));
642 print_server("{{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},\n"); /* FIXME */
643 print_server("&%s_v%d_%d_DispatchTable,\n", iface->name, LOWORD(ver), HIWORD(ver));
644 print_server("0,\n");
645 print_server("0,\n");
646 print_server("0,\n");
647 print_server("0,\n");
648 print_server("0,\n");
649 indent--;
650 print_server("};\n");
651 print_server("RPC_IF_HANDLE %s_v%d_%d_s_ifspec = (RPC_IF_HANDLE)& %s___RpcServerInterface;\n",
652 iface->name, LOWORD(ver), HIWORD(ver), iface->name);
653 fprintf(server, "\n");
654 }
655
656 static void write_formatdesc( const char *str )
657 {
658 print_server("typedef struct _MIDL_%s_FORMAT_STRING\n", str );
659 print_server("{\n");
660 indent++;
661 print_server("short Pad;\n");
662 print_server("unsigned char Format[%s_FORMAT_STRING_SIZE];\n", str);
663 indent--;
664 print_server("} MIDL_%s_FORMAT_STRING;\n", str);
665 print_server("\n");
666 }
667
668
669 static void write_formatstringsdecl(type_t *iface)
670 {
671 func_t *func;
672 var_t *var;
673 int byte_count = 1;
674
675 print_server("#define TYPE_FORMAT_STRING_SIZE %d\n", 3); /* FIXME */
676
677 /* determine the proc format string size */
678 func = iface->funcs;
679 while (NEXT_LINK(func)) func = NEXT_LINK(func);
680 while (func)
681 {
682 /* argument list size */
683 if (func->args)
684 {
685 var = func->args;
686 while (NEXT_LINK(var)) var = NEXT_LINK(var);
687 while (var)
688 {
689 byte_count += 2; /* FIXME: determine real size */
690 var = PREV_LINK(var);
691 }
692 }
693
694 /* return value size */
695 byte_count += 2; /* FIXME: determine real size */
696 func = PREV_LINK(func);
697 }
698 print_server("#define PROC_FORMAT_STRING_SIZE %d\n", byte_count);
699
700 fprintf(server, "\n");
701 write_formatdesc("TYPE");
702 write_formatdesc("PROC");
703 fprintf(server, "\n");
704 print_server("extern const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
705 print_server("extern const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
706 print_server("\n");
707 }
708
709
710 static void init_server(void)
711 {
712 if (server)
713 return;
714 if (!(server = fopen(server_name, "w")))
715 error("Could not open %s for output\n", server_name);
716
717 print_server("/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", WIDL_FULLVERSION, input_name);
718 print_server("#include<string.h>\n");
719 fprintf(server, "\n");
720 print_server("#include\"%s\"\n", header_name);
721 fprintf(server, "\n");
722 }
723
724
725 void write_server(ifref_t *ifaces)
726 {
727 ifref_t *iface = ifaces;
728
729 if (!do_server)
730 return;
731 if (!iface)
732 return;
733 END_OF_LIST(iface);
734
735 init_server();
736 if (!server)
737 return;
738
739 while (iface)
740 {
741 fprintf(server, "/*****************************************************************************\n");
742 fprintf(server, " * %s interface\n", iface->iface->name);
743 fprintf(server, " */\n");
744 fprintf(server, "\n");
745
746 write_formatstringsdecl(iface->iface);
747 write_serverinterfacedecl(iface->iface);
748 write_stubdescdecl(iface->iface);
749
750 write_function_stubs(iface->iface);
751
752 write_stubdescriptor(iface->iface);
753 write_dispatchtable(iface->iface);
754
755 print_server("#if !defined(__RPC_WIN32__)\n");
756 print_server("#error Invalid build platform for this stub.\n");
757 print_server("#endif\n");
758 fprintf(server, "\n");
759
760 write_procformatstring(iface->iface);
761 write_typeformatstring();
762
763 fprintf(server, "\n");
764
765 iface = PREV_LINK(iface);
766 }
767
768 fclose(server);
769 }