#include <fstream>
#include <iostream>
#include <cstdlib>
#include "eformat/old/eformat.h"
#include "eformat/write/eformat.h"
#include "eformat/eformat.h"
Go to the source code of this file.
Functions | |
int | main (int argc, char **argv) |
Variables | |
const size_t | MAX_ROS_SIZE = 2500000 |
Definition in file convert_ros.cxx.
int main | ( | int | argc, | |
char ** | argv | |||
) |
Reads a file and check its validity (for the time being)
Definition at line 32 of file convert_ros.cxx.
References eformat::old::convert(), eformat::BadVersionIssue::current(), HEX, eformat::MAJOR_DEFAULT_VERSION, MAX_ROS_SIZE, eformat::next_fragment(), and ers::Issue::what().
00033 { 00034 using namespace eformat; 00035 00036 if ( argc != 3 ) { 00037 std::cerr << "usage: " << argv[0] << " <v2.4 file> <v3.0 file>" 00038 << std::endl; 00039 std::exit(1); 00040 } 00041 00042 //open normally a file 00043 std::fstream in(argv[1], std::ios::in|std::ios::binary); 00044 if (!in) { 00045 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl; 00046 std::exit(1); 00047 } 00048 //open normally a file 00049 std::fstream out(argv[2], std::ios::out|std::ios::binary); 00050 if (!out) { 00051 std::cerr << "Cannot write to `" << argv[1] << "?!" << std::endl; 00052 std::exit(1); 00053 } 00054 00055 uint32_t* fragment = new uint32_t[MAX_ROS_SIZE]; 00056 uint32_t* nfragment = new uint32_t[MAX_ROS_SIZE]; 00057 00058 while (true) { 00059 00060 if (!(next_fragment(in, fragment, MAX_ROS_SIZE*4))) break; 00061 uint32_t l1id = 0; 00062 00063 old::ROSFragment ros(fragment); 00064 00065 try { 00066 ros.check_tree(); 00067 } 00068 catch (eformat::BadVersionIssue& ex) { 00069 std::cerr << " !! WARNING: found ROS fragment with format version = " 00070 << HEX(ex.current()) << std::endl; 00071 if (ex.current() != MAJOR_DEFAULT_VERSION) { 00072 std::cerr << " -> I cannot cope with this format. Skipping..." 00073 << std::endl; 00074 continue; 00075 } 00076 else { 00077 std::cout << " -> ROS fragment will be simply copied..." << std::endl; 00078 } 00079 } 00080 catch (eformat::Issue& ex) { 00081 std::cerr << "Uncaught eformat issue: " << ex.what() << std::endl; 00082 std::cerr << " -> Trying to continue..." 00083 << std::endl; 00084 continue; 00085 } 00086 catch (...) { 00087 std::cerr << std::endl << "Uncaught unknown exception" << std::endl; 00088 delete[] fragment; 00089 delete[] nfragment; 00090 std::exit(1); 00091 } 00092 00093 try { 00094 //if check is ok, print the lvl1 identifier 00095 std::cout << "ROS #" << ros.lvl1_id() << " [" << HEX(ros.version()) 00096 << "] -> [" << HEX(0x03000000) << "]" << std::endl; 00097 old::convert(fragment, nfragment, MAX_ROS_SIZE); 00098 ROSFragment<const uint32_t*> nros(nfragment); 00099 nros.check_tree(); 00100 l1id = nros.lvl1_id(); 00101 } 00102 catch (eformat::Issue& ex) { 00103 std::cerr << "Uncaught eformat issue: " << ex.what() << std::endl; 00104 std::cerr << " -> Trying to continue..." 00105 << std::endl; 00106 continue; 00107 std::exit(1); 00108 } 00109 catch (ers::Issue& ex) { 00110 std::cerr << "Uncaught ERS issue: " << ex.what() << std::endl; 00111 delete[] fragment; 00112 delete[] nfragment; 00113 std::exit(1); 00114 } 00115 catch (std::exception& ex) { 00116 std::cerr << "Uncaught std exception: " << ex.what() << std::endl; 00117 delete[] fragment; 00118 delete[] nfragment; 00119 std::exit(1); 00120 } 00121 catch (...) { 00122 std::cerr << std::endl << "Uncaught unknown exception" << std::endl; 00123 delete[] fragment; 00124 delete[] nfragment; 00125 std::exit(1); 00126 } 00127 out.write(reinterpret_cast<char*>(nfragment), 00128 sizeof(uint32_t)*nfragment[1]); 00129 //if check is ok, print the lvl1 identifier 00130 std::cout << " -> (new) ROS fragment #" << l1id 00131 << " converted, checked and saved." 00132 << std::endl; 00133 } 00134 00135 delete[] fragment; 00136 delete[] nfragment; 00137 return 0; 00138 }
const size_t MAX_ROS_SIZE = 2500000 |
The maximum event size, in words
Definition at line 27 of file convert_ros.cxx.
Referenced by main().