From 584b96617acce0f6c33802d8b70b629f707be273 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 21 Jun 2010 17:14:34 +0000 Subject: Working on a small program to view CSV files using libbu++'s codecs, not only will it be a more exact display, but it will let us see exactly what libbu++ thinks the CSV should look like. --- src/tools/viewcsv.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/tools/viewcsv.cpp (limited to 'src/tools') diff --git a/src/tools/viewcsv.cpp b/src/tools/viewcsv.cpp new file mode 100644 index 0000000..69bc6a1 --- /dev/null +++ b/src/tools/viewcsv.cpp @@ -0,0 +1,95 @@ +#include +#include +#include +#include + +using namespace Bu; + +class Options : public Bu::OptParser +{ +public: + Options( int argc, char *argv[] ) + { + setNonOption( slot( this, &Options::onNonOption ) ); + addHelpOption(); + parse( argc, argv ); + } + + virtual ~Options() + { + } + + int onNonOption( StrArray aParams ) + { + //sio << aParams << sio.nl; + sFileIn = aParams[0]; + + return 0; + } + + Bu::FString sFileIn; +}; + +typedef Bu::Array StrGrid; +typedef Bu::Array IntArray; +class CsvDoc +{ +public: + CsvDoc() : + iMaxCols( 0 ) + { + } + + virtual ~CsvDoc() + { + } + + void addRow( StrArray aStr ) + { + sgData.append( aStr ); + if( iMaxCols < aStr.getSize() ) + iMaxCols = aStr.getSize(); + while( aWidths.getSize() < iMaxCols ) + { + aWidths.append( 0 ); + } + for( int j = 0; j < aStr.getSize(); j++ ) + { + if( aWidths[j] < aStr[j].getSize() ) + aWidths[j] = aStr[j].getSize(); + } + } + + int iMaxCols; + StrGrid sgData; + IntArray aWidths; +}; + +int main( int argc, char *argv[] ) +{ + Options opt( argc, argv ); + + if( !opt.sFileIn.isSet() ) + { + sio << "No file specified." << sio.nl; + return 1; + } + + CsvDoc doc; + File fIn( opt.sFileIn, File::Read ); + CsvReader cr( fIn ); + + while( !fIn.isEos() ) + { + StrArray sa = cr.readLine(); + if( fIn.isEos() ) + break; + doc.addRow( sa ); + } + + sio << "Csv grid: " << doc.iMaxCols << " x " << doc.sgData.getSize() + << sio.nl; + + return 0; +} + -- cgit v1.2.3