31 char * s_cchar = (
char*)s.c_str();
35 long converted = strtol(s_cchar, &p, 10);
53 oss << setw(4) << setfill(
'0') << number;
67 oss << setw(3) << setfill(
'0') << number;
75 line.erase(std::remove(line.begin(), line.end(),
'\r'), line.end());
104 if (list1.size() != list2.size()) {
107 auto it1 = list1.begin();
108 auto it2 = list2.begin();
109 while (it1 != list1.end() && it2 != list2.end()) {
130 size_t pos = string(fname).find_last_of(
'.');
131 std::string extension = fname.substr(pos + 1);
134 string input_deck=rootname+
"_0000.rad";
135 if (fname == input_deck){
139 if (extension ==
"out") {
142 if (extension ==
"thy") {
146 if (extension ==
"checksum") {
147 int filename_length = rootname.length()+5+extension.length()+1;
148 if (fname.length() == filename_length){
149 std::string str_runnumber=fname.substr(rootname.length()+1,4);
159 if (extension ==
"gz"){
160 rd_run = fname.substr(fname.length()-6,3);
161 file_A=fname.substr(0,fname.length()-6);
163 rd_run = fname.substr(fname.length()-3);
164 file_A=fname.substr(0,fname.length()-3);
166 string anim_pattern=rootname+
"A";
167 if (
is_integer(rd_run) && anim_pattern == file_A){
170 string th_pattern=rootname+
"T";
171 string file_T=fname.substr(0,fname.length()-2);
172 rd_run = fname.substr(fname.length()-2);
173 if (
is_integer(rd_run) && th_pattern == file_T){
189 std::vector<std::string> files;
192 std::string search_path = directory + rootname +
"*";
194 HANDLE hFind = ::FindFirstFileA(search_path.c_str(), &fd);
195 if (hFind != INVALID_HANDLE_VALUE) {
197 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
198 string fname(fd.cFileName);
201 }
while (::FindNextFileA(hFind, &fd));
205 string directory_cp = directory;
206 if ( directory_cp.length()==0){
209 DIR* dir = opendir(directory_cp.c_str());
211 struct dirent* entry;
212 while ((entry = readdir(dir)) !=
nullptr) {
213 std::string fname(entry->d_name);
214 if (fname.find(rootname) == 0) {
250 if ( directory.length() > 0 ){
257 new_file.open(
outfile, ios::in);
259 if ( !new_file.is_open() ) {
263 cout <<
"Parsing file: " <<
outfile << endl;
267 list<string> checksum_list_out=out.
Out_File( &new_file );
273 string formated_out =
outfile +
" : " + file_checksum;
275 checksum_list.push_back(make_tuple(formated_out,checksum_list_out));
294 int found_out_file=1;
299 if ( directory.length() > 0 ){
300 anim_file = directory + item;
310 if ( success == 0 ) {
315 cout <<
"Parsing file: " << anim_file << endl;
319 list<string> checksum_list_out=out.
Animation( );
324 string formated_out = anim_file +
" : " + file_checksum;
326 checksum_list.push_back(make_tuple(formated_out,checksum_list_out));
347 int found_out_file=1;
352 if ( directory.length() > 0 ){
353 th_file = directory + item;
361 if ( success == 0 ) {
366 cout <<
"Parsing file: " << th_file << endl;
373 string formated_out = th_file +
" : " + file_checksum;
375 checksum_list.push_back(make_tuple(formated_out,checksum_list_th));
396 if ( directory.length() > 0 ){
397 chkfile = directory + item;
403 string valid_message;
405 valid_message =
"Valid Fingerprint";
407 valid_message =
"Invalid Fingerprint";
411 new_file.open(chkfile, ios::in);
413 if ( !new_file.is_open() ) {
417 cout <<
"Parsing file: " << chkfile << endl;
421 std::list<std::tuple<std::string,std::string>> checksum_list_chk;
425 string formated_out = chkfile +
" : " ;
426 list<string> verify_checksum_list;
429 for (
const auto& item2 :checksum_list_chk){
430 string filename = get<0>(item2);
435 if (computed_checksum.length() > 0){
437 verify_checksum_list.push_back(filename +
"_" +
"Valid Checksum" );
439 verify_checksum_list.push_back(filename +
"_" +
"Failed checksum check : File: "+
checksum +
" Computed: " + computed_checksum);
443 checksum_list.push_back(make_tuple(formated_out,verify_checksum_list));
460 size_t pos = filepath.find_last_of(
"/\\");
461 if (pos == std::string::npos) {
462 pos = filepath.find_last_of(
"/");
465 size_t pos = filepath.find_last_of(
"/");
467 if (pos != std::string::npos) {
469 return filepath.substr(0, pos);
491 cout <<
"Directory: " << directory << endl;
492 cout <<
"Rootname: " << rootname << endl;
504 my_checksums.
parse(deck_file);
505 list<string> deck_checksum_list=my_checksums.
get_checksums();
508 checksum_list.push_back(make_tuple(deck_file,deck_checksum_list));
511 cout <<
"Commputed Checksum list from deck: " << endl;
512 cout <<
"===================================" << endl;
513 for (
const auto& item : deck_checksum_list){
514 cout << item << endl;
516 cout <<
"==============================" << endl;
536 cout <<
"Checksum list from output files: " << endl;
537 cout <<
"==============================" << endl;
539 cout <<
"File: " << get<0>(item) << endl;
540 for (
const auto&
checksum : get<1>(item)){
543 cout <<
"==============================" << endl;
562 char rootname_c[257];
563 for (i=0;i<*lenr;i++){
564 rootname_c[i]=rootname[i];
566 rootname_c[*lenr]=
'\0';
567 string str_rootname(rootname_c);
571 for (i=0;i<*lenp;i++){
575 string str_path(path_c);
580 list<tuple<string,list<string>>> checksum_list;
582 checksum_list=chksum_tool.
chk_list(str_rootname,str_path);
586 const char* blank=
" ";
587 int len_blank= strlen(blank);
589 for (
const auto& item : checksum_list){
590 string filename=
" File. . . . "+get<0>(item);
591 const char* line=filename.c_str();
592 int len_line= strlen(line);
597 for (
const auto&
checksum : get<1>(item)){
598 size_t pos =
checksum.find_last_of(
"_");
599 string title=
checksum.substr(0,pos);
600 string digest=
checksum.substr(pos+1);
601 string checksum_line=
" "+title+
" : "+digest;
602 const char* line=checksum_line.c_str();
603 len_line= strlen(line);
632int main(
int argc,
char *argv[])
636 cout <<
"Filename to process: "<< argv[1] << endl;
637 string file=string(argv[1]);
639 string path=verify_chksum_tool.
get_path(file);
640 list<tuple<string,list<string>>> list = verify_chksum_tool.
chk_list(file,path);
643 cout <<
"Checksum list from output files: " << endl;
644 cout <<
"==============================" << endl << endl;
646 for (
const auto& item : list){
647 cout <<
"File: " << get<0>(item) << endl;
648 for (
const auto&
checksum : get<1>(item)){
651 cout <<
" "<< title <<
" : " << digest << endl;
int open_binary_file(std::string filename)
std::list< std::string > Animation()
std::list< std::string > Out_File(std::fstream *new_file)
std::list< std::string > Time_History()
std::list< std::tuple< std::string, std::string > > Checksum_File(std::fstream *new_file)
void sort_in_lists(std::string file, std::string rootname)
void parse_output_files(std::string directory, std::string rootname)
std::map< std::string, std::string > file_checksum_list
bool is_integer(const std::string s)
std::list< std::tuple< std::string, std::list< std::string > > > chk_list(std::string input, std::string directory)
std::list< std::string > th_file_list
bool is_file_valid(std::string file)
void remove_cr(std::string &line)
std::string format_as_3_digits(int number)
std::list< std::string > checksum_file_list
void parse_th_files(std::string directory, std::string rootname)
void parse_animation_files(std::string directory, std::string rootname)
std::list< std::string > anim_file_list
std::list< std::tuple< std::string, std::list< std::string > > > checksum_list
std::string format_as_4_digits(int number)
std::list< std::string > out_file_list
int compare_lists(std::list< std::string > list1, std::list< std::string > list2)
std::list< std::string > deck_file_list
std::string get_path(const std::string &filepath)
void file_list(std::string directory, std::string rootname)
void parse_checksum_files(std::string directory, std::string rootname)
void parse(std::string filenam)
std::list< std::string > get_checksums()
std::string compute_checksum(std::string file)