)
{
if ($just_did_a_node_title_line eq "true")
{ $just_did_a_node_title_line = "false";
next;
}
$linestring=$_;
$linetype=LineType($linestring);
if ($linetype!=$NODE_TITLE_LINE)
{ if ($node_title_line_found eq "false")
{
next;
}
}
if ($linetype==$LINE_TO_SKIP)
{
next;
}
if ($linetype==$BLANK_LINE)
{ next;
}
if ($linetype==$NBSP_LINE)
{
print RESULTS "\n
\n";
next;
}
if ($linetype==$OTHER_LINE)
{
$linestring=~s/ <\/P>/
/g;
$linestring=~s/
//g;
$linestring=~s/<\/P>/
\n
/g;
$linestring=~s/
]*>//g;
$linestring=~s/ / /g;
$linestring=~s/]*>//g;
$linestring=~s/]*>//g;
$linestring=~s/<\/A>//g;
$linestring=~s/<\/FONT>//g;
print RESULTS $linestring;
}
if ($linetype==$NODE_TITLE_LINE)
{ if ($node_title_line_found eq "false")
{ $node_title_line_found="true";
}
$just_did_a_node_title_line="true";
@explosion=split("--- ", $linestring);
@explosion2=split("[*]", @explosion[1]);
$node_depth=trim(@explosion2[0]);
if ($node_depth=="")
{ $node_depth=0;
}
#The deeper the node depth, the higher node_depth is.
# 0 = top level.
# 1 = deeper level
# 2 = even deeper level
if ($node_depth>$prev_node_depth)
# If we're now at a deeper level, make a new
tag
{ print RESULTS "\n";
}
if ($node_depth<=$prev_node_depth)
{ # If we're now at a shallower level or the same level...
if ($prev_node_depth!=-1)
{ print RESULTS "\n\n";
}
}
if ($node_depth<$prev_node_depth)
{ # If we're now at a shallower level...
for ($x=$prev_node_depth;$x>$node_depth;$x--)
{
if ($prev_node_depth!=-1)
{
print RESULTS "\n\n";
print RESULTS "\n
";
}
}
}
$node_title=trim(@explosion2[1]);
print RESULTS "\n- $node_title
\n";
print RESULTS "\n";
print RESULTS "\n";
print RESULTS "- ";
$prev_node_depth=$node_depth;
}
}
}
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
sub LineType
{
$thisline=$_[0];
$thislinelength=length($thisline);
if ($thisline eq "\r\n")
{ return $BLANK_LINE;
};
$node_title_line_test=LocateStringIn($thisline,"
--- ");
if ($node_title_line_test==0)
{
return $NODE_TITLE_LINE;
};
$skip_line_test=LocateStringIn($thisline,"
");
if ($skip_line_test==0)
{
return $LINE_TO_SKIP;
};
if ($thisline eq "
\r\n")
{
return $NBSP_LINE;
}
return $OTHER_LINE;
}
sub LocateStringIn
{ $stringtolookin=$_[0];
$stringtofind=$_[1];
$startofstring=index($stringtolookin,$stringtofind);
return $startofstring;
}
sub AddSlashIfNeeded
{
$this_string=$_[0];
$lastchar = substr($this_string,length($this_string)-1,1);
if ($lastchar ne "/")
{ $this_string .= "/";
}
return $this_string;
}
#####################################################################
#
#
# Stuff that gets done at the end of the script:
#
#
#
close (INPUTFILE);
close (RESULTS);
print "\n\n\n";
print "$script_name Perl script finished!\n";
# commify subroutine by Andrew Johnson, found at
# http://www.perlmonks.org/?node_id=653
sub commify
{
my $input = shift;
$input = reverse $input;
$input =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g;
return reverse $input;
}
$output_file_size = -s $output_file_name;
$output_file_size = commify($output_file_size);
print "\n\nOutput is in:
$output_folder$output_file_name
File size: $output_file_size bytes";
print "\n\n\nYou can press Return (or Enter) to close this window.\n";
$wait_for_return = ;
# If you've rather have the rxvt window automatically disappear after
# several seconds when the script is finished running, comment out
# the previous two lines, and uncomment the next lines.
# $secs=5;
# print "\n\nThis window will automatically close in $secs seconds.\n\n\n";
# sleep $secs;
die;