summaryrefslogtreecommitdiff
path: root/src/tools/viewcsv.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-06-21 17:14:34 +0000
committerMike Buland <eichlan@xagasoft.com>2010-06-21 17:14:34 +0000
commit584b96617acce0f6c33802d8b70b629f707be273 (patch)
treeeb59fc6c1abcf78260ecf9acaa313aefebb4097e /src/tools/viewcsv.cpp
parentc715b258e2d486ee4d95da7d495fd1567770fdf6 (diff)
downloadlibbu++-584b96617acce0f6c33802d8b70b629f707be273.tar.gz
libbu++-584b96617acce0f6c33802d8b70b629f707be273.tar.bz2
libbu++-584b96617acce0f6c33802d8b70b629f707be273.tar.xz
libbu++-584b96617acce0f6c33802d8b70b629f707be273.zip
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.
Diffstat (limited to 'src/tools/viewcsv.cpp')
-rw-r--r--src/tools/viewcsv.cpp95
1 files changed, 95 insertions, 0 deletions
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 @@
1#include <bu/sio.h>
2#include <bu/optparser.h>
3#include <bu/csvreader.h>
4#include <bu/file.h>
5
6using namespace Bu;
7
8class Options : public Bu::OptParser
9{
10public:
11 Options( int argc, char *argv[] )
12 {
13 setNonOption( slot( this, &Options::onNonOption ) );
14 addHelpOption();
15 parse( argc, argv );
16 }
17
18 virtual ~Options()
19 {
20 }
21
22 int onNonOption( StrArray aParams )
23 {
24 //sio << aParams << sio.nl;
25 sFileIn = aParams[0];
26
27 return 0;
28 }
29
30 Bu::FString sFileIn;
31};
32
33typedef Bu::Array<StrArray> StrGrid;
34typedef Bu::Array<int> IntArray;
35class CsvDoc
36{
37public:
38 CsvDoc() :
39 iMaxCols( 0 )
40 {
41 }
42
43 virtual ~CsvDoc()
44 {
45 }
46
47 void addRow( StrArray aStr )
48 {
49 sgData.append( aStr );
50 if( iMaxCols < aStr.getSize() )
51 iMaxCols = aStr.getSize();
52 while( aWidths.getSize() < iMaxCols )
53 {
54 aWidths.append( 0 );
55 }
56 for( int j = 0; j < aStr.getSize(); j++ )
57 {
58 if( aWidths[j] < aStr[j].getSize() )
59 aWidths[j] = aStr[j].getSize();
60 }
61 }
62
63 int iMaxCols;
64 StrGrid sgData;
65 IntArray aWidths;
66};
67
68int main( int argc, char *argv[] )
69{
70 Options opt( argc, argv );
71
72 if( !opt.sFileIn.isSet() )
73 {
74 sio << "No file specified." << sio.nl;
75 return 1;
76 }
77
78 CsvDoc doc;
79 File fIn( opt.sFileIn, File::Read );
80 CsvReader cr( fIn );
81
82 while( !fIn.isEos() )
83 {
84 StrArray sa = cr.readLine();
85 if( fIn.isEos() )
86 break;
87 doc.addRow( sa );
88 }
89
90 sio << "Csv grid: " << doc.iMaxCols << " x " << doc.sgData.getSize()
91 << sio.nl;
92
93 return 0;
94}
95