lib/scripts/fixdots.pl
author paulson
Mon, 16 Nov 1998 10:36:30 +0100
changeset 5865 2303f5a3036d
parent 4076 8315021bf7d6
child 9789 7e5e6c47c0b5
permissions -rw-r--r--
moved some facts about Pi from ex/PiSets to Fun.ML
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3824
9fdde15e3215 ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff changeset
     1
#
9fdde15e3215 ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff changeset
     2
# $Id$
9fdde15e3215 ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff changeset
     3
#
9fdde15e3215 ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff changeset
     4
# fixdots.pl - ensure that dots in formulas are followed by non-idents
9fdde15e3215 ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff changeset
     5
#
3826
wenzelm
parents: 3824
diff changeset
     6
# tries to be smart; may produce garbage if nested comments and
wenzelm
parents: 3824
diff changeset
     7
# solitary quotes (") are intermixed badly;
wenzelm
parents: 3824
diff changeset
     8
#
wenzelm
parents: 3824
diff changeset
     9
wenzelm
parents: 3824
diff changeset
    10
sub fixdots {
wenzelm
parents: 3824
diff changeset
    11
    my ($file) = @_;
wenzelm
parents: 3824
diff changeset
    12
wenzelm
parents: 3824
diff changeset
    13
    open (FILE, $file) || die $!;
wenzelm
parents: 3824
diff changeset
    14
    undef $/; $text = <FILE>; $/ = "\n";         # slurp whole file
wenzelm
parents: 3824
diff changeset
    15
    close FILE || die $!;
wenzelm
parents: 3824
diff changeset
    16
wenzelm
parents: 3824
diff changeset
    17
wenzelm
parents: 3824
diff changeset
    18
    $result = "";
wenzelm
parents: 3824
diff changeset
    19
    $rest = $text;
wenzelm
parents: 3824
diff changeset
    20
wenzelm
parents: 3824
diff changeset
    21
    while (1) {
wenzelm
parents: 3824
diff changeset
    22
	$_ = $rest;
wenzelm
parents: 3824
diff changeset
    23
	($pre, $str, $rest) =
3838
wenzelm
parents: 3826
diff changeset
    24
	    m/^((?: \(\*.*?\*\) | [^"] )*)      # pre: text or (non-nested!) comments
3826
wenzelm
parents: 3824
diff changeset
    25
            "((?: [^"\\] | \\\S | \\\s+\\ )*)"  # quoted string
3838
wenzelm
parents: 3826
diff changeset
    26
            (.*)$/sx;                           # rest of file
3826
wenzelm
parents: 3824
diff changeset
    27
	if ($str) {
wenzelm
parents: 3824
diff changeset
    28
	    $_ = $str;
wenzelm
parents: 3824
diff changeset
    29
	    if (!m/^[a-zA-Z0-9_\/\.]*$/s && !m/\.ML/s && !m/\.thy/s) {   # exclude filenames!
wenzelm
parents: 3824
diff changeset
    30
		s/([a-zA-Z][a-zA-Z0-9_']*)\.([a-zA-Z])/$1\. $2/sg;
wenzelm
parents: 3824
diff changeset
    31
	    }
wenzelm
parents: 3824
diff changeset
    32
            $result = $result . $pre . '"' . $_ . '"';
wenzelm
parents: 3824
diff changeset
    33
        } else {
wenzelm
parents: 3824
diff changeset
    34
 	    $result = $result . $_;
wenzelm
parents: 3824
diff changeset
    35
    	    last;
wenzelm
parents: 3824
diff changeset
    36
	}
wenzelm
parents: 3824
diff changeset
    37
    }
wenzelm
parents: 3824
diff changeset
    38
wenzelm
parents: 3824
diff changeset
    39
    if ($text ne $result) {
wenzelm
parents: 3824
diff changeset
    40
	print STDERR "fixing $file\n";
4076
8315021bf7d6 do not overwrite backup files;
wenzelm
parents: 3838
diff changeset
    41
        if (! -f "$file~~") {
8315021bf7d6 do not overwrite backup files;
wenzelm
parents: 3838
diff changeset
    42
	    rename $file, "$file~~" || die $!;
8315021bf7d6 do not overwrite backup files;
wenzelm
parents: 3838
diff changeset
    43
        }
3826
wenzelm
parents: 3824
diff changeset
    44
	open (FILE, "> $file") || die $!;
wenzelm
parents: 3824
diff changeset
    45
	print FILE $result;
wenzelm
parents: 3824
diff changeset
    46
	close FILE || die $!;
wenzelm
parents: 3824
diff changeset
    47
    }
wenzelm
parents: 3824
diff changeset
    48
}
wenzelm
parents: 3824
diff changeset
    49
wenzelm
parents: 3824
diff changeset
    50
wenzelm
parents: 3824
diff changeset
    51
## main
3824
9fdde15e3215 ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff changeset
    52
9fdde15e3215 ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff changeset
    53
foreach $file (@ARGV) {
3826
wenzelm
parents: 3824
diff changeset
    54
  eval { &fixdots($file); };
wenzelm
parents: 3824
diff changeset
    55
  if ($@) { print STDERR "*** fixdots $file: ", $@, "\n"; }
3824
9fdde15e3215 ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff changeset
    56
}