#include <stdexcept>
#include <dvutil/file.h>
#include <dvutil/tostring.h>
#include <dvnet/socket.h>
Go to the source code of this file.
Functions | |
int | add (Net::Socket &server, const string &path) |
int | main (int argc, char *argv[]) |
|
Definition at line 10 of file ffiles.C. Referenced by main().
00010 { 00011 // Recursively add a path to the index: if path is not 00012 // a directory, we just send a single add command to the server, 00013 // otherwise we recursively send such a command for each file in the 00014 // directory. 00015 int n(0); 00016 Util::File f(path); 00017 f.expand(); // make sure it is not a symbolic link 00018 if (f.type() == Util::File::DIRECTORY) { 00019 try { 00020 Util::Directory d(f); 00021 const vector<string>& files(d.files()); 00022 for (unsigned int i=0; i<files.size(); ++i) 00023 n += add(server, d.file(files[i])); 00024 return n; 00025 } 00026 catch (...) { 00027 return n; 00028 } 00029 } 00030 server << "add " << path << endl; 00031 string reply; 00032 getline(server, reply); 00033 return n + (reply == "OK" ? 1 : 0 ); 00034 } |
|
Definition at line 38 of file ffiles.C. References add().
00038 { 00039 static const string usage("usage: ffiles host port command"); 00040 static const string error("ERROR "); 00041 try { 00042 // Get common parameters. 00043 if (argc<4) 00044 throw runtime_error(usage); 00045 00046 const string host(argv[1]); 00047 const int port(atoi(argv[2])); 00048 const string cmd(argv[3]); 00049 00050 // Connect to server. 00051 // Net::Socket server(argv[1],atoi(argv[2]),1024,5000); 00052 Net::Socket server(host, port); 00053 if (!server) 00054 throw runtime_error(Util::tostring(port) + "@" + host + ": " + 00055 server.strerror()); 00056 00057 // Process command. 00058 00059 if ( cmd=="stop" || cmd == "save" ) { 00060 string reply; 00061 server << cmd << endl; 00062 getline(server, reply); 00063 cout << reply << endl; 00064 } 00065 else if (cmd == "add") { 00066 if (argc<5) 00067 throw runtime_error(usage); 00068 const string path(argv[4]); 00069 cout << add(server, path) << " files added" << endl; 00070 } 00071 else if (cmd == "query") { 00072 if (argc<5) 00073 throw runtime_error(usage); 00074 const string query(argv[4]); 00075 server << cmd << ' ' << query << endl; 00076 string reply; 00077 while (server) { 00078 getline(server,reply); 00079 if (reply.size()==0) 00080 break; 00081 cout << reply << endl; 00082 } 00083 } 00084 else 00085 throw runtime_error(cmd + ": bad command"); 00086 } 00087 catch (exception& e) { 00088 cerr << error << e.what() << endl; 00089 return 1; 00090 } 00091 return 0; 00092 } |
textindexer-0.2 | [27 March, 2002] |