lib/scripts/fixdots.pl
author berghofe
Thu, 30 Jul 1998 15:49:18 +0200
changeset 5213 0aa62210e67c
parent 4076 8315021bf7d6
child 9789 7e5e6c47c0b5
permissions -rw-r--r--
Script that adapts theories and proof scripts to new datatype package.

#
# $Id$
#
# fixdots.pl - ensure that dots in formulas are followed by non-idents
#
# tries to be smart; may produce garbage if nested comments and
# solitary quotes (") are intermixed badly;
#

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

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


    $result = "";
    $rest = $text;

    while (1) {
	$_ = $rest;
	($pre, $str, $rest) =
	    m/^((?: \(\*.*?\*\) | [^"] )*)      # pre: text or (non-nested!) comments
            "((?: [^"\\] | \\\S | \\\s+\\ )*)"  # quoted string
            (.*)$/sx;                           # rest of file
	if ($str) {
	    $_ = $str;
	    if (!m/^[a-zA-Z0-9_\/\.]*$/s && !m/\.ML/s && !m/\.thy/s) {   # exclude filenames!
		s/([a-zA-Z][a-zA-Z0-9_']*)\.([a-zA-Z])/$1\. $2/sg;
	    }
            $result = $result . $pre . '"' . $_ . '"';
        } else {
 	    $result = $result . $_;
    	    last;
	}
    }

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


## main

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