added "isabelle update_sub_sup" tool;
authorwenzelm
Fri Jul 12 14:54:17 2013 +0200 (2013-07-12)
changeset 526182077168aa8f7
parent 52617 42e02ddd1568
child 52619 70d5f2f7d27f
added "isabelle update_sub_sup" tool;
lib/Tools/update_sub_sup
lib/scripts/update_sub_sup
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/Tools/update_sub_sup	Fri Jul 12 14:54:17 2013 +0200
     1.3 @@ -0,0 +1,36 @@
     1.4 +#!/usr/bin/env bash
     1.5 +#
     1.6 +# Author: Makarius
     1.7 +#
     1.8 +# DESCRIPTION: update sub/sup control symbols
     1.9 +
    1.10 +
    1.11 +## diagnostics
    1.12 +
    1.13 +PRG="$(basename "$0")"
    1.14 +
    1.15 +function usage()
    1.16 +{
    1.17 +  echo
    1.18 +  echo "Usage: isabelle $PRG [FILES|DIRS...]"
    1.19 +  echo
    1.20 +  echo "  Recursively find .thy/.ML files and update control symbols for"
    1.21 +  echo "  sub- and superscript."
    1.22 +  echo
    1.23 +  echo "  Old versions of files are preserved by appending \"~~\"."
    1.24 +  echo
    1.25 +  exit 1
    1.26 +}
    1.27 +
    1.28 +
    1.29 +## process command line
    1.30 +
    1.31 +[ "$#" -eq 0 -o "$1" = "-?" ] && usage
    1.32 +
    1.33 +SPECS="$@"; shift "$#"
    1.34 +
    1.35 +
    1.36 +## main
    1.37 +
    1.38 +find $SPECS \( -name \*.ML -o -name \*.thy \) -print0 | \
    1.39 +  xargs -0 "$ISABELLE_HOME/lib/scripts/update_sub_sup"
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/lib/scripts/update_sub_sup	Fri Jul 12 14:54:17 2013 +0200
     2.3 @@ -0,0 +1,41 @@
     2.4 +#!/usr/bin/env perl
     2.5 +#
     2.6 +# Author: Makarius
     2.7 +#
     2.8 +# update_sub_sup - update sub/sup control symbols
     2.9 +
    2.10 +use warnings;
    2.11 +use strict;
    2.12 +
    2.13 +sub update_sub_sup {
    2.14 +    my ($file) = @_;
    2.15 +
    2.16 +    open (FILE, $file) || die $!;
    2.17 +    undef $/; my $text = <FILE>; $/ = "\n";         # slurp whole file
    2.18 +    close FILE || die $!;
    2.19 +
    2.20 +    $_ = $text;
    2.21 +
    2.22 +    s/\Q\<^isub>\E/\\<^sub>/g;
    2.23 +    s/\Q\<^isup>\E/\\<^sup>/g;
    2.24 +
    2.25 +    my $result = $_;
    2.26 +
    2.27 +    if ($text ne $result) {
    2.28 +        print STDERR "changing $file\n";
    2.29 +        if (! -f "$file~~") {
    2.30 +            rename $file, "$file~~" || die $!;
    2.31 +        }
    2.32 +        open (FILE, "> $file") || die $!;
    2.33 +        print FILE $result;
    2.34 +        close FILE || die $!;
    2.35 +    }
    2.36 +}
    2.37 +
    2.38 +
    2.39 +## main
    2.40 +
    2.41 +foreach my $file (@ARGV) {
    2.42 +  eval { &update_sub_sup($file); };
    2.43 +  if ($@) { print STDERR "*** update_sub_sup $file: ", $@, "\n"; }
    2.44 +}