# HG changeset patch # User igor # Date 1205403582 -7200 # Node ID 71bd999bcb04155f175a94232124368402a47b5b # Parent 73fb48eb81102b21b1f6871ec2bb0c9d703ce72e Исправлено несколько багов: * выполняется корректная привязка diff'ов * правильно запоминается raw_start и проч raw_* * временно отключен вывод признака нажатия ctrl-c (он ставился неверно) * в приглашение добавлен случайный nonce (для правильной отработки tab) diff -r 73fb48eb8110 -r 71bd999bcb04 l3-agent --- a/l3-agent Mon Mar 10 16:35:37 2008 +0200 +++ b/l3-agent Thu Mar 13 12:19:42 2008 +0200 @@ -1,13 +1,9 @@ #!/usr/bin/perl -w # -# (c) Igor Chubin, igor@chub.in, 2004-2006 +# (c) Igor Chubin, igor@chub.in, 2004-2008 # - -## Эта строчка добавлена из блокнота Windows -## Надо отдать должное, он каким-то образом научился понимать кодировку - use strict; use POSIX; use Term::VT102; @@ -18,7 +14,6 @@ use lib "/etc/lilalo"; use l3config; - our @Command_Lines; our @Command_Lines_Index; our %Diffs; @@ -122,35 +117,54 @@ my $min_dt = 10000; + if (defined($cl->{"diff"})) { + print STDERR "Command ".$cl->{time}." is already bound"; + return; + } + +# Загружаем новые diff-файлы +# Это нужно делать непосредственно перед привязкой, поскольку diff'ы могли образоваться только что + for my $lab_log (split (/\s+/, $Config{"diffs"} || $Config{"input"})) { + load_diff_files($lab_log); + } + + my $diff_to_bind; for my $diff_key (keys %Diffs) { - my $diff = $Diffs{$diff_key}; - next if ($diff->{"local_session_id"} - && $cl->{"local_session_id"} - && ($cl->{"local_session_id"} ne $diff->{"local_session_id"})); + my $diff = $Diffs{$diff_key}; + next if ($diff->{"local_session_id"} + && $cl->{"local_session_id"} + && ($cl->{"local_session_id"} ne $diff->{"local_session_id"})); - next if ($diff->{"day"} && $cl->{"day"} && ($cl->{"day"} ne $diff->{"day"})); + next if ($diff->{"day"} && $cl->{"day"} && ($cl->{"day"} ne $diff->{"day"})); - my $dt; - if ($diff->{"time"} && $cl->{"time"}) { - $dt = $diff->{"time"} - $cl->{"time"} - } - else { - $dt=($diff->{"hour"}-$hour)*3600 +($diff->{"min"}-$min)*60 + ($diff->{"sec"}-$sec); - } - if ($dt >0 - && $dt < $min_dt - && ($diff->{"time_range"} <0 - || $dt < $diff->{"time_range"})) { - print "Approppriate diff found: dt=$dt\n"; - if ($diff->{"bind_to"}) { - undef $diff->{"bind_to"}->{"diff"}; - }; - $diff->{"time_range"}=$dt; - $diff->{"bind_to"}=$cl; - - $cl->{"diff"} = $diff_key; - $min_dt = $dt; - } + my $dt; + if (not $diff->{"time"}) { + print STDERR "diff time is 0"; + print STDERR join(" ", keys(%$diff)); + print STDERR $diff->{text}; + } + if (not $cl->{"time"}) { + print STDERR "cl time is 0"; + } + if ($diff->{"time"} && $cl->{"time"}) { + $dt = $diff->{"time"} - $cl->{"time"} + } + else { + $dt=($diff->{"hour"}-$hour)*3600 +($diff->{"min"}-$min)*60 + ($diff->{"sec"}-$sec); + } + if ($dt >=0 && $dt < $min_dt && !$diff->{"bind_to"}) { + $min_dt = $dt; + $diff_to_bind = $diff_key; + } + } + if ($diff_to_bind) { + print "Approppriate diff found: dt=$min_dt\n"; + $Diffs{$diff_to_bind}->{"bind_to"}=$cl; + $cl->{"diff"} = $diff_to_bind; + } + else { + print STDERR "Diff not found\n"; + print STDERR "cl{time}",$cl->{time},"\n"; } } @@ -243,6 +257,7 @@ ([0-9]+)[\#] # pid ([0-9]+)[\#] # time (.*?)[\#] # pwd + (.*?)[\#] # nonce (.*?([\$\#]\\s?)) # prompt (.*) # command line ) @@ -344,6 +359,7 @@ # Previous command my %last_cl = %cl; + my $this_line = $1; my $err = $2 || ""; $cl{"local_session_id"} = $local_session_id; @@ -362,7 +378,7 @@ { use bytes; - $cl{"raw_start"} = tell (FILE) - length($1); + $cl{"raw_start"} = tell (FILE) - length($this_line); $cl{"raw_output_start"} = tell FILE; } $cl{"raw_file"} = $file; @@ -374,6 +390,7 @@ $cline_vt->process($cl{"raw_cline"}."\n"); $cl{"cline"} = $cline_vt->row_plaintext (1); $cl{"cline"} =~ s/\s*$//; + $cl{"cline"} =~ s/.*?[\#\$]\s*//; $cline_vt->reset(); my %commands = extract_commands_from_cline($cl{"cline"}); @@ -399,20 +416,21 @@ print " ",$cl{"last_command"}; + if (grep ($_ eq $last_cl{"last_command"}, @{$Config{"editors"}})) { + bind_diff(\%last_cl); + } + # Processing previous command line - if ($first_pass) { - $first_pass = 0; - next; - } + #if ($first_pass) { + # $first_pass = 0; + # next; + #} # Error code $last_cl{"raw_end"} = $cl{"raw_start"}; $last_cl{"err"}=$err; $last_cl{"err"}=130 if $err eq "^C"; - if (grep ($_ eq $last_cl{"last_command"}, @{$Config{"editors"}})) { - bind_diff(\%last_cl); - } # Output if (!$last_cl{"suppress_output"} || $last_cl{"err"}) { @@ -451,8 +469,9 @@ elsif (m/$cline_re_v2/ || m/$cline_re_v3/) { # Разбираем командную строку версии 2 + my $before=$_; + s/.*\x0d(?!\x0a)//; - s/.*\x0d(?!\x0a)//; my $re; if (m/$cline_re_v2/) { $re=$cline_re2_v2; @@ -460,8 +479,8 @@ else { s/.\[1K.\[10D//gs; $re=$cline_re2_v3; + print STDERR "... $_ ...\n"; } - m/$re/gs; $commandlines_loaded++; $last_output_length=0; @@ -471,6 +490,7 @@ $cl{"local_session_id"} = $local_session_id; # Parse new command + my $this_line = $1; $cl{"history"} = $2; my $err = $3; $cl{"uid"} = $4; @@ -478,13 +498,15 @@ $cl{"pid"} = $5; $cl{"time"} = $6; $cl{"pwd"} = $7; + $cl{"nonce"} = $8; #$cl{"fullprompt"} = $8; - $cl{"prompt"} = $9; - $cl{"raw_cline"}= $10; + $cl{"prompt"} = $10; + #$cl{"raw_cline"}= $10; + $cl{"raw_cline"}= $before; { use bytes; - $cl{"raw_start"} = tell (FILE) - length($1); + $cl{"raw_start"} = tell (FILE) - length($before); $cl{"raw_output_start"} = tell FILE; } $cl{"raw_file"} = $file; @@ -496,7 +518,9 @@ $cline_vt->process($cl{"raw_cline"}."\n"); $cl{"cline"} = $cline_vt->row_plaintext (1); $cl{"cline"} =~ s/\s*$//; + $cl{"cline"} =~ s/.*?[\#\$]\s*//; $cline_vt->reset(); + print STDERR "cline=".$cl{"cline"}."<<\n"; my %commands = extract_commands_from_cline($cl{"cline"}); #$cl{"euid"} = 0 if defined $commands{"sudo"}; @@ -504,6 +528,8 @@ $cl{"last_command"} = $comms[$#comms] || ""; + print STDERR "last_command=".$cl{"last_command"}."<<\n"; + if ( $Config{"suppress_editors"} =~ /^y/i && grep ($_ eq $cl{"last_command"}, @{$Config{"editors"}}) @@ -519,26 +545,20 @@ } $skip_info = 0; - if ($Config{verbose} =~ /y/i) { print "\n| " if $commandlines_loaded % 5 == 1; print " ",$cl{"last_command"}; } - # Processing previous command line - if ($first_pass) { - $first_pass = 0; - next; + if (defined($last_cl{time}) + && grep ($_ eq $last_cl{"last_command"}, @{$Config{"editors"}})) { + bind_diff(\%last_cl); } # Error code $last_cl{"err"}=$err; $last_cl{"raw_end"} = $cl{"raw_start"}; - if (grep ($_ eq $last_cl{"last_command"}, @{$Config{"editors"}})) { - bind_diff(\%last_cl); - } - # Output if (!$last_cl{"suppress_output"} || $last_cl{"err"}) { for (my $i=0; $i<$Config{"terminal_height"}; $i++) { @@ -564,14 +584,14 @@ $last_cl{$_} = $converter->convert($last_cl{$_}) } } - push @Command_Lines, \%last_cl; - - # Сохранение позиции в файле, до которой выполнен - # успешный разбор - $Script_Files{$file}->{tell} = $last_cl{raw_end}; - + if (defined($last_cl{time})) { + print STDERR "push id=".$last_cl{time}."\n"; + push @Command_Lines, \%last_cl; + # Сохранение позиции в файле, до которой выполнен + # успешный разбор + $Script_Files{$file}->{tell} = $last_cl{raw_end}; + } next; - } # Иначе, это строка вывода @@ -583,7 +603,7 @@ } else { - if (!$skip_info) { + if (!$skip_info && defined($cl{last_command})) { print "($cl{last_command})"; $skip_info = 1; } @@ -747,6 +767,7 @@ err last_command history + nonce )) { next unless defined($cl->{"$element"}); print OUT "<$element>".$cl->{$element}."\n"; @@ -882,9 +903,6 @@ if (open (CACHE, ">", $Config{"cache"})) { close(CACHE); }; - for my $lab_log (split (/\s+/, $Config{"diffs"} || $Config{"input"})) { - load_diff_files($lab_log); - } load_command_lines($Config{"input"}, $Config{"input_mask"}); sort_command_lines; #process_command_lines; @@ -941,9 +959,6 @@ while (not $Killed) { @Command_Lines = (); @Command_Lines_Index = (); - for my $lab_log (split (/\s+/, $Config{"diffs"} || $Config{"input"})) { - load_diff_files($lab_log); - } load_cache_stat(); load_command_lines($Config{"input"}, $Config{"input_mask"}); if (@Command_Lines) { diff -r 73fb48eb8110 -r 71bd999bcb04 l3-frontend --- a/l3-frontend Mon Mar 10 16:35:37 2008 +0200 +++ b/l3-frontend Thu Mar 13 12:19:42 2008 +0200 @@ -475,7 +475,7 @@ # Обработка команд с одинаковым временем # Скорее всего они набраны с помощью tab-completion if (defined($prev_cl)) { - if ($$prev_cl->{time} == $$cl->{time}) { + if ($$prev_cl->{time} == $$cl->{time} && $$prev_cl->{nonce} == $$cl->{nonce}) { $tab_seq++; } else { @@ -485,9 +485,9 @@ # Обработка команд с одинаковым номером в истории # Скорее всего они набраны с помощью Ctrl-C - if ($$prev_cl->{history} == $$cl->{history}) { - $$prev_cl->{break}=1; - } + #if ($$prev_cl->{history} == $$cl->{history}) { + # $$prev_cl->{break}=1; + #} } @@ -768,7 +768,11 @@ # COMMAND my $cline; - $prompt_hint = join (" ", map("$_=$cl->{$_}", grep (!/^(output|diff)$/, sort(keys(%{$cl}))))); + $prompt_hint = join (" ", + map("$_=$cl->{$_}", + grep (!/^(output|short_output|diff)$/, + sort(keys(%{$cl}))))); + $cline = "".$cl->{"prompt"}."" ."{time}."')\" onmouseout=\"myHint.hide()\">".$cl->{"cline"}.""; $cline =~ s/\n//; diff -r 73fb48eb8110 -r 71bd999bcb04 l3bashrc --- a/l3bashrc Mon Mar 10 16:35:37 2008 +0200 +++ b/l3bashrc Thu Mar 13 12:19:42 2008 +0200 @@ -128,8 +128,8 @@ l3_fix_prompt() { -# export PS1='\[v2#\!#$?#$UID#$$#$(/bin/date +%s)$(l3_save_last_line)#$PWD#\033[1024D\033[K\]'$PS1 - export PS1='\[$($L3_HOME/l3prompt "v3#\!#$?#$UID#$$#$(/bin/date +%s)#$PWD#")$(l3_save_last_line >& /dev/null)\]'$PS1 +## export PS1='\[v2#\!#$?#$UID#$$#$(/bin/date +%s)$(l3_save_last_line)#$PWD#\033[1024D\033[K\]'$PS1 + export PS1='\[$($L3_HOME/l3prompt "v3#\!#$?#$UID#$$#$(/bin/date +%s)#$PWD#$RANDOM#")$(l3_save_last_line >& /dev/null)\]'$PS1 } _l3_tamper_editors()