# html.pl v1.0
# Copyright Matthew Gray, 1994

package html;

sub headers {
    local($doc, @nums) = @_;

    local($ns) = join('', @nums);

    @h = &rec($doc, "<h[$ns]>", "<\\/h[$ns]>");
    for $head (@h){
	print("---> $head\n") if $main'debug;
    }
    @h;
}

sub tagged {
    local($doc, $tag) = @_;

    &rec($doc, "<$tag>", "<\\/$tag>");
}

sub anchors {
    local($doc) = @_;

    &arec($doc, "<a [^>]*>", "<\\/a>");
}

sub arec {
    local($string, $match1, $match2) = @_;
    local($in);

    if($string=~/<a [^>]*href=\"([^\"]+)\"[^>]*>/i){
	$url = $1;
	$after = $';
	if($after=~/<\/a>/i){
	    $in = $`;
	    @out = ($in."".$url, &arec($',$match1, $match2));
	}
    }
    @out;
}

sub rec {
    local($string, $match1, $match2) = @_;
    local($in) = '';
    local(@out) = ();
    if($string=~/$match1/i){
	$after = $';
	if($after=~/$match2/i){
	    $in = $`;
	    @out = ($in, &rec($',$match1, $match2));
	}
    }
    @out;
}

sub clean {
    local($doc) = @_;

    s/<[^>]>//g;
}

1;
