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 <xapian.h>
00024
00025 #include <iostream>
00026 #include <string>
00027
00028 #include <cstdlib>
00029 #include <cstring>
00030
00031 using namespace std;
00032
00033 #define PROG_NAME "xapian-metadata"
00034 #define PROG_DESC "Read and write user metadata"
00035
00036 static void show_usage() {
00037 cout << "Usage: "PROG_NAME" get PATH_TO_DATABASE KEY\n"
00038 " "PROG_NAME" set PATH_TO_DATABASE KEY VALUE" << endl;
00039 }
00040
00041 int
00042 main(int argc, char **argv)
00043 try {
00044 const char * command = argv[1];
00045 if (!command) {
00046 syntax_error:
00047 show_usage();
00048 exit(1);
00049 }
00050
00051 if (command[0] == '-') {
00052 if (strcmp(command, "--help") == 0) {
00053 cout << PROG_NAME" - "PROG_DESC"\n\n";
00054 show_usage();
00055 exit(0);
00056 }
00057 if (strcmp(command, "--version") == 0) {
00058 cout << PROG_NAME" - "PACKAGE_STRING << endl;
00059 exit(0);
00060 }
00061 }
00062
00063 if (strcmp(command, "get") == 0) {
00064 if (argc != 4) goto syntax_error;
00065 Xapian::Database db(argv[2]);
00066 cout << db.get_metadata(argv[3]) << endl;
00067 } else if (strcmp(command, "set") == 0) {
00068 if (argc != 5) goto syntax_error;
00069 Xapian::WritableDatabase db(argv[2], Xapian::DB_CREATE_OR_OPEN);
00070 db.set_metadata(argv[3], argv[4]);
00071 db.commit();
00072 } else {
00073 goto syntax_error;
00074 }
00075 } catch (const Xapian::Error &e) {
00076 cout << e.get_description() << endl;
00077 exit(1);
00078 }