Ignore:
Timestamp:
08/13/09 17:47:26 (15 years ago)
Author:
nanardon
Message:
  • add la-edit tool
Location:
LATMOS-Accounts/lib/LATMOS/Accounts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm

    r333 r334  
    396396        } 
    397397    } 
     398    return 1; 
    398399} 
    399400 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Utils.pm

    r267 r334  
    77use utf8; 
    88use LATMOS::Accounts::Log; 
     9use File::Temp qw(tempfile); 
    910 
    1011our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; 
     
    5253} 
    5354 
     55sub parse_obj_file { 
     56    my ($handle) = @_; 
    5457 
     58    my %attributes; 
     59    while (my $line = <$handle>) { 
     60        $line =~ /^#/ and next; 
     61        chomp($line); 
     62        my ($attr, $value) = $line =~ /^\s*(\S+):\s*(.*)\s*$/; 
     63        if ($attributes{$attr}) { 
     64            if (ref $attributes{$attr}) { 
     65                push(@{ $attributes{$attr} }, $value); 
     66            } else { 
     67                my $temp = $attributes{$attr}; 
     68                $attributes{$attr} = [ $temp, $value ]; 
     69            } 
     70        } else { 
     71            $attributes{$attr} = $value; 
     72        } 
     73    } 
     74    %attributes 
     75} 
     76 
     77sub dump_read_temp_file { 
     78    my ($writecb, $readcb) = @_; 
     79 
     80    my ($fh, $filename) = tempfile(CLEANUP => 0); 
     81    $writecb->($fh) or return; 
     82    $fh = undef; # closing file 
     83    my $res; 
     84     
     85    my @stat = stat($filename); 
     86    while (1) { 
     87        my $cmd = ($ENV{EDITOR} || 'vi') . " $filename"; 
     88        warn "Running $cmd\n"; 
     89        if (system($cmd) == -1 ) { 
     90            warn "Cannot run editor $!\n"; 
     91            last; 
     92        } 
     93        if ((stat($filename))[9] == $stat[9]) { 
     94            warn "No change existing\n"; 
     95            last; 
     96        } 
     97 
     98        open($fh, '<', $filename) or return; 
     99        $res = $readcb->($fh); 
     100        $fh = undef; # closing again 
     101        $res < 2 and last; 
     102    } 
     103    unlink($filename); 
     104    $res; 
     105} 
    551061; 
Note: See TracChangeset for help on using the changeset viewer.