| 52618 |      1 | #!/usr/bin/env perl
 | 
|  |      2 | #
 | 
|  |      3 | # Author: Makarius
 | 
|  |      4 | #
 | 
| 52921 |      5 | # update_sub_sup - update Isabelle symbols involving sub/superscripts
 | 
| 52618 |      6 | 
 | 
|  |      7 | use warnings;
 | 
|  |      8 | use strict;
 | 
|  |      9 | 
 | 
|  |     10 | sub update_sub_sup {
 | 
|  |     11 |     my ($file) = @_;
 | 
|  |     12 | 
 | 
|  |     13 |     open (FILE, $file) || die $!;
 | 
|  |     14 |     undef $/; my $text = <FILE>; $/ = "\n";         # slurp whole file
 | 
|  |     15 |     close FILE || die $!;
 | 
|  |     16 | 
 | 
|  |     17 |     $_ = $text;
 | 
|  |     18 | 
 | 
|  |     19 |     s/\Q\<^isub>\E/\\<^sub>/g;
 | 
|  |     20 |     s/\Q\<^isup>\E/\\<^sup>/g;
 | 
| 52921 |     21 |     s/\Q\<onesuperior>\E/\\<^sup>1/g;
 | 
|  |     22 |     s/\Q\<twosuperior>\E/\\<^sup>2/g;
 | 
|  |     23 |     s/\Q\<threesuperior>\E/\\<^sup>3/g;
 | 
| 52618 |     24 | 
 | 
|  |     25 |     my $result = $_;
 | 
|  |     26 | 
 | 
|  |     27 |     if ($text ne $result) {
 | 
|  |     28 |         print STDERR "changing $file\n";
 | 
|  |     29 |         if (! -f "$file~~") {
 | 
|  |     30 |             rename $file, "$file~~" || die $!;
 | 
|  |     31 |         }
 | 
|  |     32 |         open (FILE, "> $file") || die $!;
 | 
|  |     33 |         print FILE $result;
 | 
|  |     34 |         close FILE || die $!;
 | 
|  |     35 |     }
 | 
|  |     36 | }
 | 
|  |     37 | 
 | 
|  |     38 | 
 | 
|  |     39 | ## main
 | 
|  |     40 | 
 | 
|  |     41 | foreach my $file (@ARGV) {
 | 
|  |     42 |   eval { &update_sub_sup($file); };
 | 
|  |     43 |   if ($@) { print STDERR "*** update_sub_sup $file: ", $@, "\n"; }
 | 
|  |     44 | }
 |