#
# A file pager.  A demonstration of how to do something useful in ircII.
# This cheesy rip-off was written by hop in 1996.
# My apologies in advance to archon.
#

alias less
{
	if ([$0])
	{
		if (fexist($0) == 1)
		{
			@ fd = open($0 R)
			less_file $fd ${winsize() - 1}
		}
		{
			echo $0\: no such file.
		}
	}
	{
		echo Usage: /more <filename>
	}
}


alias less_file
{
	@ line = 0

	while (!eof($0) && (line++ < [$1]))
	{
		@ ugh = read($0)
		if (!eof($0)) 
		{
			echo $ugh
		}
	}

	if (!eof($0))
	{
		@ less.fd = [$0]
		@ less.nl = [$1]
		input_char "Enter q to quit, or anything else to continue "
		{
			if ([$0] != [q])
			{
				less_file $less.fd $less.nl
			}
		}
	}
	{
		@ close($fd)
	}
}

#hop'96
