CLI version: add option for delimiter token of csv output

This commit is contained in:
Mario Fink 2021-06-28 12:51:09 +02:00
parent fdd107fbb3
commit bafc018566
4 changed files with 28 additions and 6 deletions

View File

@ -381,7 +381,7 @@ namespace imc
} }
// print channel // print channel
void print(std::string filename, const char sep = ' ', int width = 25) void print(std::string filename, const char sep = ',', int width = 25)
{ {
std::ofstream fou(filename); std::ofstream fou(filename);

View File

@ -333,7 +333,7 @@ namespace imc
} }
// print all channels in directory // print all channels in directory
void print_channels(std::string output) void print_channels(std::string output, const char sep)
{ {
// check for given directory // check for given directory
std::filesystem::path pd = output; std::filesystem::path pd = output;
@ -352,7 +352,7 @@ namespace imc
std::filesystem::path pf = pd / filenam; std::filesystem::path pf = pd / filenam;
// and print the channel // and print the channel
it->second.print(pf); it->second.print(pf,sep);
} }
} }

View File

@ -93,7 +93,7 @@ cython-install : check-vtag $(CTAG) $(CYT)setup.py $(CYT)imc_termite.pxd $(CYT)p
cython-clean : cython-clean :
rm -vf imc_termite.cpython-*.so rm -vf imc_termite.cpython-*.so
rm -vf $(PYT)imc_termite.cpython-*.so rm -vf $(PYT)imc_termite.cpython-*.so
rm -rv build/ rm -rvf build/
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
# pip # pip

View File

@ -66,6 +66,20 @@ optkeys parse_args(int argc, char* argv[], bool list_args = false)
i = i + 1; i = i + 1;
} }
} }
else if ( std::string(argv[i]) == std::string("--delimiter")
|| std::string(argv[i]) == std::string("-s") )
{
if ( i+1 == argc || argv[i+1][0] == '-' )
{
std::cerr<<"invalid or missing --output argument\n";
prsdkeys.insert(std::pair<std::string,std::string>("invalid","delimiter"));
}
else
{
prsdkeys.insert(std::pair<std::string,std::string>("delimiter",argv[i+1]));
i = i + 1;
}
}
else if ( std::string(argv[i]) == std::string("--help") else if ( std::string(argv[i]) == std::string("--help")
|| std::string(argv[i]) == std::string("-h") ) || std::string(argv[i]) == std::string("-h") )
{ {
@ -121,9 +135,13 @@ void show_usage()
<<" -c, --listchannels list channels\n" <<" -c, --listchannels list channels\n"
<<" -b, --listblocks list IMC key-blocks\n" <<" -b, --listblocks list IMC key-blocks\n"
<<" -d, --output output directory to print channels\n" <<" -d, --output output directory to print channels\n"
<<" -s, --delimiter csv delimiter/separator char for output\n"
<<" -h, --help show this help message \n" <<" -h, --help show this help message \n"
<<" -v, --version display version\n" <<" -v, --version display version\n"
<<"\n"; <<"\n"
<<"Example:"
<<" $ ./imctermite sample/data_A.raw -c -b -d ./data -s ','"
<<"\n\n";
} }
//---------------------------------------------------------------------------// //---------------------------------------------------------------------------//
@ -209,7 +227,11 @@ int main(int argc, char* argv[])
if ( cfgopts.count("output") == 1 ) if ( cfgopts.count("output") == 1 )
{ {
try { try {
imcraw.print_channels(cfgopts.at("output")); if ( cfgopts.at("delimiter").size() > 1 )
{
throw std::runtime_error("invalid delimiter comprised of more than a single char");
}
imcraw.print_channels(cfgopts.at("output"),cfgopts.at("delimiter")[0]);
} catch (const std::exception& e) { } catch (const std::exception& e) {
std::cerr<<"failed to print channels for "<<rawfile<<": "<<e.what()<<"\n"; std::cerr<<"failed to print channels for "<<rawfile<<": "<<e.what()<<"\n";
} }