author | nipkow |
Tue, 05 Jun 2001 09:41:11 +0200 | |
changeset 11360 | 45f837f8889d |
parent 9789 | 7e5e6c47c0b5 |
child 14981 | e73f8140af78 |
permissions | -rw-r--r-- |
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$ |
9789 | 3 |
# Author: Markus Wenzel, TU Muenchen |
4 |
# License: GPL (GNU GENERAL PUBLIC LICENSE) |
|
3824
9fdde15e3215
ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff
changeset
|
5 |
# |
9fdde15e3215
ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff
changeset
|
6 |
# 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
|
7 |
# |
3826 | 8 |
# tries to be smart; may produce garbage if nested comments and |
9 |
# solitary quotes (") are intermixed badly; |
|
10 |
# |
|
11 |
||
12 |
sub fixdots { |
|
13 |
my ($file) = @_; |
|
14 |
||
15 |
open (FILE, $file) || die $!; |
|
16 |
undef $/; $text = <FILE>; $/ = "\n"; # slurp whole file |
|
17 |
close FILE || die $!; |
|
18 |
||
19 |
||
20 |
$result = ""; |
|
21 |
$rest = $text; |
|
22 |
||
23 |
while (1) { |
|
24 |
$_ = $rest; |
|
25 |
($pre, $str, $rest) = |
|
3838 | 26 |
m/^((?: \(\*.*?\*\) | [^"] )*) # pre: text or (non-nested!) comments |
3826 | 27 |
"((?: [^"\\] | \\\S | \\\s+\\ )*)" # quoted string |
3838 | 28 |
(.*)$/sx; # rest of file |
3826 | 29 |
if ($str) { |
30 |
$_ = $str; |
|
31 |
if (!m/^[a-zA-Z0-9_\/\.]*$/s && !m/\.ML/s && !m/\.thy/s) { # exclude filenames! |
|
32 |
s/([a-zA-Z][a-zA-Z0-9_']*)\.([a-zA-Z])/$1\. $2/sg; |
|
33 |
} |
|
34 |
$result = $result . $pre . '"' . $_ . '"'; |
|
35 |
} else { |
|
36 |
$result = $result . $_; |
|
37 |
last; |
|
38 |
} |
|
39 |
} |
|
40 |
||
41 |
if ($text ne $result) { |
|
42 |
print STDERR "fixing $file\n"; |
|
4076 | 43 |
if (! -f "$file~~") { |
44 |
rename $file, "$file~~" || die $!; |
|
45 |
} |
|
3826 | 46 |
open (FILE, "> $file") || die $!; |
47 |
print FILE $result; |
|
48 |
close FILE || die $!; |
|
49 |
} |
|
50 |
} |
|
51 |
||
52 |
||
53 |
## main |
|
3824
9fdde15e3215
ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff
changeset
|
54 |
|
9fdde15e3215
ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff
changeset
|
55 |
foreach $file (@ARGV) { |
3826 | 56 |
eval { &fixdots($file); }; |
57 |
if ($@) { print STDERR "*** fixdots $file: ", $@, "\n"; } |
|
3824
9fdde15e3215
ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff
changeset
|
58 |
} |