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

« back to all changes in this revision

Viewing changes to utilities/mod2vpl.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 <swmgr.h>
 
2
#include <versekey.h>
 
3
#include <iostream>
 
4
#ifndef NO_SWORD_NAMESPACE
 
5
using sword::SWMgr;
 
6
using sword::VerseKey;
 
7
using sword::SWModule;
 
8
using sword::SWKey;
 
9
using sword::SW_POSITION;
 
10
using sword::ModMap;
 
11
#endif
 
12
 
 
13
void cleanbuf(char *buf) {
 
14
        char *from = buf;
 
15
        char *to = buf;
 
16
 
 
17
        while (*from) {
 
18
                if ((*from != 10) && (*from != 13)) {
 
19
                        *to++ = *from++;
 
20
                }
 
21
                else {
 
22
                        from++;
 
23
                }
 
24
        }
 
25
        *to = 0;
 
26
}
 
27
 
 
28
int main(int argc, char **argv) {
 
29
        char *buffer = 0;
 
30
 
 
31
        if (argc < 2) {
 
32
                fprintf(stderr, "usage: %s <Mod Name> [0|1 - prepend verse reference to each line]\n", argv[0]);
 
33
                exit(-1);
 
34
        }
 
35
 
 
36
        SWMgr mgr;
 
37
 
 
38
        ModMap::iterator it = mgr.Modules.find(argv[1]);
 
39
        if (it == mgr.Modules.end()) {
 
40
                fprintf(stderr, "error: %s: couldn't find module: %s \n", argv[0], argv[1]);
 
41
                exit(-2);
 
42
        }
 
43
 
 
44
        bool vref = false;
 
45
        if (argc > 2)
 
46
                vref = (argv[2][0] == '0') ? false : true;
 
47
 
 
48
 
 
49
        SWModule *mod = it->second;
 
50
 
 
51
        SWKey *key = (*mod);
 
52
        VerseKey *vkey = 0;
 
53
        try {
 
54
                vkey = dynamic_cast<VerseKey *>(key);
 
55
        }
 
56
        catch (...) {}
 
57
 
 
58
        if (!vkey) {
 
59
                fprintf(stderr, "error: %s: %s module is not keyed to verses \n", argv[0], argv[1]);
 
60
                exit(-3);
 
61
        }
 
62
 
 
63
        vkey->Headings(1);      // turn on mod/testmnt/book/chap headings
 
64
 
 
65
        (*mod) = TOP;
 
66
 
 
67
        while (!mod->Error()) {
 
68
                buffer = new char [ strlen ((const char *)(*mod)) + 1 ];
 
69
                strcpy(buffer, (const char *)(*mod));
 
70
                cleanbuf(buffer);
 
71
                if (vref) {
 
72
                        if ((strlen(buffer) > 0) && (vref)) {
 
73
                                std::cout << (const char *)(*vkey) << " ";
 
74
                                std::cout << buffer << std::endl;
 
75
                        }
 
76
                }
 
77
                else std::cout << buffer << std::endl;
 
78
 
 
79
                delete [] buffer;
 
80
                (*mod)++;
 
81
        }
 
82
}