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

Comparing:
trunk/Search/Search.cpp (file contents), Revision 212 by douglas, 2003-07-19T21:00:25-07:00 vs.
Search/trunk/Search.cpp (file contents), Revision 372 by douglas, 2008-08-23T04:00:12-07:00

# Line 1 | Line 1
1   /* ============================================================================
2   * Douglas Thrift's Search Engine License
3   *
4 < * Copyright (C) 2002-2003, Douglas Thrift. All Rights Reserved.
4 > * Copyright (C) 2002-2004, 2008, 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   *
# Line 46 | Line 46
46   //
47   // Douglas Thrift
48   //
49 < // $Id: Search.cpp,v 1.22 2003/07/20 04:00:25 douglas Exp $
49 > // $Id$
50  
51 < #include "Search.h"
52 < #include "Indexer.h"
53 < #include "Searcher.h"
54 < #include "Outputer.h"
51 > #include "Search.hpp"
52 > #include "Indexer.hpp"
53 > #include "Searcher.hpp"
54 > #include "Outputter.hpp"
55  
56   #ifndef _WIN32
57   #include <sys/utsname.h>
58   #else
59   #include <windows.h>
60 +
61 + // Stupid MinGW
62 + #ifndef PROCESSOR_ARCHITECTURE_AMD64
63 + #define PROCESSOR_ARCHITECTURE_AMD64 9
64 + #endif
65 + #ifndef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
66 + #define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 10
67   #endif
68  
69 < string program;
70 < string programName = "Douglas Thrift's Search Engine";
71 < string programVersion = "1.2alpha1";
72 < bool debug = false;
69 > #endif
70 >
71 > string program, programName("Douglas Thrift's Search Engine"),
72 >        programVersion("1.3beta");
73 > bool debug(false);
74  
75   int main(int argc, char* argv[])
76   {
77          program = argv[0];
78  
79 <        bool indexMode = false;
80 <        string indexURL;
81 <        set<string> indexDomains;
74 <        set<string> indexRestrictions;
75 <
76 <        unsigned page = 1;
77 <        string query;
78 <
79 >        bool indexMode(false);
80 >        set<string> indexDomains, indexRestrictions;
81 >        size_t page(1);
82          vector<string> indices;
83 +        string indexURL, query, header("header.html"), body("body.html"),
84 +                footer("footer.html"), notfound("notfound.html"), pages("pages.html");
85  
86 <        string header = "header.html";
82 <        string body = "body.html";
83 <        string footer = "footer.html";
84 <        string notfound = "notfound.html";
85 <        string pages = "pages.html";
86 <
87 <        string email;
88 <
89 <        for (int index = 1; index < argc; index++)
86 >        for (int index(1); index < argc; index++)
87          {
88                  string arg(argv[index]);
89  
# Line 267 | Line 264 | int main(int argc, char* argv[])
264          else
265          {
266                  string line;
267 +
268                  getline(cin, line);
269 +
270                  query = line;
271  
272                  Searcher searcher(query);
273 +                Outputter outputter(header, body, footer, notfound, pages);
274  
275                  searcher.search(indices);
276 <
277 <                Outputer outputer(header, body, footer, notfound,
278 <                        pages);
279 <
280 <                outputer.output(searcher, page < 1 ? page : --page);
276 >                outputter.output(searcher, page < 1 ? page : --page);
277          }
278  
279          return 0;
280   }
281  
286 string agent(bool version)
287 {
288        string agent = programName + (version ? ('/' + programVersion) : "");
289
290        return agent;
291 }
292
282   string platform()
283   {
284 <        string platform;
285 <        string os;
286 <        string version;
298 <        string architecture;
299 <        string marketing;
284 >        ostringstream platform;
285 >
286 >        platform << '(';
287  
288   #ifdef _WIN32
289          OSVERSIONINFO* computer = new OSVERSIONINFO;
290 +
291          computer->dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
292 +
293          GetVersionEx(computer);
294  
295 <        os = computer->dwPlatformId == VER_PLATFORM_WIN32_NT ? "Windows NT" :
296 <                "Windows";
297 <        unsigned major = computer->dwMajorVersion;
298 <        unsigned minor = computer->dwMinorVersion;
295 >        string os(computer->dwPlatformId == VER_PLATFORM_WIN32_NT ? "Windows NT" :
296 >                "Windows");
297 >        size_t major(computer->dwMajorVersion), minor(computer->dwMinorVersion);
298 >
299 >        platform << os << ' ' << major << '.' << minor;
300  
301          delete computer;
302  
303 +        if (major == 4 && minor <= 3 && os != "Windows NT")
304 +        {
305 +                platform << " [Windows 95]";
306 +        }
307 +        else if (major == 4 && minor == 10 && os != "Windows NT")
308 +        {
309 +                platform << " [Windows 98]";
310 +        }
311 +        else if (major == 5 && minor == 0 && os == "Windows NT")
312 +        {
313 +                platform << " [Windows 2000]";
314 +        }
315 +        else if (major == 4 && minor == 90 && os != "Windows NT")
316 +        {
317 +                platform << " [Windows ME]";
318 +        }
319 +        else if (major == 5 && minor == 1 && os == "Windows NT")
320 +        {
321 +                platform << " [Windows XP]";
322 +        }
323 +        else if (major == 5 && minor == 2 && os == "Windows NT")
324 +        {
325 +                platform << " [Windows Server 2003 or Windows XP x64]";
326 +        }
327 +        else if (major == 6 && minor == 0 && os == "Windows NT")
328 +        {
329 +                platform << " [Windows Vista or Windows Server 2008]";
330 +        }
331 +
332 +        platform << ' ';
333 +
334          SYSTEM_INFO* system = new SYSTEM_INFO;
335 +
336          GetSystemInfo(system);
337  
338          switch (system->wProcessorArchitecture)
339          {
340          case PROCESSOR_ARCHITECTURE_INTEL:
341 <                architecture = "ix86";
341 >                platform << "ix86";
342                  break;
343          case PROCESSOR_ARCHITECTURE_MIPS:
344 <                architecture = "mips";
344 >                platform << "mips";
345                  break;
346          case PROCESSOR_ARCHITECTURE_ALPHA:
347 <                architecture = "alpha";
347 >                platform << "alpha";
348                  break;
349          case PROCESSOR_ARCHITECTURE_PPC:
350 <                architecture = "ppc";
350 >                platform << "ppc";
351                  break;
352          case PROCESSOR_ARCHITECTURE_IA64:
353 <                architecture = "ia64";
353 >                platform << "ia64";
354                  break;
355          case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
356 <                architecture = "ix86_on_win64";
356 >                platform << "ix86_on_win64";
357                  break;
358          case PROCESSOR_ARCHITECTURE_AMD64:
359 <                architecture = "amd64";
359 >                platform << "amd64";
360                  break;
361          default:
362 <                architecture = "unknown";
362 >                platform << "unknown";
363                  break;
364          }
365  
344        char* cversion = new char[1024];
345        sprintf(cversion, "%u.%u", major, minor);
346        version = cversion;
347
348        delete [] cversion;
349
350        if (major == 4 && minor <= 3 && os != "Windows NT")
351        {
352                marketing = " [Windows 95]";
353        }
354        else if (major == 4 && minor == 10 && os != "Windows NT")
355        {
356                marketing = " [Windows 98]";
357        }
358        else if (major == 5 && minor == 0 && os == "Windows NT")
359        {
360                marketing = " [Windows 2000]";
361        }
362        else if (major == 4 && minor == 90 && os != "Windows NT")
363        {
364                marketing = " [Windows ME]";
365        }
366        else if (major == 5 && minor == 1 && os == "Windows NT")
367        {
368                marketing = " [Windows XP]";
369        }
370        else if (major == 5 && minor == 2 && os == "Windows NT")
371        {
372                marketing = " [Windows .NET Server]";
373        }
366   #else // _WIN32
367          struct utsname* computer = new struct utsname;
368 +
369          uname(computer);
370  
371 <        os =  computer->sysname;
372 <        version = computer->release;
380 <        architecture = computer->machine;
371 >        platform << computer->sysname << ' ' << computer->release << ' ' <<
372 >                computer->machine;
373  
374          delete computer;
375   #endif // _WIN32
376  
377 <        platform = "(" + os + " " + version + marketing + " " + architecture + ")";
377 >        platform << ')';
378  
379 <        return platform;
379 >        return platform.str();
380   }
381  
382   void usage()
383   {
384   #ifdef _WIN32
385 +        string program(program);
386          OSVERSIONINFO* computer = new OSVERSIONINFO;
387 +
388          computer->dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
389 +
390          GetVersionEx(computer);
391  
392 <        string program = ::program;
398 <        if (computer->dwPlatformId != VER_PLATFORM_WIN32_NT)
399 <        {
400 <                program = "Search";
401 <        }
392 >        if (computer->dwPlatformId != VER_PLATFORM_WIN32_NT) program = "Search";
393  
394          delete computer;
395   #endif // _WIN32
# Line 436 | Line 427 | void usage()
427   void version()
428   {
429          cout << programName << " " << programVersion << " "<< platform() << "\n\n"
430 <                << "   Copyright (C) 2002-2003, Douglas Thrift. All Rights Reserved.\n"
430 >                << "   Copyright (C) 2002-2004, 2008, Douglas Thrift. All Rights Reserved.\n"
431                  << "\n"
432                  << "   This product includes software developed by Douglas Thrift\n"
433                  << "   (http://computers.douglasthrift.net/searchengine/).\n";
# Line 450 | Line 441 | void license()
441   {
442          cout << "License:\n"
443                  << "   Douglas Thrift's Search Engine License\n\n"
444 <                << "   Copyright (C) 2002-2003, Douglas Thrift. All Rights Reserved.\n"
444 >                << "   Copyright (C) 2002-2004, 2008, Douglas Thrift. All Rights Reserved.\n"
445                  << "\n"
446                  << "   Redistribution and use in source and binary forms, with or with"
447                  << "out\n"
# Line 508 | Line 499 | void license()
499                  << "   EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n";
500   }
501  
502 < void entities(string& line, char character, char* entity)
502 > void entities(string& line, char character, const string& entity)
503   {
504 <        int begin = 0;
504 >        size_t begin(0);
505  
506          while (begin < line.length())
507          {
508 <                int spot = line.find(character, begin);
518 <
519 <                int end = spot + 1;
508 >                size_t spot(line.find(character, begin)), end(spot + 1);
509  
510                  if (spot != string::npos)
511                  {
512                          line.replace(spot, 1, entity);
513                  }
514 <                else
526 <                {
527 <                        break;
528 <                }
514 >                else break;
515  
516                  begin = end;
517          }
518   }
519  
520 < void entities(string& line, char* entity, char character)
520 > void entities(string& line, const string& entity, char character)
521   {
522 <        int begin = 0;
522 >        size_t begin(0);
523  
524          while (begin < line.length())
525          {
526 <                int spot = line.find(entity, begin);
541 <
542 <                int end = spot + 1;
526 >                size_t spot(line.find(entity, begin)), end(spot + 1);
527  
528                  if (spot != string::npos)
529                  {
530 <                        line.replace(spot, strlen(entity), 1, character);
547 <                }
548 <                else
549 <                {
550 <                        break;
530 >                        line.replace(spot, entity.length(), 1, character);
531                  }
532 +                else break;
533  
534                  begin = end;
535          }
# Line 556 | Line 537 | void entities(string& line, char* entity
537  
538   void normalize(string& abbynormal)
539   {
540 <        for (unsigned index = 0; index < abbynormal.length(); index++)
540 >        for (size_t index(0); index < abbynormal.length(); index++)
541          {
542                  if (isspace(abbynormal[index]))
543                  {
544 <                        unsigned next = index + 1;
545 <                        while (isspace(abbynormal[next]))
546 <                        {
547 <                                next++;
567 <                        }
544 >                        size_t next(index + 1);
545 >
546 >                        while (isspace(abbynormal[next])) next++;
547 >
548                          abbynormal.replace(index, next - index, 1, abbynormal[index]);
549                  }
550          }

Comparing:
trunk/Search/Search.cpp (property svn:eol-style), Revision 212 by douglas, 2003-07-19T21:00:25-07:00 vs.
Search/trunk/Search.cpp (property svn:eol-style), Revision 372 by douglas, 2008-08-23T04:00:12-07:00

# Line 0 | Line 1
1 + native

Comparing:
trunk/Search/Search.cpp (property svn:keywords), Revision 212 by douglas, 2003-07-19T21:00:25-07:00 vs.
Search/trunk/Search.cpp (property svn:keywords), Revision 372 by douglas, 2008-08-23T04:00:12-07:00

# Line 0 | Line 1
1 + Id

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines