40 #define PROG_NAME "xapian-inspect-honey"
41 #define PROG_DESC "Inspect a honey table for development or debugging"
49 cout <<
"Usage: " PROG_NAME " [OPTIONS] TABLE\n"
50 " " PROG_NAME " [OPTIONS] -t TABLE DB\n\n"
52 " -t, --table=TABLE which table to inspect\n"
53 " --help display this help and exit\n"
54 " --version output version information and exit\n";
60 for (
unsigned char ch : data) {
61 if (ch < 32 || ch >= 127) {
63 case '\n': cout <<
"\\n";
break;
64 case '\r': cout <<
"\\r";
break;
65 case '\t': cout <<
"\\t";
break;
68 <<
"0123456789abcdef"[ch >> 4]
69 <<
"0123456789abcdef"[ch & 0x0f];
72 }
else if (ch ==
'\\') {
84 auto bslash = s.find(
'\\');
85 if (bslash == string::npos)
87 string r(s, 0, bslash);
88 for (
auto i = s.begin() + bslash; i != s.end(); ++i) {
132 cout <<
"Bad escaping in specified key value, assuming literal\n";
139 cout <<
"Commands:\n"
140 "next : Next entry (alias 'n' or '')\n"
141 "prev : Previous entry (alias 'p')\n"
142 "first : First entry (alias 'f')\n"
143 "last : Last entry (alias 'l')\n"
144 "goto K : Goto first entry with key >= K (alias 'g')\n"
145 "until K: Display entries until key >= K (alias 'u')\n"
146 "until : Display entries until end (alias 'u')\n"
147 "count K: Count entries until key >= K (alias 'c')\n"
148 "count : Count entries until end (alias 'c')\n"
149 "open T : Open table T instead (alias 'o') - e.g. open postlist\n"
150 "keys : Toggle showing keys (default: true) (alias 'k')\n"
151 "tags : Toggle showing tags (default: true) (alias 't')\n"
152 "help : Show this (alias 'h' or '?')\n"
153 "quit : Quit this utility (alias 'q')\n";
160 cout <<
"After end\n";
164 cout <<
"Before start\n";
184 cout <<
"At end already.\n";
188 if (!target.empty()) {
192 cout <<
"Already after specified key.\n";
194 cout <<
"Already at specified key.\n";
200 while (cursor.
next()) {
209 cout <<
"No exact match, stopping at entry after, "
210 "having advanced by " << count <<
" entries.\n";
214 cout <<
"Advanced by " << count <<
" entries.\n";
219 cout <<
"Reached end, having advanced by " << count <<
" entries.\n";
259 string db_path(argv[
optind]);
261 if (arg_is_directory && table_name.empty()) {
263 <<
": You need to specify a table name to inspect with "
267 int single_file_fd = -1;
268 if (table_name.empty()) {
273 db_path.resize(db_path.size() -
275 }
else if (
endswith(db_path,
'.')) {
276 db_path.resize(db_path.size() - 1);
278 size_t slash = db_path.find_last_of(
DIR_SEPS);
281 table_name.assign(db_path, slash + 1, string::npos);
282 if (slash != string::npos) {
283 db_path.resize(slash);
287 }
else if (!arg_is_directory) {
288 single_file_fd =
open(db_path.c_str(), O_RDONLY |
O_BINARY);
289 if (single_file_fd < 0) {
290 cerr << argv[0] <<
": Couldn't open file '" << db_path <<
"'\n";
296 if (single_file_fd < 0) {
309 open_different_table:
312 if (table_name ==
"docdata") {
314 }
else if (table_name ==
"spelling") {
316 }
else if (table_name ==
"synonym") {
318 }
else if (table_name ==
"termlist") {
320 }
else if (table_name ==
"position") {
322 }
else if (table_name ==
"postlist") {
325 cerr <<
"Unknown table: '" << table_name <<
"'\n";
330 if (single_file_fd < 0) {
331 string table_path = db_path;
333 table_path += table_name;
335 table_ptr =
new HoneyTable(
"", table_path,
true);
338 table_ptr =
new HoneyTable(
"", single_file_fd, offset,
true);
345 if (!cursor.
next()) {
346 cout <<
"No entries!\n";
355 cout <<
"? " << flush;
359 if (cin.eof())
break;
366 cout <<
"At end already.\n";
372 if (!cursor.
prev()) {
373 cout <<
"Before start already.\n";
383 }
else if (
input ==
"u" ||
input ==
"until") {
392 }
else if (
input ==
"c" ||
input ==
"count") {
395 }
else if (
input ==
"f" ||
input ==
"first") {
405 cout <<
"No exact match, going to entry after.\n";
410 cout <<
"No exact match, going to entry after.\n";
414 size_t trim = (
input[1] ==
' ' ? 2 : 5);
415 table_name.assign(
input, trim, string::npos);
417 table_name.resize(table_name.size() -
420 table_name.resize(table_name.size() - 1);
421 goto open_different_table;
424 cout <<
"Showing tags: " << boolalpha <<
tags <<
'\n';
427 cout <<
"Showing keys: " << boolalpha <<
keys <<
'\n';
434 cout <<
"Unknown command.\n";
bool read_tag(bool keep_compressed=false)
void rewind()
Position cursor on the dummy empty key.
bool prev()
Move to the item before the current one.
bool find_entry_ge(std::string_view key)
honey_tablesize_t get_entry_count() const
void open(int flags_, const Honey::RootInfo &root_info, honey_revision_number_t)
The HoneyVersion class manages the revision files.
honey_revision_number_t get_revision() const
void read()
Read the version file and check it's a version we understand.
const Honey::RootInfo & get_root(Honey::table_type tbl) const
All exceptions thrown by Xapian are subclasses of Xapian::Error.
std::string get_description() const
Return a string describing this object.
Utility functions for testing files.
bool dir_exists(const char *path)
Test if a directory exists.
Wrappers to allow GNU getopt to be used cleanly from C++ code.
#define required_argument
int gnu_getopt_long(int argc_, char *const *argv_, const char *shortopts_, const struct option *longopts_, int *optind_)
Definitions, types, etc for use inside honey.
#define HONEY_TABLE_EXTENSION
Honey table extension.
uint4 honey_revision_number_t
The revision number of a honey database.
Database open(std::string_view host, unsigned int port, unsigned timeout=10000, unsigned connect_timeout=10000)
Construct a Database object for read-only access to a remote database accessed via a TCP connection.
XAPIAN_REVISION_TYPE rev
Revision number of a database.
Various handy string-related helpers.
char hex_decode(char ch1, char ch2)
Decode a pair of ASCII hex digits.
#define CONST_STRLEN(S)
Returns the length of a string constant.
bool endswith(std::string_view s, char sfx)
bool startswith(std::string_view s, char pfx)
int main(int argc, char **argv)
static void display_nicely(const string &data)
static void do_until(HoneyCursor &cursor, const string &target, bool show)
static string unescape(const string &s)
static void show_entry(HoneyCursor &cursor)
static const struct option long_opts[]
Public interfaces for the Xapian library.