Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill old CVS $Id$ lines.
[simgrid.git] / tools / gras / windows_stub_generator.c
1 /* gras_stub_generator - creates the main() to use a GRAS program           */
2
3 /* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier.   */
4 /* All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "gras_stub_generator.h"
10
11 /* specific to Borland Compiler */
12 #ifdef __BORLANDDC__
13 #pragma hdrstop
14 #endif
15
16 #include <stdio.h>
17 #include "xbt/sysdep.h"
18 #include "xbt/function_types.h"
19 #include "xbt/log.h"
20 #include "surf/surfxml_parse.h"
21 #include "surf/surf.h"
22 #include "portable.h"           /* Needed for the time of the SIMIX convertion */
23
24 #include <stdarg.h>
25
26
27
28 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(stubgen);
29
30 #ifdef __BORLANDDC__
31
32 char *__gras_path = NULL;
33
34 /* tabulation level (used to indent the lines of the borland project file */
35 static unsigned int level = 0;
36
37
38 #ifndef MAX_PATH
39 #define MAX_PATH 260
40 #endif
41
42 /*
43  * A structure which represents a borland project file.
44  */
45 typedef struct s_borland_project {
46   const char *xml_version;      /* the xml version used to write the borland project file                   */
47   const char *encoding;         /* the encoding used to write the borland project file                      */
48   const char *comment;          /* the xml comment to write at the begining of the borland project file     */
49   char *name;                   /* the name of the borland project file                                                                         */
50   FILE *stream;                 /* the stream to the borland project file                                                                       */
51   const char *version;          /* the builder version of the borland project file                                                      */
52   char *bin_dir;                /* the directory used to store the generated program                                            */
53   char *obj_dir;                /* the directory used to store the generated object files                                       */
54   char *lib_dir;                /* the directory used to store the librairies used in the borland project       */
55   char *src_dir;                /* the directory use to store the source files of the project                           */
56 } s_borland_project_t, *borland_project_t;
57
58
59 /*
60  * A structure which represents a visual C++ project file.
61  */
62 typedef struct s_dsp {
63   FILE *stream;
64   char *lib_dir;
65   char *src_dir;
66   char *name;
67 } s_dsp_t, *dsp_t;
68
69 /*
70  * Write tabs in a borland project file.
71  * @param project The project concerned by the operation.
72  * @param count The count tab to write
73  */
74 static void
75 borland_project_write_tabs(borland_project_t project, unsigned int count);
76
77 /*
78  * Write the begin of an xml node in the borland project file.
79  * @param project The borland project concerned by this operation.
80  * @param name The name of the node.
81  */
82 static void
83 borland_project_begin_xml_node(borland_project_t project,
84                                const char *name);
85
86
87 /*
88  * Write the end of an xml node in the borland project file.
89  * @param project The borland project concerned by this operation.
90  * @param name The name of the node.
91  */
92 static void
93 borland_project_end_xml_node(borland_project_t project, const char *name);
94
95 /*
96  * Write an xml element in a borland project file.
97  * @param project The borland project concerned by this operation.
98  * @param name The name of the element to write
99  * @param value The value of the element  
100  */
101 static void
102 borland_project_write_xml_element(borland_project_t project,
103                                   const char *name, const char *value);
104
105 /*
106  * Write a FILE xml element in the borland project file.
107  * @param project The borland project concerned by this operation.
108  * @param file_name The value of the attribute FILENAME.
109  * @param form_name The value of the attribute FORMNAME.
110  * @param unit_name The value of the attribute UNITNAME.
111  * @param container_id The value of the attribute CONTAINERID.
112  * @param design_claas The value of the attribute DESIGNCLASS.
113  * @param local_command The value of the attribute LOCALCOMMAND.
114  */
115 static void
116 borland_project_write_file_element(borland_project_t project,
117                                    const char *file_name,
118                                    const char *form_name,
119                                    const char *unit_name,
120                                    const char *container_id,
121                                    const char *design_class,
122                                    const char *local_command);
123 /*
124  * Write all options of the IDE of the Borland Builder C++ compiler.
125  * @ param project The project concerned by this operation.
126  */
127
128 static void borland_project_write_ide_options(borland_project_t project);
129
130 /*
131  * Write the xml header of the xml document.
132  * @param project The project concerned by the operation.
133  */
134 static void borland_project_write_xml_header(borland_project_t project);
135
136 /*
137  * Write an xml comment in a borland project file
138  * @param project The project concerned by this operation.
139  */
140 static void borland_project_write_xml_comment(borland_project_t project);
141
142 /*
143  * Create a bpf file used by a borland project file.
144  * @param name The name of the bpf file to create.
145  */
146 static void borland_project_create_main_file(const char *name);
147
148 /*
149  * Create a borland project file.
150  * @param project The project concerned by this operation.
151  */
152 static void borland_project_create(borland_project_t project);
153
154 /*
155  * Close a borland project file.
156  * @param project the borland project file to close.
157  */
158 static void borland_project_close(borland_project_t project);
159
160
161 /*
162  * Generate a borland project file.
163  * @param project The borland project to generate.
164  */
165 static void
166 generate_borland_project(borland_project_t project, int is_rl,
167                          const char *name);
168
169 /*
170  * Find the path of a file.
171  * @param file_name The file name to find.
172  * @path path If founded this parameter will contain the path of file.
173  * @return If successful the function returns 1. Otherwise the function
174  *  retruns 0;
175  */
176 static int
177 find_file_path(const char *root_dir, const char *file_name, char *path);
178
179
180 /*
181  * Functions used to create a Microsoft Visual C++ project file (*.dsp).
182  */
183
184 /*
185  * generate a Microsoft Visual project file*/
186 static void generate_dsp_project(dsp_t project, int is_rl,
187                                  const char *name);
188
189 static void
190 generate_borland_project(borland_project_t project, int is_rl,
191                          const char *name)
192 {
193   char *binary_path;            /* the path of the generated binary file                                */
194   char *obj_path;               /* the path of the generated object file                                */
195   char *lib_files;              /* a list of the libraries used in the borland project  */
196   char *main_source;            /* the name of the bpf file used by the borland project */
197   char *file_name;              /* the file name of the main source file                                */
198   char *include_path;           /* the include path                                     */
199   char *buffer;
200
201   /* create the borland project file */
202   borland_project_create(project);
203
204   /* write the xml document header */
205   borland_project_write_xml_header(project);
206
207   /* write the xml comment to identify a borland project file */
208   borland_project_write_xml_comment(project);
209
210   /* write the begin of the node PROJECT */
211   borland_project_begin_xml_node(project, "PROJECT");
212
213   /* write the begin of node MACROS */
214   borland_project_begin_xml_node(project, "MACROS");
215
216   /* write the borland project version */
217   borland_project_write_xml_element(project, "VERSION", project->version);
218
219   /* construct and write the borland project binary path */
220   binary_path =
221       xbt_new0(char, strlen(project->name) + strlen(project->bin_dir) + 6);
222   sprintf(binary_path, "%s\\%s.exe", project->bin_dir, project->name);
223   borland_project_write_xml_element(project, "PROJECT", binary_path);
224   xbt_free(binary_path);
225
226   /* construct an write the object files to generate by the compiler */
227   obj_path =
228       xbt_new0(char,
229                strlen(project->name) + strlen(name) +
230                (2 * strlen(project->obj_dir)) + 11);
231   sprintf(binary_path, "%s\\%s.obj\n%s\\%s.obj", project->obj_dir,
232           project->name, project->obj_dir, name);
233   borland_project_write_xml_element(project, "OBJFILES", obj_path);
234   xbt_free(obj_path);
235
236   /* write the resource files used by the compiler (no resource file used) */
237   borland_project_write_xml_element(project, "RESFILES", "");
238
239   /* write the IDL files of the project (no IDL files used) */
240   borland_project_write_xml_element(project, "IDLFILES", "");
241
242   /* write the IDLGENFILES element (not used) */
243   borland_project_write_xml_element(project, "IDLGENFILES", "");
244
245   /* write the DEFFILE element (not used) */
246   borland_project_write_xml_element(project, "DEFFILE", "");
247
248   /* write the RESDEPEN element (not used, no resource file used) */
249   borland_project_write_xml_element(project, "RESDEPEN", "$(RESFILES)");
250
251   /* construct and write the list of libraries used by the project */
252   /*
253      lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
254      sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
255    */
256
257   if (is_rl) {
258     lib_files =
259         xbt_new0(char,
260                  (2 * (strlen(project->lib_dir) + 1)) +
261                  strlen("libgras.lib") + 2);
262     sprintf(lib_files, "%s\\libgras.lib", project->lib_dir);
263   } else {
264     lib_files =
265         xbt_new0(char,
266                  (2 * (strlen(project->lib_dir) + 1)) +
267                  strlen("simgrid.lib") + 2);
268     sprintf(lib_files, "%s\\simgrid.lib", project->lib_dir);
269   }
270
271   borland_project_write_xml_element(project, "LIBFILES", lib_files);
272   xbt_free(lib_files);
273
274   /* write the SPARELIBS element (not used) */
275   borland_project_write_xml_element(project, "SPARELIBS", "");
276
277   /* write the PACKAGES element (no package used) */
278   borland_project_write_xml_element(project, "PACKAGES", "");
279
280   /* write the PATHCPP element (the path of the source files of the project) */
281   borland_project_write_xml_element(project, "PATHCPP", ".;");
282
283   /* write the PATHPAS element (not used) */
284   borland_project_write_xml_element(project, "PATHPAS", "");
285
286   /* write the PATHRC element (not used) */
287   borland_project_write_xml_element(project, "PATHRC", "");
288
289   /* write the PATHASM element (not used) */
290   borland_project_write_xml_element(project, "PATHASM", "");
291
292   /* write the DEBUGLIBPATH element (the path for debug) */
293   borland_project_write_xml_element(project, "DEBUGLIBPATH",
294                                     "$(BCB)\\lib\\debug");
295
296   /* write the RELEASELIBPATH element (the path for release) */
297   borland_project_write_xml_element(project, "RELEASELIBPATH",
298                                     "$(BCB)\\lib\\release");
299
300   /* specify the linker to use */
301   borland_project_write_xml_element(project, "LINKER", "ilink32");
302
303   /* write the USERDEFINES element (user definitions (#define _DEBUG)) */
304   borland_project_write_xml_element(project, "USERDEFINES", "_DEBUG");
305
306   /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL) */
307   borland_project_write_xml_element(project, "SYSDEFINES",
308                                     "NO_STRICT;_NO_VCL");
309
310   /* construct and write the MAINSOURCE element */
311   main_source = xbt_new0(char, strlen(project->name) + 5);
312   sprintf(main_source, "%s.bpf", project->name);
313   /* write the main source file to use in the borland project file */
314   borland_project_write_xml_element(project, "MAINSOURCE", main_source);
315
316   /* create the bpf file used by the borland project */
317   borland_project_create_main_file(main_source);
318
319   /* FIXME resolve the include path */
320   /* write the INCLUDEPATH element  */
321
322   if (!__gras_path) {
323     buffer = xbt_new0(char, MAX_PATH);
324     GetEnvironmentVariable("SG_INSTALL_DIR", buffer, MAX_PATH);
325
326     __gras_path = xbt_new0(char, MAX_PATH);
327     sprintf(__gras_path, "%s\\simgrid\\include", buffer);
328     free(buffer);
329
330     /*find_file_path("C:\\","gras.h",__gras_path); */
331   }
332
333   include_path =
334       xbt_new0(char, strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
335   sprintf(include_path, "$(BCB)\\include;%s", __gras_path);
336
337   borland_project_write_xml_element(project, "INCLUDEPATH", include_path);
338
339   xbt_free(include_path);
340
341   /* write the LIBPATH element (no librarie paths specified) */
342   borland_project_write_xml_element(project, "LIBPATH",
343                                     "$(BCB)\\lib;$(BCB)\\lib\\obj");
344
345   /*
346    * write the WARNINGS element :
347    *  -w-sus (-w-8075) disabled the suspect conversion pointer warning
348    *  -w-rvl (-w-8070) disabled the function must return warning
349    *  -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
350    *  -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
351    *  -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
352    *  -w-par (-w-8057) disabled the warning that detect an unused variable
353    *  -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
354    *  -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
355    *  -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
356    */
357   borland_project_write_xml_element(project, "WARNINGS",
358                                     "-w-sus -w-rvl -w-rch -w-pia -w-pch -w-par -w-csu -w-ccc -w-aus");
359
360   /* write the OTHERFILES element (no other files used used) */
361   borland_project_write_xml_element(project, "OTHERFILES", "");
362
363   /* write the end of the node MACROS */
364   borland_project_end_xml_node(project, "MACROS");
365
366   /* write the begin of the node OPTIONS */
367   borland_project_begin_xml_node(project, "OPTIONS");
368
369   /* FIXME check the idlcflags */
370   /* write the IDLCFLAGS element */
371   borland_project_write_xml_element(project, "IDLCFLAGS", "");
372
373   /*
374    * write the CFLAG1 element (compiler options ) :
375    *
376    *  -Od     this flag disable all compiler optimisation
377    *  -H      this flag specify the name of the file which will contain the precompiled header
378    *  -Hc     this flag specify to the compiler to cach the precompiled header
379    *  -Vx     this flag specify to the compiler to allow the empty structures
380    *  -Ve     this flag specify to the compiler to allow the empty base classes
381    *  -X-     this flag activate the auto-depend informations of the compiler
382    *  -r-     this flag disabled the use of the processor register
383    *  -a1     this flag specify that the data must be aligned on one byte
384    *  -b-     this flag specify that the enums are the smallest size of the integer
385    *  -k      (used during debug)
386    *  -y      this flag generate the line number for debug
387    *  -v      this flag enabled the debugging of the source files
388    *  -vi     check the expansion of the inline functions
389    *  -tWC    specify that it's a console application
390    *  -tWM-   specify that the application is not multithread
391    *  -c      generate the object file, no link
392    */
393   borland_project_write_xml_element(project, "CFLAG1",
394                                     "-Od -H=$(BCB)\\lib\\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -tWC -tWM- -c");
395
396   /* write the PFLAGS element */
397   borland_project_write_xml_element(project, "PFLAGS",
398                                     "-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
399
400   /* write the RFLAGS element */
401   borland_project_write_xml_element(project, "RFLAGS", "");
402
403   /* write the AFLAGS element (assembler flags) :
404    *
405    *  /mx (not documented)
406    *  /w2 (not documented)
407    *  /zd (not documented)
408    *
409    */
410   borland_project_write_xml_element(project, "AFLAGS", "/mx /w2 /zd");
411
412   /* write the LFLAGS element (linker flags) :
413    *
414    *  -I      specify the output directory for object files
415    *  -D      register the specified description (no description "")
416    *  -ap     build a win32 console application
417    *  -Tpe    generate a exe file
418    *  -x      do not create the map file
419    *  -Gn     do not generate the state file
420    *  -v      include the complete debug informations  
421    */
422   borland_project_write_xml_element(project, "LFLAGS",
423                                     "-Iobj -D&quot;&quot; -ap -Tpe -x -Gn -v");
424
425   /* write the OTHERFILES element (not used) */
426   borland_project_write_xml_element(project, "OTHERFILES", "");
427
428   /* write the end of the node OPTIONS */
429   borland_project_end_xml_node(project, "OPTIONS");
430
431   /* write the begin of the node LINKER */
432   borland_project_begin_xml_node(project, "LINKER");
433
434   /* write the ALLOBJ element */
435   borland_project_write_xml_element(project, "ALLOBJ",
436                                     "c0x32.obj $(OBJFILES)");
437
438   /* write the ALLRES element (not used) */
439   borland_project_write_xml_element(project, "ALLRES", "");
440
441   /* write the ALLLIB element */
442   borland_project_write_xml_element(project, "ALLLIB",
443                                     "$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
444
445   /* write the OTHERFILES element (not used) */
446   borland_project_write_xml_element(project, "OTHERFILES", "");
447
448   /* write the end of the node LINKER */
449   borland_project_end_xml_node(project, "LINKER");
450
451   /* write the begin of the node FILELIST */
452   borland_project_begin_xml_node(project, "FILELIST");
453
454   /* construct and write the list of file elements */
455
456   /* add the bpf file to the list */
457   borland_project_write_file_element(project, main_source, "",
458                                      project->name, "BPF", "", "");
459   xbt_free(main_source);
460
461   /* FIXME : check the source file directory */
462   /* add the generated source file to the list */
463
464   file_name =
465       xbt_new0(char, strlen(project->src_dir) + strlen(project->name) + 5);
466   sprintf(file_name, "%s\\_%s.c", project->src_dir, project->name);
467   borland_project_write_file_element(project, file_name, "", project->name,
468                                      "CCompiler", "", "");
469
470   memset(file_name, 0,
471          strlen(project->src_dir) + strlen(project->name) + 4);
472   sprintf(file_name, "%s\\%s.c", project->src_dir, name);
473   borland_project_write_file_element(project, file_name, "", name,
474                                      "CCompiler", "", "");
475
476   xbt_free(file_name);
477
478   /* FIXME : check the libraries directory */
479   /* add the simgrid library to the list */
480
481   if (is_rl) {
482     file_name =
483         xbt_new0(char,
484                  strlen(project->lib_dir) + strlen("libgras.lib") + 2);
485     sprintf(file_name, "%s\\libgras.lib", project->lib_dir);
486     borland_project_write_file_element(project, file_name, "",
487                                        "libgras.lib", "LibTool", "", "");
488   } else {
489     file_name =
490         xbt_new0(char,
491                  strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
492     sprintf(file_name, "%s\\simgrid.lib", project->lib_dir);
493     borland_project_write_file_element(project, file_name, "",
494                                        "simgrid.lib", "LibTool", "", "");
495   }
496
497
498   xbt_free(file_name);
499
500   /* write the end of the node FILELIST */
501   borland_project_end_xml_node(project, "FILELIST");
502
503   /* write the begin of the node BUILDTOOLS (not used) */
504   borland_project_begin_xml_node(project, "BUILDTOOLS");
505
506   /* write the end of the node BUILDTOOLS (not used) */
507   borland_project_end_xml_node(project, "BUILDTOOLS");
508
509   /* write the begin of the node IDEOPTIONS */
510   borland_project_begin_xml_node(project, "IDEOPTIONS");
511
512   /* write all of the option of the IDE of Borland C++ Builder */
513   borland_project_write_ide_options(project);
514
515   /* write the end of the node IDEOPTIONS */
516   borland_project_end_xml_node(project, "IDEOPTIONS");
517
518   /* write the end of the node PROJECT */
519   borland_project_end_xml_node(project, "PROJECT");
520
521   /* close the borland project file */
522   borland_project_close(project);
523 }
524
525 void borland_project_write_tabs(borland_project_t project,
526                                 unsigned int count)
527 {
528   unsigned int pos;
529
530   for (pos = 0; pos < count; pos++)
531     fprintf(project->stream, "\t");
532 }
533
534 void
535 borland_project_begin_xml_node(borland_project_t project, const char *name)
536 {
537   if (level)
538     borland_project_write_tabs(project, level);
539
540   fprintf(project->stream, "<%s>\n", name);
541
542   level++;
543 }
544
545 void borland_project_end_xml_node(borland_project_t project,
546                                   const char *name)
547 {
548   level--;
549
550   if (level)
551     borland_project_write_tabs(project, level);
552
553   fprintf(project->stream, "</%s>\n", name);
554 }
555
556
557 void
558 borland_project_write_xml_element(borland_project_t project,
559                                   const char *name, const char *value)
560 {
561   borland_project_write_tabs(project, level);
562   fprintf(project->stream, "<%s value=\"%s\"/>\n", name, value);
563 }
564
565 void borland_project_write_xml_header(borland_project_t project)
566 {
567   fprintf(project->stream, "<?xml version='%s' encoding='%s' ?>\n",
568           project->xml_version, project->encoding);
569 }
570
571 void borland_project_create_main_file(const char *name)
572 {
573   FILE *stream = fopen(name, "w+");
574
575   fprintf(stream,
576           "Ce fichier est uniquement utilis� par le gestionnaire de projets et doit ï¿½tre trait� comme le fichier projet\n\n\nmain\n");
577
578   fclose(stream);
579 }
580
581 void borland_project_create(borland_project_t project)
582 {
583   char *file_name = xbt_new0(char, strlen(project->name) + 5);
584   sprintf(file_name, "%s.bpr", project->name);
585   project->stream = fopen(file_name, "w+");
586   xbt_free(file_name);
587 }
588
589 void borland_project_write_xml_comment(borland_project_t project)
590 {
591   fprintf(project->stream, "<!-- %s -->\n", project->comment);
592 }
593
594 void
595 borland_project_write_file_element(borland_project_t project,
596                                    const char *file_name,
597                                    const char *form_name,
598                                    const char *unit_name,
599                                    const char *container_id,
600                                    const char *design_class,
601                                    const char *local_command)
602 {
603   borland_project_write_tabs(project, level);
604
605   fprintf(project->stream,
606           "<FILE FILENAME=\"%s\" FORMNAME=\"%s\" UNITNAME=\"%s\" CONTAINERID=\"%s\" DESIGNCLASS=\"%s\" LOCALCOMMAND=\"%s\"/>\n",
607           file_name, form_name, unit_name, container_id, design_class,
608           local_command);
609 }
610
611 void borland_project_write_ide_options(borland_project_t project)
612 {
613
614   const char *ide_options =
615       "[Version Info]\nIncludeVerInfo=0\nAutoIncBuild=0\nMajorVer=1\nMinorVer=0\nRelease=0\nBuild=0\nDebug=0\nPreRelease=0\nSpecial=0\nPrivate=0\nDLL=0\nLocale=1036\nCodePage=1252\n\n"
616       "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n"
617       "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n"
618       "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n"
619       "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n"
620       "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n"
621       "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n"
622       "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n"
623       "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n"
624       "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n"
625       "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n"
626       "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n"
627       "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n"
628       "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n"
629       "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
630
631   fprintf(project->stream, ide_options);
632 }
633
634 void borland_project_close(borland_project_t project)
635 {
636   fclose(project->stream);
637 }
638
639 void generate_borland_simulation_project(const char *name)
640 {
641   char buffer[MAX_PATH] = { 0 };
642
643   HANDLE hDir;
644   WIN32_FIND_DATA wfd = { 0 };
645
646   s_borland_project_t borland_project = { 0 };
647   borland_project.xml_version = "1.0";
648   borland_project.encoding = "utf-8";
649   borland_project.comment = "C++Builder XML Project";
650   borland_project.version = "BCB.06.00";
651
652   borland_project.lib_dir = xbt_new0(char, MAX_PATH);
653
654
655   GetEnvironmentVariable("LIB_SIMGRID_PATH", borland_project.lib_dir,
656                          MAX_PATH);
657
658
659   GetCurrentDirectory(MAX_PATH, buffer);
660
661   borland_project.src_dir = xbt_strdup(buffer);
662
663   borland_project.name =
664       xbt_new0(char, strlen(name) + strlen("simulator") + 2);
665   sprintf(borland_project.name, "%s_simulator", name);
666
667   borland_project.bin_dir =
668       xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1);
669   sprintf(borland_project.bin_dir, "%s\\bin", buffer);
670
671   hDir = FindFirstFile(borland_project.bin_dir, &wfd);
672
673   if (!hDir)
674     CreateDirectory(borland_project.bin_dir, NULL);
675
676   borland_project.obj_dir =
677       xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1);
678   sprintf(borland_project.obj_dir, "%s\\obj", buffer);
679
680   hDir = FindFirstFile(borland_project.obj_dir, &wfd);
681
682   if (INVALID_HANDLE_VALUE == hDir)
683     CreateDirectory(borland_project.obj_dir, NULL);
684
685   generate_borland_project(&borland_project, 0, name);
686
687   xbt_free(borland_project.name);
688   xbt_free(borland_project.src_dir);
689   xbt_free(borland_project.bin_dir);
690   xbt_free(borland_project.obj_dir);
691   xbt_free(borland_project.lib_dir);
692 }
693
694 void generate_borland_real_life_project(const char *name)
695 {
696   HANDLE hDir;
697   WIN32_FIND_DATA wfd = { 0 };
698   char buffer[MAX_PATH] = { 0 };
699   xbt_dict_cursor_t cursor = NULL;
700   char *key = NULL;
701   void *data = NULL;
702   s_borland_project_t borland_project = { 0 };
703
704   borland_project.xml_version = "1.0";
705   borland_project.encoding = "utf-8";
706   borland_project.comment = "C++Builder XML Project";
707   borland_project.version = "BCB.06.00";
708
709   borland_project.lib_dir = xbt_new0(char, MAX_PATH);
710
711   GetEnvironmentVariable("LIB_GRAS_PATH", borland_project.lib_dir,
712                          MAX_PATH);
713
714   GetCurrentDirectory(MAX_PATH, buffer);
715
716   borland_project.src_dir = xbt_strdup(buffer);
717
718   borland_project.bin_dir =
719       xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1);
720   sprintf(borland_project.bin_dir, "%s\\bin", buffer);
721
722   hDir = FindFirstFile(borland_project.bin_dir, &wfd);
723
724   if (INVALID_HANDLE_VALUE == hDir)
725     CreateDirectory(borland_project.bin_dir, NULL);
726
727   borland_project.obj_dir =
728       xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1);
729   sprintf(borland_project.obj_dir, "%s\\obj", buffer);
730
731   hDir = FindFirstFile(borland_project.obj_dir, &wfd);
732
733   if (!hDir)
734     CreateDirectory(borland_project.obj_dir, NULL);
735
736
737   xbt_dict_foreach(process_function_set, cursor, key, data) {
738     borland_project.name = xbt_new0(char, strlen(name) + strlen(key) + 2);
739
740     sprintf(borland_project.name, "%s_%s", name, key);
741
742     generate_borland_project(&borland_project, 1, name);
743     xbt_free(borland_project.name);
744   }
745
746   xbt_free(borland_project.src_dir);
747   xbt_free(borland_project.bin_dir);
748   xbt_free(borland_project.obj_dir);
749   xbt_free(borland_project.lib_dir);
750 }
751
752 int find_file_path(const char *root_dir, const char *file_name, char *path)
753 {
754   HANDLE hFind;
755   WIN32_FIND_DATA wfd;
756   char *prev_dir = xbt_new(char, MAX_PATH);
757   GetCurrentDirectory(MAX_PATH, prev_dir);
758   SetCurrentDirectory(root_dir);
759
760   // begining of the scan
761   hFind = FindFirstFile("*.*", &wfd);
762
763   if (hFind != INVALID_HANDLE_VALUE) {
764
765     /* it's a file */
766     if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
767
768       if (!strcmp(file_name, wfd.cFileName)) {
769         GetCurrentDirectory(MAX_PATH, path);
770         SetCurrentDirectory(prev_dir);
771         xbt_free(prev_dir);
772         FindClose(hFind);
773         return 1;
774       }
775
776     }
777     /* it's a directory, scan it */
778     else {
779
780       if (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")) {
781         if (find_file_path(wfd.cFileName, file_name, path)) {
782           FindClose(hFind);
783           SetCurrentDirectory(prev_dir);
784           return 1;
785         }
786       }
787     }
788
789     /* next file or directory */
790     while (FindNextFile(hFind, &wfd)) {
791       /* it's a file */
792       if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
793         if (!strcmp(file_name, wfd.cFileName)) {
794           GetCurrentDirectory(MAX_PATH, path);
795           SetCurrentDirectory(prev_dir);
796           xbt_free(prev_dir);
797           FindClose(hFind);
798           return 1;
799         }
800       }
801       /* it's a file scan it */
802       else {
803
804         if (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")) {
805
806           if (find_file_path(wfd.cFileName, file_name, path)) {
807             SetCurrentDirectory(prev_dir);
808             FindClose(hFind);
809             return 1;
810           }
811
812         }
813
814       }
815     }
816   }
817
818   SetCurrentDirectory(prev_dir);
819   xbt_free(prev_dir);
820   FindClose(hFind);
821   return 0;
822 }
823
824 /* Implementation of the functions used to create a Visual C++ project.*/
825
826 int generate_simulation_dsp_file(const char *name)
827 {
828   char buffer[MAX_PATH] = { 0 };
829   s_dsp_t dsp = { 0 };
830   dsp.lib_dir = xbt_new0(char, MAX_PATH);
831
832   GetEnvironmentVariable("LIB_SIMGRID_PATH", dsp.lib_dir, MAX_PATH);
833   GetCurrentDirectory(MAX_PATH, buffer);
834
835   dsp.src_dir = xbt_strdup(buffer);
836   dsp.name = xbt_new0(char, strlen(name) + strlen("simulator") + 2);
837   sprintf(dsp.name, "%s_simulator", name);
838
839   generate_dsp_project(&dsp, 0, name);
840
841   xbt_free(dsp.name);
842   xbt_free(dsp.src_dir);
843   xbt_free(dsp.lib_dir);
844
845   return 0;
846 }
847
848 /*
849  * Create the Microsoft visual C++ real life project file.
850  */
851 int generate_real_live_dsp_file(const char *name)
852 {
853
854   char buffer[MAX_PATH] = { 0 };
855   xbt_dict_cursor_t cursor = NULL;
856   char *key = NULL;
857   void *data = NULL;
858   s_dsp_t dsp = { 0 };
859
860
861   dsp.lib_dir = xbt_new0(char, MAX_PATH);
862
863   GetEnvironmentVariable("LIB_GRAS_PATH", dsp.lib_dir, MAX_PATH);
864
865   GetCurrentDirectory(MAX_PATH, buffer);
866
867   dsp.src_dir = xbt_strdup(buffer);
868
869
870   xbt_dict_foreach(process_function_set, cursor, key, data) {
871     dsp.name = xbt_new0(char, strlen(name) + strlen(key) + 2);
872
873     sprintf(dsp.name, "%s_%s", name, key);
874
875     generate_dsp_project(&dsp, 1, name);
876     xbt_free(dsp.name);
877   }
878
879   xbt_free(dsp.src_dir);
880   xbt_free(dsp.lib_dir);
881   return 0;
882 }
883
884 void generate_dsp_project(dsp_t project, int is_rl, const char *name)
885 {
886   /* create the visual C++ project file */
887   char *buffer;
888   char *file_name = xbt_new0(char, strlen(project->name) + 5);
889   sprintf(file_name, "%s.dsp", project->name);
890   project->stream = fopen(file_name, "w+");
891   xbt_free(file_name);
892
893   if (!__gras_path) {
894     buffer = xbt_new0(char, MAX_PATH);
895     GetEnvironmentVariable("SG_INSTALL_DIR", buffer, MAX_PATH);
896
897     __gras_path = xbt_new0(char, MAX_PATH);
898     sprintf(__gras_path, "%s\\simgrid\\include", buffer);
899     free(buffer);
900   }
901
902   /* dsp file header */
903   fprintf(project->stream,
904           "# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",
905           project->name);
906   fprintf(project->stream,
907           "# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
908   fprintf(project->stream, "# ** DO NOT EDIT **\n\n");
909
910   /* target type is a win32 x86 console application */
911   fprintf(project->stream,
912           "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
913
914   /* the current config is win32-debug */
915   fprintf(project->stream, "CFG=%s - Win32 Debug\n", project->name);
916
917   /* warning */
918   fprintf(project->stream,
919           "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
920
921   /* NMAKE usage */
922   fprintf(project->stream,
923           "!MESSAGE use the Export Makefile command and run\n");
924   fprintf(project->stream, "!MESSAGE\n");
925   fprintf(project->stream, "!MESSAGE NMAKE /f \"%s.mak\".\n",
926           project->name);
927   fprintf(project->stream, "!MESSAGE\n");
928   fprintf(project->stream,
929           "!MESSAGE You can specify a configuration when running NMAKE\n");
930   fprintf(project->stream,
931           "!MESSAGE by defining the macro CFG on the command line. For example:\n");
932   fprintf(project->stream, "!MESSAGE\n");
933   fprintf(project->stream,
934           "!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",
935           project->name, project->name);
936   fprintf(project->stream, "!MESSAGE\n");
937   fprintf(project->stream,
938           "!MESSAGE Possible choices for configuration are:\n");
939   fprintf(project->stream, "!MESSAGE\n");
940   fprintf(project->stream,
941           "!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",
942           project->name);
943   fprintf(project->stream,
944           "!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",
945           project->name);
946   fprintf(project->stream, "!MESSAGE\n\n");
947
948   fprintf(project->stream, "# Begin Project\n\n");
949   fprintf(project->stream, "# PROP AllowPerConfigDependencies 0\n");
950   fprintf(project->stream, "# PROP Scc_ProjName\n");
951   fprintf(project->stream, "# PROP Scc_LocalPath\n");
952   fprintf(project->stream, "CPP=cl.exe\n");
953   fprintf(project->stream, "RSC=rc.exe\n\n");
954
955   fprintf(project->stream, "!IF  \"$(CFG)\" == \"%s - Win32 Release\"\n\n",
956           project->name);
957
958   fprintf(project->stream, "# PROP BASE Use_MFC 0\n");
959   fprintf(project->stream, "# PROP BASE Use_Debug_Libraries 0\n");
960   fprintf(project->stream, "# PROP BASE Output_Dir \"Release\"\n");
961   fprintf(project->stream, "# PROP BASE Intermediate_Dir \"Release\"\n");
962   fprintf(project->stream, "# PROP BASE Target_Dir \"\"\n");
963   fprintf(project->stream, "# PROP Use_MFC 0\n");
964   fprintf(project->stream, "# PROP Use_Debug_Libraries 0\n");
965   fprintf(project->stream, "# PROP Output_Dir \"Release\"\n");
966   fprintf(project->stream, "# PROP Intermediate_Dir \"Release\"\n");
967   fprintf(project->stream, "# PROP Target_Dir \"\"\n");
968   /* TODO : the include directory */
969   /*fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /GX /O2 /I \"./%s\" /D \"_XBT_WIN32\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",__gras_path); */
970   fprintf(project->stream,
971           "# ADD BASE CPP /nologo /W3 /GX /O2 /I \"%s\" /D \"_XBT_WIN32\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",
972           __gras_path);
973   fprintf(project->stream,
974           "# ADD CPP /nologo /W3 /GX /O2 /D \"_XBT_WIN32\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
975   fprintf(project->stream, "# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
976   fprintf(project->stream, "# ADD RSC /l 0x40c /d \"NDEBUG\n");
977   fprintf(project->stream, "BSC32=bscmake.exe\n");
978   fprintf(project->stream, "# ADD BASE BSC32 /nologo\n");
979   fprintf(project->stream, "# ADD BSC32 /nologo\n");
980   fprintf(project->stream, "LINK32=link.exe\n");
981   fprintf(project->stream,
982           "# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n");
983
984   if (is_rl)
985     fprintf(project->stream,
986             "# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libgras.lib /nologo /subsystem:console /machine:I386\n\n");
987   else
988     fprintf(project->stream,
989             "# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib /nologo /subsystem:console /machine:I386\n\n");
990
991   fprintf(project->stream, "!ELSEIF  \"$(CFG)\" == \"%s - Win32 Debug\"\n",
992           project->name);
993
994   fprintf(project->stream, "# PROP BASE Use_MFC 0\n");
995   fprintf(project->stream, "# PROP BASE Use_Debug_Libraries 1\n");
996   fprintf(project->stream, "# PROP BASE Output_Dir \"Debug\"\n");
997   fprintf(project->stream, "# PROP BASE Intermediate_Dir \"Debug\"\n");
998   fprintf(project->stream, "# PROP BASE Target_Dir \"\"\n");
999   fprintf(project->stream, "# PROP Use_MFC 0\n");
1000   fprintf(project->stream, "# PROP Use_Debug_Libraries 1\n");
1001   fprintf(project->stream, "# PROP Output_Dir \"Debug\"\n");
1002   fprintf(project->stream, "# PROP Intermediate_Dir \"Debug\"\n");
1003   fprintf(project->stream, "# PROP Ignore_Export_Lib 0\n");
1004   fprintf(project->stream, "# PROP Target_Dir \"\"\n");
1005   /* TODO : the include directory */
1006   /*fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od  /I \"./%s\" /D \"_XBT_WIN32\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ  /c\n",__gras_path); */
1007   fprintf(project->stream,
1008           "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od  /I \"%s\" /D \"_XBT_WIN32\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ  /c\n",
1009           __gras_path);
1010   fprintf(project->stream,
1011           "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_XBT_WIN32\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ  /c\n");
1012   fprintf(project->stream, "# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
1013   fprintf(project->stream, "# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
1014   fprintf(project->stream, "BSC32=bscmake.exe\n");
1015   fprintf(project->stream, "# ADD BASE BSC32 /nologo\n");
1016   fprintf(project->stream, "# ADD BSC32 /nologo\n");
1017   fprintf(project->stream, "LINK32=link.exe\n");
1018   fprintf(project->stream,
1019           "# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n");
1020
1021   if (is_rl)
1022     fprintf(project->stream,
1023             "# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib  libgras.lib  /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n\n");
1024   else
1025     fprintf(project->stream,
1026             "# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib  simgrid.lib  /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n\n");
1027
1028   fprintf(project->stream, "!ENDIF\n\n");
1029
1030   fprintf(project->stream, "# Begin Target\n\n");
1031   fprintf(project->stream, "# Name \"%s - Win32 Release\"\n",
1032           project->name);
1033   fprintf(project->stream, "# Name \"%s - Win32 Debug\"\n", project->name);
1034   fprintf(project->stream, "# Begin Group \"Source Files\"\n\n");
1035   fprintf(project->stream,
1036           "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
1037
1038   fprintf(project->stream, "# Begin Source File\n");
1039   fprintf(project->stream, "SOURCE=%s\\_%s.c\n", project->src_dir,
1040           project->name);
1041   fprintf(project->stream, "# End Source File\n\n");
1042
1043   fprintf(project->stream, "# Begin Source File\n");
1044   fprintf(project->stream, "SOURCE=%s\\%s.c\n", project->src_dir, name);
1045   fprintf(project->stream, "# End Source File\n\n");
1046
1047   fprintf(project->stream, "# End Group\n");
1048   fprintf(project->stream, "# Begin Group \"Header Files\"\n\n");
1049   fprintf(project->stream, "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1050   fprintf(project->stream, "# End Group\n");
1051   fprintf(project->stream, "# Begin Group \"Resource Files\"\n\n");
1052   fprintf(project->stream,
1053           "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1054   fprintf(project->stream, "# End Group\n");
1055   fprintf(project->stream, "# End Target\n");
1056   fprintf(project->stream, "# End Project\n");
1057
1058 }
1059
1060 #endif