summaryrefslogtreecommitdiff
path: root/examples/cmdline/search.cpp
blob: 72110eed11971da1813ede02004acf3cc39da7d7 (plain)
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
#include <stdio.h>
#include <rawtext.h>
#include <swmgr.h>
#include <markupfiltmgr.h>
#include <regex.h> // GNU
#include <iostream>

#ifndef NO_SWORD_NAMESPACE
using namespace sword;
#endif

void percentUpdate(char percent, void *userData) {
	static char printed = 0;
	char maxHashes = *((char *)userData);
	
	while ((((float)percent)/100) * maxHashes > printed) {
		std::cout << "=";
		printed++;
		std::cout.flush();
	}
/*
	std::cout << (int)percent << "% ";
*/
	std::cout.flush();
}


int main(int argc, char **argv)
{
	SWMgr manager(0, 0, true, new MarkupFilterMgr(FMT_RTF, ENC_RTF));
//	SWMgr manager;
	SWModule *target;
	ListKey listkey;
	ListKey scope;
	VerseKey parser;
	ModMap::iterator it;

	if ((argc != 3) && (argc != 4)) {
		fprintf(stderr, "usage: %s <modname> <\"search string\"> [\"search_scope\"]\n", argv[0]);
		exit(-1);
	}

	it = manager.Modules.find(argv[1]);
	if (it == manager.Modules.end()) {
		fprintf(stderr, "Could not find module [%s].  Available modules:\n", argv[1]);
		for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) {
			fprintf(stderr, "[%s]\t - %s\n", (*it).second->Name(), (*it).second->Description());
		}
		exit(-1);
	}

	target = (*it).second;

	if (argc == 4) {			// if min / max specified
		scope = parser.ParseVerseList(argv[3], parser, true);
		scope.Persist(1);
		target->setKey(scope);
	}

	std::cout << "[0=================================50===============================100]\n ";
	char lineLen = 70;
	listkey = target->Search(argv[2], -3, 0/*REG_ICASE*/, 0, 0, &percentUpdate, &lineLen);
	std::cout << "\n";
	while (!listkey.Error()) {
		std::cout << (const char *)listkey << std::endl;
		listkey++;
	}

}