devi@23: #!/usr/bin/perl -w
devi@23:
devi@23: use lib '.';
devi@23: use l3config;
devi@23:
devi@23: our @Command_Lines;
devi@23:
devi@23: # vvv Инициализация переменных выполняется процедурой init_variables
devi@23: our @Day_Name;
devi@23: our @Month_Name;
devi@23: our @Of_Month_Name;
devi@23: our %Search_Machines;
devi@23: our %Elements_Visibility;
devi@23: # ^^^
devi@23:
devi@23: sub search_buy;
devi@23: sub make_comment;
devi@23: sub load_command_lines_from_xml;
devi@23: sub print_command_lines;
devi@23: sub init_variables;
devi@23: sub main;
devi@23:
devi@23: main();
devi@23:
devi@23: sub main
devi@23: {
devi@23: $| = 1;
devi@23:
devi@23: init_variables();
devi@23: init_config();
devi@23:
devi@27: load_command_lines_from_xml($Config{"backend_datafile"});
devi@23: print_command_lines($Config{"output"});
devi@23: }
devi@23:
devi@23:
devi@23: sub search_by
devi@23: {
devi@23: my $sm = shift;
devi@23: my $topic = shift;
devi@23: $topic =~ s/ /+/;
devi@23:
devi@23: return "";
devi@23: }
devi@23:
devi@23: sub make_comment
devi@23: {
devi@23: my $commands = $_[0];
devi@23: my $files = $_[1];
devi@23: chomp $commands;
devi@23: chomp $files;
devi@23: return if (!$commands && !$files);
devi@23:
devi@23: my $comment="";
devi@23:
devi@23: # Commands
devi@23: for my $command (split /\s+/,$commands) {
devi@23: $command =~ s/'//g;
devi@23: my $description="";
devi@28: eval { $description=`/home/devi/bin/mywi-client '$command'`; } ;
devi@23: $description = join ("
\n", grep(/\([18]\)/, split(/\n/, $description)));
devi@23: $description =~ s/.*?-//;
devi@23: next if $description =~ /^\s*$/;
devi@23:
devi@23: my $query=$command." ".$Config{"keywords"};
devi@23: $query =~ s/\ /+/g;
devi@23: my $search= search_by("opennet",$query).
devi@23: search_by("local",$command).
devi@23: search_by("google",$query);
devi@23:
devi@23: $comment .= "
$command | ".
devi@23: "$search | ".
devi@23: "
".
devi@23: "$description |
";
devi@23: }
devi@23:
devi@23: # Files
devi@23: for my $file (split /\s+/,$files) {
devi@23: $file =~ s@.*/@@;
devi@23: $file =~ s/'//g;
devi@23: next if $file =~ /^\s*$/;
devi@23: next if $file =~ /^-/;
devi@23:
devi@23: my $description=`mywi '$file'`;
devi@23: $description = join ("
\n", grep(/\(5\)/, split(/\n/, $description)));
devi@23: next if $description =~ /^\s*$/;
devi@23:
devi@23: my $query=$file." ".$Config{"files_keywords"};
devi@23: $query =~ s/\ /+/g;
devi@23: my $search= search_by("opennet",$query).
devi@23: search_by("local",$file).
devi@23: search_by("google",$query);
devi@23:
devi@23: $comment .= "$file | ".
devi@23: "$search | ".
devi@23: "
".
devi@23: "$description |
";
devi@23: }
devi@23:
devi@23:
devi@23: return $comment;
devi@23: }
devi@23:
devi@23: =cut
devi@23: Процедура load_command_lines_from_xml выполняет загрузку разобранного lab-скрипта
devi@23: из XML-документа в переменную @Command_Lines
devi@23:
devi@23: Предупреждение!
devi@23: Процедура не в состоянии обрабатывать XML-документ любой структуры.
devi@23: В действительности файл cache из которого загружаются данные
devi@23: просто напоминает XML с виду.
devi@23: =cut
devi@23: sub load_command_lines_from_xml
devi@23: {
devi@23: my $datafile = $_[0];
devi@23:
devi@23: open (CLASS, $datafile)
devi@23: or die "Can't open file of the class ",$datafile,"\n";
devi@23: local $/;
devi@23: $data = ;
devi@23: close(CLASS);
devi@23:
devi@23: for $command ($data =~ m@(.*?)@sg) {
devi@23: my %cl;
devi@23: while ($command =~ m@<([^>]*?)>(.*?)\1>@sg) {
devi@23: $cl{$1} = $2;
devi@23: }
devi@23: push @Command_Lines, \%cl;
devi@23: }
devi@23: }
devi@23:
devi@23: =cut
devi@23: Процедура print_command_lines выводит HTML-представление
devi@23: разобранного lab-скрипта.
devi@23:
devi@23: Разобранный lab-скрипт должен находиться в массиве @Command_Lines
devi@23: =cut
devi@23:
devi@23: sub print_command_lines
devi@23: {
devi@23: my $output_filename=$_[0];
devi@23:
devi@23: my $course_name = $Config{"course-name"};
devi@23: my $course_code = $Config{"course-code"};
devi@23: my $course_date = $Config{"course-date"};
devi@23: my $course_center = $Config{"course-center"};
devi@23: my $course_trainer = $Config{"course-trainer"};
devi@23: my $course_student = $Config{"course-student"};
devi@23:
devi@23:
devi@23: # Результат выполнения процедуры равен
devi@23: # join("", @Result{header,body,stat,help,about,footer})
devi@23: my %Result;
devi@23: my $toc =""; # Хранит оглавление по дням
devi@23:
devi@23: $Result{"body"} = "\n";
devi@23:
devi@23: my $cl;
devi@23: my $last_tty="";
devi@23: my $last_day="";
devi@23: my $in_range=0;
devi@23:
devi@23: for my $cl (@Command_Lines) {
devi@23:
devi@23: if ($Config{"from"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"from"}/) {
devi@23: $in_range=1;
devi@23: next;
devi@23: }
devi@23: if ($Config{"to"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"to"}/) {
devi@23: $in_range=0;
devi@23: next;
devi@23: }
devi@23: next if ($Config{"from"} && $Config{"to"} && !$in_range)
devi@23: ||
devi@23: ($Config{"skip_empty"} =~ /^y/i && $cl->{"cline"} =~ /^\s*$/ )
devi@23: ||
devi@23: ($Config{"skip_wrong"} =~ /^y/i && $cl->{"err"} != 0)
devi@23: ||
devi@23: ($Config{"skip_interrupted"} =~ /^y/i && $cl->{"err"} == 130);
devi@23:
devi@23: #my @new_commands=@{$cl->{"new_commands"}};
devi@23: #my @new_files=@{$cl->{"new_files"}};
devi@23:
devi@23: my $cl_class="cline";
devi@23: my $out_class="output";
devi@23: if ($cl->{"class"}) {
devi@23: $cl_class = $cl->{"class"}."_".$cl_class;
devi@23: $out_class = $cl->{"class"}."_".$out_class;
devi@23: }
devi@23:
devi@23: my @new_commands;
devi@23: my @new_files;
devi@23: @new_commands = split (/\s+/, $cl->{"new_commands"}) if defined $cl->{"new_commands"};
devi@23: @new_files = split (/\s+/, $cl->{"new_files"}) if defined $cl->{"new_files"};
devi@23:
devi@23: my $output="";
devi@23: if ($Config{"head_lines"} || $Config{"tail_lines"}) {
devi@23: # Partialy output
devi@23: my @lines = split '\n', $cl->{"output"};
devi@23: # head
devi@23: my $mark=1;
devi@23: for (my $i=0; $i<= $#lines && $i < $Config{"head_lines"}; $i++) {
devi@23: $output .= $lines[$i]."\n";
devi@23: }
devi@23: # tail
devi@23: my $start=$#lines-$Config{"tail_lines"}+1;
devi@23: if ($start < 0) {
devi@23: $start=0;
devi@23: $mark=0;
devi@23: }
devi@23: if ($start < $Config{"head_lines"}) {
devi@23: $start=$Config{"head_lines"};
devi@23: $mark=0;
devi@23: }
devi@23: $output .= $Config{"skip_text"}."\n" if $mark;
devi@23: for (my $i=$start; $i<= $#lines; $i++) {
devi@23: $output .= $lines[$i]."\n";
devi@23: }
devi@23: }
devi@23: else {
devi@23: # Full output
devi@23: $output .= $cl->{"output"};
devi@23: }
devi@23: #$output .= "^C\n" if ($cl->{"err"} eq "130");
devi@23:
devi@23: #
devi@23: ##
devi@23: ## Начинается собственно вывод
devi@23: ##
devi@23: #
devi@23:
devi@23: #
devi@23:
devi@23: my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime($cl->{time});
devi@23: # Добавляем спереди 0 для удобочитаемости
devi@23: $min = "0".$min if $min =~ /^.$/;
devi@23: $hour = "0".$hour if $hour =~ /^.$/;
devi@23: $sec = "0".$sec if $sec =~ /^.$/;
devi@23:
devi@23: $class=$cl->{"out_class"};
devi@23: $class =~ s/output$//;
devi@23:
devi@23:
devi@23: $Result{"body"} .= "\n";
devi@23:
devi@23:
devi@23: # DAY CHANGE
devi@23: if ( $last_day ne $day) {
devi@23: #$Result{"body"} .= "День ",$day," |
";
devi@23: $Result{"body"} .= "".$Day_Name[$wday]." |
";
devi@23: $toc .= "".$Day_Name[$wday]."\n";
devi@23: $last_day=$day;
devi@23: }
devi@23:
devi@23: # CONSOLE CHANGE
devi@23: if ( $last_tty ne $cl->{"tty"}) {
devi@23: $Result{"body"} .= " |
";
devi@23: $last_tty=$cl->{"tty"};
devi@23: }
devi@23:
devi@23: # TIME
devi@23: if ($Config{"show_time"} =~ /^y/i) {
devi@23: $Result{"body"} .= "".
devi@23: $hour. ":". $min. ":". $sec.
devi@23: " | ";
devi@23: } else {
devi@23: $Result{"body"} .= " | "
devi@23: }
devi@23:
devi@23: # COMMAND
devi@23: $Result{"body"} .= "\n";
devi@23: $Result{"body"} .= "\n";
devi@23: my $cline = $cl->{"cline"};
devi@23: $cline =~ s/\n//;
devi@23: $Result{"body"} .= $cl->{"prompt"}.$cl->{"cline"};
devi@23: $Result{"body"} .= " \n";
devi@23:
devi@23: my $last_command = $cl->{"last_command"};
devi@23: if (!(
devi@23: $Config{"suppress_editors"} =~ /^y/i && grep ($_ eq $last_command, @{$Config{"editors"}}) ||
devi@23: $Config{"suppress_pagers"} =~ /^y/i && grep ($_ eq $last_command, @{$Config{"pagers"}}) ||
devi@23: $Config{"suppress_terminal"}=~ /^y/i && grep ($_ eq $last_command, @{$Config{"terminal"}})
devi@23: )) {
devi@23:
devi@23: $Result{"body"} .= "";
devi@23: $Result{"body"} .= $output;
devi@23: $Result{"body"} .= " \n";
devi@23: }
devi@23:
devi@23: # DIFF
devi@23: if ( $Config{"show_diffs"} =~ /^y/i && $cl->{"diff"}) {
devi@23: $Result{"body"} .= " | ";
devi@23: $Result{"body"} .= $cl->{"diff"};
devi@23: $Result{"body"} .= " | ";
devi@23: }
devi@23:
devi@23: # COMMENT
devi@23: if ( $Config{"show_comments"} =~ /^y/i) {
devi@23: my $comment = make_comment(join(" ",@new_commands), join (" ",@new_files));
devi@23: if ($comment) {
devi@23: $Result{"body"} .= "".
devi@23: " | ";
devi@23: $Result{"body"} .= "";
devi@23: $Result{"body"} .= $comment;
devi@23: $Result{"body"} .= " \n";
devi@23: $Result{"body"} .= " | ";
devi@23: }
devi@23: }
devi@23:
devi@23: # Вывод очередной команды окончен
devi@23: $Result{"body"} .= " | \n";
devi@23: $Result{"body"} .= "
\n";
devi@23: }
devi@23:
devi@23: $Result{"body"} .= "
\n";
devi@23:
devi@23: $Result{"stat"} = "
";
devi@23: $Result{"stat"} .= "Статистика
";
devi@23: $Result{"stat"} .= "Статистическая информация о журнале
";
devi@23: $Result{"help"} .= "
";
devi@23: $Result{"help"} .= "Справка
";
devi@23: $Result{"help"} .= "$Html_Help
";
devi@23: $Result{"about"} .= "
";
devi@23: $Result{"about"} .= "О программе
";
devi@23: $Result{"about"} .= "$Html_About";
devi@23: $Result{"footer"} .= "