lib/scripts/update_sub_sup
author blanchet
Thu, 12 Jun 2014 01:00:49 +0200
changeset 57225 ff69e42ccf92
parent 52921 0ea2b657eb42
permissions -rwxr-xr-x
register record extensions as freely generated types

#!/usr/bin/env perl
#
# Author: Makarius
#
# update_sub_sup - update Isabelle symbols involving sub/superscripts

use warnings;
use strict;

sub update_sub_sup {
    my ($file) = @_;

    open (FILE, $file) || die $!;
    undef $/; my $text = <FILE>; $/ = "\n";         # slurp whole file
    close FILE || die $!;

    $_ = $text;

    s/\Q\<^isub>\E/\\<^sub>/g;
    s/\Q\<^isup>\E/\\<^sup>/g;
    s/\Q\<onesuperior>\E/\\<^sup>1/g;
    s/\Q\<twosuperior>\E/\\<^sup>2/g;
    s/\Q\<threesuperior>\E/\\<^sup>3/g;

    my $result = $_;

    if ($text ne $result) {
        print STDERR "changing $file\n";
        if (! -f "$file~~") {
            rename $file, "$file~~" || die $!;
        }
        open (FILE, "> $file") || die $!;
        print FILE $result;
        close FILE || die $!;
    }
}


## main

foreach my $file (@ARGV) {
  eval { &update_sub_sup($file); };
  if ($@) { print STDERR "*** update_sub_sup $file: ", $@, "\n"; }
}