Admin/isa-migrate
changeset 16404 5f263e81e366
parent 16382 4fc8d8c99e9e
child 16406 4f393b8f84b7
equal deleted inserted replaced
16403:294a7864063e 16404:5f263e81e366
    21     id => sub {
    21     id => sub {
    22         my ($file, @content) = @_;
    22         my ($file, @content) = @_;
    23     },
    23     },
    24     thyheader => sub {
    24     thyheader => sub {
    25         my ($file, @content) = @_;
    25         my ($file, @content) = @_;
       
    26         #~ my $diag = 1;
       
    27         my $diag = 0;
    26         $_ = join("", @content);
    28         $_ = join("", @content);
    27         if (m!^theory!cgoms) {
    29         if (m!^theory!cgoms) {
    28             my $prelude = $';
    30             my $prelude = $';
    29             my $thyheader = "theory";
    31             my $thyheader = "theory";
    30             $thyheader .= skip_wscomment();
    32             $thyheader .= skip_wscomment();
    31             if (m!\G(\S+)!cgoms) {
    33             if (m!\G(\S+)!cgoms) {
    32                 $thyheader .= $1;
    34                 $thyheader .= $1;
    33                 $thyheader .= skip_wscomment();
    35                 $thyheader .= skip_wscomment();
    34                 print "--->\n>>>$thyheader<<<\n<---\n";
    36                 $diag and print "--->\n(1)>>>$thyheader<<<\n<---\n";
    35                 if (m!\G(?:imports|=)!cgoms) {
    37                 if (m!\G(?:imports|=)!cgoms) {
    36                     $thyheader .= "imports";
    38                     $thyheader .= "imports";
    37                     $thyheader .= skip_wscomment() || " ";
    39                     $thyheader .= skip_wscomment() || " ";
    38                     print "--->\n>>>$thyheader<<<\n<---\n";
    40                     $diag and print "--->\n(2)>>>$thyheader<<<\n<---\n";
    39                     while () {
    41                     while (m/\G(?!uses|files|begin|:)/cgoms && m!\G\w+!cgoms) {
    40                         my $str = read_plainstring();
    42                         $diag and print "--->\n(3)>>>$&<<<\n<---\n";
    41                         print "--->\n>>>$str<<<\n<---\n";
    43                         $thyheader .= $&;
    42                         if (! $str) {
    44                         $thyheader .= skip_wscomment();
    43                             last;
    45                         m/\G\+? ?/cgoms;
    44                         }
       
    45                         $thyheader .= $str;
       
    46                         $thyheader .= skip_wscomment();
    46                         $thyheader .= skip_wscomment();
    47                     }
    47                     }
    48                     #~ print "--->\n>>>$thyheader<<<\n<---\n";
    48                     $diag and print "--->\n(4)>>>$thyheader<<<\n<---\n";
    49                 }
    49                 }
    50                 if (m!\G(?:files|uses)!cgoms) {
    50                 if (m!\G(?:files|uses)!cgoms) {
    51                     $thyheader .= "uses";
    51                     $thyheader .= "uses";
    52                     $thyheader .= skip_wscomment();
    52                     $thyheader .= skip_wscomment();
    53                     while () {
    53                     $diag and print "--->\n(5)>>>$thyheader<<<\n<---\n";
    54                         my $str = read_plainstring();
    54                     while (m/\G(?!begin|:)/cgoms && m!\G(\("[^"]+"\)|"[^"]+"|[^"\s]+)!cgoms) {
    55                         if (! $str) {
    55                         $diag and print "--->\n(6)>>>$&<<<\n<---\n";
    56                             last;
    56                         $thyheader .= $&;
    57                         }
       
    58                         $thyheader .= $str;
       
    59                         $thyheader .= skip_wscomment();
    57                         $thyheader .= skip_wscomment();
    60                     }
    58                     }
       
    59                     $diag and print "--->\n(7)>>>$thyheader<<<\n<---\n";
    61                 }
    60                 }
       
    61                 #~ m!\G.{19}!cgoms;
       
    62                 #~ print "***$&\n";
       
    63 
    62                 if (m!\G(?:begin|:)!cgoms) {
    64                 if (m!\G(?:begin|:)!cgoms) {
    63                     my $postlude = $';
    65                     my $postlude = $';
       
    66                     if ($& == ":") {
       
    67                         $thyheader .= " ";
       
    68                     }
    64                     $thyheader .=  "begin";
    69                     $thyheader .=  "begin";
    65                     # do replacement here
    70                     # do replacement here
    66                     print "$file:\n$thyheader\n\n";
    71                     print "$file:\n$thyheader\n\n";
    67                 }
    72                 }
    68             }
    73             }
    95             return join('', @skipped);
   100             return join('', @skipped);
    96         }
   101         }
    97     }
   102     }
    98 }
   103 }
    99 
   104 
   100 sub read_plainstring {
       
   101     m!\G("[^"]+"|[^"\s]+)!cgoms or return "";
       
   102     return $&;
       
   103 }
       
   104 
       
   105 # process dir tree
   105 # process dir tree
   106 sub process_tree {
   106 sub process_tree {
   107     my ($root, $migrator, $backupext) = @_;
   107     my ($root, $migrator, $backupext) = @_;
   108     find(sub { process($File::Find::name, $migrator, $backupext) }, $root);
   108     find(sub { process($_, $migrator, $backupext) }, $root);
   109 }
   109 }
   110 
   110 
   111 # process single file
   111 # process single file
   112 sub process {
   112 sub process {
   113     my ($file, $migrator, $backupext) = @_;
   113     my ($file, $migrator, $backupext) = @_;
   137         process_tree($fileloc, $migrator, $backupext);
   137         process_tree($fileloc, $migrator, $backupext);
   138     } else {
   138     } else {
   139         process($fileloc, $migrator, $backupext);
   139         process($fileloc, $migrator, $backupext);
   140     }
   140     }
   141 }
   141 }
       
   142 
       
   143 #!!! example file: