"Fossies" - the Fresh Open Source Software Archive

Member "namefix.pl/libs/undo.pm" (13 Dec 2008, 1611 Bytes) of package /linux/privat/old/namefix.pl_4.0.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "undo.pm" see the Fossies "Dox" file reference documentation.

    1 # undo routines
    2 
    3 use warnings;
    4 use strict;
    5 
    6 sub clear_undo
    7 {
    8     # clear undo arrays, atm we only have 1 level of undo
    9     &plog(3, "sub clear_undo: wiping undo history");
   10     @main::undo_cur     = ();
   11     @main::undo_pre     = ();
   12 
   13     &save_file($main::undo_cur_file, "");
   14     &save_file($main::undo_pre_file, "");
   15     &save_file($main::undo_dir_file, $main::dir);
   16     $main::undo_dir = $main::dir;
   17 }
   18 
   19 sub undo_add
   20 {
   21     my $f1 = shift;
   22     my $f2 = shift;
   23 
   24     push @main::undo_pre, $f1;
   25     push @main::undo_cur, $f2;
   26 
   27     &file_append($main::undo_pre_file, "$f1\n");
   28     &file_append($main::undo_cur_file, "$f2\n");
   29 }
   30 
   31 sub undo_rename
   32 {
   33     # for some reason when CLI called undo full paths were causing havoc
   34     # I read up on perls rename and it doesnt have the most relaible behaviour
   35     # especicially when cross platform coding.
   36     # undo_rename needs to be able to handle for paths for recursive undos
   37     #
   38     # Work around:
   39     # grabs directory from filename
   40     # changes to directory
   41     # chops FQ filename to filename.
   42 
   43     &plog(3, "sub undo_rename");
   44     &plog(1, "Preforming Undo");
   45     my $c = 0;
   46     my $pre = "";
   47     my $dir = "";
   48 
   49     for my $cur(@main::undo_cur)
   50     {
   51         $pre = $main::undo_pre[$c];
   52         $cur =~ m/^(.*\/)(.*?)$/;
   53         $dir = $1;
   54         $cur = $2;
   55         chdir $dir;
   56         $pre =~ m/^(.*\/)(.*?)$/;
   57         $pre = $2;
   58 
   59         if(!-f "$cur")
   60         {
   61             &plog(0, "sub undo_rename: \"$cur\" current file does not exist");
   62         }
   63         if(-f "$pre")
   64         {
   65             &plog(0, "sub undo_rename: \"$pre\" previous filename to revert undo to allready exists");
   66         }
   67  
   68         &plog(4, "sub undo_rename: rename $cur $pre");
   69         rename $cur, $pre;
   70         &nf_print($cur, $pre);
   71         $c++;
   72     }
   73     chdir $main::dir;
   74     return 1;
   75 }
   76 
   77 
   78 
   79 1;