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

« back to all changes in this revision

Viewing changes to src/modules/filters/thmlstrongs.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
 * thmlstrongs -        SWFilter descendant to hide or show strongs number
 
4
 *                      in a ThML module.
 
5
 */
 
6
 
 
7
 
 
8
#include <stdlib.h>
 
9
#include <stdio.h>
 
10
#include <thmlstrongs.h>
 
11
#include <swmodule.h>
 
12
#ifndef __GNUC__
 
13
#else
 
14
#include <unixstr.h>
 
15
#endif
 
16
#include <ctype.h>
 
17
 
 
18
SWORD_NAMESPACE_START
 
19
 
 
20
const char oName[] = "Strong's Numbers";
 
21
const char oTip[] = "Toggles Strong's Numbers On and Off if they exist";
 
22
 
 
23
const SWBuf choices[3] = {"On", "Off", ""};
 
24
const StringList oValues(&choices[0], &choices[2]);
 
25
 
 
26
ThMLStrongs::ThMLStrongs() : SWOptionFilter(oName, oTip, &oValues) {
 
27
        setOptionValue("Off");
 
28
}
 
29
 
 
30
 
 
31
ThMLStrongs::~ThMLStrongs() {
 
32
}
 
33
 
 
34
 
 
35
char ThMLStrongs::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
 
36
        char token[2048]; // cheese.  Fix.
 
37
        const char *from;
 
38
        int tokpos = 0;
 
39
        bool intoken = false;
 
40
        int len;
 
41
        bool lastspace = false;
 
42
        int word = 1;
 
43
        char val[128];
 
44
        char wordstr[5];
 
45
        char *valto;
 
46
        char *ch;
 
47
        unsigned int textStart = 0, textEnd = 0;
 
48
        SWBuf tmp;
 
49
        bool newText = false;
 
50
 
 
51
                SWBuf orig = text;
 
52
                from = orig.c_str();
 
53
 
 
54
                for (text = ""; *from; from++) {
 
55
                if (*from == '<') {
 
56
                        intoken = true;
 
57
                        tokpos = 0;
 
58
                        token[0] = 0;
 
59
                        token[1] = 0;
 
60
                        token[2] = 0;
 
61
                        textEnd = text.length();
 
62
                        continue;
 
63
                }
 
64
                if (*from == '>') {     // process tokens
 
65
                        intoken = false;
 
66
                        if (!strnicmp(token, "sync type=\"Strongs\" ", 20)) {   // Strongs
 
67
                                if (module->isProcessEntryAttributes()) {
 
68
                                        valto = val;
 
69
                                        for (unsigned int i = 27; 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
 
 
88
                                if (!option) {  // if we don't want strongs
 
89
                                        if ((from[1] == ' ') || (from[1] == ',') || (from[1] == ';') || (from[1] == '.') || (from[1] == '?') || (from[1] == '!') || (from[1] == ')') || (from[1] == '\'') || (from[1] == '\"')) {
 
90
                                                if (lastspace)
 
91
                                                        text--;
 
92
                                        }
 
93
                                        if (newText) {textStart = text.length(); newText = false; }
 
94
                                        continue;
 
95
                                }
 
96
                        }
 
97
                        if (module->isProcessEntryAttributes()) {
 
98
                                if (!strncmp(token, "sync type=\"morph\"", 17)) {
 
99
                                        for (ch = token+17; *ch; ch++) {
 
100
                                                if (!strncmp(ch, "class=\"", 7)) {
 
101
                                                        valto = val;
 
102
                                                        for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++)
 
103
                                                                *valto++ = ch[i];
 
104
                                                        *valto = 0;
 
105
                                                        sprintf(wordstr, "%03d", word-1);
 
106
                                                        module->getEntryAttributes()["Word"][wordstr]["MorphClass"] = val;
 
107
                                                }
 
108
                                                if (!strncmp(ch, "value=\"", 7)) {
 
109
                                                        valto = val;
 
110
                                                        for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++)
 
111
                                                                *valto++ = ch[i];
 
112
                                                        *valto = 0;
 
113
                                                        sprintf(wordstr, "%03d", word-1);
 
114
                                                        module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
 
115
                                                }
 
116
                                        }
 
117
                                }
 
118
                        }
 
119
                        // if not a strongs token, keep token in text
 
120
                        text += '<';
 
121
                        text += token;
 
122
                        text += '>';
 
123
                        if (newText) {textStart = text.length(); newText = false; }
 
124
                        continue;
 
125
                }
 
126
                if (intoken) {
 
127
                        if (tokpos < 2045)
 
128
                                token[tokpos++] = *from;
 
129
                                token[tokpos+2] = 0;
 
130
                }
 
131
                else    {
 
132
                        text += *from;
 
133
                        lastspace = (*from == ' ');
 
134
                }
 
135
        }
 
136
        return 0;
 
137
}
 
138
 
 
139
SWORD_NAMESPACE_END