31 line.erase(std::remove(line.begin(), line.end(),
'\r'), line.end());
53 size_t pos = filepath.find_last_of(
"/\\");
54 if (pos == std::string::npos) {
55 pos = filepath.find_last_of(
"/");
58 size_t pos = filepath.find_last_of(
"/");
60 if (pos != std::string::npos) {
62 return filepath.substr(0, pos);
79 string md5_digest(16,
'0');
80 md5_states_tmp->push_front(make_tuple(1,title,new_md5,md5_digest));
92 for (
auto& item : *md5_states_tmp ) {
93 if (get<0>(item) == 1){
94 md5_state_t state = get<2>(item);
95 md5_append( &state, (
const md5_byte_t *) line.c_str(), line.length() );
110 for (
auto& item : *md5_states_tmp ) {
116 md5_state_t state = get<2>(item);
117 unsigned char md5[16];
118 md5_finish (&state, md5);
121 ostringstream formatted_line;
122 for (
int i = 0; i < 16; ++i) {
123 formatted_line << hex << setw(2) << setfill('0') << static_cast<int>(md5[i]);
125 get<3>(item)=formatted_line.str();
140 for (
auto& item : *md5_states_tmp ) {
146 md5_state_t state = get<2>(item);
147 unsigned char md5[16];
148 md5_finish (&state, md5);
151 ostringstream formatted_line;
152 for (
int i = 0; i < 16; ++i) {
153 formatted_line << hex << setw(2) << setfill('0') << static_cast<int>(md5[i]);
155 get<3>(item)=formatted_line.str();
169 int MD5Checksum::file_read(
string filename,
string deck_directory,
int level,list<tuple<int,string, md5_state_t, string>> *md5_states_tmp){
171 string chksum_start=(
"/CHECKSUM/START");
172 string chksum_end=(
"/CHECKSUM/END");
173 string chksum_include=(
"#include ");
175 new_file.open(filename, ios::in);
178 if (level > 15)
return 0;
180 if ( !new_file.is_open() ) {
185 while (getline(new_file, line)) {
189 if (line == chksum_start) {
191 getline(new_file, title);
197 if (line == chksum_end) {
202 string comp=line.substr(0,chksum_include.length());
203 if (
comp == chksum_include) {
205 string include_file = line.substr(chksum_include.length());
206 if (deck_directory.length() > 0){
207 include_file = deck_directory+
separator()+include_file;
210 cout <<
"Include file: " << include_file << endl;
214 file_read(include_file,deck_directory, level + 1,md5_states_tmp);
218 if (line[0] ==
'#') {
237 list<tuple<int,string, md5_state_t, string>> md5_states_tmp;
238 string deck_directory =
get_path(filenam);
239 file_read(filenam,deck_directory,0,&md5_states_tmp);
242 for (
const auto& item : md5_states_tmp){
246 md5_states_tmp.clear();
272 cout <<
"Error: N=" <<
N <<
" is greater than the number of checksums " <<
count << endl;
274 checksum_title[0]=
'\0';
282 int size_title = get<1>(*it).size();
283 get<1>(*it).copy(checksum_title ,size_title);
284 checksum_title[size_title]=
'\0';
285 *len_title=size_title;
288 int size_checksum = get<3>(*it).size();
289 get<3>(*it).copy(
checksum ,size_checksum);
291 *len_checksum=size_checksum;
305 list<string> checksums;
307 if (get<0>(item) == 0){
308 string chksum_item=get<1>(item)+
"_"+get<3>(item);
309 checksums.push_back(chksum_item);
320 cout <<
"Checksum list " << endl;
321 cout <<
"==============" << endl;
323 if (get<0>(item) == 0){
324 cout <<
"Checksum : " << get<1>(item) <<
" " << get<3>(item) << endl;
341 char * c_filename = (
char*) malloc(len_filename+1);
342 for (i=0; i<len_filename; i++){
343 c_filename[i]=filename[i];
345 c_filename[len_filename]=
'\0';
346 string cpp_filename(c_filename);
348 md_compute->
parse(cpp_filename);
354 return md_compute->
count();
358 md_compute->
member(count,checksum_title,len_title,
checksum,len_checksum);
void deck_checksum_read(MD5Checksum *md_compute, int count, char *checksum_title, int *len_title, char *checksum, int *len_checksum)
int deck_checksum_count(MD5Checksum *md_compute)
MD5Checksum * deck_checksum_creation(int len_filename, char filename[])
std::list< std::tuple< int, std::string, md5_state_t, std::string > > md5_states
void end_checksum(std::list< std::tuple< int, std::string, md5_state_t, std::string > > *md5_states_tmp)
void parse(std::string filenam)
std::list< std::string > get_checksums()
std::string get_path(const std::string &filepath)
void member(int N, char *checksum_title, int *len_title, char *checksum, int *len_checksum)
void process_checksum(std::string line, std::list< std::tuple< int, std::string, md5_state_t, std::string > > *md5_states_tmp)
int file_read(std::string filename, std::string deck_directory, int level, std::list< std::tuple< int, std::string, md5_state_t, std::string > > *md5_states_tmp)
void finalize_checksum(std::list< std::tuple< int, std::string, md5_state_t, std::string > > *md5_states_tmp)
void new_checksum(std::string title, std::list< std::tuple< int, std::string, md5_state_t, std::string > > *md5_states_tmp)
void remove_carriage_return(std::string &line)