forked from grenaud/libgab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PutProgramInHeader.cpp
118 lines (96 loc) · 2.89 KB
/
PutProgramInHeader.cpp
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
108
109
110
111
112
113
114
115
116
117
118
/*
* PutProgramInHeader
* Date: Dec-04-2012
* Author : Gabriel Renaud gabriel.reno [at sign here ] gmail.com
*
*/
#include "PutProgramInHeader.h"
// string returnGitHubVersion(const string programName,const string suffixToAdd){
// //getting github version
// string directoryProgram;
// string commandPath=string(programName);
// unsigned posSlash=commandPath.find_last_of("/");
// if(posSlash == string::npos){
// directoryProgram="";
// }else{
// directoryProgram=commandPath.substr(0,posSlash);
// }
// string gitFileLog=directoryProgram+"/"+suffixToAdd+"/.git/logs/HEAD";
// string gitVersion="NA";
// if(isFile(gitFileLog)){
// ifstream myFile;
// string line;
// myFile.open(gitFileLog.c_str(), ios::in);
// if (myFile.is_open()){
// while ( getline (myFile,line)){
// vector<string> vs=allTokens(line,' ');
// gitVersion=vs[1];
// }
// myFile.close();
// }else{
// cerr << "Unable to open github file "<<gitFileLog<<endl;
// return "NA";
// }
// }
// return gitVersion;
// }
void putProgramInHeader(SamHeader * header,
const string & programID,
const string & programName,
const string & programCL,
const string & programVersion){
//BEGIN DETECTING PREVIOUS PROGRAM
string previousProgram="";
map<string,bool> program2foundasPP;
SamProgramChain allPrograms =header->Programs;
SamProgramConstIterator it;
//we will try to find a program that was never
//specified as PP in another program
for(it= allPrograms.ConstBegin();
it!=allPrograms.ConstEnd();
it++){
if(!it->HasID ()){
cerr<<"Program does not have an ID"<<endl;
exit(1);
}
// if(it->ID == programID){
// cerr<<"Program ID already exists"<<endl;
// exit(1);
// }
program2foundasPP.insert( pair<string,bool>(it->ID,false) );
}
for(it= allPrograms.ConstBegin();
it!=allPrograms.ConstEnd();
it++){
if(!it->HasID ()){
cerr<<"Program does not have an ID"<<endl;
exit(1);
}
if(it->HasPreviousProgramID() )
program2foundasPP[ it->PreviousProgramID ] =true;
}
map<string,bool>::iterator program2foundasPP_it;
for(program2foundasPP_it= program2foundasPP.begin();
program2foundasPP_it!=program2foundasPP.end();
program2foundasPP_it++){
if(! program2foundasPP_it->second ){ //program not found as PP
if(previousProgram!=""){
cerr<<"Many program without PP ex:"<<previousProgram<<" replacing with "<<program2foundasPP_it->first<<endl;
}
previousProgram=program2foundasPP_it->first;
}
}
//END DETECTING PREVIOUS PROGRAM
//cout<<previousProgram<<endl;
// exit(1);
SamProgram sp;
sp.ID = programID;
sp.Name = programName;
sp.CommandLine = programCL;
sp.Version = programVersion;
if(previousProgram != ""){
sp.PreviousProgramID=previousProgram;
}
header->Programs.Add(sp);
}
// }