-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfodestination.cpp
238 lines (213 loc) · 4.9 KB
/
infodestination.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*Copyright 2001
*
* infodestination.cpp
*
* Author: Gregory Ford greg@reddfish.co.nz
* RTF token parser based on:
* rtf2html by Dmitry Porapov <dpotapov@capitalsoft.com>,
* based on earlier work of Chuck Shotton.
* distributed under BSD-style license
* RTF token lists and hashing algorithm based on
* RTF Tools, Release 1.10
* 6 April 1994
* Paul DuBois dubois@primate.wisc.edu
*
* Copying permitted under GNU licence (see COPYING)
*/
// infodestination.cpp: implementation of the InfoDestination class.
//
//////////////////////////////////////////////////////////////////////
#ifdef WIN32
#pragma warning( disable : 4786 )
#endif
#include <string>
#include <vector>
// #include <cstring>
using namespace std;
#include <stdio.h>
#include "linktracker.h"
#include "token.h"
#include "charsource.h"
#include "charoutput.h"
#include "tokeniser.h"
#include "destination.h"
#include "infodestination.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
InfoDestination::InfoDestination()
{
groupLevel = 0;
}
InfoDestination::~InfoDestination()
{
}
bool InfoDestination::handleToken(Token *token)
{
if ( token->getType() == groupToken ) {
GroupToken *g = (GroupToken *)token;
if ( g->group == startGroup ) {
groupLevel++;
} else {
groupLevel--;
}
if (groupLevel <0) {
groupLevel = 0; // reinitialise this object
// ready for reusing on another group!
return true;
}
}
return false; // no change
}
svec FootnoteDest::footnotes;
FootnoteDest::FootnoteDest()
{
groupLevel = 0;
}
FootnoteDest::~FootnoteDest()
{
}
bool FootnoteDest::handleToken(Token *token)
{
switch (token->getType()) {
case groupToken:
{
GroupToken *g = (GroupToken *)token;
if ( g->group == startGroup ) {
groupLevel++;
} else {
groupLevel--;
}
if (groupLevel <0) {
char fnString[64];
footnotes.push_back( current );
sprintf( fnString,
"<sup><a href=\"#footnote_%d\">%d</a></sup>", footnotes.size(), footnotes.size() );
out->putString( fnString );
groupLevel = 0; // reinitialise this object
current = "";
// ready for reusing on another footnote!
return true;
}
}
break;
case controlToken:
// ignore all formatting in footnotes
break;
case charToken:
current += token->text;
break;
default:
break;
}
return false;
}
CharOutput *FootnoteDest::out= NULL;
void FootnoteDest::setOutput(CharOutput *out)
{
FootnoteDest::out= out;
}
void FootnoteDest::outputAll()
{
char fnString[96];
if ( out == NULL ) {
return;
}
out->putString ( "<hr>" );
for ( int i = 0; i < footnotes.size() ; i++ ) {
string str(footnotes[i]);
sprintf( fnString,
"<p class=\"footnote\"><sup><a name=\"footnote_%d\">%d</a></sup> ",
i+1,
i+1
);
out->putString( fnString );
out->putString( str );
out->putString( "</p>" );
}
}
//////////////////////////////////////////////////////////////////////
// FieldDest Class
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
FieldDest::FieldDest()
{
groupLevel =0;
}
FieldDest::~FieldDest()
{
}
FieldDest::FieldDest(CharOutput *out, LinkTracker *tracker)
{
groupLevel = 0;
this->out= out;
linkTracker = tracker;
}
bool FieldDest::handleToken(Token *token)
{
switch (token->getType()) {
case groupToken:
{
GroupToken *g = (GroupToken *)token;
if ( g->group == startGroup ) {
groupLevel++;
} else {
groupLevel--;
}
if (groupLevel <= 0) {
groupLevel = 0; // reinitialise this object
// ready for reusing on another footnote!
return true; // end of field destination
}
}
break;
case controlToken:
return handleControlToken( (ControlToken *) token );
// ignore all formatting in fields
break;
case charToken:
// strip out the spaces
switch ( source ) {
case rtfFieldInst:
if ( token->text != " " && token->text != "\"") {
linkTracker->link.append( token->text );
}
if ( linkTracker->link.find( string("HYPERLINK" ) ) != -1 ) {
linkTracker->hyperlink = true;
linkTracker->link = "";
}
break;
case rtfFieldResult:
linkTracker->hasResult = true;
linkTracker->result.append( token->text );
break;
}
break;
default:
break;
}
return false;
}
bool FieldDest::handleControlToken(ControlToken *token)
{
switch ( token->rtfMinor ) {
case rtfField:
source = rtfField;
linkTracker->hyperlink = false; // don't know what kind of field yet!
linkTracker->link = "";
linkTracker->hasResult = false; //
linkTracker->result = "";
break;
case rtfFieldInst:
source = rtfFieldInst;
break;
case rtfFieldResult:
source = rtfFieldResult;
break;
default:
break;
}
return false;
}