-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOCamlModule.cpp
More file actions
107 lines (85 loc) · 2.68 KB
/
OCamlModule.cpp
File metadata and controls
107 lines (85 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "App.h"
#include "OCamlModule.h"
OCamlModule::OCamlModule(OCamlModule* ocamlModule) {
fSource = new BString(*ocamlModule->fSource);
fDependances = new BString(*ocamlModule->fDependances);
if (ocamlModule->fOCamlChemin == NULL) {
fOCamlChemin = NULL;
} else {
fOCamlChemin = new BPath(*(ocamlModule->fOCamlChemin));
}
}
OCamlModule::OCamlModule(BPath* ocamlChemin)
:fSource(new BString("")),
fDependances(new BString(""))
{
BString *module = LatexUtils::Normalize(new BString(ocamlChemin->Leaf()));
//Normalisation au cas où…
ocamlChemin->GetParent(ocamlChemin);
//TODO check return status
fOCamlChemin = new BPath(ocamlChemin->Path(), module->String());
}
OCamlModule::OCamlModule(BMessage* archive) {
fOCamlChemin = new BPath();
fSource = new BString();
fDependances = new BString();
archive->FindFlat("fOCamlChemin", fOCamlChemin);
archive->FindString("fSource", fSource);
archive->FindString("fDependances", fDependances);
}
void OCamlModule::SetOCamlChemin(BPath* chemin) {
fOCamlChemin = chemin;
}
BPath* OCamlModule::GetOCamlChemin() {
return fOCamlChemin;
}
void OCamlModule::AddDependance(BString* dependance){
fDependances->Append(" -I ");
fDependances->Append(dependance->String());
fDependances->Append(" ");
}
/////////////////////
//Compilation OCaml//
/////////////////////
void OCamlModule::SetSource(BString *source) {
fSource = new BString(source->CharacterEscape("\\",'\\'));
}
status_t OCamlModule::Compile(bool native) {
BString sourceName;
BString objectName;
BString command("");
objectName = fOCamlChemin->Path();
objectName << (native?".cmx":".cmo");
sourceName = fOCamlChemin->Path();
sourceName << ".ml";
BFile *source = new BFile(sourceName, B_CREATE_FILE|B_ERASE_FILE|B_WRITE_ONLY);
//TODO Gérer status
int octetsEcrits = source->Write(fSource->String(), fSource->Length());
if (octetsEcrits < 0 || octetsEcrits != fSource->Length()) {
//TODO Gérer l'erreur
}
//((App *)be_app)->SendOCaml(*fSource);
//Compilation dans la fenetre
/*Compilation en ligne*/
BPath *chemin = new BPath();
fOCamlChemin->GetParent(chemin);
chdir(chemin->Path());
command << (native?"ocamlopt.opt":"ocamlc.opt")
<< " -c "
<< fDependances->String()
<< " -o"
<< " "
<< objectName
<< " " << sourceName;
return //system(command);
B_OK;
}
status_t OCamlModule::Archive(BMessage *archive, bool deep) {
status_t status;
status = archive->AddString("fDependances", fDependances->String());
if (status != B_OK) return status;
archive->AddString("fSource", fSource->String());
if (status != B_OK) return status;
archive->AddFlat("fOCamlChemin", fOCamlChemin);
return status;
}