author | wenzelm |
Sat, 04 Sep 1999 21:05:01 +0200 | |
changeset 7474 | 43cedde6d52a |
parent 4076 | 8315021bf7d6 |
child 9789 | 7e5e6c47c0b5 |
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$ |
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 | 6 |
# tries to be smart; may produce garbage if nested comments and |
7 |
# solitary quotes (") are intermixed badly; |
|
8 |
# |
|
9 |
||
10 |
sub fixdots { |
|
11 |
my ($file) = @_; |
|
12 |
||
13 |
open (FILE, $file) || die $!; |
|
14 |
undef $/; $text = <FILE>; $/ = "\n"; # slurp whole file |
|
15 |
close FILE || die $!; |
|
16 |
||
17 |
||
18 |
$result = ""; |
|
19 |
$rest = $text; |
|
20 |
||
21 |
while (1) { |
|
22 |
$_ = $rest; |
|
23 |
($pre, $str, $rest) = |
|
3838 | 24 |
m/^((?: \(\*.*?\*\) | [^"] )*) # pre: text or (non-nested!) comments |
3826 | 25 |
"((?: [^"\\] | \\\S | \\\s+\\ )*)" # quoted string |
3838 | 26 |
(.*)$/sx; # rest of file |
3826 | 27 |
if ($str) { |
28 |
$_ = $str; |
|
29 |
if (!m/^[a-zA-Z0-9_\/\.]*$/s && !m/\.ML/s && !m/\.thy/s) { # exclude filenames! |
|
30 |
s/([a-zA-Z][a-zA-Z0-9_']*)\.([a-zA-Z])/$1\. $2/sg; |
|
31 |
} |
|
32 |
$result = $result . $pre . '"' . $_ . '"'; |
|
33 |
} else { |
|
34 |
$result = $result . $_; |
|
35 |
last; |
|
36 |
} |
|
37 |
} |
|
38 |
||
39 |
if ($text ne $result) { |
|
40 |
print STDERR "fixing $file\n"; |
|
4076 | 41 |
if (! -f "$file~~") { |
42 |
rename $file, "$file~~" || die $!; |
|
43 |
} |
|
3826 | 44 |
open (FILE, "> $file") || die $!; |
45 |
print FILE $result; |
|
46 |
close FILE || die $!; |
|
47 |
} |
|
48 |
} |
|
49 |
||
50 |
||
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 | 54 |
eval { &fixdots($file); }; |
55 |
if ($@) { print STDERR "*** fixdots $file: ", $@, "\n"; } |
|
3824
9fdde15e3215
ensure that dots in formulas are followed by non-idents;
wenzelm
parents:
diff
changeset
|
56 |
} |