Reimplement Language Modelling weights
[xapian.git] / xapian-core / bin / xapian-check.cc
blob73ebb59b2c1dfc9b949aec8fb2d0e2a279f40c0e
1 /** @file
2 * @brief Tool to check the consistency of a database or table.
3 */
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2014,2016 Olly Betts
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 * USA
23 #include <config.h>
25 #include <xapian.h>
27 #include <cstdlib>
28 #include <cstring>
29 #include <stdexcept>
30 #include <iostream>
32 using namespace std;
34 #define PROG_NAME "xapian-check"
35 #define PROG_DESC "Check the consistency of a database or table"
37 static void show_usage() {
38 cout << "Usage: " PROG_NAME " DATABASE_DIRECTORY|PATH_TO_BTREE [[F][t][f][b][v][+]]\n\n"
39 "If a whole database is checked, then additional cross-checks between\n"
40 "the tables are performed.\n\n"
41 "The btree(s) is/are always checked - control the output verbosity with:\n"
42 " F = attempt to fix a broken database (implemented for glass currently)\n"
43 " t = short tree printing\n"
44 " f = full tree printing\n"
45 " b = show free blocks\n"
46 " v = show stats about B-tree (default)\n"
47 " + = same as tbv\n"
48 " e.g. " PROG_NAME " /var/lib/xapian/data/default\n"
49 " " PROG_NAME " /var/lib/xapian/data/default/postlist fbv\n";
52 int
53 main(int argc, char **argv)
55 if (argc > 1 && argv[1][0] == '-') {
56 if (strcmp(argv[1], "--help") == 0) {
57 cout << PROG_NAME " - " PROG_DESC "\n\n";
58 show_usage();
59 exit(0);
61 if (strcmp(argv[1], "--version") == 0) {
62 cout << PROG_NAME " - " PACKAGE_STRING "\n";
63 exit(0);
66 if (argc < 2 || argc > 3) {
67 show_usage();
68 exit(1);
71 int opts = 0;
72 const char * opt_string = argv[2];
73 if (!opt_string) opt_string = "v";
74 for (const char *p = opt_string; *p; ++p) {
75 switch (*p) {
76 case 't': opts |= Xapian::DBCHECK_SHORT_TREE; break;
77 case 'f': opts |= Xapian::DBCHECK_FULL_TREE; break;
78 case 'b': opts |= Xapian::DBCHECK_SHOW_FREELIST; break;
79 case 'v': opts |= Xapian::DBCHECK_SHOW_STATS; break;
80 case '+':
81 opts |= Xapian::DBCHECK_SHORT_TREE;
82 opts |= Xapian::DBCHECK_SHOW_FREELIST;
83 opts |= Xapian::DBCHECK_SHOW_STATS;
84 break;
85 case 'F':
86 opts |= Xapian::DBCHECK_FIX;
87 break;
88 default:
89 cerr << "option " << opt_string << " unknown\n";
90 cerr << "use t,f,b,v and/or + in the option string\n";
91 exit(1);
95 try {
96 size_t errors = Xapian::Database::check(argv[1], opts, &cout);
97 if (errors > 0) {
98 cout << "Total errors found: " << errors << '\n';
99 exit(1);
101 cout << "No errors found\n";
102 } catch (const Xapian::Error &error) {
103 cerr << argv[0] << ": " << error.get_description() << '\n';
104 exit(1);
105 } catch (...) {
106 cerr << argv[0] << ": Unknown exception\n";
107 exit(1);