/usr/share/doc/xapian1.3-examples/examples/xapian-metadata.cc is in xapian1.3-examples 1.3.4-0ubuntu6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | /** @file xapian-metadata.cc
* @brief Read and write user metadata
*/
/* Copyright (C) 2007,2010,2015 Olly Betts
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <xapian.h>
#include <iostream>
#include <string>
#include <cstdlib> // For exit().
#include <cstring>
using namespace std;
#define PROG_NAME "xapian-metadata"
#define PROG_DESC "Read and write user metadata"
static void show_usage() {
cout << "Usage: " PROG_NAME " get PATH_TO_DATABASE KEY\n"
" " PROG_NAME " list PATH_TO_DATABASE [PREFIX]\n"
" " PROG_NAME " set PATH_TO_DATABASE KEY VALUE" << endl;
}
int
main(int argc, char **argv)
try {
const char * command = argv[1];
if (!command) {
syntax_error:
show_usage();
exit(1);
}
if (command[0] == '-') {
if (strcmp(command, "--help") == 0) {
cout << PROG_NAME " - " PROG_DESC "\n\n";
show_usage();
exit(0);
}
if (strcmp(command, "--version") == 0) {
cout << PROG_NAME " - " PACKAGE_STRING << endl;
exit(0);
}
}
if (strcmp(command, "get") == 0) {
if (argc != 4) goto syntax_error;
Xapian::Database db(argv[2]);
cout << db.get_metadata(argv[3]) << endl;
} else if (strcmp(command, "list") == 0) {
if (argc != 3 && argc != 4) goto syntax_error;
Xapian::Database db(argv[2]);
string prefix;
if (argc == 4) prefix = argv[3];
for (Xapian::TermIterator t = db.metadata_keys_begin(prefix);
t != db.metadata_keys_end(prefix);
++t) {
cout << *t << '\n';
}
} else if (strcmp(command, "set") == 0) {
if (argc != 5) goto syntax_error;
Xapian::WritableDatabase db(argv[2], Xapian::DB_CREATE_OR_OPEN);
db.set_metadata(argv[3], argv[4]);
db.commit();
} else {
goto syntax_error;
}
} catch (const Xapian::Error &e) {
cout << e.get_description() << endl;
exit(1);
}
|