#!/usr/bin/perl our $change_matix = ''; our $change_matrix = ' um über mit von vom nach zum zur in an auf der das des dem den ein einer einem einen eines '; our $change_matrix = ' router network ip route '; if (open(FILE, $ARGV[0])) { local $/; $change_matrix = ; } shift @ARGV; my $BaseURL = $ARGV[0]; shift; my $Subdir = $ARGV[0]; shift; my $StateFile = $ARGV[0]; shift; sub load_state() { my %state; my $entries = 0; if (open(FILE, "$StateFile")) { while() { chomp; my ($k,$v) = split /\s+/, $_, 2; $state{$k} = $v; $entries += 1; } } $state{"ENTRIES"} = $entries; return \%state; } @colors = qw(ccccff 7aedaa ddeecc ffccee); our %change_matrix; our %color; our $dropdown_number = 0; $i = 0; for (split /\n/, $change_matrix){ next if /^\s*$/; my @words = sort(split /\s+/); for my $kw (@words) { $change_matrix{$kw} = [ "???", @words ]; $color{$kw} = $colors[$i%@colors]; } # uppercase for (@words) { s/(.)(.*)/\U$1\E$2/; } for my $kw (@words) { $change_matrix{$kw} = [ "???", @words ]; $color{$kw} = $colors[$i%@colors]; } $i += 1; }; #for (keys(%change_matrix)) { # print "$_ => ".join(", ", @{$change_matrix{$_}})."\n"; # print "$_ => ".$color{$_}."\n"; #} our $CorrectAnswers = 0; sub generate_drop_down($$) { my $word = $_[0]; my %state = %{$_[1]}; my $name = "dropdown$dropdown_number"; my $value = $state{$name}; $dropdown_number += 1; my @variants = @{$change_matrix{$word}}; $options = join("", map {my $selected = ""; $selected='selected="selected"' if $_ eq $value; ""} @variants); my $color = $color{$word}; if ($word eq $value) { $color = "ffffff"; $CorrectAnswers += 1; } if ($color) { $color = "background:#$color"; } my $disabled = ""; if ($value eq $word) { $disabled = "disabled"; } my $onchange = "onchange='javascript:myAlert(\"$name\", this.form.$name, \"$word\")'"; return "
"; } sub highlight_word($$$) { my $tag = $_[0]; my $text = $_[1]; my $state = $_[2]; if ($tag=~/^<[aA]/) { return $tag.$text; } my $re = join("|", keys(%change_matrix)); $text =~ s@(^|[;> ])($re)(?=([ <]|$))@"$1".generate_drop_down($2, $state)@egms; return $tag.$text; } my $state = load_state(); #my %a = %{$state}; #print join(", ", keys(%a)),"\n"; $jquery = ""; local $/; $text = <>; $text =~ s@()(.*?)()@$2@g; $text =~ s@(.*)(]*>)@$2@ims; my $before_body = $1; $text =~ s@(]*>)@$1@ims; $text =~ s/(<.*?>)([^<]*)(?=<)/highlight_word($1, $2, $state)/egms; $text = $before_body.$text; my $wrong_answers = $$state{"ENTRIES"} - $CorrectAnswers; $info_div = "
$wrong_answers   $CorrectAnswers   $dropdown_number
"; $text =~ s@(]*>)@$jquery$1$info_div@i; $text =~ s@(]*>)@$1@i; print $text;