68 |
|
|
69 |
|
#endif |
70 |
|
|
71 |
< |
string program; |
72 |
< |
string programName = "Douglas Thrift's Search Engine"; |
73 |
< |
string programVersion = "1.3svn"; |
74 |
< |
bool debug = false; |
71 |
> |
string program, programName("Douglas Thrift's Search Engine"), |
72 |
> |
programVersion("1.3svn"); |
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; |
83 |
< |
set<string> indexRestrictions; |
84 |
< |
|
85 |
< |
unsigned page = 1; |
86 |
< |
string query; |
87 |
< |
|
79 |
> |
bool indexMode(false); |
80 |
> |
set<string> indexDomains, indexRestrictions; |
81 |
> |
unsigned 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"; |
91 |
< |
string body = "body.html"; |
92 |
< |
string footer = "footer.html"; |
93 |
< |
string notfound = "notfound.html"; |
94 |
< |
string pages = "pages.html"; |
95 |
< |
|
96 |
< |
string email; |
97 |
< |
|
98 |
< |
for (int index = 1; index < argc; index++) |
86 |
> |
for (int index(1); index < argc; index++) |
87 |
|
{ |
88 |
|
string arg(argv[index]); |
89 |
|
|
264 |
|
else |
265 |
|
{ |
266 |
|
string line; |
267 |
+ |
|
268 |
|
getline(cin, line); |
269 |
+ |
|
270 |
|
query = line; |
271 |
|
|
272 |
|
Searcher searcher(query); |
273 |
+ |
Outputer outputer(header, body, footer, notfound, pages); |
274 |
|
|
275 |
|
searcher.search(indices); |
285 |
– |
|
286 |
– |
Outputer outputer(header, body, footer, notfound, |
287 |
– |
pages); |
288 |
– |
|
276 |
|
outputer.output(searcher, page < 1 ? page : --page); |
277 |
|
} |
278 |
|
|
279 |
|
return 0; |
280 |
|
} |
281 |
|
|
295 |
– |
string agent(bool version) |
296 |
– |
{ |
297 |
– |
string agent = programName + (version ? ('/' + programVersion) : ""); |
298 |
– |
|
299 |
– |
return agent; |
300 |
– |
} |
301 |
– |
|
282 |
|
string platform() |
283 |
|
{ |
284 |
< |
string platform; |
285 |
< |
string os; |
286 |
< |
string version; |
307 |
< |
string architecture; |
308 |
< |
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 |
> |
unsigned 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 .NET Server]"; |
326 |
+ |
} |
327 |
+ |
|
328 |
+ |
platform << ' '; |
329 |
+ |
|
330 |
|
SYSTEM_INFO* system = new SYSTEM_INFO; |
331 |
+ |
|
332 |
|
GetSystemInfo(system); |
333 |
|
|
334 |
|
switch (system->wProcessorArchitecture) |
335 |
|
{ |
336 |
|
case PROCESSOR_ARCHITECTURE_INTEL: |
337 |
< |
architecture = "ix86"; |
337 |
> |
platform << "ix86"; |
338 |
|
break; |
339 |
|
case PROCESSOR_ARCHITECTURE_MIPS: |
340 |
< |
architecture = "mips"; |
340 |
> |
platform << "mips"; |
341 |
|
break; |
342 |
|
case PROCESSOR_ARCHITECTURE_ALPHA: |
343 |
< |
architecture = "alpha"; |
343 |
> |
platform << "alpha"; |
344 |
|
break; |
345 |
|
case PROCESSOR_ARCHITECTURE_PPC: |
346 |
< |
architecture = "ppc"; |
346 |
> |
platform << "ppc"; |
347 |
|
break; |
348 |
|
case PROCESSOR_ARCHITECTURE_IA64: |
349 |
< |
architecture = "ia64"; |
349 |
> |
platform << "ia64"; |
350 |
|
break; |
351 |
|
case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64: |
352 |
< |
architecture = "ix86_on_win64"; |
352 |
> |
platform << "ix86_on_win64"; |
353 |
|
break; |
354 |
|
case PROCESSOR_ARCHITECTURE_AMD64: |
355 |
< |
architecture = "amd64"; |
355 |
> |
platform << "amd64"; |
356 |
|
break; |
357 |
|
default: |
358 |
< |
architecture = "unknown"; |
358 |
> |
platform << "unknown"; |
359 |
|
break; |
360 |
|
} |
361 |
|
|
353 |
– |
char* cversion = new char[1024]; |
354 |
– |
sprintf(cversion, "%u.%u", major, minor); |
355 |
– |
version = cversion; |
356 |
– |
|
357 |
– |
delete [] cversion; |
358 |
– |
|
359 |
– |
if (major == 4 && minor <= 3 && os != "Windows NT") |
360 |
– |
{ |
361 |
– |
marketing = " [Windows 95]"; |
362 |
– |
} |
363 |
– |
else if (major == 4 && minor == 10 && os != "Windows NT") |
364 |
– |
{ |
365 |
– |
marketing = " [Windows 98]"; |
366 |
– |
} |
367 |
– |
else if (major == 5 && minor == 0 && os == "Windows NT") |
368 |
– |
{ |
369 |
– |
marketing = " [Windows 2000]"; |
370 |
– |
} |
371 |
– |
else if (major == 4 && minor == 90 && os != "Windows NT") |
372 |
– |
{ |
373 |
– |
marketing = " [Windows ME]"; |
374 |
– |
} |
375 |
– |
else if (major == 5 && minor == 1 && os == "Windows NT") |
376 |
– |
{ |
377 |
– |
marketing = " [Windows XP]"; |
378 |
– |
} |
379 |
– |
else if (major == 5 && minor == 2 && os == "Windows NT") |
380 |
– |
{ |
381 |
– |
marketing = " [Windows .NET Server]"; |
382 |
– |
} |
362 |
|
#else // _WIN32 |
363 |
|
struct utsname* computer = new struct utsname; |
364 |
+ |
|
365 |
|
uname(computer); |
366 |
|
|
367 |
< |
os = computer->sysname; |
368 |
< |
version = computer->release; |
389 |
< |
architecture = computer->machine; |
367 |
> |
platform << computer->sysname << ' ' << computer->release << ' ' << |
368 |
> |
computer->machine; |
369 |
|
|
370 |
|
delete computer; |
371 |
|
#endif // _WIN32 |
372 |
|
|
373 |
< |
platform = "(" + os + " " + version + marketing + " " + architecture + ")"; |
373 |
> |
platform << ')'; |
374 |
|
|
375 |
< |
return platform; |
375 |
> |
return platform.str(); |
376 |
|
} |
377 |
|
|
378 |
|
void usage() |
379 |
|
{ |
380 |
|
#ifdef _WIN32 |
381 |
+ |
string program(program); |
382 |
|
OSVERSIONINFO* computer = new OSVERSIONINFO; |
383 |
+ |
|
384 |
|
computer->dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
385 |
+ |
|
386 |
|
GetVersionEx(computer); |
387 |
|
|
388 |
< |
string program = ::program; |
407 |
< |
if (computer->dwPlatformId != VER_PLATFORM_WIN32_NT) |
408 |
< |
{ |
409 |
< |
program = "Search"; |
410 |
< |
} |
388 |
> |
if (computer->dwPlatformId != VER_PLATFORM_WIN32_NT) program = "Search"; |
389 |
|
|
390 |
|
delete computer; |
391 |
|
#endif // _WIN32 |
495 |
|
<< " EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"; |
496 |
|
} |
497 |
|
|
498 |
< |
void entities(string& line, char character, char* entity) |
498 |
> |
void entities(string& line, char character, const string& entity) |
499 |
|
{ |
500 |
< |
int begin = 0; |
500 |
> |
int begin(0); |
501 |
|
|
502 |
|
while (begin < line.length()) |
503 |
|
{ |
504 |
< |
int spot = line.find(character, begin); |
527 |
< |
|
528 |
< |
int end = spot + 1; |
504 |
> |
int spot(line.find(character, begin)), end(spot + 1); |
505 |
|
|
506 |
|
if (spot != string::npos) |
507 |
|
{ |
508 |
|
line.replace(spot, 1, entity); |
509 |
|
} |
510 |
< |
else |
535 |
< |
{ |
536 |
< |
break; |
537 |
< |
} |
510 |
> |
else break; |
511 |
|
|
512 |
|
begin = end; |
513 |
|
} |
514 |
|
} |
515 |
|
|
516 |
< |
void entities(string& line, char* entity, char character) |
516 |
> |
void entities(string& line, const string& entity, char character) |
517 |
|
{ |
518 |
< |
int begin = 0; |
518 |
> |
int begin(0); |
519 |
|
|
520 |
|
while (begin < line.length()) |
521 |
|
{ |
522 |
< |
int spot = line.find(entity, begin); |
550 |
< |
|
551 |
< |
int end = spot + 1; |
522 |
> |
int spot(line.find(entity, begin)), end(spot + 1); |
523 |
|
|
524 |
|
if (spot != string::npos) |
525 |
|
{ |
526 |
< |
line.replace(spot, strlen(entity), 1, character); |
556 |
< |
} |
557 |
< |
else |
558 |
< |
{ |
559 |
< |
break; |
526 |
> |
line.replace(spot, entity.length(), 1, character); |
527 |
|
} |
528 |
+ |
else break; |
529 |
|
|
530 |
|
begin = end; |
531 |
|
} |
533 |
|
|
534 |
|
void normalize(string& abbynormal) |
535 |
|
{ |
536 |
< |
for (unsigned index = 0; index < abbynormal.length(); index++) |
536 |
> |
for (unsigned index(0); index < abbynormal.length(); index++) |
537 |
|
{ |
538 |
|
if (isspace(abbynormal[index])) |
539 |
|
{ |
540 |
< |
unsigned next = index + 1; |
541 |
< |
while (isspace(abbynormal[next])) |
542 |
< |
{ |
543 |
< |
next++; |
576 |
< |
} |
540 |
> |
unsigned next(index + 1); |
541 |
> |
|
542 |
> |
while (isspace(abbynormal[next])) next++; |
543 |
> |
|
544 |
|
abbynormal.replace(index, next - index, 1, abbynormal[index]); |
545 |
|
} |
546 |
|
} |