Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace a combination of malloc+strcpy by xbt_strdup.
[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_strdup(buffer);
664
665   borland_project.name =
666       xbt_new0(char, strlen(name) + strlen("simulator") + 2);
667   sprintf(borland_project.name, "%s_simulator", name);
668
669   borland_project.bin_dir =
670       xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1);
671   sprintf(borland_project.bin_dir, "%s\\bin", buffer);
672
673   hDir = FindFirstFile(borland_project.bin_dir, &wfd);
674
675   if (!hDir)
676     CreateDirectory(borland_project.bin_dir, NULL);
677
678   borland_project.obj_dir =
679       xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1);
680   sprintf(borland_project.obj_dir, "%s\\obj", buffer);
681
682   hDir = FindFirstFile(borland_project.obj_dir, &wfd);
683
684   if (INVALID_HANDLE_VALUE == hDir)
685     CreateDirectory(borland_project.obj_dir, NULL);
686
687   generate_borland_project(&borland_project, 0, name);
688
689   xbt_free(borland_project.name);
690   xbt_free(borland_project.src_dir);
691   xbt_free(borland_project.bin_dir);
692   xbt_free(borland_project.obj_dir);
693   xbt_free(borland_project.lib_dir);
694 }
695
696 void generate_borland_real_life_project(const char *name)
697 {
698   HANDLE hDir;
699   WIN32_FIND_DATA wfd = { 0 };
700   char buffer[MAX_PATH] = { 0 };
701   xbt_dict_cursor_t cursor = NULL;
702   char *key = NULL;
703   void *data = NULL;
704   s_borland_project_t borland_project = { 0 };
705
706   borland_project.xml_version = "1.0";
707   borland_project.encoding = "utf-8";
708   borland_project.comment = "C++Builder XML Project";
709   borland_project.version = "BCB.06.00";
710
711   borland_project.lib_dir = xbt_new0(char, MAX_PATH);
712
713   GetEnvironmentVariable("LIB_GRAS_PATH", borland_project.lib_dir,
714                          MAX_PATH);
715
716   GetCurrentDirectory(MAX_PATH, buffer);
717
718   borland_project.src_dir = xbt_strdup(buffer);
719
720   borland_project.bin_dir =
721       xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1);
722   sprintf(borland_project.bin_dir, "%s\\bin", buffer);
723
724   hDir = FindFirstFile(borland_project.bin_dir, &wfd);
725
726   if (INVALID_HANDLE_VALUE == hDir)
727     CreateDirectory(borland_project.bin_dir, NULL);
728
729   borland_project.obj_dir =
730       xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1);
731   sprintf(borland_project.obj_dir, "%s\\obj", buffer);
732
733   hDir = FindFirstFile(borland_project.obj_dir, &wfd);
734
735   if (!hDir)
736     CreateDirectory(borland_project.obj_dir, NULL);
737
738
739   xbt_dict_foreach(process_function_set, cursor, key, data) {
740     borland_project.name = xbt_new0(char, strlen(name) + strlen(key) + 2);
741
742     sprintf(borland_project.name, "%s_%s", name, key);
743
744     generate_borland_project(&borland_project, 1, name);
745     xbt_free(borland_project.name);
746   }
747
748   xbt_free(borland_project.src_dir);
749   xbt_free(borland_project.bin_dir);
750   xbt_free(borland_project.obj_dir);
751   xbt_free(borland_project.lib_dir);
752 }
753
754 int find_file_path(const char *root_dir, const char *file_name, char *path)
755 {
756   HANDLE hFind;
757   WIN32_FIND_DATA wfd;
758   char *prev_dir = xbt_new(char, MAX_PATH);
759   GetCurrentDirectory(MAX_PATH, prev_dir);
760   SetCurrentDirectory(root_dir);
761
762   // begining of the scan
763   hFind = FindFirstFile("*.*", &wfd);
764
765   if (hFind != INVALID_HANDLE_VALUE) {
766
767     /* it's a file */
768     if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
769
770       if (!strcmp(file_name, wfd.cFileName)) {
771         GetCurrentDirectory(MAX_PATH, path);
772         SetCurrentDirectory(prev_dir);
773         xbt_free(prev_dir);
774         FindClose(hFind);
775         return 1;
776       }
777
778     }
779     /* it's a directory, scan it */
780     else {
781
782       if (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")) {
783         if (find_file_path(wfd.cFileName, file_name, path)) {
784           FindClose(hFind);
785           SetCurrentDirectory(prev_dir);
786           return 1;
787         }
788       }
789     }
790
791     /* next file or directory */
792     while (FindNextFile(hFind, &wfd)) {
793       /* it's a file */
794       if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
795         if (!strcmp(file_name, wfd.cFileName)) {
796           GetCurrentDirectory(MAX_PATH, path);
797           SetCurrentDirectory(prev_dir);
798           xbt_free(prev_dir);
799           FindClose(hFind);
800           return 1;
801         }
802       }
803       /* it's a file scan it */
804       else {
805
806         if (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")) {
807
808           if (find_file_path(wfd.cFileName, file_name, path)) {
809             SetCurrentDirectory(prev_dir);
810             FindClose(hFind);
811             return 1;
812           }
813
814         }
815
816       }
817     }
818   }
819
820   SetCurrentDirectory(prev_dir);
821   xbt_free(prev_dir);
822   FindClose(hFind);
823   return 0;
824 }
825
826 /* Implementation of the functions used to create a Visual C++ project.*/
827
828 int generate_simulation_dsp_file(const char *name)
829 {
830   char buffer[MAX_PATH] = { 0 };
831   s_dsp_t dsp = { 0 };
832   dsp.lib_dir = xbt_new0(char, MAX_PATH);
833
834   GetEnvironmentVariable("LIB_SIMGRID_PATH", dsp.lib_dir, MAX_PATH);
835   GetCurrentDirectory(MAX_PATH, buffer);
836
837   dsp.src_dir = xbt_strdup(buffer);
838   dsp.name = xbt_new0(char, strlen(name) + strlen("simulator") + 2);
839   sprintf(dsp.name, "%s_simulator", name);
840
841   generate_dsp_project(&dsp, 0, name);
842
843   xbt_free(dsp.name);
844   xbt_free(dsp.src_dir);
845   xbt_free(dsp.lib_dir);
846
847   return 0;
848 }
849
850 /*
851  * Create the Microsoft visual C++ real life project file.
852  */
853 int generate_real_live_dsp_file(const char *name)
854 {
855
856   char buffer[MAX_PATH] = { 0 };
857   xbt_dict_cursor_t cursor = NULL;
858   char *key = NULL;
859   void *data = NULL;
860   s_dsp_t dsp = { 0 };
861
862
863   dsp.lib_dir = xbt_new0(char, MAX_PATH);
864
865   GetEnvironmentVariable("LIB_GRAS_PATH", dsp.lib_dir, MAX_PATH);
866
867   GetCurrentDirectory(MAX_PATH, buffer);
868
869   dsp.src_dir = xbt_strdup(buffer);
870
871
872   xbt_dict_foreach(process_function_set, cursor, key, data) {
873     dsp.name = xbt_new0(char, strlen(name) + strlen(key) + 2);
874
875     sprintf(dsp.name, "%s_%s", name, key);
876
877     generate_dsp_project(&dsp, 1, name);
878     xbt_free(dsp.name);
879   }
880
881   xbt_free(dsp.src_dir);
882   xbt_free(dsp.lib_dir);
883   return 0;
884 }
885
886 void generate_dsp_project(dsp_t project, int is_rl, const char *name)
887 {
888   /* create the visual C++ project file */
889   char *buffer;
890   char *file_name = xbt_new0(char, strlen(project->name) + 5);
891   sprintf(file_name, "%s.dsp", project->name);
892   project->stream = fopen(file_name, "w+");
893   xbt_free(file_name);
894
895   if (!__gras_path) {
896     buffer = xbt_new0(char, MAX_PATH);
897     GetEnvironmentVariable("SG_INSTALL_DIR", buffer, MAX_PATH);
898
899     __gras_path = xbt_new0(char, MAX_PATH);
900     sprintf(__gras_path, "%s\\simgrid\\include", buffer);
901     free(buffer);
902   }
903
904   /* dsp file header */
905   fprintf(project->stream,
906           "# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",
907           project->name);
908   fprintf(project->stream,
909           "# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
910   fprintf(project->stream, "# ** DO NOT EDIT **\n\n");
911
912   /* target type is a win32 x86 console application */
913   fprintf(project->stream,
914           "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
915
916   /* the current config is win32-debug */
917   fprintf(project->stream, "CFG=%s - Win32 Debug\n", project->name);
918
919   /* warning */
920   fprintf(project->stream,
921           "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
922
923   /* NMAKE usage */
924   fprintf(project->stream,
925           "!MESSAGE use the Export Makefile command and run\n");
926   fprintf(project->stream, "!MESSAGE\n");
927   fprintf(project->stream, "!MESSAGE NMAKE /f \"%s.mak\".\n",
928           project->name);
929   fprintf(project->stream, "!MESSAGE\n");
930   fprintf(project->stream,
931           "!MESSAGE You can specify a configuration when running NMAKE\n");
932   fprintf(project->stream,
933           "!MESSAGE by defining the macro CFG on the command line. For example:\n");
934   fprintf(project->stream, "!MESSAGE\n");
935   fprintf(project->stream,
936           "!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",
937           project->name, project->name);
938   fprintf(project->stream, "!MESSAGE\n");
939   fprintf(project->stream,
940           "!MESSAGE Possible choices for configuration are:\n");
941   fprintf(project->stream, "!MESSAGE\n");
942   fprintf(project->stream,
943           "!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",
944           project->name);
945   fprintf(project->stream,
946           "!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",
947           project->name);
948   fprintf(project->stream, "!MESSAGE\n\n");
949
950   fprintf(project->stream, "# Begin Project\n\n");
951   fprintf(project->stream, "# PROP AllowPerConfigDependencies 0\n");
952   fprintf(project->stream, "# PROP Scc_ProjName\n");
953   fprintf(project->stream, "# PROP Scc_LocalPath\n");
954   fprintf(project->stream, "CPP=cl.exe\n");
955   fprintf(project->stream, "RSC=rc.exe\n\n");
956
957   fprintf(project->stream, "!IF  \"$(CFG)\" == \"%s - Win32 Release\"\n\n",
958           project->name);
959
960   fprintf(project->stream, "# PROP BASE Use_MFC 0\n");
961   fprintf(project->stream, "# PROP BASE Use_Debug_Libraries 0\n");
962   fprintf(project->stream, "# PROP BASE Output_Dir \"Release\"\n");
963   fprintf(project->stream, "# PROP BASE Intermediate_Dir \"Release\"\n");
964   fprintf(project->stream, "# PROP BASE Target_Dir \"\"\n");
965   fprintf(project->stream, "# PROP Use_MFC 0\n");
966   fprintf(project->stream, "# PROP Use_Debug_Libraries 0\n");
967   fprintf(project->stream, "# PROP Output_Dir \"Release\"\n");
968   fprintf(project->stream, "# PROP Intermediate_Dir \"Release\"\n");
969   fprintf(project->stream, "# PROP Target_Dir \"\"\n");
970   /* TODO : the include directory */
971   /*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); */
972   fprintf(project->stream,
973           "# ADD BASE CPP /nologo /W3 /GX /O2 /I \"%s\" /D \"_XBT_WIN32\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",
974           __gras_path);
975   fprintf(project->stream,
976           "# ADD CPP /nologo /W3 /GX /O2 /D \"_XBT_WIN32\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
977   fprintf(project->stream, "# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
978   fprintf(project->stream, "# ADD RSC /l 0x40c /d \"NDEBUG\n");
979   fprintf(project->stream, "BSC32=bscmake.exe\n");
980   fprintf(project->stream, "# ADD BASE BSC32 /nologo\n");
981   fprintf(project->stream, "# ADD BSC32 /nologo\n");
982   fprintf(project->stream, "LINK32=link.exe\n");
983   fprintf(project->stream,
984           "# 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");
985
986   if (is_rl)
987     fprintf(project->stream,
988             "# 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");
989   else
990     fprintf(project->stream,
991             "# 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");
992
993   fprintf(project->stream, "!ELSEIF  \"$(CFG)\" == \"%s - Win32 Debug\"\n",
994           project->name);
995
996   fprintf(project->stream, "# PROP BASE Use_MFC 0\n");
997   fprintf(project->stream, "# PROP BASE Use_Debug_Libraries 1\n");
998   fprintf(project->stream, "# PROP BASE Output_Dir \"Debug\"\n");
999   fprintf(project->stream, "# PROP BASE Intermediate_Dir \"Debug\"\n");
1000   fprintf(project->stream, "# PROP BASE Target_Dir \"\"\n");
1001   fprintf(project->stream, "# PROP Use_MFC 0\n");
1002   fprintf(project->stream, "# PROP Use_Debug_Libraries 1\n");
1003   fprintf(project->stream, "# PROP Output_Dir \"Debug\"\n");
1004   fprintf(project->stream, "# PROP Intermediate_Dir \"Debug\"\n");
1005   fprintf(project->stream, "# PROP Ignore_Export_Lib 0\n");
1006   fprintf(project->stream, "# PROP Target_Dir \"\"\n");
1007   /* TODO : the include directory */
1008   /*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); */
1009   fprintf(project->stream,
1010           "# 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",
1011           __gras_path);
1012   fprintf(project->stream,
1013           "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_XBT_WIN32\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ  /c\n");
1014   fprintf(project->stream, "# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
1015   fprintf(project->stream, "# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
1016   fprintf(project->stream, "BSC32=bscmake.exe\n");
1017   fprintf(project->stream, "# ADD BASE BSC32 /nologo\n");
1018   fprintf(project->stream, "# ADD BSC32 /nologo\n");
1019   fprintf(project->stream, "LINK32=link.exe\n");
1020   fprintf(project->stream,
1021           "# 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");
1022
1023   if (is_rl)
1024     fprintf(project->stream,
1025             "# 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");
1026   else
1027     fprintf(project->stream,
1028             "# 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");
1029
1030   fprintf(project->stream, "!ENDIF\n\n");
1031
1032   fprintf(project->stream, "# Begin Target\n\n");
1033   fprintf(project->stream, "# Name \"%s - Win32 Release\"\n",
1034           project->name);
1035   fprintf(project->stream, "# Name \"%s - Win32 Debug\"\n", project->name);
1036   fprintf(project->stream, "# Begin Group \"Source Files\"\n\n");
1037   fprintf(project->stream,
1038           "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
1039
1040   fprintf(project->stream, "# Begin Source File\n");
1041   fprintf(project->stream, "SOURCE=%s\\_%s.c\n", project->src_dir,
1042           project->name);
1043   fprintf(project->stream, "# End Source File\n\n");
1044
1045   fprintf(project->stream, "# Begin Source File\n");
1046   fprintf(project->stream, "SOURCE=%s\\%s.c\n", project->src_dir, name);
1047   fprintf(project->stream, "# End Source File\n\n");
1048
1049   fprintf(project->stream, "# End Group\n");
1050   fprintf(project->stream, "# Begin Group \"Header Files\"\n\n");
1051   fprintf(project->stream, "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1052   fprintf(project->stream, "# End Group\n");
1053   fprintf(project->stream, "# Begin Group \"Resource Files\"\n\n");
1054   fprintf(project->stream,
1055           "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1056   fprintf(project->stream, "# End Group\n");
1057   fprintf(project->stream, "# End Target\n");
1058   fprintf(project->stream, "# End Project\n");
1059
1060 }
1061
1062 #endif