lilalo

view l3-frontend @ 89:62001c1e3295

Доделан вызов окна редактирования журнала.

+ исправлен баг с unicode
author devi
date Thu Mar 02 20:13:31 2006 +0200 (2006-03-02)
parents 385499ec544a
children d3182b751893
line source
1 #!/usr/bin/perl -w
3 use IO::Socket;
4 use lib '.';
5 use l3config;
6 use utf8;
8 our @Command_Lines;
9 our @Command_Lines_Index;
10 our %Commands_Description;
11 our %Args_Description;
12 our $Mywi_Socket;
13 our %Sessions;
15 our %filter;
16 our $filter_url;
17 sub init_filter;
19 our %Files;
21 # vvv Инициализация переменных выполняется процедурой init_variables
22 our @Day_Name;
23 our @Month_Name;
24 our @Of_Month_Name;
25 our %Search_Machines;
26 our %Elements_Visibility;
27 # ^^^
29 our %Stat;
30 our %frequency_of_command; # Сколько раз в журнале встречается какая команда
31 our $table_number=1;
33 my %mywi_cache_for; # Кэш для экономии обращений к mywi
35 sub make_comment;
36 sub make_new_entries_table;
37 sub load_command_lines_from_xml;
38 sub load_sessions_from_xml;
39 sub sort_command_lines;
40 sub process_command_lines;
41 sub init_variables;
42 sub main;
43 sub collapse_list($);
45 sub minutes_passed;
47 sub print_all_txt;
48 sub print_all_html;
49 sub print_edit_all_html;
50 sub print_command_lines_html;
51 sub print_command_lines_txt;
52 sub print_files_html;
53 sub print_stat_html;
54 sub print_header_html;
55 sub print_footer_html;
57 main();
59 sub main
60 {
61 $| = 1;
63 init_variables();
64 init_config();
65 $Config{frontend_ico_path}=$Config{frontend_css};
66 $Config{frontend_ico_path}=~s@/[^/]*$@@;
67 init_filter();
69 open_mywi_socket();
70 load_command_lines_from_xml($Config{"backend_datafile"});
71 load_sessions_from_xml($Config{"backend_datafile"});
72 sort_command_lines;
73 process_command_lines;
74 if (defined($filter{action}) && $filter{action} eq "edit") {
75 print_edit_all_html($Config{"output"});
76 }
77 else {
78 print_all_html($Config{"output"});
79 }
80 close_mywi_socket;
81 }
83 sub init_filter
84 {
85 if ($Config{filter}) {
86 # Инициализация фильтра
87 for (split /&/,$Config{filter}) {
88 my ($var, $val) = split /=/;
89 $filter{$var} = $val || "";
90 }
91 }
92 $filter_url = join ("&", map("$_=$filter{$_}", keys %filter));
93 }
95 # extract_from_cline
97 # In: $what = commands | args
98 # Out: return ссылка на хэш, содержащий результаты разбора
99 # команда => позиция
101 # Разобрать командную строку $_[1] и возвратить хэш, содержащий
102 # номер первого появление команды в строке:
103 # команда => первая позиция
104 sub extract_from_cline
105 {
106 my $what = $_[0];
107 my $cline = $_[1];
108 my @lists = split /\;/, $cline;
111 my @command_lines = ();
112 for my $command_list (@lists) {
113 push(@command_lines, split(/\|/, $command_list));
114 }
116 my %position_of_command;
117 my %position_of_arg;
118 my $i=0;
119 for my $command_line (@command_lines) {
120 $command_line =~ s@^\s*@@;
121 $command_line =~ /\s*(\S+)\s*(.*)/;
122 if ($1 && $1 eq "sudo" ) {
123 $position_of_command{"$1"}=$i++;
124 $command_line =~ s/\s*sudo\s+//;
125 }
126 if ($command_line !~ m@^\s*\S*/etc/@) {
127 $command_line =~ s@^\s*\S+/@@;
128 }
130 $command_line =~ /\s*(\S+)\s*(.*)/;
131 my $command = $1;
132 my $args = $2;
133 if ($command && !defined $position_of_command{"$command"}) {
134 $position_of_command{"$command"}=$i++;
135 };
136 if ($args) {
137 my @args = split (/\s+/, $args);
138 for my $a (@args) {
139 $position_of_arg{"$a"}=$i++
140 if !defined $position_of_arg{"$a"};
141 };
142 }
143 }
145 if ($what eq "commands") {
146 return \%position_of_command;
147 } else {
148 return \%position_of_arg;
149 }
151 }
156 #
157 # Подпрограммы для работы с mywi
158 #
160 sub open_mywi_socket
161 {
162 $Mywi_Socket = IO::Socket::INET->new(
163 PeerAddr => $Config{mywi_server},
164 PeerPort => $Config{mywi_port},
165 Proto => "tcp",
166 Type => SOCK_STREAM);
167 }
169 sub close_mywi_socket
170 {
171 close ($Mywi_Socket) if $Mywi_Socket ;
172 }
175 sub mywi_client
176 {
177 my $query = $_[0];
178 my $mywi;
180 open_mywi_socket;
181 if ($Mywi_Socket) {
182 local $| = 1;
183 local $/ = "";
184 print $Mywi_Socket $query."\n";
185 $mywi = <$Mywi_Socket>;
186 $mywi = "" if $mywi =~ /nothing app/;
187 }
188 close_mywi_socket;
189 return $mywi;
190 }
192 sub make_comment
193 {
194 my $cline = $_[0];
195 #my $files = $_[1];
197 my @comments;
198 my @commands = keys %{extract_from_cline("commands", $cline)};
199 my @args = keys %{extract_from_cline("args", $cline)};
200 return if (!@commands && !@args);
201 #return "commands=".join(" ",@commands)."; files=".join(" ",@files);
203 # Commands
204 for my $command (@commands) {
205 $command =~ s/'//g;
206 $frequency_of_command{$command}++;
207 if (!$Commands_Description{$command}) {
208 $mywi_cache_for{$command} ||= mywi_client ($command) || "";
209 my $mywi = join ("\n", grep(/\([18]|sh|script\)/, split(/\n/, $mywi_cache_for{$command})));
210 $mywi =~ s/\s+/ /;
211 if ($mywi !~ /^\s*$/) {
212 $Commands_Description{$command} = $mywi;
213 }
214 else {
215 next;
216 }
217 }
219 push @comments, $Commands_Description{$command};
220 }
221 return join("&#10;\n", @comments);
223 # Files
224 for my $arg (@args) {
225 $arg =~ s/'//g;
226 if (!$Args_Description{$arg}) {
227 my $mywi;
228 $mywi = mywi_client ($arg);
229 $mywi = join ("\n", grep(/\([5]\)/, split(/\n/, $mywi)));
230 $mywi =~ s/\s+/ /;
231 if ($mywi !~ /^\s*$/) {
232 $Args_Description{$arg} = $mywi;
233 }
234 else {
235 next;
236 }
237 }
239 push @comments, $Args_Description{$arg};
240 }
242 }
244 =cut
245 Процедура load_command_lines_from_xml выполняет загрузку разобранного lab-скрипта
246 из XML-документа в переменную @Command_Lines
248 # In: $datafile имя файла
249 # Out: @CommandLines загруженные командные строки
251 Предупреждение!
252 Процедура не в состоянии обрабатывать XML-документ любой структуры.
253 В действительности файл cache из которого загружаются данные
254 просто напоминает XML с виду.
255 =cut
256 sub load_command_lines_from_xml
257 {
258 my $datafile = $_[0];
260 open (CLASS, $datafile)
261 or die "Can't open file with xml lablog ",$datafile,"\n";
262 local $/;
263 binmode CLASS, ":utf8";
264 $data = <CLASS>;
265 close(CLASS);
267 for $command ($data =~ m@<command>(.*?)</command>@sg) {
268 my %cl;
269 while ($command =~ m@<([^>]*?)>(.*?)</\1>@sg) {
270 $cl{$1} = $2;
271 }
272 push @Command_Lines, \%cl;
273 }
274 }
276 sub load_sessions_from_xml
277 {
278 my $datafile = $_[0];
280 open (CLASS, $datafile)
281 or die "Can't open file with xml lablog ",$datafile,"\n";
282 local $/;
283 binmode CLASS, ":utf8";
284 my $data = <CLASS>;
285 close(CLASS);
287 my $i=0;
288 for my $session ($data =~ m@<session>(.*?)</session>@msg) {
289 my %session_hash;
290 while ($session =~ m@<([^>]*?)>(.*?)</\1>@sg) {
291 $session_hash{$1} = $2;
292 }
293 $Sessions{$session_hash{local_session_id}} = \%session_hash;
294 }
295 }
298 # sort_command_lines
299 # In: @Command_Lines
300 # Out: @Command_Lies_Index
302 sub sort_command_lines
303 {
305 my @index;
306 for (my $i=0;$i<=$#Command_Lines;$i++) {
307 $index[$i]=$i;
308 }
310 @Command_Lines_Index = sort {
311 $Command_Lines[$index[$a]]->{"time"} <=> $Command_Lines[$index[$b]]->{"time"}
312 } @index;
314 }
316 ##################
317 # process_command_lines
318 #
319 # Обрабатываются командные строки @Command_Lines
320 # Для каждой строки определяется:
321 # class класс
322 # note комментарий
323 #
324 # In: @Command_Lines_Index
325 # In-Out: @Command_Lines
327 sub process_command_lines
328 {
330 COMMAND_LINE_PROCESSING:
331 for my $i (@Command_Lines_Index) {
332 my $cl = \$Command_Lines[$i];
334 next if !$cl;
336 for my $filter_key (keys %filter) {
337 next COMMAND_LINE_PROCESSING
338 if defined($$cl->{local_session_id})
339 && defined($Sessions{$$cl->{local_session_id}}->{$filter_key})
340 && $Sessions{$$cl->{local_session_id}}->{$filter_key} ne $filter{$filter_key};
341 }
343 $$cl->{id} = $$cl->{"time"};
345 $$cl->{err} ||=0;
347 # Класс команды
349 $$cl->{"class"} = $$cl->{"err"} eq 130 ? "interrupted"
350 : $$cl->{"err"} eq 127 ? "mistyped"
351 : $$cl->{"err"} ? "wrong"
352 : "normal";
354 if ($$cl->{"cline"} &&
355 $$cl->{"cline"} =~ /[^|`]\s*sudo/
356 || $$cl->{"uid"} eq 0) {
357 $$cl->{"class"}.="_root";
358 }
360 # my $hint;
361 # $hint = make_comment($$cl->{"cline"});
362 # if ($hint) {
363 # $$cl->{hint} = $hint;
364 # }
365 $$cl->{hint}="";
367 # Выводим <head_lines> верхних строк
368 # и <tail_lines> нижних строк,
369 # если эти параметры существуют
370 my $output="";
372 if ($$cl->{"last_command"} eq "cat" && !$$cl->{"err"} && !($$cl->{"cline"} =~ /</)) {
373 my $filename = $$cl->{"cline"};
374 $filename =~ s/.*\s+(\S+)\s*$/$1/;
375 $Files{$filename}->{"content"} = $$cl->{"output"};
376 $Files{$filename}->{"source_command_id"} = $$cl->{"id"}
377 }
378 my @lines = split '\n', $$cl->{"output"};
379 if ((
380 $Config{"head_lines"}
381 || $Config{"tail_lines"}
382 )
383 && $#lines > $Config{"head_lines"} + $Config{"tail_lines"} ) {
384 #
385 for (my $i=0; $i<= $#lines && $i < $Config{"head_lines"}; $i++) {
386 $output .= $lines[$i]."\n";
387 }
388 $output .= $Config{"skip_text"}."\n";
390 my $start_line=$#lines-$Config{"tail_lines"}+1;
391 for (my $i=$start_line; $i<= $#lines; $i++) {
392 $output .= $lines[$i]."\n";
393 }
394 }
395 else {
396 $output = $$cl->{"output"};
397 }
398 $$cl->{short_output} = $output;
400 #Обработка пометок
401 # Если несколько пометок (notes) идут подряд,
402 # они все объединяются
404 if ($$cl->{cline} =~ /l3shot/) {
405 if ($$cl->{output} =~ m@Screenshot is written to.*/(.*)\.xwd@) {
406 $$cl->{screenshot}="$1";
407 }
408 }
410 if ($$cl->{cline}=~ m@cat[^#]*#([\^=v])\s*(.*)@) {
412 my $note_operator = $1;
413 my $note_title = $2;
415 if ($note_operator eq "=") {
416 $$cl->{"class"} = "note";
417 $$cl->{"note"} = $$cl->{"output"};
418 $$cl->{"note_title"} = $2;
419 }
420 else {
421 my $j = $i;
422 if ($note_operator eq "^") {
423 $j--;
424 $j-- while ($j >=0 && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty}));
425 }
426 elsif ($note_operator eq "v") {
427 $j++;
428 $j++ while ($j <= @Command_Lines && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty}));
429 }
430 $Command_Lines[$j]->{note_title}=$note_title;
431 $Command_Lines[$j]->{note}.=$$cl->{output};
432 $$cl=0;
433 }
434 }
435 elsif ($$cl->{cline}=~ /#([\^=v])(.*)/) {
437 my $note_operator = $1;
438 my $note_text = $2;
440 if ($note_operator eq "=") {
441 $$cl->{"class"} = "note";
442 $$cl->{"note"} = $note_text;
443 }
444 else {
445 my $j=$i;
446 if ($note_operator eq "^") {
447 $j--;
448 $j-- while ($j >=0 && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty}));
449 }
450 elsif ($note_operator eq "v") {
451 $j++;
452 $j++ while ($j <= @Command_Lines && $Command_Lines[$j]->{tty} ne $$cl->{tty} || !$Command_Lines[$j]);
453 }
454 $Command_Lines[$j]->{note}.="$note_text\n";
455 $$cl=0;
456 }
457 }
458 if ($$cl->{"class"} eq "note") {
459 my $note_html = $$cl->{note};
460 $note_html = join ("\n", map ("<p>$_</p>", split (/-\n/, $note_html)));
461 $note_html =~ s@(http:[a-zA-Z.0-9/?\_%-]*)@<a href='$1'>$1</a>@g;
462 $note_html =~ s@(www\.[a-zA-Z.0-9/?\_%-]*)@<a href='$1'>$1</a>@g;
463 $$cl->{"note_html"} = $note_html;
464 }
465 }
467 }
470 =cut
471 Процедура print_command_lines выводит HTML-представление
472 разобранного lab-скрипта.
474 Разобранный lab-скрипт должен находиться в массиве @Command_Lines
475 =cut
477 sub print_command_lines_html
478 {
480 my @toc; # Оглавление
481 my $note_number=0;
483 my $result = q();
484 my $this_day_resut = q();
486 my $cl;
487 my $last_tty="";
488 my $last_session="";
489 my $last_day=q();
490 my $last_wday=q();
491 my $in_range=0;
493 my $current_command=0;
495 my @known_commands;
499 $Stat{LastCommand} ||= 0;
500 $Stat{TotalCommands} ||= 0;
501 $Stat{ErrorCommands} ||= 0;
502 $Stat{MistypedCommands} ||= 0;
504 my %new_entries_of = (
505 "1 1" => "программы пользователя",
506 "2 8" => "программы администратора",
507 "3 sh" => "команды интерпретатора",
508 "4 script"=> "скрипты",
509 );
511 COMMAND_LINE:
512 for my $k (@Command_Lines_Index) {
514 my $cl=$Command_Lines[$Command_Lines_Index[$current_command++]];
515 next unless $cl;
517 # Пропускаем команды, с одинаковым временем
518 # Это не совсем правильно.
519 # Возможно, что это команды, набираемые с помощью <completion>
520 # или запомненные с помощью <ctrl-c>
522 next if $Stat{LastCommand} == $cl->{time};
524 # Пропускаем строки, которые противоречат фильтру
525 # Если у нас недостаточно информации о том, подходит строка под фильтр или нет,
526 # мы её выводим
528 for my $filter_key (keys %filter) {
529 next COMMAND_LINE
530 if defined($cl->{local_session_id})
531 && defined($Sessions{$cl->{local_session_id}}->{$filter_key})
532 && $Sessions{$cl->{local_session_id}}->{$filter_key} ne $filter{$filter_key};
533 }
535 # Набираем статистику
536 # Хэш %Stat
538 $Stat{FirstCommand} = $cl->{time} unless $Stat{FirstCommand};
539 if ($cl->{time} - $Stat{LastCommand} < $Config{stat_inactivity_interval}) {
540 $Stat{TotalTime} += $cl->{time} - $Stat{LastCommand}
541 }
542 my $seconds_since_last_command = $cl->{time} - $Stat{LastCommand};
544 if ($Stat{LastCommand} > $cl->{time}) {
545 $result .= "Время идёт вспять<br/>";
546 };
547 $Stat{LastCommand} = $cl->{time};
548 $Stat{TotalCommands}++;
550 # Пропускаем строки, выходящие за границу "signature",
551 # при условии, что границы указаны
552 # Пропускаем неправильные/прерванные/другие команды
553 if ($Config{"from"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"from"}/) {
554 $in_range=1;
555 next;
556 }
557 if ($Config{"to"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"to"}/) {
558 $in_range=0;
559 next;
560 }
561 next if ($Config{"from"} && $Config{"to"} && !$in_range)
562 || ($Config{"skip_empty"} =~ /^y/i && $cl->{"cline"} =~ /^\s*$/ )
563 || ($Config{"skip_wrong"} =~ /^y/i && $cl->{"err"} != 0)
564 || ($Config{"skip_interrupted"} =~ /^y/i && $cl->{"err"} == 130);
569 #
570 ##
571 ## Начинается собственно вывод
572 ##
573 #
575 ### Сначала обрабатываем границы разделов
576 ### Если тип команды "note", это граница
578 if ($cl->{class} eq "note") {
579 $this_day_result .= "<tr><td colspan='6'>"
580 . "<h4 id='note$note_number'>".$cl->{note_title}."</h4>" if $cl->{note_title}
581 . "".$cl->{note_html}."<p/><p/></td></tr>";
583 if ($cl->{note_title}) {
584 push @{$toc[@toc]},"<a href='#note$note_number'>".$cl->{note_title}."</a>";
585 $note_number++;
586 }
587 next;
588 }
590 my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime($cl->{time});
592 # Добавляем спереди 0 для удобочитаемости
593 $min = "0".$min if $min =~ /^.$/;
594 $hour = "0".$hour if $hour =~ /^.$/;
595 $sec = "0".$sec if $sec =~ /^.$/;
597 $class=$cl->{"class"};
598 $Stat{ErrorCommands}++ if $class =~ /wrong/;
599 $Stat{MistypedCommands}++ if $class =~ /mistype/;
601 # DAY CHANGE
602 if ( $last_day ne $day) {
603 if ($last_day) {
605 # Вычисляем разность множеств.
606 # Что-то вроде этого, если бы так можно было писать:
607 # @new_commands = keys %frequency_of_command - @known_commands;
610 $result .= "<h3 id='day$last_day'>".$Day_Name[$last_wday]."</h3>";
611 for my $entry_class (sort keys %new_entries_of) {
612 my $table_caption = "Таблица ".$table_number++.".".$Day_Name[$last_wday]
613 .". Новые ".$new_entries_of{$entry_class};
614 my $new_commands_section = make_new_entries_table(
615 $table_caption,
616 $entry_class=~/[0-9]+\s+(.*)/,
617 \@known_commands);
618 }
619 @known_commands = keys %frequency_of_command;
620 $result .= $this_day_result;
621 }
623 push @toc, "<a href='#day$day'>".$Day_Name[$wday]."</a>\n";
624 $last_day=$day;
625 $last_wday=$wday;
626 $this_day_result = q();
627 }
628 else {
629 $this_day_result .= minutes_passed($seconds_since_last_command);
630 }
632 $this_day_result .= "<div class='command' id='command:".$cl->{"id"}."' >\n";
634 # CONSOLE CHANGE
635 if ($cl->{"tty"} && $last_tty ne $cl->{"tty"} && 0) {
636 my $tty = $cl->{"tty"};
637 $this_day_result .= "<div class='ttychange'>"
638 . $tty
639 ."</div>";
640 $last_tty=$cl->{"tty"};
641 }
643 # Session change
644 if ( $last_session ne $cl->{"local_session_id"}) {
645 my $tty;
646 if (defined $Sessions{$cl->{"local_session_id"}}->{"tty"}) {
647 $this_day_result .= "<div class='ttychange'><a href='?local_session_id=".$cl->{"local_session_id"}."'>"
648 . $Sessions{$cl->{"local_session_id"}}->{"tty"}
649 ."</a></div>";
650 }
651 $last_session=$cl->{"local_session_id"};
652 }
654 # TIME
655 if ($Config{"show_time"} =~ /^y/i) {
656 $this_day_result .= "<div class='time'>$hour:$min:$sec</div>"
657 }
659 # COMMAND
660 my $cline;
661 $prompt_hint = join ("&#10;", map("$_=$cl->{$_}", grep (!/^(output|diff)$/, sort(keys(%{$cl})))));
662 $cline = "<span title='$prompt_hint'>".$cl->{"prompt"}."</span>".$cl->{"cline"};
663 $cline =~ s/\n//;
665 if ($cl->{"hint"}) {
666 $cline = "<span title='$cl->{hint}' class='with_hint'>$cline</span>" ;
667 }
668 else {
669 $cline = "<span class='without_hint'>$cline</span>";
670 }
672 $this_day_result .= "<table cellpadding='0' cellspacing='0'><tr><td>\n<div class='cblock_$cl->{class}'>\n";
673 $this_day_result .= "<div class='cline'>\n" . $cline ; #cline
674 $this_day_result .= "<span title='Код завершения ".$cl->{"err"}."'>\n"
675 . "<img src='".$Config{frontend_ico_path}."/error.png'/>\n"
676 . "</span>\n" if $cl->{"err"};
677 $this_day_result .= "</div>\n"; #cline
679 # OUTPUT
680 my $last_command = $cl->{"last_command"};
681 if (!(
682 $Config{"suppress_editors"} =~ /^y/i && grep ($_ eq $last_command, @{$Config{"editors"}}) ||
683 $Config{"suppress_pagers"} =~ /^y/i && grep ($_ eq $last_command, @{$Config{"pagers"}}) ||
684 $Config{"suppress_terminal"}=~ /^y/i && grep ($_ eq $last_command, @{$Config{"terminal"}})
685 )) {
686 $this_day_result .= "<pre class='output'>\n" . $cl->{short_output} . "</pre>\n";
687 }
689 # DIFF
690 $this_day_result .= "<pre class='diff'>".$cl->{"diff"}."</pre>"
691 if ( $Config{"show_diffs"} =~ /^y/i && $cl->{"diff"});
692 # SHOT
693 $this_day_result .= "<img src='"
694 .$Config{l3shot_path}
695 .$cl->{"screenshot"}
696 .$Config{l3shot_suffix}
697 ."' alt ='screenshot id ".$cl->{"screenshot"}
698 ."'/>"
699 if ( $Config{"show_screenshots"} =~ /^y/i && $cl->{"screenshot"});
701 #NOTES
702 if ( $Config{"show_notes"} =~ /^y/i && $cl->{"note"}) {
703 my $note=$cl->{"note"};
704 $note =~ s/\n/<br\/>\n/msg;
705 if (not $note =~ s@(http:[a-zA-Z.0-9/_?%-]*)@<a href='$1'>$1</a>@g) {
706 $note =~ s@(www\.[a-zA-Z.0-9/_?%-]*)@<a href='$1'>$1</a>@g;
707 };
708 $this_day_result .= "<div class='note'>";
709 $this_day_result .= "<div class='note_title'>".$cl->{note_title}."</div>" if $cl->{note_title};
710 $this_day_result .= "<div class='note_text'>".$note."</div>";
711 $this_day_result .= "</div>\n";
712 }
714 # Вывод очередной команды окончен
715 $this_day_result .= "</div>\n"; # cblock
716 $this_day_result .= "</td></tr></table>\n"
717 . "</div>\n"; # command
718 }
719 last: {
720 $result .= "<h3 id='day$last_day'>".$Day_Name[$last_wday]."</h3>";
722 for my $entry_class (keys %new_entries_of) {
723 my $table_caption = "Таблица ".$table_number++.".".$Day_Name[$last_wday]
724 . ". Новые ".$new_entries_of{$entry_class};
725 my $new_commands_section = make_new_entries_table(
726 $table_caption,
727 $entry_class=~/[0-9]+\s+(.*)/,
728 \@known_commands);
729 }
730 @known_commands = keys %frequency_of_command;
731 $result .= $this_day_result;
732 }
734 return ($result, collapse_list (\@toc));
736 }
738 #############
739 # make_new_entries_table
740 #
741 # Напечатать таблицу неизвестных команд
742 #
743 # In: $_[0] table_caption
744 # $_[1] entries_class
745 # @_[2..] known_commands
746 # Out:
748 sub make_new_entries_table
749 {
750 my $table_caption;
751 my $entries_class = shift;
752 my @known_commands = @{$_[0]};
753 my $result = "";
755 my %count;
756 my @new_commands = ();
757 for my $c (keys %frequency_of_command, @known_commands) {
758 $count{$c}++
759 }
760 for my $c (keys %frequency_of_command) {
761 push @new_commands, $c if $count{$c} != 2;
762 }
764 my $new_commands_section;
765 if (@new_commands){
766 my $hint;
767 for my $c (reverse sort { $frequency_of_command{$a} <=> $frequency_of_command{$b} } @new_commands) {
768 $hint = make_comment($c);
769 next unless $hint;
770 my ($command, $hint) = $hint =~ m/(.*?) \s*- \s*(.*)/;
771 next unless $command =~ s/\($entries_class\)//i;
772 $new_commands_section .= "<tr><td valign='top'>$command</td><td>$hint</td></tr>";
773 }
774 }
775 if ($new_commands_section) {
776 $result .= "<table class='new_commands_table' width='700' cellspacing='0' cellpadding='0'>"
777 . "<tr class='new_commands_caption'>"
778 . "<td colspan='2' align='right'>$table_caption</td>"
779 . "</tr>"
780 . "<tr class='new_commands_header'>"
781 . "<td width=100>Команда</td><td width=600>Описание</td>"
782 . "</tr>"
783 . $new_commands_section
784 . "</table>"
785 }
786 return $result;
787 }
789 #############
790 # minutes_passed
791 #
792 #
793 #
794 # In: $_[0] seconds_since_last_command
795 # Out: "minutes passed" text
797 sub minutes_passed
798 {
799 my $seconds_since_last_command = shift;
800 my $result = "";
801 if ($seconds_since_last_command > 7200) {
802 my $hours_passed = int($seconds_since_last_command/3600);
803 my $passed_word = $hours_passed % 10 == 1 ? "прошла"
804 : "прошло";
805 my $hours_word = $hours_passed % 10 == 1 ? "часа":
806 "часов";
807 $result .= "<div class='much_time_passed'>"
808 . $passed_word." &gt;".$hours_passed." ".$hours_word
809 . "</div>\n";
810 }
811 elsif ($seconds_since_last_command > 600) {
812 my $minutes_passed = int($seconds_since_last_command/60);
815 my $passed_word = $minutes_passed % 100 > 10
816 && $minutes_passed % 100 < 20 ? "прошло"
817 : $minutes_passed % 10 == 1 ? "прошла"
818 : "прошло";
820 my $minutes_word = $minutes_passed % 100 > 10
821 && $minutes_passed % 100 < 20 ? "минут" :
822 $minutes_passed % 10 == 1 ? "минута":
823 $minutes_passed % 10 == 0 ? "минут" :
824 $minutes_passed % 10 > 4 ? "минут" :
825 "минуты";
827 if ($seconds_since_last_command < 1800) {
828 $result .= "<div class='time_passed'>"
829 . $passed_word." ".$minutes_passed." ".$minutes_word
830 . "</div>\n";
831 }
832 else {
833 $result .= "<div class='much_time_passed'>"
834 . $passed_word." ".$minutes_passed." ".$minutes_word
835 . "</div>\n";
836 }
837 }
838 return $result;
839 }
841 #############
842 # print_all_txt
843 #
844 # Вывести журнал в текстовом формате
845 #
846 # In: $_[0] output_filename
847 # Out:
849 sub print_command_lines_txt
850 {
852 my $output_filename=$_[0];
853 my $note_number=0;
855 my $result = q();
856 my $this_day_resut = q();
858 my $cl;
859 my $last_tty="";
860 my $last_session="";
861 my $last_day=q();
862 my $last_wday=q();
863 my $in_range=0;
865 my $current_command=0;
867 my $cursor_position = 0;
870 if ($Config{filter}) {
871 # Инициализация фильтра
872 for (split /&/,$Config{filter}) {
873 my ($var, $val) = split /=/;
874 $filter{$var} = $val || "";
875 }
876 }
879 COMMAND_LINE:
880 for my $k (@Command_Lines_Index) {
882 my $cl=$Command_Lines[$Command_Lines_Index[$current_command++]];
883 next unless $cl;
886 # Пропускаем строки, которые противоречат фильтру
887 # Если у нас недостаточно информации о том, подходит строка под фильтр или нет,
888 # мы её выводим
890 for my $filter_key (keys %filter) {
891 next COMMAND_LINE
892 if defined($cl->{local_session_id})
893 && defined($Sessions{$cl->{local_session_id}}->{$filter_key})
894 && $Sessions{$cl->{local_session_id}}->{$filter_key} ne $filter{$filter_key};
895 }
897 # Пропускаем строки, выходящие за границу "signature",
898 # при условии, что границы указаны
899 # Пропускаем неправильные/прерванные/другие команды
900 if ($Config{"from"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"from"}/) {
901 $in_range=1;
902 next;
903 }
904 if ($Config{"to"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"to"}/) {
905 $in_range=0;
906 next;
907 }
908 next if ($Config{"from"} && $Config{"to"} && !$in_range)
909 || ($Config{"skip_empty"} =~ /^y/i && $cl->{"cline"} =~ /^\s*$/ )
910 || ($Config{"skip_wrong"} =~ /^y/i && $cl->{"err"} != 0)
911 || ($Config{"skip_interrupted"} =~ /^y/i && $cl->{"err"} == 130);
914 #
915 ##
916 ## Начинается собственно вывод
917 ##
918 #
920 ### Сначала обрабатываем границы разделов
921 ### Если тип команды "note", это граница
923 if ($cl->{class} eq "note") {
924 $this_day_result .= " === ".$cl->{note_title}." === \n" if $cl->{note_title};
925 $this_day_result .= $cl->{note}."\n";
926 next;
927 }
929 my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime($cl->{time});
931 # Добавляем спереди 0 для удобочитаемости
932 $min = "0".$min if $min =~ /^.$/;
933 $hour = "0".$hour if $hour =~ /^.$/;
934 $sec = "0".$sec if $sec =~ /^.$/;
936 $class=$cl->{"class"};
938 # DAY CHANGE
939 if ( $last_day ne $day) {
940 if ($last_day) {
941 $result .= "== ".$Day_Name[$last_wday]." == \n";
942 $result .= $this_day_result;
943 }
944 $last_day = $day;
945 $last_wday = $wday;
946 $this_day_result = q();
947 }
949 # CONSOLE CHANGE
950 if ($cl->{"tty"} && $last_tty ne $cl->{"tty"} && 0) {
951 my $tty = $cl->{"tty"};
952 $this_day_result .= " #l3: ------- другая консоль ----\n";