ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/Search/Outputer.cpp
(Generate patch)

Comparing trunk/Search/Outputer.cpp (file contents):
Revision 43 by douglas, 2003-01-22T22:12:34-08:00 vs.
Revision 211 by douglas, 2003-07-19T18:46:12-07:00

# Line 46 | Line 46
46   //
47   // Douglas Thrift
48   //
49 < // Outputer.cpp
49 > // $Id: Outputer.cpp,v 1.11 2003/07/20 01:46:12 douglas Exp $
50  
51   #include "Outputer.h"
52  
# Line 86 | Line 86 | void Outputer::output(Searcher& searcher
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  
# Line 132 | Line 132 | void Outputer::header(const string& quer
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());
# Line 166 | Line 171 | void Outputer::body()
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, '&', "&amp;");
181                  entities(address, '\"', "&quot;");
# Line 192 | Line 195 | void Outputer::body()
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                  }
# Line 219 | Line 222 | void Outputer::footer(const string& quer
222                  conditional(line, fin, "<?ifcommon?>", common.size() == 1);
223                  conditional(line, fin, "<?ifmanycommon?>", common.size() > 1);
224  
225 + #ifndef _OpenSSL_
226                  tag(line, "<?version?>", programName + ' ' + programVersion + ' ' +
227                          platform());
228 + #else
229 +                tag(line, "<?version?>", programName + ' ' + programVersion + ' ' +
230 +                        platform() + ' ' + openssl());
231 + #endif
232                  tag(line, "<?query?>", query);
233                  tag(line, "<?range?>", range(page));
234                  tag(line, "<?total?>", total());
# Line 303 | Line 311 | string Outputer::pages(string query, uns
311                  conditional(line, fin, "<?ifnum?>", false);
312                  conditional(line, fin, "<?ifnext?>", false);
313  
314 <                char* cprevious = new char[1024];
307 <
308 <                sprintf(cprevious, "%u", page);
314 >                ostringstream previous;
315  
316 <                string previous = cprevious;
311 <
312 <                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          }
# Line 334 | Line 338 | string Outputer::pages(string query, uns
338                                  conditional(line, fin, "<?ifnum?>", false);
339                                  conditional(line, fin, "<?ifnext?>", false);
340  
341 <                                char* cpage = new char[1024];
338 <
339 <                                sprintf(cpage, "%u", (index + 1));
341 >                                ostringstream current;
342  
343 <                                string spage = cpage;
343 >                                current << index + 1;
344  
345 <                                delete [] cpage;
344 <
345 <                                tag(line, "<?page?>", spage);
345 >                                tag(line, "<?page?>", current.str());
346                          }
347                          else
348                          {
# Line 351 | Line 351 | string Outputer::pages(string query, uns
351                                  conditional(line, fin, "<?ifnum?>", true);
352                                  conditional(line, fin, "<?ifnext?>", false);
353  
354 <                                char* cnum = new char[1024];
355 <
356 <                                sprintf(cnum, "%u", (index + 1));
354 >                                ostringstream num;
355  
356 <                                string num = cnum;
359 <
360 <                                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" : "");
# Line 380 | Line 376 | string Outputer::pages(string query, uns
376                  conditional(line, fin, "<?ifnum?>", false);
377                  conditional(line, fin, "<?ifnext?>", page + 2 <= numPages);
378  
379 <                char* cnext = new char[1024];
384 <
385 <                sprintf(cnext, "%u", (page + 2));
386 <
387 <                string next = cnext;
379 >                ostringstream next;
380  
381 <                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          }
# Line 403 | Line 395 | string Outputer::range(unsigned page)
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];
408 <        char* ctop = new char[1024];
409 <
410 <        sprintf(cbottom, "%u", bottom);
411 <        sprintf(ctop, "%u", top);
412 <
413 <        string range = string(cbottom) + " - " + ctop;
400 >        range << bottom << " - " << top;
401  
402 <        delete [] cbottom;
416 <        delete [] ctop;
417 <
418 <        return range;
402 >        return range.str();
403   }
404  
405   string Outputer::total()
406   {
407 <        char* ctotal = new char[1024];
424 <
425 <        sprintf(ctotal, "%u", numWebpages);
407 >        ostringstream total;
408  
409 <        string total = ctotal;
409 >        total << numWebpages;
410  
411 <        delete [] ctotal;
430 <
431 <        return total;
411 >        return total.str();
412   }
413  
414   string Outputer::duration()
415   {
416 <        char* ctime = new char[1024];
437 <        sprintf(ctime, "%.2f", time);
438 <
439 <        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)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines