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

« back to all changes in this revision

Viewing changes to src/modules/filters/gbfstrongs.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
/******************************************************************************
 
2
 *
 
3
 * gbfstrongs - SWFilter descendant to hide or show strongs number
 
4
 *                      in a GBF module.
 
5
 */
 
6
 
 
7
 
 
8
#include <stdlib.h>
 
9
#include <gbfstrongs.h>
 
10
#include <swmodule.h>
 
11
#ifndef __GNUC__
 
12
#else
 
13
#include <unixstr.h>
 
14
#endif
 
15
#include <ctype.h>
 
16
 
 
17
SWORD_NAMESPACE_START
 
18
 
 
19
const char oName[] = "Strong's Numbers";
 
20
const char oTip[] = "Toggles Strong's Numbers On and Off if they exist";
 
21
 
 
22
const SWBuf choices[3] = {"On", "Off", ""};
 
23
const StringList oValues(&choices[0], &choices[2]);
 
24
 
 
25
GBFStrongs::GBFStrongs() : SWOptionFilter(oName, oTip, &oValues) {
 
26
        setOptionValue("Off");
 
27
}
 
28
 
 
29
 
 
30
GBFStrongs::~GBFStrongs() {
 
31
}
 
32
 
 
33
 
 
34
char GBFStrongs::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
 
35
        char token[2048]; // cheese.  Fix.
 
36
        int tokpos = 0;
 
37
        bool intoken = false;
 
38
        int len;
 
39
        bool lastspace = false;
 
40
        int word = 1;
 
41
        char val[128];
 
42
        char wordstr[5];
 
43
        char *valto;
 
44
        char *ch;
 
45
        unsigned int textStart = 0, textEnd = 0;
 
46
        bool newText = false;
 
47
        SWBuf tmp;
 
48
        const char *from;
 
49
 
 
50
        SWBuf orig = text;
 
51
        from = orig.c_str();
 
52
 
 
53
        for (text = ""; *from; from++) {
 
54
                if (*from == '<') {
 
55
                        intoken = true;
 
56
                        tokpos = 0;
 
57
                        token[0] = 0;
 
58
                        token[1] = 0;
 
59
                        token[2] = 0;
 
60
                        textEnd = text.size();
 
61
                        continue;
 
62
                }
 
63
                if (*from == '>') {     // process tokens
 
64
                        intoken = false;
 
65
 
 
66
                        if (*token == 'W' && (token[1] == 'G' || token[1] == 'H')) {    // Strongs
 
67
                                if (module->isProcessEntryAttributes()) {
 
68
                                        valto = val;
 
69
                                        for (unsigned int i = 2; ((token[i]) && (i < 150)); i++)
 
70
                                                *valto++ = token[i];
 
71
                                        *valto = 0;
 
72
                                        if (atoi((!isdigit(*val))?val+1:val) < 5627) {
 
73
                                                // normal strongs number
 
74
                                                sprintf(wordstr, "%03d", word++);
 
75
                                                module->getEntryAttributes()["Word"][wordstr]["Strongs"] = val;
 
76
                                                tmp = "";
 
77
                                                tmp.append(text.c_str()+textStart, (int)(textEnd - textStart));
 
78
                                                module->getEntryAttributes()["Word"][wordstr]["Text"] = tmp;
 
79
                                                newText = true;
 
80
                                        }
 
81
                                        else {
 
82
                                                // verb morph
 
83
                                                sprintf(wordstr, "%03d", word-1);
 
84
                                                module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
 
85
                                        }
 
86
                                }
 
87
                                if (!option) {
 
88
                                        if ((from[1] == ' ') || (from[1] == ',') || (from[1] == ';') || (from[1] == '.') || (from[1] == '?') || (from[1] == '!') || (from[1] == ')') || (from[1] == '\'') || (from[1] == '\"')) {
 
89
                                                if (lastspace)
 
90
                                                        text--;
 
91
                                        }
 
92
                                        if (newText) {textStart = text.size(); newText = false; }
 
93
                                        continue;
 
94
                                }
 
95
                        }
 
96
                        // if not a strongs token, keep token in text
 
97
                        text += '<';
 
98
                        text += token;
 
99
                        text += '>';
 
100
                        if (newText) {textStart = text.size(); newText = false; }
 
101
                        continue;
 
102
                }
 
103
                if (intoken) {
 
104
                        if (tokpos < 2045)
 
105
                                token[tokpos++] = *from;
 
106
                                token[tokpos+2] = 0;
 
107
                }
 
108
                else    {
 
109
                        text += *from;
 
110
                        lastspace = (*from == ' ');
 
111
                }
 
112
        }
 
113
        return 0;
 
114
}
 
115
 
 
116
SWORD_NAMESPACE_END