Logo AND Algorithmique Numérique Distribuée

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