Logo AND Algorithmique Numérique Distribuée

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