46 |
|
// |
47 |
|
// Douglas Thrift |
48 |
|
// |
49 |
< |
// $Id: Outputer.cpp,v 1.8 2003/07/17 07:03:08 douglas Exp $ |
49 |
> |
// $Id: Outputer.cpp,v 1.11 2003/07/20 01:46:12 douglas Exp $ |
50 |
|
|
51 |
|
#include "Outputer.h" |
52 |
|
|
132 |
|
conditional(line, fin, "<?ifcommon?>", common.size() == 1); |
133 |
|
conditional(line, fin, "<?ifmanycommon?>", common.size() > 1); |
134 |
|
|
135 |
+ |
#ifndef _OpenSSL_ |
136 |
|
tag(line, "<?version?>", programName + ' ' + programVersion + ' ' + |
137 |
|
platform()); |
138 |
+ |
#else |
139 |
+ |
tag(line, "<?version?>", programName + ' ' + programVersion + ' ' + |
140 |
+ |
platform() + ' ' + openssl()); |
141 |
+ |
#endif |
142 |
|
tag(line, "<?query?>", query); |
143 |
|
tag(line, "<?range?>", range(page)); |
144 |
|
tag(line, "<?total?>", total()); |
171 |
|
string address = webpage.getURL(); |
172 |
|
string sample = webpage.getSample(); |
173 |
|
string description = webpage.getDescription(); |
174 |
+ |
ostringstream size; |
175 |
|
|
176 |
< |
char* csize = new char[1024]; |
177 |
< |
sprintf(csize, "%.0fk", (double(webpage.getSize()) / double(1024))); |
178 |
< |
|
173 |
< |
string size = csize; |
174 |
< |
|
175 |
< |
delete [] csize; |
176 |
> |
size.precision(0); |
177 |
> |
size.setf(ios_base::fixed, ios_base::floatfield); |
178 |
> |
size << double(webpage.getSize()) / double(1024) << "k"; |
179 |
|
|
180 |
|
entities(address, '&', "&"); |
181 |
|
entities(address, '\"', """); |
195 |
|
tag(line, "<?title?>", title); |
196 |
|
tag(line, "<?sample?>", sample); |
197 |
|
tag(line, "<?description?>", description); |
198 |
< |
tag(line, "<?size?>", size); |
198 |
> |
tag(line, "<?size?>", size.str()); |
199 |
|
|
200 |
|
cout << line << (fin.good() ? "\n" : ""); |
201 |
|
} |
311 |
|
conditional(line, fin, "<?ifnum?>", false); |
312 |
|
conditional(line, fin, "<?ifnext?>", false); |
313 |
|
|
314 |
< |
char* cprevious = new char[1024]; |
312 |
< |
|
313 |
< |
sprintf(cprevious, "%u", page); |
314 |
< |
|
315 |
< |
string previous = cprevious; |
314 |
> |
ostringstream previous; |
315 |
|
|
316 |
< |
delete [] cprevious; |
316 |
> |
previous << page; |
317 |
|
|
318 |
|
tag(line, "<?query?>", query); |
319 |
< |
tag(line, "<?previous?>", previous); |
319 |
> |
tag(line, "<?previous?>", previous.str()); |
320 |
|
|
321 |
|
lines += line + (fin.good() ? "\n" : ""); |
322 |
|
} |
338 |
|
conditional(line, fin, "<?ifnum?>", false); |
339 |
|
conditional(line, fin, "<?ifnext?>", false); |
340 |
|
|
341 |
< |
char* cpage = new char[1024]; |
343 |
< |
|
344 |
< |
sprintf(cpage, "%u", (index + 1)); |
345 |
< |
|
346 |
< |
string spage = cpage; |
341 |
> |
ostringstream current; |
342 |
|
|
343 |
< |
delete [] cpage; |
343 |
> |
current << index + 1; |
344 |
|
|
345 |
< |
tag(line, "<?page?>", spage); |
345 |
> |
tag(line, "<?page?>", current.str()); |
346 |
|
} |
347 |
|
else |
348 |
|
{ |
351 |
|
conditional(line, fin, "<?ifnum?>", true); |
352 |
|
conditional(line, fin, "<?ifnext?>", false); |
353 |
|
|
354 |
< |
char* cnum = new char[1024]; |
354 |
> |
ostringstream num; |
355 |
|
|
356 |
< |
sprintf(cnum, "%u", (index + 1)); |
362 |
< |
|
363 |
< |
string num = cnum; |
364 |
< |
|
365 |
< |
delete [] cnum; |
356 |
> |
num << index + 1; |
357 |
|
|
358 |
|
tag(line, "<?query?>", query); |
359 |
< |
tag(line, "<?num?>", num); |
359 |
> |
tag(line, "<?num?>", num.str()); |
360 |
|
} |
361 |
|
|
362 |
|
lines += line + (fin.good() ? "\n" : ""); |
376 |
|
conditional(line, fin, "<?ifnum?>", false); |
377 |
|
conditional(line, fin, "<?ifnext?>", page + 2 <= numPages); |
378 |
|
|
379 |
< |
char* cnext = new char[1024]; |
389 |
< |
|
390 |
< |
sprintf(cnext, "%u", (page + 2)); |
379 |
> |
ostringstream next; |
380 |
|
|
381 |
< |
string next = cnext; |
393 |
< |
|
394 |
< |
delete [] cnext; |
381 |
> |
next << page + 2; |
382 |
|
|
383 |
|
tag(line, "<?query?>", query); |
384 |
< |
tag(line, "<?next?>", next); |
384 |
> |
tag(line, "<?next?>", next.str()); |
385 |
|
|
386 |
|
lines += line + (fin.good() ? "\n" : ""); |
387 |
|
} |
395 |
|
{ |
396 |
|
unsigned bottom = page * 10 + 1; |
397 |
|
unsigned top = numWebpages > page * 10 + 10 ? page * 10 + 10 : numWebpages; |
398 |
+ |
ostringstream range; |
399 |
|
|
400 |
< |
char* cbottom = new char[1024]; |
413 |
< |
char* ctop = new char[1024]; |
414 |
< |
|
415 |
< |
sprintf(cbottom, "%u", bottom); |
416 |
< |
sprintf(ctop, "%u", top); |
400 |
> |
range << bottom << " - " << top; |
401 |
|
|
402 |
< |
string range = string(cbottom) + " - " + ctop; |
419 |
< |
|
420 |
< |
delete [] cbottom; |
421 |
< |
delete [] ctop; |
422 |
< |
|
423 |
< |
return range; |
402 |
> |
return range.str(); |
403 |
|
} |
404 |
|
|
405 |
|
string Outputer::total() |
406 |
|
{ |
407 |
< |
char* ctotal = new char[1024]; |
429 |
< |
|
430 |
< |
sprintf(ctotal, "%u", numWebpages); |
407 |
> |
ostringstream total; |
408 |
|
|
409 |
< |
string total = ctotal; |
409 |
> |
total << numWebpages; |
410 |
|
|
411 |
< |
delete [] ctotal; |
435 |
< |
|
436 |
< |
return total; |
411 |
> |
return total.str(); |
412 |
|
} |
413 |
|
|
414 |
|
string Outputer::duration() |
415 |
|
{ |
416 |
< |
char* ctime = new char[1024]; |
442 |
< |
sprintf(ctime, "%.2f", time); |
443 |
< |
|
444 |
< |
string duration = ctime; |
416 |
> |
ostringstream duration; |
417 |
|
|
418 |
< |
delete [] ctime; |
418 |
> |
duration.precision(2); |
419 |
> |
duration << time; |
420 |
|
|
421 |
< |
return duration; |
421 |
> |
return duration.str(); |
422 |
|
} |
423 |
|
|
424 |
|
string Outputer::manycommon(vector<string> common) |