| 1 |
#!/usr/bin/perl |
| 2 |
# $Id: homonym,v 1.3 1995/09/04 21:48:25 rd Exp $ |
| 3 |
# |
| 4 |
# Replacement of old homonym C program |
| 5 |
# |
| 6 |
# Format of homfile: |
| 7 |
# // any line starting with '//' is ignored |
| 8 |
# Full name 1 = |
| 9 |
# Variant A of 1 |
| 10 |
# Variant B_of_1 |
| 11 |
# Full_name 2 = |
| 12 |
# Variant of 2 |
| 13 |
# etc. |
| 14 |
# i.e. the correct names come first, followed by an '=' sign |
| 15 |
# all names on subsequent lines up until the next '=' sign are treated |
| 16 |
# as homonyms. NOTE THAT THIS IS DIFFERENT FROM THE OLD FORMAT. |
| 17 |
# |
| 18 |
# By default Author lines are substituted, but you can apply to any other |
| 19 |
# tag using option "-T tag" |
| 20 |
# |
| 21 |
# Option -c will just output information on changes that will be made |
| 22 |
# |
| 23 |
# Option -2 is like -T, but looks for items 2 in from the tag |
| 24 |
# |
| 25 |
# Lines ending with '// fix' will not be changed |
| 26 |
|
| 27 |
$usage = "Usage: homonym [-T tag] [-c] [-2 tag] homfile [files]\n" ; |
| 28 |
|
| 29 |
$tag = "Author" ; # default tag |
| 30 |
|
| 31 |
while ($ARGV[0] =~ /^-/) { # process switches |
| 32 |
$_ = shift ; |
| 33 |
if (/^-T(.*)/) { $tag = $1 ? $1 : shift ; } |
| 34 |
if (/^-2(.*)/) { $tag2 = $1 ? $1 : shift ; } |
| 35 |
elsif (/^-c$/) { $check = 1 ; } |
| 36 |
else { die "Unrecognized switch: $_\n" ; } |
| 37 |
} |
| 38 |
|
| 39 |
# process homfile into %map ; |
| 40 |
|
| 41 |
die $usage unless @ARGV ; |
| 42 |
open (HOM, shift) || die "Can't open homfile $_\n" ; |
| 43 |
|
| 44 |
while (<HOM>) { |
| 45 |
/^\s+\/\// && next ; # ignore comment lines |
| 46 |
if ( /\s*(\S.*\S)\s+=\s*$/ ) { |
| 47 |
$target = $1 ; |
| 48 |
} |
| 49 |
elsif ( /(\S.*\S)/ ) { |
| 50 |
$map{$1} = $target ; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
die $usage unless @ARGV || !-t ; |
| 55 |
|
| 56 |
while (<>) { |
| 57 |
s/(\S+)\s+:/$1/ ; # strip out horrible colons |
| 58 |
if ( (/^$tag\s+"(.+)"/o || |
| 59 |
/^$tag\s+"(.+)"?$/o || |
| 60 |
/^$tag\s+(\S+)/o ) && |
| 61 |
$_ !~ /\/\/ fix$/ && |
| 62 |
defined $map{$1}) { |
| 63 |
if ($check) { |
| 64 |
print "$.\t$1 -> $map{$1}\n" ; |
| 65 |
} |
| 66 |
else { |
| 67 |
s/$1/$map{$1}/ ; |
| 68 |
} |
| 69 |
if ( (/^$tag2\s+".+"\s+"(.+)"/o || |
| 70 |
/^$tag2\s+".+"\s+"(.+)"?$/o || |
| 71 |
/^$tag2\s+".+"\s(\S+)/o || |
| 72 |
/^$tag2\s+\S+\s+"(.+)"/o || |
| 73 |
/^$tag2\s+\S+\s+"(.+)"?$/o || |
| 74 |
/^$tag2\s+\S+\s(\S+)/o) && |
| 75 |
$_ !~ /\/\/ fix$/ && |
| 76 |
defined $map{$1}) { |
| 77 |
if ($check) { |
| 78 |
print "$.\t$1 -> $map{$1}\n" ; |
| 79 |
} |
| 80 |
else { |
| 81 |
s/$1/$map{$1}/ ; |
| 82 |
} |
| 83 |
} |
| 84 |
print unless $check ; |
| 85 |
} |
| 86 |
|
| 87 |
############# end of file ############ |