1 |
|
/* ============================================================================ |
2 |
|
* Douglas Thrift's Search Engine License |
3 |
|
* |
4 |
< |
* Copyright (C) 2002, Douglas Thrift. All Rights Reserved. |
4 |
> |
* Copyright (C) 2002-2003, Douglas Thrift. All Rights Reserved. |
5 |
|
* Redistribution and use in source and binary forms, with or without |
6 |
|
* modification, are permitted provided that the following conditions are met: |
7 |
|
* |
46 |
|
// |
47 |
|
// Douglas Thrift |
48 |
|
// |
49 |
< |
// Outputer.cpp |
49 |
> |
// $Id: Outputer.cpp,v 1.8 2003/07/17 07:03:08 douglas Exp $ |
50 |
|
|
51 |
|
#include "Outputer.h" |
52 |
|
|
53 |
< |
Outputer::Outputer(string& headerFile, string& bodyFile, string& footerFile, |
54 |
< |
string& notfoundFile, string& pagesFile) |
53 |
> |
Outputer::Outputer(const string& headerFile, const string& bodyFile, const |
54 |
> |
string& footerFile, const string& notfoundFile, const string& pagesFile) |
55 |
|
{ |
56 |
|
this->headerFile = headerFile; |
57 |
|
this->bodyFile = bodyFile; |
86 |
|
|
87 |
|
if (debug) |
88 |
|
{ |
89 |
< |
cerr << "query = " << (this->query ? "true" : "false") << "\n" |
90 |
< |
<< "results = " << (results ? "true" : "false") << "\n" |
89 |
> |
cerr << "query = " << this->query << "\n" |
90 |
> |
<< "results = " << results << "\n" |
91 |
|
<< "time = " << duration() << "\n"; |
92 |
|
} |
93 |
|
|
114 |
|
ignore); |
115 |
|
} |
116 |
|
|
117 |
< |
void Outputer::header(string& query, unsigned page, vector<string> common, |
118 |
< |
bool and_, bool or_, string& ignore) |
117 |
> |
void Outputer::header(const string& query, unsigned page, vector<string> |
118 |
> |
common, bool and_, bool or_, const string& ignore) |
119 |
|
{ |
120 |
|
ifstream fin(headerFile.c_str()); |
121 |
|
|
132 |
|
conditional(line, fin, "<?ifcommon?>", common.size() == 1); |
133 |
|
conditional(line, fin, "<?ifmanycommon?>", common.size() > 1); |
134 |
|
|
135 |
+ |
tag(line, "<?version?>", programName + ' ' + programVersion + ' ' + |
136 |
+ |
platform()); |
137 |
|
tag(line, "<?query?>", query); |
138 |
< |
|
139 |
< |
string fred = range(page); |
140 |
< |
|
141 |
< |
tag(line, "<?range?>", fred); |
140 |
< |
|
141 |
< |
string martha = total(); |
142 |
< |
|
143 |
< |
tag(line, "<?total?>", martha); |
144 |
< |
|
145 |
< |
string george = duration(); |
146 |
< |
|
147 |
< |
tag(line, "<?time?>", george); |
148 |
< |
|
149 |
< |
string derf = pages(query, page); |
150 |
< |
|
151 |
< |
tag(line, "<?pages?>", derf); |
138 |
> |
tag(line, "<?range?>", range(page)); |
139 |
> |
tag(line, "<?total?>", total()); |
140 |
> |
tag(line, "<?time?>", duration()); |
141 |
> |
tag(line, "<?pages?>", pages(query, page)); |
142 |
|
tag(line, "<?ignore?>", ignore); |
143 |
|
tag(line, "<?common?>", common[0]); |
144 |
+ |
tag(line, "<?manycommon?>", manycommon(common)); |
145 |
|
|
146 |
< |
string elaine = manycommon(common); |
156 |
< |
|
157 |
< |
tag(line, "<?manycommon?>", elaine); |
158 |
< |
|
159 |
< |
cout << line << "\n"; |
146 |
> |
cout << line << (fin.good() ? "\n" : ""); |
147 |
|
} |
148 |
|
|
149 |
|
fin.close(); |
194 |
|
tag(line, "<?description?>", description); |
195 |
|
tag(line, "<?size?>", size); |
196 |
|
|
197 |
< |
cout << line << "\n"; |
197 |
> |
cout << line << (fin.good() ? "\n" : ""); |
198 |
|
} |
199 |
|
|
200 |
|
fin.close(); |
201 |
|
} |
202 |
|
} |
203 |
|
|
204 |
< |
void Outputer::footer(string& query, unsigned page, vector<string> common, |
205 |
< |
bool and_, bool or_, string& ignore) |
204 |
> |
void Outputer::footer(const string& query, unsigned page, vector<string> |
205 |
> |
common, bool and_, bool or_, const string& ignore) |
206 |
|
{ |
207 |
|
ifstream fin(footerFile.c_str()); |
208 |
|
|
219 |
|
conditional(line, fin, "<?ifcommon?>", common.size() == 1); |
220 |
|
conditional(line, fin, "<?ifmanycommon?>", common.size() > 1); |
221 |
|
|
222 |
+ |
#ifndef _OpenSSL_ |
223 |
+ |
tag(line, "<?version?>", programName + ' ' + programVersion + ' ' + |
224 |
+ |
platform()); |
225 |
+ |
#else |
226 |
+ |
tag(line, "<?version?>", programName + ' ' + programVersion + ' ' + |
227 |
+ |
platform() + ' ' + openssl()); |
228 |
+ |
#endif |
229 |
|
tag(line, "<?query?>", query); |
230 |
< |
|
231 |
< |
string fred = range(page); |
232 |
< |
|
233 |
< |
tag(line, "<?range?>", fred); |
240 |
< |
|
241 |
< |
string martha = total(); |
242 |
< |
|
243 |
< |
tag(line, "<?total?>", martha); |
244 |
< |
|
245 |
< |
string george = duration(); |
246 |
< |
|
247 |
< |
tag(line, "<?time?>", george); |
248 |
< |
|
249 |
< |
string derf = pages(query, page); |
250 |
< |
|
251 |
< |
tag(line, "<?pages?>", derf); |
230 |
> |
tag(line, "<?range?>", range(page)); |
231 |
> |
tag(line, "<?total?>", total()); |
232 |
> |
tag(line, "<?time?>", duration()); |
233 |
> |
tag(line, "<?pages?>", pages(query, page)); |
234 |
|
tag(line, "<?ignore?>", ignore); |
235 |
|
tag(line, "<?common?>", common[0]); |
236 |
+ |
tag(line, "<?manycommon?>", manycommon(common)); |
237 |
|
|
238 |
< |
string elaine = manycommon(common); |
256 |
< |
|
257 |
< |
tag(line, "<?manycommon?>", elaine); |
258 |
< |
|
259 |
< |
cout << line << "\n"; |
238 |
> |
cout << line << (fin.good() ? "\n" : ""); |
239 |
|
} |
240 |
|
|
241 |
|
fin.close(); |
242 |
|
} |
243 |
|
|
244 |
< |
void Outputer::notfound(string& query, unsigned keywords) |
244 |
> |
void Outputer::notfound(const string& query, unsigned keywords) |
245 |
|
{ |
246 |
|
ifstream fin(notfoundFile.c_str()); |
247 |
|
|
254 |
|
|
255 |
|
tag(line, "<?query?>", query); |
256 |
|
|
257 |
< |
cout << line << "\n"; |
257 |
> |
cout << line << (fin.good() ? "\n" : ""); |
258 |
|
} |
259 |
|
|
260 |
|
fin.close(); |
319 |
|
tag(line, "<?query?>", query); |
320 |
|
tag(line, "<?previous?>", previous); |
321 |
|
|
322 |
< |
lines += line + "\n"; |
322 |
> |
lines += line + (fin.good() ? "\n" : ""); |
323 |
|
} |
324 |
|
|
325 |
|
fin.close(); |
368 |
|
tag(line, "<?num?>", num); |
369 |
|
} |
370 |
|
|
371 |
< |
lines += line + "\n"; |
371 |
> |
lines += line + (fin.good() ? "\n" : ""); |
372 |
|
} |
373 |
|
|
374 |
|
fin.close(); |
396 |
|
tag(line, "<?query?>", query); |
397 |
|
tag(line, "<?next?>", next); |
398 |
|
|
399 |
< |
lines += line + "\n"; |
399 |
> |
lines += line + (fin.good() ? "\n" : ""); |
400 |
|
} |
401 |
|
|
402 |
|
fin.close(); |
462 |
|
return line; |
463 |
|
} |
464 |
|
|
465 |
< |
void Outputer::tag(string& line, char* tag, string& replacement) |
465 |
> |
void Outputer::tag(string& line, char* tag, const string& replacement) |
466 |
|
{ |
467 |
|
int begin = 0; |
468 |
|
while (begin < line.length()) |