00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include "remoteserver.h"
00024
00025 #include "gnu_getopt.h"
00026
00027 #include <cstdlib>
00028 #include <iostream>
00029 #include <string>
00030
00031 using namespace std;
00032
00033 #define PROG_NAME "xapian-progsrv"
00034 #define PROG_DESC "Piped server for use with Xapian's remote backend"
00035
00036 #define OPT_HELP 1
00037 #define OPT_VERSION 2
00038
00039 static const char * opts = "t:w";
00040 static const struct option long_opts[] = {
00041 {"timeout", required_argument, 0, 't'},
00042 {"writable", no_argument, 0, 'w'},
00043 {"help", no_argument, 0, OPT_HELP},
00044 {"version", no_argument, 0, OPT_VERSION},
00045 {NULL, 0, 0, 0}
00046 };
00047
00048 static void show_usage() {
00049 cout << "Usage: "PROG_NAME" [OPTIONS] DATABASE_DIRECTORY...\n\n"
00050 "Options:\n"
00051 " --timeout MSECS set timeout\n"
00052 " --writable allow updates (only one database directory allowed)\n"
00053 " --help display this help and exit\n"
00054 " --version output version information and exit" << endl;
00055 }
00056
00057 int main(int argc, char **argv)
00058 {
00059 unsigned int timeout = 60000;
00060 bool writable = false;
00061 bool syntax_error = false;
00062
00063 int c;
00064 while ((c = gnu_getopt_long(argc, argv, opts, long_opts, NULL)) != -1) {
00065 switch (c) {
00066 case OPT_HELP:
00067 cout << PROG_NAME" - "PROG_DESC"\n\n";
00068 show_usage();
00069 exit(0);
00070 case OPT_VERSION:
00071 cout << PROG_NAME" - "PACKAGE_STRING << endl;
00072 exit(0);
00073 case 't':
00074 timeout = atoi(optarg);
00075 break;
00076 case 'w':
00077 writable = true;
00078 break;
00079 default:
00080 syntax_error = true;
00081 }
00082 }
00083
00084 if (syntax_error || optind == argc) {
00085 show_usage();
00086 exit(1);
00087 }
00088
00089 if (writable && (argc - optind) != 1) {
00090 cerr << "Error: only one database directory allowed with '--writable'."
00091 << endl;
00092 exit(1);
00093 }
00094
00095
00096
00097
00098
00099
00100 vector<string> dbnames(argv + optind, argv + argc);
00101
00102 try {
00103
00104
00105 RemoteServer server(dbnames, 0, 1, timeout, timeout, writable);
00106
00107
00108
00109
00110
00111 server.run();
00112 } catch (...) {
00113
00114
00115
00116
00117
00118
00119
00120
00121 }
00122 }