From c1af9697acaf6dbc98afa5ffe18d2c5c7ab12c59 Mon Sep 17 00:00:00 2001 From: Carl N Baldwin Date: Sat, 15 Oct 2005 21:54:27 -0600 Subject: [PATCH] Some more work. --- Makefile.am | 4 +++- filedata.cpp | 20 ++++++++++++++++++++ filedata.hpp | 26 ++++++++++++++++++++++++++ main.cc | 27 ++++++++++++++++++++++++++- 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 filedata.cpp create mode 100644 filedata.hpp diff --git a/Makefile.am b/Makefile.am index d4632fe..a9d90e3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,7 +4,9 @@ bin_SCRIPTS = find-cmd.sh EXTRA_DIST = $(bin_SCRIPTS) -lsbackups_SOURCES = main.cc +lsbackups_SOURCES = main.cc \ + filedata.hpp \ + filedata.cpp AM_CPPFLAGS = $(SQLITE3_CFLAGS) LDADD = $(SQLITE3_LIBS) diff --git a/filedata.cpp b/filedata.cpp new file mode 100644 index 0000000..c3a8840 --- /dev/null +++ b/filedata.cpp @@ -0,0 +1,20 @@ +#include + +#include "filedata.hpp" + +using namespace std; + +FileData::FileData( char _type, + string _permissions, + string _user, + string _group, + unsigned int _size, + unsigned long long _modified_date, + string _name ) +: type( _type ), + permissions( _permissions ), + user( _user ), + group( _group ), + size( _size ), + modified_date( _modified_date ), + name( _name ) {} diff --git a/filedata.hpp b/filedata.hpp new file mode 100644 index 0000000..0393ecd --- /dev/null +++ b/filedata.hpp @@ -0,0 +1,26 @@ +#include + +class FileData { + public: + // Construct a FileData object with default values + FileData( char, + std::string, + std::string, + std::string, + unsigned int, + unsigned long long, + std::string + ); + + private: + FileData(); + FileData( const FileData & ); + + char type; + std::string permissions; + std::string user; + std::string group; + unsigned int size; + unsigned long long modified_date; + std::string name; +}; diff --git a/main.cc b/main.cc index bd744b6..b809f58 100644 --- a/main.cc +++ b/main.cc @@ -1,8 +1,30 @@ #include +#include +#include +#include #include using namespace std; +vector split( const string &line, char c, int limit = -1 ) { + string::size_type start = 0, end = 0; + + vector out; + while( 0 != limit-- && end != line.size() ) { + if( 0 == limit ) { + end = line.size(); + } else { + end = line.find( c, start ); + if( end == string::npos ) { + end = line.size(); + } + } + out.push_back( line.substr( start, end-start ) ); + start = end + 1; + } + return out; +} + int main() { string file_string; do { @@ -11,7 +33,10 @@ int main() { file_string.push_back( c ); } if( 0 != file_string.size() ) { - cout << file_string << endl; + // Example entry + // type perms user group size datemodified name (7 total) + // f 0600 cnb cnb 424 20051015205340 ./.git/index + vector values = split( file_string, ' ', 7 ); } } while( ! cin.eof() ); } -- 2.34.1