#!perl -w
# Version 0.01
use RISCOS::Filespec;

# use RISCOS::File ':DEFAULT', '/glob/';
# glob_control (&fileglob_PrintOriginalPath);

$/ = "\0";	# Read null termintated lines

foreach $pattern (@ARGV)
{
    foreach $file (glob($pattern))
    {
	unless (open (MOD, "<$file"))
	{
	    warn "Could not open file '$file': $!";
	    next;
	}

	unless (seek MOD, 0x14 ,0)
	{
	    warn "Could not seek to &14 in file '$file': $!";
	    next;
	}

	unless (read MOD, $where ,4)
	{
	    warn "Could not read help offset from file '$file': $!";
	    next;
	}

	$where = unpack 'I', $where;
	# Hmm. there's no unsigned V to force read little endian

	unless ($where)
	{
	    warn "Zero offset of help text in '$file'";
	    next;
	}

	if ($where > ($length = -s $file))
	{
	    warn "Offset of help text in '$file' at $where > length ($length)";
	    next;
	}

	unless (seek MOD, $where ,0)
	{
	    warn "Could not seek to $where in file '$file': $!";
	    next;
	}
	
	unless (defined ($text = <MOD>))
	{
	    warn
	      "Could not read help text at offset $where in file '$file': $!";
	    next;
	}
	
	# Hey, got the text.
	chomp $text;
	
	print "$file:\n\t$text\n";
    }
}
