Just a regular commit
[backups/.git] / main.cc
1 #include <iostream>
2 #include <iterator>
3 #include <string>
4 #include <vector>
5 #include <algorithm>
6 #include <set>
7
8 #include <sqlite3.h>
9
10 #include "filedata.hpp"
11
12 using namespace std;
13
14 vector<string> split( const string &line, char c, int limit = -1 ) {
15   string::size_type start = 0, end = 0;
16
17   vector<string> out;
18   while( 0 != limit-- && end != line.size() ) {
19     if( 0 == limit ) {
20       end = line.size();
21     } else {
22       end = line.find( c, start );
23       if( end == string::npos ) {
24         end = line.size();
25       }
26     }
27     out.push_back( line.substr( start, end-start ) );
28     start = end + 1;
29   }
30   return out;
31 }
32
33 int callback( void *NotUsed, int argc, char **argv, char **azColName ) {
34   int i;
35   for( int i = 0; i < argc; ++i ) {
36     cout << azColName[i] << " = " << ( argv[i] ? argv[i] : "NULL" ) << endl;
37   }
38   cout << endl;
39   return 0;
40 }
41
42 void sql_experimenting() {
43   sqlite3 *db;
44   char *sqliteErrMsg = 0;
45   int rc;
46
47   const char *dbname = "test.db";
48   rc = sqlite3_open( dbname, &db );
49   if( SQLITE_OK != rc ) {
50     cerr << "Cannot open database: " << dbname << ".  Error message is..." << endl;
51     cerr << sqlite3_errmsg(db) << endl;
52   }
53
54   rc = sqlite3_exec( db, "select * from filedata;", callback, 0, &sqliteErrMsg );
55   if( SQLITE_OK != rc ) {
56     cerr << "Problem with database.  Message is..." << endl;
57     cerr << sqliteErrMsg << endl;
58   }
59
60   sqlite3_close( db );
61 }
62
63 int main() {
64   string file_string;
65   set<FileData*,FileDataPtrCmp> current_files;
66
67   // Parse the list of files on stdin
68   do {
69     file_string.clear();
70     for( int c = cin.get(); 0 != c && ! cin.eof(); c = cin.get() ) {
71       file_string.push_back( c );
72     }
73     if( 0 != file_string.size() ) {
74       // Example entry
75       // type perms user group size datemodified name (7 total)
76       // f 0600 cnb cnb 424 20051015205340 ./.git/index
77       vector<string> vals = split( file_string, ' ', 7 );
78       current_files.insert( new FileData( vals[0][0],
79             vals[1],
80             vals[2],
81             vals[3],
82             atoi( vals[4].c_str() ),
83             atoi( vals[5].c_str() ),
84             vals[6]) );
85     }
86   } while( ! cin.eof() );
87
88   set<FileData*,FileDataPtrCmp> previous_files;
89 }