lilalo

changeset 56:43aeb3036aaa

l3-frontend:

Наведение порядка в коде. Пока что, он ещё достаточно сырой
и некрасивый, но это всё же лучше, чем то, что было раньше.
Добавлено:
* команды, набранные с ошибками показываются зачёркнутым текстом
* в статистике подсвечиваются известные/неизвестные команды,
как раньше по тексту
* в названиях программ/скриптов пути, содержащие /etc, не отрезаются

l3-agent:
Неправильно передавался код завершения. Fixed
Код откровенно мерзкий и требует доработок
author devi
date Wed Dec 28 01:01:00 2005 +0200 (2005-12-28)
parents d3fcff5e3757
children 187b6636a3be
files l3-agent l3-frontend
line diff
     1.1 --- a/l3-agent	Thu Dec 22 11:56:06 2005 +0200
     1.2 +++ b/l3-agent	Wed Dec 28 01:01:00 2005 +0200
     1.3 @@ -814,7 +814,7 @@
     1.4  		print OUT "<raw_file>",$cl->{raw_file},"</raw_file>\n";
     1.5  		print OUT "<tty>",$cl->{tty},"</tty>\n";
     1.6  		print OUT "<out_class>",$out_class,"</out_class>\n";
     1.7 -		print OUT "<err>",$out_class,"</err>\n";
     1.8 +		print OUT "<err>",$cl->{err},"</err>\n";
     1.9  		print OUT "<prompt>";
    1.10  			printq(\*OUT,,$cl->{"prompt"});
    1.11  		print OUT "</prompt>";
     2.1 --- a/l3-frontend	Thu Dec 22 11:56:06 2005 +0200
     2.2 +++ b/l3-frontend	Wed Dec 28 01:01:00 2005 +0200
     2.3 @@ -25,18 +25,21 @@
     2.4  
     2.5  my %mywi_cache_for;         # Кэш для экономии обращений к mywi
     2.6  
     2.7 -
     2.8 -sub search_buy;
     2.9  sub make_comment;
    2.10  sub load_command_lines_from_xml;
    2.11  sub load_sessions_from_xml;
    2.12 -sub print_command_lines;
    2.13  sub sort_command_lines;
    2.14  sub process_command_lines;
    2.15  sub init_variables;
    2.16  sub main;
    2.17  sub collapse_list($);
    2.18  
    2.19 +sub print_all;
    2.20 +sub print_command_lines;
    2.21 +sub print_stat;
    2.22 +sub print_header;
    2.23 +sub print_footer;
    2.24 +
    2.25  main();
    2.26  
    2.27  sub main
    2.28 @@ -51,71 +54,75 @@
    2.29      load_sessions_from_xml($Config{"backend_datafile"});
    2.30      sort_command_lines;
    2.31      process_command_lines;
    2.32 -    print_command_lines($Config{"output"});
    2.33 +    print_all($Config{"output"});
    2.34      close_mywi_socket;
    2.35  }
    2.36  
    2.37 +# extract_from_cline
    2.38  
    2.39 -sub search_by
    2.40 -{
    2.41 -    my $sm = shift;
    2.42 -    my $topic = shift;
    2.43 -    $topic =~ s/ /+/;
    2.44 -    
    2.45 -    return "<a href='". $Search_Machines{$sm}->{"query"}."$topic'><img width='16' height='16' src='".
    2.46 -                $Search_Machines{$sm}->{"icon"}."' border='0'/></a>";
    2.47 -}
    2.48 +# In:   $what       = commands | args
    2.49 +# Out:  return      ссылка на хэш, содержащий результаты разбора
    2.50 +#                   команда => позиция
    2.51  
    2.52 -sub extract_from_cline
    2.53  # Разобрать командную строку $_[1] и возвратить хэш, содержащий 
    2.54  # номер первого появление команды в строке:
    2.55  #   команда => первая позиция
    2.56 +sub extract_from_cline
    2.57  {
    2.58      my $what = $_[0];
    2.59      my $cline = $_[1];
    2.60      my @lists = split /\;/, $cline;
    2.61      
    2.62      
    2.63 -    my @commands = ();
    2.64 -    for my $list (@lists) {
    2.65 -        push @commands, split /\|/, $list;
    2.66 +    my @command_lines = ();
    2.67 +    for my $command_list (@lists) {
    2.68 +        push(@command_lines, split(/\|/, $command_list));
    2.69      }
    2.70  
    2.71 -    my %commands;
    2.72 -    my %args;
    2.73 +    my %position_of_command;
    2.74 +    my %position_of_arg;
    2.75      my $i=0;
    2.76 -    for my $command (@commands) {
    2.77 -        $command =~ s@^\s*\S+/@@;
    2.78 -        $command =~ /\s*(\S+)\s*(.*)/;
    2.79 +    for my $command_line (@command_lines) {
    2.80 +        $command_line =~ s@^\s*@@;
    2.81 +        $command_line =~ /\s*(\S+)\s*(.*)/;
    2.82          if ($1 && $1 eq "sudo" ) {
    2.83 -            $commands{"$1"}=$i++;
    2.84 -            $command =~ s/\s*sudo\s+//;
    2.85 +            $position_of_command{"$1"}=$i++;
    2.86 +            $command_line =~ s/\s*sudo\s+//;
    2.87          }
    2.88 -        $command =~ s@^\s*\S+/@@;
    2.89 -        $command =~ /\s*(\S+)\s*(.*)/;
    2.90 -        if ($1 && !defined $commands{"$1"}) {
    2.91 -                $commands{"$1"}=$i++;
    2.92 +        if ($command_line !~ m@^\s*\S*/etc/@) {
    2.93 +            $command_line =~ s@^\s*\S+/@@;
    2.94 +        }
    2.95 +
    2.96 +        $command_line =~ /\s*(\S+)\s*(.*)/;
    2.97 +        my $command = $1;
    2.98 +        my $args = $2;
    2.99 +        if ($command && !defined $position_of_command{"$command"}) {
   2.100 +                $position_of_command{"$command"}=$i++;
   2.101          };  
   2.102 -        if ($2) {
   2.103 -            my $args = $2;
   2.104 +        if ($args) {
   2.105              my @args = split (/\s+/, $args);
   2.106              for my $a (@args) {
   2.107 -                $args{"$a"}=$i++
   2.108 -                    if !defined $args{"$a"};
   2.109 +                $position_of_arg{"$a"}=$i++
   2.110 +                    if !defined $position_of_arg{"$a"};
   2.111              };  
   2.112 -
   2.113 -                
   2.114          }
   2.115      }
   2.116  
   2.117      if ($what eq "commands") {
   2.118 -        return \%commands;
   2.119 +        return \%position_of_command;
   2.120      } else {
   2.121 -        return \%args;
   2.122 +        return \%position_of_arg;
   2.123      }
   2.124      
   2.125  }
   2.126  
   2.127 +
   2.128 +
   2.129 +
   2.130 +#
   2.131 +# Подпрограммы для работы с mywi
   2.132 +#
   2.133 +
   2.134  sub open_mywi_socket
   2.135  {
   2.136      $Mywi_Socket = IO::Socket::INET->new(
   2.137 @@ -204,6 +211,9 @@
   2.138  Процедура load_command_lines_from_xml выполняет загрузку разобранного lab-скрипта
   2.139  из XML-документа в переменную @Command_Lines
   2.140  
   2.141 +# In:       $datafile           имя файла
   2.142 +# Out:      @CommandLines       загруженные командные строки
   2.143 +
   2.144  Предупреждение!
   2.145  Процедура не в состоянии обрабатывать XML-документ любой структуры.
   2.146  В действительности файл cache из которого загружаются данные 
   2.147 @@ -248,11 +258,12 @@
   2.148  }
   2.149  
   2.150  
   2.151 +# sort_command_lines
   2.152 +# In:   @Command_Lines
   2.153 +# Out:  @Command_Lies_Index
   2.154  
   2.155  sub sort_command_lines
   2.156  {
   2.157 -    # Sort Command_Lines
   2.158 -    # Write Command_Lines to Command_Lines_Index
   2.159  
   2.160      my @index;
   2.161      for (my $i=0;$i<=$#Command_Lines;$i++) {
   2.162 @@ -265,99 +276,87 @@
   2.163  
   2.164  }
   2.165  
   2.166 +##################
   2.167 +# process_command_lines
   2.168 +#
   2.169 +# Обрабатываются командные строки @Command_Lines
   2.170 +# Для каждой строки определяется:
   2.171 +#   class   класс    
   2.172 +#   note    комментарий 
   2.173 +#
   2.174 +# In:        @Command_Lines_Index
   2.175 +# In-Out:    @Command_Lines
   2.176 +
   2.177  sub process_command_lines
   2.178  {
   2.179      for my $i (@Command_Lines_Index) {
   2.180 +        my $cl = \$Command_Lines[$i];
   2.181  
   2.182 -        my $cl = \$Command_Lines[$i];
   2.183 -        #@{${$cl}->{"new_commands"}} =();
   2.184 -        #@{${$cl}->{"new_files"}} =();
   2.185 -        $$cl->{"class"} = ""; 
   2.186 +        next if !$cl;
   2.187  
   2.188 -        if ($$cl->{"err"}) {
   2.189 -            $$cl->{"class"}="wrong";
   2.190 -            $$cl->{"class"}="interrupted"
   2.191 -                if ($$cl->{"err"} eq 130);
   2.192 -        }   
   2.193 +        $$cl->{err} ||=0;
   2.194 +
   2.195 +        # Класс команды
   2.196 +
   2.197 +        $$cl->{"class"} =   $$cl->{"err"} eq 130 ?  "interrupted"
   2.198 +                        :   $$cl->{"err"} eq 127 ?  "mistyped"
   2.199 +                        :   $$cl->{"err"}        ?  "wrong"
   2.200 +                        :                           "";
   2.201 +
   2.202          if (!$$cl->{"euid"}) {
   2.203              $$cl->{"class"}.="_root";
   2.204          }
   2.205 -        
   2.206 -#tab#       my @tab_words=split /\s+/, $$cl->{"output"};
   2.207 -#tab#       my $last_word= $$cl->{"cline"} =~ /(\S*)$/;
   2.208 -#tab#       $last_word =~ s@.*/@@;
   2.209 -#tab#       my $this_is_tab=1;
   2.210 -#tab#
   2.211 -#tab#       if ($last_word && @tab_words >2) {
   2.212 -#tab#           for my $tab_words (@tab_words) {
   2.213 -#tab#               if ($tab_words !~ /^$last_word/) {
   2.214 -#tab#                   $this_is_tab=0;
   2.215 -#tab#                   last;
   2.216 -#tab#               }
   2.217 -#tab#           }
   2.218 -#tab#       }   
   2.219 -#tab#       $$cl->{"class"}="tab" if $this_is_tab;
   2.220 -        
   2.221  
   2.222 -#       if ( !$$cl->{"err"}) {
   2.223 -#           # Command does not contain mistakes
   2.224 -#           
   2.225 -#           my %commands = extract_from_cline("commands", ${$cl}->{"cline"});
   2.226 -#           my %files = extract_from_cline("files", ${$cl}->{"cline"});
   2.227 -#
   2.228 -#           # Searching for new commands only
   2.229 -#           for my $command (keys  %commands) {
   2.230 -#               if (!defined $Commands_Stat{$command}) {
   2.231 -#                   push @{$$cl->{new_commands}}, $command;
   2.232 -#               }   
   2.233 -#               $Commands_Stat{$command}++;
   2.234 -#           }
   2.235 -#           
   2.236 -#           for my $file (keys  %files) {
   2.237 -#               if (!defined $Files_Stat{$file}) {
   2.238 -#                   push @{$$cl->{new_files}}, $file;
   2.239 -#               }   
   2.240 -#               $Files_Stat{$file}++;
   2.241 -#           }
   2.242 -#       }   
   2.243 +
   2.244 +#Обработка пометок
   2.245 +#  Если несколько пометок (notes) идут подряд, 
   2.246 +#  они все объединяются
   2.247  
   2.248          if ($$cl->{cline}=~ m@cat[^#]*#([\^=v])\s*(.*)@) {
   2.249 -            if ($1 eq "=") {
   2.250 +
   2.251 +            my $note_operator = $1;
   2.252 +            my $note_title = $2;
   2.253 +
   2.254 +            if ($note_operator eq "=") {
   2.255                  $$cl->{"class"} = "note";
   2.256                  $$cl->{"note"} = $$cl->{"output"};
   2.257                  $$cl->{"note_title"} = $2;
   2.258              }
   2.259              else {
   2.260                  my $j = $i;
   2.261 -                if ($1 eq "^") {
   2.262 +                if ($note_operator eq "^") {
   2.263                      $j--;
   2.264                      $j-- while ($j >=0  && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty}));
   2.265                  }
   2.266 -                elsif ($1 eq "v") {
   2.267 +                elsif ($note_operator eq "v") {
   2.268                      $j++;
   2.269                      $j++ while ($j <= @Command_Lines  && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty}));
   2.270                  }
   2.271 -                $Command_Lines[$j]->{note_title}="$2";
   2.272 -                $Command_Lines[$j]->{note}=$$cl->{output};
   2.273 +                $Command_Lines[$j]->{note_title}=$note_title;
   2.274 +                $Command_Lines[$j]->{note}.=$$cl->{output};
   2.275                  $$cl=0;
   2.276              }
   2.277          }
   2.278          elsif ($$cl->{cline}=~ /#([\^=v])(.*)/) {
   2.279 -            if ($1 eq "=") {
   2.280 +
   2.281 +            my $note_operator = $1;
   2.282 +            my $note_text = $2;
   2.283 +
   2.284 +            if ($note_operator eq "=") {
   2.285                  $$cl->{"class"} = "note";
   2.286 -                $$cl->{"note"} = $2;
   2.287 +                $$cl->{"note"} = $note_text;
   2.288              }
   2.289              else {
   2.290                  my $j=$i;
   2.291 -                if ($1 eq "^") {
   2.292 +                if ($note_operator eq "^") {
   2.293                      $j--;
   2.294                      $j-- while ($j >=0  && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty}));
   2.295                  }
   2.296 -                elsif ($1 eq "v") {
   2.297 +                elsif ($note_operator eq "v") {
   2.298                      $j++;
   2.299                      $j++ while ($j <= @Command_Lines  && $Command_Lines[$j]->{tty} ne $$cl->{tty} || !$Command_Lines[$j]);
   2.300                  }
   2.301 -                $Command_Lines[$j]->{note}.="$2\n";
   2.302 +                $Command_Lines[$j]->{note}.="$note_text\n";
   2.303                  $$cl=0;
   2.304              }
   2.305          }
   2.306 @@ -375,64 +374,74 @@
   2.307  
   2.308  sub print_command_lines
   2.309  {
   2.310 -    my $output_filename=$_[0];
   2.311  
   2.312 -    my $course_name = $Config{"course-name"};
   2.313 -    my $course_code = $Config{"course-code"};
   2.314 -    my $course_date = $Config{"course-date"};
   2.315 -    my $course_center = $Config{"course-center"};
   2.316 -    my $course_trainer = $Config{"course-trainer"};
   2.317 -    my $course_student = $Config{"course-student"};
   2.318 -    
   2.319 -
   2.320 -    # Результат выполнения процедуры равен 
   2.321 -    # join("", @Result{header,body,stat,help,about,footer})
   2.322 -    my %Result;
   2.323 -    my @toc;  # Хранит оглавление
   2.324 +    my @toc;                # Оглавление
   2.325      my $note_number=0;
   2.326  
   2.327 -    $Result{"body"} = "<table width='100%'>\n";
   2.328 +    my $result = q();
   2.329 +    my $this_day_resut = q();
   2.330      
   2.331      my $cl;
   2.332      my $last_tty="";
   2.333 -    my $last_day="";
   2.334 +    my $last_day=q();
   2.335 +    my $last_wday=q();
   2.336      my $in_range=0;
   2.337  
   2.338      my $current_command=0;
   2.339  
   2.340 +    my %filter;
   2.341 +
   2.342 +    if ($Config{filter}) {
   2.343 +        # Инициализация фильтра
   2.344 +        my %filter;
   2.345 +        for (split /&/,$Config{filter}) {
   2.346 +            my ($var, $val) = split /=/;
   2.347 +            $filter{$var} = $val || "";
   2.348 +        }
   2.349 +    }
   2.350 +
   2.351 +    $Stat{LastCommand}   ||= 0;
   2.352 +    $Stat{TotalCommands} ||= 0;
   2.353 +    $Stat{ErrorCommands} ||= 0;
   2.354 +    $Stat{MistypedCommands} ||= 0;
   2.355 +
   2.356  COMMAND_LINE:
   2.357      for my $k (@Command_Lines_Index) {
   2.358  
   2.359          my $cl=$Command_Lines[$Command_Lines_Index[$current_command++]];
   2.360 -        
   2.361          next unless $cl;
   2.362  
   2.363 +# Пропускаем команды, с одинаковым временем
   2.364 +# Это не совсем правильно.
   2.365 +# Возможно, что это команды, набираемые с помощью <completion>
   2.366 +# или запомненные с помощью <ctrl-c>
   2.367  
   2.368 -        if ($Config{filter}) {
   2.369 -            # Инициализация фильтра
   2.370 -            my %filter;
   2.371 -            for (split /&/,$Config{filter}) {
   2.372 -                my ($var, $val) = split /=/;
   2.373 -                $filter{$var} = $val || "";
   2.374 -            }
   2.375 +        next if $Stat{LastCommand} == $cl->{time};
   2.376  
   2.377 -            for my $filter_key (keys %filter) {
   2.378 -                next COMMAND_LINE if 
   2.379 -                    defined($cl->{local_session_id}) 
   2.380 -                    && defined($Sessions{$cl->{local_session_id}}->{$filter_key}) 
   2.381 -                    && $Sessions{$cl->{local_session_id}}->{$filter_key} ne $filter{$filter_key};
   2.382 -		#print $filter_key,"\n";	
   2.383 -            }
   2.384 +# Набираем статистику
   2.385 +# Хэш %Stat
   2.386  
   2.387 -            #if ($filter{user}) {
   2.388 -            #   next COMMAND_LINE unless $Sessions{$cl->{local_session_id}}->{user} eq $filter{user};
   2.389 -            #}
   2.390 +        $Stat{FirstCommand} = $cl->{time} unless $Stat{FirstCommand};
   2.391 +        if ($cl->{time} - $Stat{LastCommand} < $Config{stat_inactivity_interval}) {
   2.392 +            $Stat{TotalTime} += $cl->{time} - $Stat{LastCommand}
   2.393 +        }
   2.394 +        $Stat{LastCommand} = $cl->{time};
   2.395 +        $Stat{TotalCommands}++;
   2.396  
   2.397 -            #for my $filter_field (keys %filter) {
   2.398 -            #   next COMMAND_LINE unless $Sessions{$cl->{local_session_id}}->{$filter_field} eq $filter{$filter_field};
   2.399 -            #}
   2.400 +# Пропускаем строки, которые противоречат фильтру
   2.401 +# Если у нас недостаточно информации о том, подходит строка под  фильтр или нет, 
   2.402 +# мы её выводим
   2.403 +
   2.404 +        for my $filter_key (keys %filter) {
   2.405 +            next COMMAND_LINE if 
   2.406 +                defined($cl->{local_session_id}) 
   2.407 +                && defined($Sessions{$cl->{local_session_id}}->{$filter_key}) 
   2.408 +                && $Sessions{$cl->{local_session_id}}->{$filter_key} ne $filter{$filter_key};
   2.409          }
   2.410  
   2.411 +# Пропускаем строки, выходящие за границу "signature",
   2.412 +# при условии, что границы указаны
   2.413 +# Пропускаем неправильные/прерванные/другие команды
   2.414          if ($Config{"from"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"from"}/) {
   2.415              $in_range=1;
   2.416              next;
   2.417 @@ -441,25 +450,19 @@
   2.418              $in_range=0;
   2.419              next;
   2.420          }
   2.421 -        next if ($Config{"from"} && $Config{"to"} && !$in_range) 
   2.422 -            ||
   2.423 -                ($Config{"skip_empty"} =~ /^y/i && $cl->{"cline"} =~ /^\s*$/ )
   2.424 -            ||
   2.425 -            ($Config{"skip_wrong"} =~ /^y/i && $cl->{"err"} != 0)
   2.426 -            ||
   2.427 -            ($Config{"skip_interrupted"} =~ /^y/i && $cl->{"err"} == 130);
   2.428 +        next    if ($Config{"from"} && $Config{"to"}   && !$in_range) 
   2.429 +                || ($Config{"skip_empty"} =~ /^y/i     && $cl->{"cline"} =~ /^\s*$/ )
   2.430 +                || ($Config{"skip_wrong"} =~ /^y/i     && $cl->{"err"} != 0)
   2.431 +                || ($Config{"skip_interrupted"} =~ /^y/i && $cl->{"err"} == 130);
   2.432          
   2.433 -        #my @new_commands=@{$cl->{"new_commands"}};
   2.434 -        #my @new_files=@{$cl->{"new_files"}};
   2.435 -
   2.436          if ($cl->{class} eq "note") {
   2.437              my $note = $cl->{note};
   2.438              $note = join ("\n", map ("<p>$_</p>", split (/-\n/, $note)));
   2.439              $note =~ s@(http:[a-zA-Z.0-9/?\_%-]*)@<a href='$1'>$1</a>@g;
   2.440              $note =~ s@(www\.[a-zA-Z.0-9/?\_%-]*)@<a href='$1'>$1</a>@g;
   2.441 -            $Result{"body"} .= "<tr><td colspan='6'>";
   2.442 -            $Result{"body"} .= "<h4 id='note$note_number'>".$cl->{note_title}."</h4>" if $cl->{note_title};
   2.443 -            $Result{"body"} .= "".$note."<p/><p/></td></td>";
   2.444 +            $result .= "<tr><td colspan='6'>";
   2.445 +            $result .= "<h4 id='note$note_number'>".$cl->{note_title}."</h4>" if $cl->{note_title};
   2.446 +            $result .= "".$note."<p/><p/></td></td>";
   2.447  
   2.448              if ($cl->{note_title}) {
   2.449                  push @{$toc[@toc]},"<a href='#note$note_number'>".$cl->{note_title}."</a>";
   2.450 @@ -468,192 +471,343 @@
   2.451              next;
   2.452          }
   2.453  
   2.454 -        my $cl_class="cline";
   2.455 -        my $out_class="output";
   2.456 -        if ($cl->{"class"}) {
   2.457 -            $cl_class = $cl->{"class"}."_".$cl_class;
   2.458 -            $out_class = $cl->{"class"}."_".$out_class;
   2.459 -        }
   2.460 -
   2.461 -        my @new_commands;
   2.462 -        my @new_files;
   2.463 -        @new_commands = split (/\s+/, $cl->{"new_commands"}) if defined $cl->{"new_commands"};
   2.464 -        @new_files = split (/\s+/, $cl->{"new_files"}) if defined $cl->{"new_files"};
   2.465  
   2.466          my $output="";
   2.467 -        if ($Config{"head_lines"} || $Config{"tail_lines"}) {
   2.468 -            # Partialy output
   2.469 -            my @lines = split '\n', $cl->{"output"};
   2.470 -            # head
   2.471 -            my $mark=1;
   2.472 +# Выводим <head_lines> верхних строк
   2.473 +# и <tail_lines> нижних строк,
   2.474 +# если эти параметры существуют
   2.475 +
   2.476 +        my @lines = split '\n', $cl->{"output"};
   2.477 +        if (($Config{"head_lines"} || $Config{"tail_lines"})
   2.478 +             && $#lines >  $Config{"head_lines"} + $Config{"tail_lines"} ) {
   2.479 +
   2.480              for (my $i=0; $i<= $#lines && $i < $Config{"head_lines"}; $i++) {
   2.481                  $output .= $lines[$i]."\n";
   2.482              }
   2.483 -            # tail
   2.484 -            my $start=$#lines-$Config{"tail_lines"}+1;
   2.485 -            if ($start < 0) {
   2.486 -                $start=0;
   2.487 -                $mark=0;
   2.488 -            }   
   2.489 -            if ($start < $Config{"head_lines"}) {
   2.490 -                $start=$Config{"head_lines"};
   2.491 -                $mark=0;
   2.492 -            }   
   2.493 -            $output .= $Config{"skip_text"}."\n" if $mark;
   2.494 -            for ($i=$start; $i<= $#lines; $i++) {
   2.495 +            $output .= $Config{"skip_text"}."\n";
   2.496 +
   2.497 +            my $start_line=$#lines-$Config{"tail_lines"}+1;
   2.498 +            for ($i=$start_line; $i<= $#lines; $i++) {
   2.499                  $output .= $lines[$i]."\n";
   2.500              }
   2.501          } 
   2.502          else {
   2.503 -            # Full output
   2.504              $output .= $cl->{"output"};
   2.505          }   
   2.506 -        #$output .= "^C\n" if ($cl->{"err"} eq "130");
   2.507  
   2.508 -        #
   2.509 -        ##
   2.510 -        ## Начинается собственно вывод
   2.511 -        ##
   2.512 -        #
   2.513 -
   2.514 -        # <command>
   2.515 +#
   2.516 +##
   2.517 +## Начинается собственно вывод
   2.518 +##
   2.519 +#
   2.520  
   2.521          my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime($cl->{time});
   2.522 -        next if $Stat{LastCommand} == $cl->{time};
   2.523 -        $Stat{FirstCommand} = $cl->{time} unless $Stat{FirstCommand};
   2.524 -        $Stat{LastCommand} = 0 unless defined $Stat{LastCommand};   
   2.525 -        $Stat{TotalTime} += $cl->{time} - $Stat{LastCommand}
   2.526 -            if $cl->{time} - $Stat{LastCommand} < $Config{stat_inactivity_interval};
   2.527 -        $Stat{LastCommand} = $cl->{time};
   2.528 -        $Stat{TotalCommands} = 0 unless $Stat{TotalCommands};
   2.529 -        $Stat{TotalCommands}++;
   2.530  
   2.531          # Добавляем спереди 0 для удобочитаемости
   2.532 -        $min = "0".$min if $min =~ /^.$/;
   2.533 +        $min  = "0".$min  if $min  =~ /^.$/;
   2.534          $hour = "0".$hour if $hour =~ /^.$/;
   2.535 -        $sec = "0".$sec if $sec =~ /^.$/;
   2.536 +        $sec  = "0".$sec  if $sec  =~ /^.$/;
   2.537  
   2.538 -        $class=$cl->{"out_class"};
   2.539 -        $class =~ s/output$//;
   2.540 +        #my @new_commands;
   2.541 +        #my @new_files;
   2.542 +        #@new_commands = split (/\s+/, $cl->{"new_commands"}) if defined $cl->{"new_commands"};
   2.543 +        #@new_files = split (/\s+/, $cl->{"new_files"}) if defined $cl->{"new_files"};
   2.544  
   2.545 -        $Stat{ErrorCommands}++
   2.546 -            if $class =~ /wrong/;
   2.547 +        $class=$cl->{"class"};
   2.548 +        $Stat{ErrorCommands}++          if $class =~ /wrong/;
   2.549 +        $Stat{MistypedCommands}++       if $class =~ /mistype/;
   2.550          
   2.551 -        $Result{"body"} .= "<tr class='command'>\n";
   2.552 -                        
   2.553          
   2.554 -        # DAY CHANGE
   2.555 +# DAY CHANGE
   2.556          if ( $last_day ne $day) {
   2.557 -            #$Result{"body"} .= "<td colspan='6'><p></p><h3>День ",$day,"</h4></td></tr><tr>";
   2.558 -            $Result{"body"} .= "<td colspan='6'><p></p><h3 id='day$day'>".$Day_Name[$wday]."</h4></td></tr><tr>";
   2.559 +            if ($last_day) {
   2.560 +                $result .= "<h3 id='day$last_day'>".$Day_Name[$last_wday]."</h3>";
   2.561 +                #$result .= "Новые команды<br/>";
   2.562 +                $result .= "<table width='100%'>\n";
   2.563 +                $result .= $this_day_result;
   2.564 +                $result .= "</table>";
   2.565 +            }
   2.566 +
   2.567              push @toc, "<a href='#day$day'>".$Day_Name[$wday]."</a>\n";
   2.568              $last_day=$day;
   2.569 +            $last_wday=$wday;
   2.570 +            $this_day_result = q();
   2.571          }
   2.572  
   2.573 -        # CONSOLE CHANGE
   2.574 +        $this_day_result .= "<tr class='command'>\n";
   2.575 +                        
   2.576 +
   2.577 +# CONSOLE CHANGE
   2.578          if ( $last_tty ne $cl->{"tty"}) {
   2.579 -            my $host;
   2.580 -            #$host = $Sessions{$cl->{local_session_id}}->{user}."@".$Sessions{$cl->{local_session_id}}->{hostname};
   2.581 -            my $body = $cl->{"tty"};
   2.582 -            $body .= " \@$host" if $host;
   2.583 -            $Result{"body"} .= "<td colspan='6'><table><tr><td class='ttychange' width='140' align='center'>".$body."</td></tr></table></td></tr><tr>";
   2.584 +            my $tty = $cl->{"tty"};
   2.585 +            $this_day_result .= "<td colspan='6'>"
   2.586 +                                ."<table><tr><td class='ttychange' width='140' align='center'>"
   2.587 +                                . $tty
   2.588 +                                ."</td></tr></table>"
   2.589 +                                ."</td></tr><tr>";
   2.590              $last_tty=$cl->{"tty"};
   2.591          }
   2.592  
   2.593 -        # TIME
   2.594 -        if ($Config{"show_time"} =~ /^y/i) {
   2.595 -            $Result{"body"} .= "<td valign='top' class='time' width='$Config{time_width}'><pre>".
   2.596 -                $hour. ":". $min. ":". $sec.
   2.597 -                "</td>";
   2.598 -        } else {
   2.599 -            $Result{"body"} .= "<td width='0'/>"
   2.600 -        }
   2.601 +# TIME
   2.602 +        $this_day_result .= $Config{"show_time"} =~ /^y/i
   2.603 +                 ? "<td valign='top' class='time' width='$Config{time_width}'>$hour:$min:$sec</td>"
   2.604 +                 : "<td width='0'/>";
   2.605  
   2.606 -        # COMMAND
   2.607 -        $Result{"body"} .= "<td class='script'>\n";
   2.608 -        $Result{"body"} .= "<pre class='${class}cline'>\n";
   2.609 -        my $cline = $cl->{"prompt"}.$cl->{"cline"};
   2.610 +# COMMAND
   2.611 +        my $hint = make_comment($cl->{"cline"});
   2.612 +
   2.613 +        my $cline;
   2.614 +        $cline = $cl->{"prompt"}.$cl->{"cline"};
   2.615          $cline =~ s/\n//;
   2.616  
   2.617 -        #$cline .= "(".$Sessions{$cl->{local_session_id}}.")";
   2.618 -        
   2.619 -        my $hint = make_comment($cl->{"cline"});
   2.620          $cline = "<span title='$hint' class='with_hint'>$cline</span>" if $hint;
   2.621          $cline = "<span class='without_hint'>$cline</span>" if !$hint;
   2.622 -        $Result{"body"} .= $cline;
   2.623 -        $Result{"body"} .= "</pre>\n";
   2.624  
   2.625 +        $this_day_result .= "<td class='script'>\n";
   2.626 +        $this_day_result .= "<pre class='${class}_cline'>\n" . $cline . "</pre>\n";
   2.627 +
   2.628 +# OUTPUT
   2.629          my $last_command = $cl->{"last_command"};
   2.630          if (!( 
   2.631          $Config{"suppress_editors"} =~ /^y/i && grep ($_ eq $last_command, @{$Config{"editors"}}) ||
   2.632          $Config{"suppress_pagers"}  =~ /^y/i && grep ($_ eq $last_command, @{$Config{"pagers"}}) ||
   2.633          $Config{"suppress_terminal"}=~ /^y/i && grep ($_ eq $last_command, @{$Config{"terminal"}})
   2.634              )) {
   2.635 -
   2.636 -            $Result{"body"} .= "<pre class='".$cl->{out_class}."'>";
   2.637 -            $Result{"body"} .= $output;
   2.638 -            $Result{"body"} .= "</pre>\n";
   2.639 +            $this_day_result .= "<pre class='".$class."_output'>" . $output . "</pre>\n";
   2.640          }   
   2.641  
   2.642 -        # DIFF
   2.643 +# DIFF
   2.644          if ( $Config{"show_diffs"} =~ /^y/i && $cl->{"diff"}) {
   2.645 -            $Result{"body"} .= "<table><tr><td width='5'/><td class='diff'><pre>";
   2.646 -            $Result{"body"} .= $cl->{"diff"};
   2.647 -            $Result{"body"} .= "</pre></td></tr></table>";
   2.648 +            $this_day_result .= "<table><tr><td width='5'/><td class='diff'><pre>"
   2.649 +                    .  $cl->{"diff"}
   2.650 +                    .  "</pre></td></tr></table>";
   2.651          }
   2.652 -        
   2.653 -        #NOTES
   2.654 +
   2.655 +#NOTES
   2.656          if ( $Config{"show_notes"} =~ /^y/i && $cl->{"note"}) {
   2.657              my $note=$cl->{"note"};
   2.658              $note =~ s/\n/<br\/>\n/msg;
   2.659              if (not $note =~ s@(http:[a-zA-Z.0-9/_?%-]*)@<a href='$1'>$1</a>@g) {
   2.660 -		     $note =~ s@(www\.[a-zA-Z.0-9/_?%-]*)@<a href='$1'>$1</a>@g;
   2.661 -	    };
   2.662 +              $note =~ s@(www\.[a-zA-Z.0-9/_?%-]*)@<a href='$1'>$1</a>@g;
   2.663 +            };
   2.664          #   Ширину пока не используем
   2.665 -        #   $Result{"body"} .= "<table width='$Config{note_width}' class='note'>";
   2.666 -            $Result{"body"} .= "<table class='note'>";
   2.667 -            $Result{"body"} .= "<tr><td class='note_title'>".$cl->{note_title}."</td></tr>" if $cl->{note_title};
   2.668 -            $Result{"body"} .= "<tr><td width='100%' class='note_text'>".$note."</td></tr>";
   2.669 -            $Result{"body"} .= "</table>\n";
   2.670 +        #   $this_day_result .= "<table width='$Config{note_width}' class='note'>";
   2.671 +            $this_day_result .= "<table class='note'>";
   2.672 +            $this_day_result .= "<tr><td class='note_title'>".$cl->{note_title}."</td></tr>" if $cl->{note_title};
   2.673 +            $this_day_result .= "<tr><td width='100%' class='note_text'>".$note."</td></tr>";
   2.674 +            $this_day_result .= "</table>\n";
   2.675          }
   2.676  
   2.677 -        # COMMENT
   2.678 +# COMMENT
   2.679          if ( $Config{"show_comments"} =~ /^y/i) {
   2.680              my $comment = make_comment($cl->{"cline"});
   2.681              if ($comment) {
   2.682 -                $Result{"body"} .= "<table width='$Config{comment_width}'>".
   2.683 -                        "<tr><td width='5'/><td>";
   2.684 -                $Result{"body"} .= "<table class='note' width='100%'>";
   2.685 -                $Result{"body"} .= $comment;
   2.686 -                $Result{"body"} .= "</table>\n";
   2.687 -                $Result{"body"} .= "</td></tr></table>";
   2.688 +                $this_day_result .= "<table width='$Config{comment_width}'><tr><td width='5'/><td>"
   2.689 +                        .  "<table class='note' width='100%'>"
   2.690 +                        .  $comment
   2.691 +                        .  "</table>\n"
   2.692 +                        .  "</td></tr></table>";
   2.693              }
   2.694          }
   2.695  
   2.696          # Вывод очередной команды окончен
   2.697 -        $Result{"body"} .= "</td>\n";
   2.698 -        $Result{"body"} .= "</tr>\n";
   2.699 +        $this_day_result .= "</td>\n";
   2.700 +        $this_day_result .= "</tr>\n";
   2.701      }
   2.702  
   2.703 -    $Result{"body"} .= "</table>\n";
   2.704 +    $result .= "<h3 id='day$last_day'>".$Day_Name[$last_wday]."</h3>";
   2.705 +    $result .= "<table width='100%'>\n";
   2.706 +    $result .= $this_day_result;
   2.707 +    $result .= "</table>";
   2.708  
   2.709 -    #$Result{"stat"} = "<hr/>";
   2.710 +    return ($result, collapse_list (\@toc));
   2.711  
   2.712 +}
   2.713 +
   2.714 +
   2.715 +
   2.716 +
   2.717 +#############
   2.718 +# print_all
   2.719 +#
   2.720 +#
   2.721 +#
   2.722 +# In:       $_[0]       output_filename
   2.723 +# Out:
   2.724 +
   2.725 +
   2.726 +sub print_all
   2.727 +{
   2.728 +    my $output_filename=$_[0];
   2.729 +
   2.730 +    my $result;
   2.731 +    my ($command_lines,$toc)  = print_command_lines;
   2.732 +
   2.733 +    $result = print_header($toc);
   2.734 +    $result.= "<h2 id='log'>Журнал</h2>"       . $command_lines;
   2.735 +    $result.= "<h2 id='stat'>Статистика</h2>"  . print_stat;
   2.736 +    $result.= "<h2 id='help'>Справка</h2>"     . $Html_Help . "<br/>"; 
   2.737 +    $result.= "<h2 id='about'>О программе</h2>". $Html_About. "<br/>"; 
   2.738 +    $result.= print_footer;
   2.739 +
   2.740 +    if ($output_filename eq "-") {
   2.741 +        print $result;
   2.742 +    }
   2.743 +    else {
   2.744 +        open(OUT, ">", $output_filename)
   2.745 +            or die "Can't open $output_filename for writing\n";
   2.746 +        print OUT $result;
   2.747 +        close(OUT);
   2.748 +    }
   2.749 +}
   2.750 +
   2.751 +#############
   2.752 +# print_header
   2.753 +#
   2.754 +#
   2.755 +#
   2.756 +# In:   $_[0]       Содержание
   2.757 +# Out:              Распечатанный заголовок
   2.758 +
   2.759 +sub print_header
   2.760 +{
   2.761 +    my $toc = $_[0];
   2.762 +    my $course_name = $Config{"course-name"};
   2.763 +    my $course_code = $Config{"course-code"};
   2.764 +    my $course_date = $Config{"course-date"};
   2.765 +    my $course_center = $Config{"course-center"};
   2.766 +    my $course_trainer = $Config{"course-trainer"};
   2.767 +    my $course_student = $Config{"course-student"};
   2.768 +
   2.769 +    my $title    = "Журнал лабораторных работ";
   2.770 +    $title      .= " -- ".$course_student if $course_student;
   2.771 +    if ($course_date) {
   2.772 +        $title  .= " -- ".$course_date; 
   2.773 +        $title  .= $course_code ? "/".$course_code 
   2.774 +                                : "";
   2.775 +    }
   2.776 +    else {
   2.777 +        $title  .= " -- ".$course_code if $course_code;
   2.778 +    }
   2.779 +
   2.780 +    # Управляющая форма
   2.781 +    my $control_form .= "<table id='visibility_form' class='visibility_form'><tr><td>Видимые элементы</TD></tr><tr><td><form>\n";
   2.782 +    for my $element (keys %Elements_Visibility)
   2.783 +    {
   2.784 +        my @e = split /\s+/, $element;
   2.785 +        my $showhide = join "", map { "ShowHide('$_');" } @e ;
   2.786 +        $control_form .= "<input type='checkbox' name='$e[0]' onclick=\"$showhide\" checked>".
   2.787 +                $Elements_Visibility{$element}.
   2.788 +                "</input><br>\n";
   2.789 +    }
   2.790 +    $control_form .= "</form></td></tr></table>\n";
   2.791 +
   2.792 +    my $result;
   2.793 +    $result = <<HEADER;
   2.794 +    <html>
   2.795 +    <head>
   2.796 +    <meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
   2.797 +    <link rel='stylesheet' href='$Config{frontend_css}' type='text/css'/>
   2.798 +    <title>$title</title>
   2.799 +    </head>
   2.800 +    <body>
   2.801 +    <script>
   2.802 +    $Html_JavaScript
   2.803 +    </script>
   2.804 +    <h1>Журнал лабораторных работ</h1>
   2.805 +HEADER
   2.806 +    if (    $course_student 
   2.807 +            || $course_trainer 
   2.808 +            || $course_name 
   2.809 +            || $course_code 
   2.810 +            || $course_date 
   2.811 +            || $course_center) {
   2.812 +            $result .= "<p>";
   2.813 +            $result .= "Выполнил $course_student<br/>"  if $course_student;
   2.814 +            $result .= "Проверил $course_trainer <br/>" if $course_trainer;
   2.815 +            $result .= "Курс "                          if $course_name 
   2.816 +                                                            || $course_code 
   2.817 +                                                            || $course_date;
   2.818 +            $result .= "$course_name "                  if $course_name;
   2.819 +            $result .= "($course_code)"                 if $course_code;
   2.820 +            $result .= ", $course_date<br/>"            if $course_date;
   2.821 +            $result .= "Учебный центр $course_center <br/>" if $course_center;
   2.822 +            $result .= "</p>";
   2.823 +    }
   2.824 +
   2.825 +    $result .= <<HEADER;
   2.826 +    <table width='100%'>
   2.827 +    <tr>
   2.828 +    <td width='*'>
   2.829 +
   2.830 +    <table border=0 id='toc' class='toc'>
   2.831 +    <tr>
   2.832 +    <td>
   2.833 +    <div class='toc_title'>Содержание</div>
   2.834 +    <ul>
   2.835 +        <li><a href='#log'>Журнал</a></li>
   2.836 +        <ul>$toc</ul>
   2.837 +        <li><a href='#stat'>Статистика</a></li>
   2.838 +        <li><a href='#help'>Справка</a></li>
   2.839 +        <li><a href='#about'>О программе</a></li>
   2.840 +    </ul>
   2.841 +    </td>
   2.842 +    </tr>
   2.843 +    </table>
   2.844 +
   2.845 +    </td>
   2.846 +    <td valign='top' width=200>$control_form</td>
   2.847 +    </tr>
   2.848 +    </table>
   2.849 +HEADER
   2.850 +
   2.851 +    return $result;
   2.852 +}
   2.853 +
   2.854 +
   2.855 +#############
   2.856 +# print_footer
   2.857 +#
   2.858 +#
   2.859 +#
   2.860 +#
   2.861 +#
   2.862 +
   2.863 +sub print_footer
   2.864 +{
   2.865 +    return "</body>\n</html>\n";
   2.866 +}
   2.867 +
   2.868 +
   2.869 +
   2.870 +
   2.871 +#############
   2.872 +# print_stat
   2.873 +#
   2.874 +#
   2.875 +#
   2.876 +# In:
   2.877 +# Out:
   2.878 +
   2.879 +sub print_stat
   2.880 +{
   2.881      %StatNames = (
   2.882 -        FirstCommand => "Время первой команды журнала",
   2.883 -        LastCommand => "Время последней команды журнала",
   2.884 -        TotalCommands => "Количество командных строк в журнале",
   2.885 -        ErrorsPercentage => "Процент команд с ненулевым кодом завершения, %",
   2.886 -        TotalTime => "Суммарное время работы с терминалом <sup><font size='-2'>*</font></sup>, час",
   2.887 -        CommandsPerTime => "Количество командных строк в единицу времени, команда/мин",
   2.888 -        CommandsFrequency => "Частота использования команд",
   2.889 -        RareCommands    => "Частота использования этих команд < 0.5%",
   2.890 +        FirstCommand        => "Время первой команды журнала",
   2.891 +        LastCommand         => "Время последней команды журнала",
   2.892 +        TotalCommands       => "Количество командных строк в журнале",
   2.893 +        ErrorsPercentage    => "Процент команд с ненулевым кодом завершения, %",
   2.894 +        MistypesPercentage  => "Процент синтаксически неверное набранных команд, %",
   2.895 +        TotalTime           => "Суммарное время работы с терминалом <sup><font size='-2'>*</font></sup>, час",
   2.896 +        CommandsPerTime     => "Количество командных строк в единицу времени, команда/мин",
   2.897 +        CommandsFrequency   => "Частота использования команд",
   2.898 +        RareCommands        => "Частота использования этих команд < 0.5%",
   2.899      );
   2.900      @StatOrder = (
   2.901          FirstCommand,
   2.902          LastCommand,
   2.903          TotalCommands,
   2.904          ErrorsPercentage,
   2.905 +        MistypesPercentage,
   2.906          TotalTime,
   2.907          CommandsPerTime,
   2.908          CommandsFrequency,
   2.909 @@ -671,8 +825,10 @@
   2.910      $Stat{FirstCommand} = sprintf "%02i:%02i:%02i %04i-%2i-%2i", $hour, $min, $sec,  $year+1900, $mon+1, $mday;
   2.911      ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($Stat{LastCommand} || 0);
   2.912      $Stat{LastCommand} = sprintf "%02i:%02i:%02i %04i-%2i-%2i", $hour, $min, $sec,  $year+1900, $mon+1, $mday;
   2.913 -    $Stat{ErrorsPercentage} = sprintf "%5.2f", $Stat{ErrorCommands}*100/$Stat{TotalCommands}    
   2.914 -        if $Stat{TotalCommands};
   2.915 +    if ($Stat{TotalCommands}) {
   2.916 +        $Stat{ErrorsPercentage} = sprintf "%5.2f", $Stat{ErrorCommands}*100/$Stat{TotalCommands};
   2.917 +        $Stat{MistypesPercentage} = sprintf "%5.2f", $Stat{MistypedCommands}*100/$Stat{TotalCommands};
   2.918 +    }
   2.919      $Stat{CommandsPerTime} = sprintf "%5.2f", $Stat{TotalCommands}*60/$Stat{TotalTime}
   2.920          if $Stat{TotalTime};
   2.921      $Stat{TotalTime} = sprintf "%5.2f", $Stat{TotalTime}/60/60;
   2.922 @@ -688,14 +844,16 @@
   2.923              if ($percentage < 0.5) {
   2.924                  my $hint = make_comment($command);
   2.925                  $command_html = "$command";
   2.926 -                $command_html = "<span title='$hint' class='hint'>$command_html</span>" if $hint;
   2.927 +                $command_html = "<span title='$hint' class='with_hint'>$command_html</span>" if $hint;
   2.928 +                $command_html = "<span class='without_hint'>$command_html</span>" if not $hint;
   2.929                  my $command_html = "<tt>$command_html</tt>";
   2.930                  $Stat{RareCommands} .= $command_html."<sub><font size='-2'>".$CommandsFrequency{$command}."</font></sub> , ";
   2.931              }
   2.932              else {
   2.933                  my $hint = make_comment($command);
   2.934                  $command_html = "$command";
   2.935 -                $command_html = "<span title='$hint' class='hint'>$command_html</span>" if $hint;
   2.936 +                $command_html = "<span title='$hint' class='with_hint'>$command_html</span>" if $hint;
   2.937 +                $command_html = "<span class='without_hint'>$command_html</span>" if not $hint;
   2.938                  my $command_html = "<tt>$command_html</tt>";
   2.939                  $percentage = sprintf "%5.2f",$percentage;
   2.940                  $Stat{CommandsFrequency} .= "<tr><td>".$command_html."</td><td>".$CommandsFrequency{$command}."</td>".
   2.941 @@ -706,106 +864,20 @@
   2.942          $Stat{RareCommands} =~ s/, $// if $Stat{RareCommands};
   2.943      }
   2.944  
   2.945 -    $Result{"stat"} .= "<h2 id='stat'>Статистика</h2>";
   2.946 -    $Result{"stat"} .= "<table>";
   2.947 +    my $result = q();
   2.948      for my $stat (@StatOrder) {
   2.949 -    $Result{"stat"} .= "<tr valign='top'><td width='300'>".$StatNames{"$stat"}."</td><td>".$Stat{"$stat"}."</td></tr>"
   2.950 -        if $Stat{"$stat"};
   2.951 +        next unless $Stat{"$stat"};
   2.952 +        $result .= "<tr valign='top'><td width='300'>".$StatNames{"$stat"}."</td><td>".$Stat{"$stat"}."</td></tr>"
   2.953      }
   2.954 -    
   2.955 -    $Result{"stat"} .= "</table>";
   2.956 -    $Result{"stat"} .= "<font size='-2'>____<br/>*) Интервалы неактивности длительностью ".($Config{stat_inactivity_interval}/60)." минут и более не учитываются</font></br>";
   2.957 +    $result  = "<table>$result</table>"
   2.958 +             . "<font size='-2'>____<br/>*) Интервалы неактивности длительностью "
   2.959 +             .  ($Config{stat_inactivity_interval}/60)
   2.960 +             . " минут и более не учитываются</font></br>";
   2.961  
   2.962 -    #$Result{"help"} .= "<hr/>";
   2.963 -    $Result{"help"} .= "<h2 id='help'>Справка</h2>";
   2.964 -    $Result{"help"} .= "$Html_Help<br/>";
   2.965 -    #$Result{"about"} .= "<hr/>";
   2.966 -    $Result{"about"} .= "<h2 id='about'>О программе</h2>";
   2.967 -    $Result{"about"} .= "$Html_About";
   2.968 -    $Result{"footer"} .= "</body>\n";
   2.969 -    $Result{"footer"} .= "</html>\n";
   2.970 -
   2.971 -    $Result{"title"} = "Журнал лабораторных работ";
   2.972 -    $Result{"title"}.= " -- ".$course_student if $course_student;
   2.973 -    if ($course_date) {
   2.974 -        $Result{"title"}.= " -- ".$course_date; 
   2.975 -        $Result{"title"}.= "/".$course_code if $course_code;
   2.976 -    }
   2.977 -    else {
   2.978 -        $Result{"title"}.= " -- ".$course_code if $course_code;
   2.979 -    }
   2.980 -
   2.981 -    # Заголовок генерируется позже всего
   2.982 -    # Тогда, когда известно уже, что должно быть написано в 
   2.983 -    # оглавлении
   2.984 -    $Result{"header"} = <<HEADER;
   2.985 -    <html>
   2.986 -    <head>
   2.987 -    <meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
   2.988 -    <link rel='stylesheet' href='$Config{frontend_css}' type='text/css'/>
   2.989 -    <title>$Result{title}</title>
   2.990 -    </head>
   2.991 -    <body>
   2.992 -    <script>
   2.993 -    $Html_JavaScript
   2.994 -    </script>
   2.995 -    <h1>Журнал лабораторных работ</h1>
   2.996 -
   2.997 -HEADER
   2.998 -    $Result{"header"} .= "<p>" if $course_student || $course_trainer || $course_name || $course_code || $course_date || $course_center;
   2.999 -    $Result{"header"} .= "Выполнил $course_student<br/>" if $course_student;
  2.1000 -    $Result{"header"} .= "Проверил $course_trainer <br/>" if $course_trainer;
  2.1001 -    $Result{"header"} .= "Курс " if $course_name || $course_code || $course_date;
  2.1002 -    $Result{"header"} .= "$course_name " if $course_name;
  2.1003 -    $Result{"header"} .= "($course_code)" if $course_code;
  2.1004 -    $Result{"header"} .= ", $course_date<br/>" if $course_date;
  2.1005 -    $Result{"header"} .= "Учебный центр $course_center <br/>" if $course_center;
  2.1006 -    $Result{"header"} .= "</p>" if $course_student || $course_trainer || $course_name || $course_code || $course_date || $course_center;
  2.1007 -
  2.1008 -    my $toc = collapse_list (\@toc);
  2.1009 -    $Result{"header"} .= <<HEADER;
  2.1010 -    <table border=0 id='toc' class='toc'>
  2.1011 -    <tr>
  2.1012 -    <td>
  2.1013 -    <div class='toc_title'>Содержание</div>
  2.1014 -    <ul>
  2.1015 -        <li><a href='#log'>Журнал</a></li>
  2.1016 -        <ul>$toc</ul>
  2.1017 -        <li><a href='#stat'>Статистика</a></li>
  2.1018 -        <li><a href='#help'>Справка</a></li>
  2.1019 -        <li><a href='#about'>О программе</a></li>
  2.1020 -    </ul>
  2.1021 -    </td>
  2.1022 -    </tr>
  2.1023 -    </table>
  2.1024 -
  2.1025 -    <h2 id="log">Журнал</h2>
  2.1026 -HEADER
  2.1027 -    $Result{"header"} .= "<table id='visibility_form' class='visibility_form'><tr><td><form>\n";
  2.1028 -    for my $element (keys %Elements_Visibility)
  2.1029 -    {
  2.1030 -        my @e = split /\s+/, $element;
  2.1031 -        my $showhide = join "", map { "ShowHide('$_');" } @e ;
  2.1032 -        $Result{"header"} .= "<input type='checkbox' name='$e[0]' onclick=\"$showhide\" checked>".
  2.1033 -                $Elements_Visibility{$element}.
  2.1034 -                "</input><br>\n";
  2.1035 -    }
  2.1036 -
  2.1037 -    $Result{"header"} .= "</form></td></tr></table>\n";
  2.1038 -
  2.1039 -    if ($output_filename eq "-") {
  2.1040 -        print $Result{"header"}, $Result{"body"}, $Result{"stat"}, $Result{"help"}, $Result{"about"}, $Result{"footer"};
  2.1041 -    }
  2.1042 -    else {
  2.1043 -        open(OUT, ">", $output_filename)
  2.1044 -            or die "Can't open $output_filename for writing\n";
  2.1045 -        print OUT $Result{"header"}, $Result{"body"}, $Result{"stat"}, $Result{"help"}, $Result{"about"}, $Result{"footer"};
  2.1046 -        close(OUT);
  2.1047 -    }
  2.1048 +    return $result;
  2.1049  }
  2.1050  
  2.1051  
  2.1052 -
  2.1053  sub collapse_list($)
  2.1054  {
  2.1055      my $res = "";
  2.1056 @@ -831,7 +903,7 @@
  2.1057      всё происходит само собой.
  2.1058      Однако, чтобы ведение и последующее использование журналов
  2.1059      было как можно более эффективным, желательно иметь в виду следующее:
  2.1060 -    <ul>
  2.1061 +    <ol>
  2.1062      <li><p> 
  2.1063      В журнал автоматически попадают все команды, данные в любом терминале системы.
  2.1064      </p></li>
  2.1065 @@ -1020,7 +1092,7 @@
  2.1066      добавляются точно таким же способом, только вместо симолов #^ или #v 
  2.1067      нужно использовать символы #=
  2.1068      </p></li>
  2.1069 -</ul>
  2.1070 +</ol>
  2.1071  HELP
  2.1072  
  2.1073  $Html_About = <<ABOUT;
  2.1074 @@ -1115,3 +1187,20 @@
  2.1075  @Of_Month_Name = qw/ Января Февраля Марта Апреля Мая Июня Июля Августа Сентября Октября Ноября Декабря /;
  2.1076  }
  2.1077  
  2.1078 +
  2.1079 +
  2.1080 +
  2.1081 +# Временно удалённый код
  2.1082 +# Возможно, он не понадобится уже никогда
  2.1083 +
  2.1084 +
  2.1085 +sub search_by
  2.1086 +{
  2.1087 +    my $sm = shift;
  2.1088 +    my $topic = shift;
  2.1089 +    $topic =~ s/ /+/;
  2.1090 +    
  2.1091 +    return "<a href='". $Search_Machines{$sm}->{"query"}."$topic'><img width='16' height='16' src='".
  2.1092 +                $Search_Machines{$sm}->{"icon"}."' border='0'/></a>";
  2.1093 +}
  2.1094 +