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

« back to all changes in this revision

Viewing changes to src/modules/filters/gbfheadings.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
 * gbfheadings -        SWFilter descendant to hide or show headings
 
4
 *                      in a GBF module.
 
5
 */
 
6
 
 
7
 
 
8
#include <stdlib.h>
 
9
#include <gbfheadings.h>
 
10
#ifndef __GNUC__
 
11
#else
 
12
#include <unixstr.h>
 
13
#endif
 
14
 
 
15
SWORD_NAMESPACE_START
 
16
 
 
17
 
 
18
const char oName[] = "Headings";
 
19
const char oTip[] = "Toggles Headings On and Off if they exist";
 
20
 
 
21
const SWBuf choices[3] = {"On", "Off", ""};
 
22
const StringList oValues(&choices[0], &choices[2]);
 
23
 
 
24
GBFHeadings::GBFHeadings() : SWOptionFilter(oName, oTip, &oValues) {
 
25
        setOptionValue("Off");
 
26
}
 
27
 
 
28
 
 
29
GBFHeadings::~GBFHeadings() {
 
30
}
 
31
 
 
32
 
 
33
char GBFHeadings::processText (SWBuf &text, const SWKey *key, const SWModule *module) {
 
34
        if (!option) {  // if we don't want headings
 
35
                char token[2048]; // cheese.  Fix.
 
36
                int tokpos = 0;
 
37
                bool intoken = false;
 
38
                int len;
 
39
                bool hide = false;
 
40
 
 
41
        const char *from;
 
42
        SWBuf orig = text;
 
43
        from = orig.c_str();
 
44
        for (text = ""; *from; from++) {
 
45
                        if (*from == '<') {
 
46
                                intoken = true;
 
47
                                tokpos = 0;
 
48
//                              memset(token, 0, 2048);
 
49
                                token[0] = 0;
 
50
                                token[1] = 0;
 
51
                                token[2] = 0;
 
52
                                continue;
 
53
                        }
 
54
                        if (*from == '>') {     // process tokens
 
55
                                intoken = false;
 
56
                                switch (*token) {
 
57
                                case 'T':                               // Reference
 
58
                                        switch(token[1]) {
 
59
                                        case 'S':               // Begin heading
 
60
                                                hide = true;
 
61
                                                break;
 
62
                                        case 's':               // end heading
 
63
                                                hide = false;
 
64
                                                break;
 
65
                                        }
 
66
                                        continue;       // skip token
 
67
                                }
 
68
                                // if not a heading token, keep token in text
 
69
                                if (!hide) {
 
70
                                        text += '<';
 
71
                                        for (char *tok = token; *tok; tok++)
 
72
                                                text += *tok;
 
73
                                        text += '>';
 
74
                                }
 
75
                                continue;
 
76
                        }
 
77
                        if (intoken) {
 
78
                                if (tokpos < 2045)
 
79
                                        token[tokpos++] = *from;
 
80
                                        token[tokpos+2] = 0;
 
81
                        }
 
82
                        else    {
 
83
                                if (!hide) {
 
84
                                        text += *from;
 
85
                                }
 
86
                        }
 
87
                }
 
88
        }
 
89
        return 0;
 
90
}
 
91
 
 
92
SWORD_NAMESPACE_END