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 205 by douglas, 2003-07-17T00:03:08-07:00 vs.
Revision 207 by douglas, 2003-07-17T20:52:39-07:00

# Line 46 | Line 46
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.10 2003/07/18 03:52:39 douglas Exp $
50  
51   #include "Outputer.h"
52  
# 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)));
172 <
173 <                string size = csize;
174 <
175 <                delete [] csize;
176 >                size.precision(1);
177 >                size << double(webpage.getSize()) / double(1024) << "k";
178  
179                  entities(address, '&', "&amp;");
180                  entities(address, '\"', "&quot;");
# Line 192 | Line 194 | void Outputer::body()
194                          tag(line, "<?title?>", title);
195                          tag(line, "<?sample?>", sample);
196                          tag(line, "<?description?>", description);
197 <                        tag(line, "<?size?>", size);
197 >                        tag(line, "<?size?>", size.str());
198  
199                          cout << line << (fin.good() ? "\n" : "");
200                  }
# Line 308 | Line 310 | string Outputer::pages(string query, uns
310                  conditional(line, fin, "<?ifnum?>", false);
311                  conditional(line, fin, "<?ifnext?>", false);
312  
313 <                char* cprevious = new char[1024];
312 <
313 <                sprintf(cprevious, "%u", page);
314 <
315 <                string previous = cprevious;
313 >                ostringstream previous;
314  
315 <                delete [] cprevious;
315 >                previous << page;
316  
317                  tag(line, "<?query?>", query);
318 <                tag(line, "<?previous?>", previous);
318 >                tag(line, "<?previous?>", previous.str());
319  
320                  lines += line + (fin.good() ? "\n" : "");
321          }
# Line 339 | Line 337 | string Outputer::pages(string query, uns
337                                  conditional(line, fin, "<?ifnum?>", false);
338                                  conditional(line, fin, "<?ifnext?>", false);
339  
340 <                                char* cpage = new char[1024];
343 <
344 <                                sprintf(cpage, "%u", (index + 1));
345 <
346 <                                string spage = cpage;
340 >                                ostringstream current;
341  
342 <                                delete [] cpage;
342 >                                current << index + 1;
343  
344 <                                tag(line, "<?page?>", spage);
344 >                                tag(line, "<?page?>", current.str());
345                          }
346                          else
347                          {
# Line 356 | Line 350 | string Outputer::pages(string query, uns
350                                  conditional(line, fin, "<?ifnum?>", true);
351                                  conditional(line, fin, "<?ifnext?>", false);
352  
353 <                                char* cnum = new char[1024];
353 >                                ostringstream num;
354  
355 <                                sprintf(cnum, "%u", (index + 1));
362 <
363 <                                string num = cnum;
364 <
365 <                                delete [] cnum;
355 >                                num << index + 1;
356  
357                                  tag(line, "<?query?>", query);
358 <                                tag(line, "<?num?>", num);
358 >                                tag(line, "<?num?>", num.str());
359                          }
360  
361                          lines += line + (fin.good() ? "\n" : "");
# Line 385 | Line 375 | string Outputer::pages(string query, uns
375                  conditional(line, fin, "<?ifnum?>", false);
376                  conditional(line, fin, "<?ifnext?>", page + 2 <= numPages);
377  
378 <                char* cnext = new char[1024];
389 <
390 <                sprintf(cnext, "%u", (page + 2));
378 >                ostringstream next;
379  
380 <                string next = cnext;
393 <
394 <                delete [] cnext;
380 >                next << page + 2;
381  
382                  tag(line, "<?query?>", query);
383 <                tag(line, "<?next?>", next);
383 >                tag(line, "<?next?>", next.str());
384  
385                  lines += line + (fin.good() ? "\n" : "");
386          }
# Line 408 | Line 394 | string Outputer::range(unsigned page)
394   {
395          unsigned bottom = page * 10 + 1;
396          unsigned top = numWebpages > page * 10 + 10 ? page * 10 + 10 : numWebpages;
397 +        ostringstream range;
398  
399 <        char* cbottom = new char[1024];
413 <        char* ctop = new char[1024];
414 <
415 <        sprintf(cbottom, "%u", bottom);
416 <        sprintf(ctop, "%u", top);
399 >        range << bottom << " - " << top;
400  
401 <        string range = string(cbottom) + " - " + ctop;
419 <
420 <        delete [] cbottom;
421 <        delete [] ctop;
422 <
423 <        return range;
401 >        return range.str();
402   }
403  
404   string Outputer::total()
405   {
406 <        char* ctotal = new char[1024];
429 <
430 <        sprintf(ctotal, "%u", numWebpages);
406 >        ostringstream total;
407  
408 <        string total = ctotal;
408 >        total << numWebpages;
409  
410 <        delete [] ctotal;
435 <
436 <        return total;
410 >        return total.str();
411   }
412  
413   string Outputer::duration()
414   {
415 <        char* ctime = new char[1024];
442 <        sprintf(ctime, "%.2f", time);
443 <
444 <        string duration = ctime;
415 >        ostringstream duration;
416  
417 <        delete [] ctime;
417 >        duration.precision(2);
418 >        duration << time;
419  
420 <        return duration;
420 >        return duration.str();
421   }
422  
423   string Outputer::manycommon(vector<string> common)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines