#!/usr/bin/perl
use strict;
use warnings;
&Rule_0_PrintRule_Preamble();
foreach (@ARGV) {
my @fields = split /[\\\/:]/;
my $file_name = $fields[$#fields];
&Rule_1_link_Check_File($file_name, $file_name);
next unless open FILE, $_;
while (<FILE>) {
chomp;
@fields = split;
my ($g,$o)=(0,0);
pos = 0;
s/\t/$g=8-($o+pos)%8; $o+=$g-1; ' 'x$g/ge;
&Rule_1_link_Input_Line($_, @fields);
}
close FILE;
}
&Rule_1_link_End_Data();
&Rule_0_PrintRule_Appendix();
INIT {
my $starting_level = 1;
my $current_level = 0;
my $begin_a_block = 0;
sub Rule_1_link_Check_File {
my ($line, @fields) = @_;
my $selected_string;
$begin_a_block = 1;
$current_level = $starting_level;
}
sub Rule_1_link_Input_Line {
my ($line, @fields) = @_;
my $selected_string;
if ($current_level>=1) {
if (defined($fields[0]) && length($fields[0])>6) {
$selected_string = substr($fields[0], 6, 42);
} else {
$selected_string = undef;
}
if (defined($selected_string) && $selected_string eq "http:\/\/mp3.xianlai.com\/viewthread.php?tid=") {
$selected_string = $fields[0];
if (defined($selected_string)) {
&Rule_2_QuoteRule($begin_a_block, $current_level, $selected_string);
$begin_a_block = 0;
}
}
}
}
sub Rule_1_link_End_Data {
my $selected_string = undef;
&Rule_2_QuoteRule(0, 0, $selected_string);
}
}
INIT {
sub Rule_2_QuoteRule {
my ($begin_a_block, $current_level, $input_string) = @_;
unless (defined($input_string)) {
&Rule_0_PrintRule_Data(1, 0, 0, $input_string);
return;
}
my $left = 0;
my $right = 0;
my $len = length($input_string);
for ( ; $left<$len; $left=$right+1) {
if (($left=index($input_string, "\"", $left))<0) {
return;
} else {
$left += 1;
}
if (($right=index($input_string, "&", $left))<0) {
return;
}
if ($right>$left) {
my $selected_string = substr($input_string, $left, $right-$left);
&Rule_0_PrintRule_Data(1, $begin_a_block, $current_level, $selected_string);
$begin_a_block=0;
}
}
}
}
INIT {
my @data_array;
for (my $i=0; $i<2; $i++) {
push @data_array, [ ];
}
my @line_stuff;
$line_stuff[0] = "";
$line_stuff[1] = "\n";
my @line_limit;
my $available = 1;
my $finished = 1;
sub Rule_0_PrintRule_Data {
my ($part, $block, $level, $input_string) = @_;
unless (defined($input_string)) {
&Rule_0_PrintRule_End();
return;
}
push @{$data_array[$part]}, $input_string;
&Rule_0_PrintRule_Print($part);
}
sub Rule_0_PrintRule_Print {
my ($part) = @_;
return if @{$data_array[$part]}>1;
$available++;
return if $available<2;
print $line_stuff[0];
for (my $i=1; $i<2; $i++) {
my $output_string = shift @{$data_array[$i]};
$available-- if @{$data_array[$i]}<1;
&Rule_0_PrintRule_Output($i, $output_string);
print $line_stuff[$i];
}
}
sub Rule_0_PrintRule_End {
$finished++;
return if $finished<2;
while ($available>1) {
print $line_stuff[0];
for (my $i=1; $i<2; $i++) {
my $output_string = shift @{$data_array[$i]};
unless (defined($output_string)) {
print "<no_data>";
} else {
$available-- if @{$data_array[$i]}<1;
&Rule_0_PrintRule_Output($i, $output_string);
}
print $line_stuff[$i];
}
}
}
sub Rule_0_PrintRule_Preamble {
print "";
}
sub Rule_0_PrintRule_Output {
my ($i, $output_string) = @_;
unless (defined($line_limit[$i])) {
print "$output_string";
} else {
my $j = 0;
while (1) {
print substr($output_string, $j, $line_limit[$i]);
$j += $line_limit[$i];
if ($j<length($output_string)) {
print "\n";
} else {
last;
}
}
}
}
sub Rule_0_PrintRule_Appendix {
print "";
}
} |