#!/usr/bin/perl
# $Id: phpdoc.pl,v 1.3 2004/11/26 15:55:20 weby Exp $

use strict;
use constant 'BASE' => '/usr/share/doc/phpdoc/html/function.';
use constant 'TMP'  => '/tmp/phpdoc.swp';

my $phpfunc = $ARGV[0];
&usage unless $phpfunc;
man($phpfunc);

sub usage
{
    print "  Usage:\n";
    print "    $0 is_array\n\n";
    exit;
}

sub man
{
    my $func = shift;
    my $function = $func;

    $func =~ s|_|-|g;
    my $man_file = BASE."$func.html";

    if (-f $man_file) {
	my $output = [split("\n", `lynx --dump $man_file`)];
	my $tmp = TMP;

	open FH, ">$tmp" or die $!;
	for(@{$output}){
	    last if m/References/;
	    print FH $_, "\n";
	}
	close FH;
	
	system("less",  $tmp);
	unlink($tmp) or die $!;
	
    } else {
	print "Function - $func not found!\n$man_file\n";
    }
}