~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to examples/cmdline/search.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Glassey
  • Date: 2004-01-15 15:50:07 UTC
  • Revision ID: james.westby@ubuntu.com-20040115155007-n9mz4x0zxrs1isd3
Tags: upstream-1.5.7
ImportĀ upstreamĀ versionĀ 1.5.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <rawtext.h>
 
3
#include <swmgr.h>
 
4
#include <markupfiltmgr.h>
 
5
#include <regex.h> // GNU
 
6
#include <iostream>
 
7
 
 
8
#ifndef NO_SWORD_NAMESPACE
 
9
using namespace sword;
 
10
#endif
 
11
 
 
12
void percentUpdate(char percent, void *userData) {
 
13
        static char printed = 0;
 
14
        char maxHashes = *((char *)userData);
 
15
        
 
16
        while ((((float)percent)/100) * maxHashes > printed) {
 
17
                std::cout << "=";
 
18
                printed++;
 
19
                std::cout.flush();
 
20
        }
 
21
/*
 
22
        std::cout << (int)percent << "% ";
 
23
*/
 
24
        std::cout.flush();
 
25
}
 
26
 
 
27
 
 
28
int main(int argc, char **argv)
 
29
{
 
30
        SWMgr manager(0, 0, true, new MarkupFilterMgr(FMT_RTF, ENC_RTF));
 
31
//      SWMgr manager;
 
32
        SWModule *target;
 
33
        ListKey listkey;
 
34
        ListKey scope;
 
35
        VerseKey parser;
 
36
        ModMap::iterator it;
 
37
 
 
38
        if ((argc != 3) && (argc != 4)) {
 
39
                fprintf(stderr, "usage: %s <modname> <\"search string\"> [\"search_scope\"]\n", argv[0]);
 
40
                exit(-1);
 
41
        }
 
42
 
 
43
        it = manager.Modules.find(argv[1]);
 
44
        if (it == manager.Modules.end()) {
 
45
                fprintf(stderr, "Could not find module [%s].  Available modules:\n", argv[1]);
 
46
                for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) {
 
47
                        fprintf(stderr, "[%s]\t - %s\n", (*it).second->Name(), (*it).second->Description());
 
48
                }
 
49
                exit(-1);
 
50
        }
 
51
 
 
52
        target = (*it).second;
 
53
 
 
54
        if (argc == 4) {                        // if min / max specified
 
55
                scope = parser.ParseVerseList(argv[3], parser, true);
 
56
                scope.Persist(1);
 
57
                target->setKey(scope);
 
58
        }
 
59
 
 
60
        std::cout << "[0=================================50===============================100]\n ";
 
61
        char lineLen = 70;
 
62
        listkey = target->Search(argv[2], -3, 0/*REG_ICASE*/, 0, 0, &percentUpdate, &lineLen);
 
63
        std::cout << "\n";
 
64
        while (!listkey.Error()) {
 
65
                std::cout << (const char *)listkey << std::endl;
 
66
                listkey++;
 
67
        }
 
68
 
 
69
}