File: recat

package info (click to toggle)
perl-tk 1%3A800.015-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,636 kB
  • ctags: 18,270
  • sloc: ansic: 195,135; perl: 37,385; makefile: 4,380; sh: 2,286; yacc: 762
file content (67 lines) | stat: -rwxr-xr-x 1,242 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/local/bin/perl -w
use strict;
my $sec;            
my %cat;       
my @cat;
while (<>)
 {
  if (/^beginBookmark\s+'(.*)'\s*$/)
   {
    $sec = $1;
    unless (exists $cat{$sec})
     {
      $cat{$sec} = [];
      push(@cat,$sec); 
     }
    }
  elsif (/^file\s+(\S+)/)
   {
    my $file = $1;
    push(@{$cat{$sec}},$file);
   }
 }
                 
$^I = ".bak";
foreach my $sec (@cat)
 {
  foreach my $file (@{$cat{$sec}})
   {
    my $undo = 0;
    $/ = "";
    @ARGV = ($file);
    while (<>)
     {
      if (/^=head1\sNAME/)
       {
        do {
             print if (defined $^I);
             $_ = <>;
           } until (eof || /^=\w+/);
        if (/^=for\s+category\s+(.*)\n+/)
         {
          if ($1 eq $sec)
           {          
            warn "$file okay\n";
            $undo = 1;
           }
          else
           {
            warn "Change $file $1 -> $sec\n";
            $_ = "=for category $sec\n\n";
           }  
         } 
        else
         {
          warn "$_ Add $file -> $sec\n";
          print "=for category $sec\n\n";
         }
       }
      print if (defined $^I);
     }
    if ($undo && defined $^I)
     {
      unlink($file);
      rename("$file$^I",$file);
     }
   }
 }