lib/scripts/unsymbolize
author wenzelm
Thu May 20 20:20:52 2010 +0200 (2010-05-20)
changeset 37012 106c56e916f8
parent 35022 c844b93dd147
child 41457 3bb2f035203f
permissions -rwxr-xr-x
enable shell script editor mode;
     1 #!/usr/bin/env perl
     2 #
     3 # Author: Markus Wenzel, TU Muenchen
     4 #
     5 # unsymbolize.pl - remove unreadable symbol names from sources
     6 #
     7 
     8 use warnings;
     9 use strict;
    10 
    11 sub unsymbolize {
    12     my ($file) = @_;
    13 
    14     open (FILE, $file) || die $!;
    15     undef $/; my $text = <FILE>; $/ = "\n";         # slurp whole file
    16     close FILE || die $!;
    17 
    18     $_ = $text;
    19 
    20     # Pure
    21     s/\\?\\<And>/!!/g;
    22     s/\\?\\<Colon>/::/g;
    23     s/\\?\\<Longrightarrow>/==>/g;
    24     s/\\?\\<Midarrow>\\?\\<Rightarrow>/==>/g;
    25     s/\\?\\<Rightarrow>/=>/g;
    26     s/\\?\\<equiv>/==/g;
    27     s/\\?\\<dots>/.../g;
    28     s/\\?\\<lbrakk> ?/[| /g;
    29     s/\\?\\ ?<rbrakk>/ |]/g;
    30     s/\\?\\<lparr> ?/(| /g;
    31     s/\\?\\ ?<rparr>/ |)/g;
    32     # HOL
    33     s/\\?\\<longleftrightarrow>/<->/g;
    34     s/\\?\\<longrightarrow>/-->/g;
    35     s/\\?\\<midarrow>\\?\\<rightarrow>/-->/g;
    36     s/\\?\\<rightarrow>/->/g;
    37     s/\\?\\<not>/~/g;
    38     s/\\?\\<notin>/~:/g;
    39     s/\\?\\<noteq>/~=/g;
    40     s/\\?\\<some> ?/SOME /g;
    41     # outer syntax
    42     s/\\?\\<rightleftharpoons>/==/g;
    43     s/\\?\\<rightharpoonup>/=>/g;
    44     s/\\?\\<leftharpoondown>/<=/g;
    45 
    46     my $result = $_;
    47 
    48     if ($text ne $result) {
    49 	print STDERR "fixing $file\n";
    50         if (! -f "$file~~") {
    51 	    rename $file, "$file~~" || die $!;
    52         }
    53 	open (FILE, "> $file") || die $!;
    54 	print FILE $result;
    55 	close FILE || die $!;
    56     }
    57 }
    58 
    59 
    60 ## main
    61 
    62 foreach my $file (@ARGV) {
    63   eval { &unsymbolize($file); };
    64   if ($@) { print STDERR "*** unsymbolize $file: ", $@, "\n"; }
    65 }