#!/usr/local/bin/perl
# ts, boone, 07/27/92
# Search for keywords in Gopher user-visible filenames
# Copyright (C) 1992, Trustees of Michigan State University
#
# Modifications:
# 07/27/92 Boone      Initial coding
# 09/10/92 Boone      Ts was losing some items due to identical paths.
#                     These were mostly root directory items and telnet
#                     sessions.  The way ts build the associative array
#                     index now includes both the user string and the
#                     selector.  Ts now searches just the user visible
#                     title field.
# 11/20/92 Bryan Buus (buus@spica.bu.edu)
#          Jeff Kellem (composer@beyond.dreams.org)
#                     They added the 'o' option to the grep, which I had
#                     left off because my Perl core dumps when I use
#                     that option.  This is a major performance win.
#                     Also, added code to take all arguments instead of
#                     just the first one.  This makes it easier to test
#                     this beast from the command line.  Be aware that the
#                     gopher daemon actually puts all of the keywords into
#                     the first argument.  Removed sort.
# 01/22/93 Boone      Merged above mods from Buus and Kellem.
#                     Note that the sort is commented out, and can be
#                     revived if you happen to be in love with it.
# End Modifications
#
# Version 1.6
#
# Description:
#
# Ts searches for a keyword in an index file containing a complete
# Gopher-style directory of a file tree.  The index can be created with
# the tb program.  The search is caseless.
#
# Comments and bug reports to drbmaint@ibm.cl.msu.edu.
# End Description

open(TSLOG, ">>.ts/.tslog");
chop($d = `date`);
open(DB, ".ts/.tsdata") || die;
$words = join(" ", @ARGV);
$words = join("|", split(/ /, $words));
@plist = grep(/^[^\t]*($words)[^\t]*\t/io, <DB>);
#sort(@plist);
foreach $i (@plist)
{
	print stdout $i;
}
print stdout ".\n";
close(TSLOG);
close(DB);
