diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/ivymon | 69 |
1 files changed, 43 insertions, 26 deletions
@@ -92,7 +92,7 @@ use vars qw/$VERSION $opt_help $opt_b $opt_bus $opt_history @opt_bind @opt_send $opt_undersize $opt_out $opt_loadingmode $opt_replayrepeat $opt_replaystartregexp $opt_replaystopregexp $opt_replaytimegranularity/; # **** VERSION *** -$VERSION = '1.12'; +$VERSION = '1.13'; # options initialisation $opt_loadingmode = 'replay-pause'; @@ -157,6 +157,8 @@ my $stopFlag = 0; my $noMessageYet = 1; my $jump_cnt = 0; +my $outputfile; + my $noUpdateFlag = 0; my $loadedFileFlag = 0; my $loadingFlag = 0; @@ -997,13 +999,6 @@ for my $bind (@effectivebind) { # Options and arguments test # #================================================================================= -# output file -if ($opt_out) { - unless (open(OUT, ">$opt_out")) { - $mw->Tk::Error("Can't write to file '$opt_out' ($!)"); - $opt_out = undef; - } -} # loading mode $mw->Tk::Error("syntax error : -loadingmode accepts 'replay', 'replay-pause' ". "or 'display' value") @@ -1034,7 +1029,7 @@ if (@ARGV > 0) { } } - +$ivy->bindRegexp("Ivymon Output=(.*)", [sub { $outputfile = $_[1]; }]); MainLoop; #================================================================================== @@ -1577,7 +1572,8 @@ sub newBinding { # skip expressions between parenthesis $msg =~ s/=\(.*?\)/= /g; - + $msg =~ s/\s+$//; + # duplicate expressions containing the | character my @expr; my $msgsnum = 1; @@ -2443,12 +2439,14 @@ sub savefile { my ($d, $m, $y, $h, $M) = (localtime(time))[3,4,5,2,1]; $y =~ s/^\d// if $y >= 100; $m++; - my $default = 'ivylog'.$d.$m.$y."_".$h.":".$M.".ivy"; + my $default = (defined $outputfile) ? $outputfile : + sprintf("ivylog%02s%02s%02s_%02s:%02s.ivy", $d, $m, $y, $h, $M); my $file = $mw->getSaveFile(-initialfile => $default, -filetypes => [['Ivy Files', '.ivy'], ['All Files', '*']], ); return unless $file; + $outputfile = $file; &showProgressbar(); # disable other buttons my $jumpstate = $jumpButton->cget(-state); @@ -2474,15 +2472,8 @@ sub savefile { }; my $status = 0; - # open file - unless (open(OUT, ">$file")) { + if (&save < 0) { $mw->Tk::Error("$!\n"); - &$restorestate; - return; - } - unless (&save) { - $mw->Tk::Error("$!\n"); - close(OUT); &$restorestate; return; } @@ -2492,8 +2483,37 @@ sub savefile { } # end savefile +sub openfile { + + my $file = $outputfile; + $file = $opt_out unless defined $file; + return 0 unless defined $file; + if (open(OUT, ">$file")) { + return 1; + } else { + close(OUT); + $mw->Tk::messageBox(-icon => "warning", + -message => + "Can't write to file $file ($!). ". + "Save data in ivymon-rescue.ivy", + -type => 'OK', + ); + if (open(OUT, ">ivymon-rescue.ivy")) { + return 1; + } else { + close(OUT); + $mw->Tk::Error("Can't write to output file ($!)"); + return -1; + } + } + +} # sub openfile + + sub save { + my $of = &openfile(); + return $of unless $of == 1; my $tpl = $mw->Toplevel; $tpl->Popup; $tpl->title("Save"); @@ -2501,7 +2521,7 @@ sub save { $tpl->Label(-text => "Saving data...")->pack(-expand => 1, -fill => 'both'); # save connected applications name my @clients = $clientsListbox->get(0, 'end'); - print OUT "applications=", join(',', @clients),"\n" or return; + print OUT "applications=", join(',', @clients),"\n" or return -1; my $nblines = $messagesText->index('end'); #print "nblines=$nblines\n"; @@ -2510,7 +2530,7 @@ sub save { $progressbar->configure(-to => $nblines); my $step = int($nblines/10); #print "step=$step\n"; - print OUT "messages_number=$nblines\n" or return; + print OUT "messages_number=$nblines\n" or return -1; # save messages 100 by 100, in order to reduce memory usage my $index = "1.0"; my $counter = 0; @@ -2522,7 +2542,7 @@ sub save { $progressbar->update; last; } - print OUT $messages or return; + print OUT $messages or return -1; &setProgressbar($counter); $counter += 100; $progressbar->update if ($step == 0 or $counter % $step == 0); @@ -2850,10 +2870,7 @@ sub warning3 { sub quit { print "Quit\n"; - if (defined $opt_out) { - $mw->Tk::Error("$!\n") unless (&save); - close(OUT); - } + $mw->Tk::Error("$!\n") if &save < 0; exit; } # end quit |