/* Seen Companion script to JoinLog.AMIRX for AmIRC 1.x
// $VER Seen.amirx 1.02 (13.03.97)
// Written by Deryk Robosson 4.3.97
//
// newlook@ameritech.net newlook on #amiga IRC (EfNet/IRCnet)
//
// 4.3.97 Initial Creation
// 5.3.97 Enhanced search capability
// 7.3.97 Added external parsing support due
//        to limitations of ARexx
//        Slimmed down the parsing of args
// 13.03.97 - Cleaned up the code
*/
bold = d2c(2)
underline = '1F'x

/* default maximum shown occurances */
defseen = 5

/* set path to log here */
path = 't:'

/* path to parse.temp file (shouldn't need to change this) */
parsetemppath = 't:'

/* path and filename for the tempfile (shouldn't need to change this either */
parsetempfile = parsetemppath||'parse.temp'

/* set path to parse command here */
parsepath = 'c:parse'

/* counter variable */
i = 0

options results
parse arg who' 'command' 'user' 'number
who = strip(upper(who))
command = strip(upper(command))
user = strip(upper(user))
number = strip(upper(number))

'GETCHANNEL'
channel = result
parse var channel '#'channel
filename = path||channel||'.log'

if who ~= '' then do
    if datatype(command) ~= 'NUM' then do
        if number ='' then number = defseen
    end
    else number = command
end
if who = ''|who = 'VER' then signal version
if who = 'HELP' then signal help

/* call our external program to slim the list down a bit */
if(pos('.',who)) ~= 0 then address command parsepath||' '||filename||' 0 *.'||who
else address command parsepath||' '||filename||' 1 '||who

/* parse the slimmed list */
call ParseList()

/* find out where we should start in the list */
if totalcount > number then count = totalcount - number
if totalcount < number then count = 0

/* act on commands. if no commands then echo to user */
do while count ~= totalcount
    select
        when command = 'SAY' then 'SAY 'listitems.count
        when command = 'SHOW' then 'RAW NOTICE' user ':'listitems.count
        otherwise
            call echo(listitems.count)
    end
    count = count+1
end
address command 'delete 'parsetempfile' quiet'
call echo(bold'Search finished.')
exit

ParseList:
totalcount = 0
if open(file,parsetempfile,'R') then do
    do until eof(file)
        line = ReadLn(file)
        if(pos(upper(who),upper(line))) ~= 0 then do
            listitems.totalcount = line
            totalcount = totalcount+1
        end
    end
    close(file)
    if totalcount = 0 then do
        call echo(bold'User not found')
        exit
    end
    return
end
else do
    call echo(bold'Error opening #'channel' logfile.')
    exit
end

Version:
	call echo(bold'Seen.AMIRX'bold' Version 'subword(sourceline(2),4,2))
	call echo('Read the top of Seen.AMIRX script for history.')
	call echo(bold'©1997'bold' Deryk Robosson 'bold'(newlook)'bold' - [newlook@ameritech.net]')
	call echo('Type /<alias> help for command information')
exit

Help:
	call echo(bold'Seen.AMIRX'bold' Help')
	call echo(bold'SAY - 'bold'ECHOs output to window')
	call echo(bold'VER - 'bold'displays script author and version info')
	call echo(bold'SHOW - 'bold'displays outout to user')
	call echo(bold'HELP - 'bold'displays this file')
	call echo(bold||UNDERLINE'EXAMPLES:'bold||UNDERLINE)
	call echo(bold'/Seen user 'bold'to see output yourself')
	call echo(bold'/Seen site.com SAY 'bold'to show output to channel')
	call echo(bold'/Seen site SHOW usernick 'bold'to show output to a user')
	call echo(bold'/Seen site SHOW usernick 2'bold' to show last x occurances')
exit

echo: procedure
	parse arg a
	'echo P='d2c(27)'b«Seen» 'a
return 1
