-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremoveHeaderRefs.pl
More file actions
executable file
·77 lines (66 loc) · 2.24 KB
/
Copy pathremoveHeaderRefs.pl
File metadata and controls
executable file
·77 lines (66 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl
# Find all occurrences like this in Sara Ngam NT:
# \p 1:11
# \p (Mise 5:1)
# Anna Beth Wivell reports that the first case were running headers
# left in by the people who put the text into Paratext. It concerned
# page layout in the print version and is not right.
# The second case is an example of a cross-ref that should be a \r
# instead of a \p.
# Problem: I was seeing this script INTRODUCE ^M carriage returns into
# the output when they were NOT there in the original source .SFM files.
# I did not understand this. Some files had and some did not.
# The issue was in part that 0d0a line endings were present in the original,
# but Emacs was not visually showing it. Strange.
# To make everything work right, I had to add
# $ln =~ s/[\r\n]+//g;
# at the beginning of the loop to clear out everything offending,
# and then put a \n at the end of every line as I want it.
#
# Something was also messed up in the pattern match, but I got rid of $
# at the end of them, and that works better.
# After doing this, I found another case that needs attention:
# \p
# 4:27
# in 44JHNNgam.SFM
# around line 235. There were quite a few of these in there.
# Need to figure out what to do
# Usage: removeHeaderRefs *.SFM
sub removeHeaderRefs {
my $fni = shift(@_);
my $fno = shift(@_);
open (my $fhi, "<", $fni);
open (my $fho, ">", "$fno");
while ($ln = <$fhi>) {
$ln =~ s/[\r\n]+//g;
if ($ln =~ /^\\p [0-9]+:[0-9]+\s*/) {
#print "This looks suspicious, remove: $ln\n";
# Do not print it
}
elsif ($ln =~ /^\\p (\([\w\.]+\s[0-9]+:[0-9]+\))\s*/) {
#print "This looks like it could be \\r: $ln\n";
print $fho "\\r $1\n";
}
else {
print $fho "$ln\n";
}
}
close($fhi);
close($fho);
}
## MAIN ##
# Tip: to do a mass rename, do this:
# rename 's/\.bak$//' *.bak
# This removes .bak from every filename.bak file
foreach $filename (@ARGV) {
print "Processing $filename\n";
$filenamebak = "$filename.bak";
# rename the file to .bak
if (!rename ($filename, $filenamebak)) {
die "Cannot backup $filename : $!";
exit(1);
}
# Now put the contents of the backup (original) file into the
# new file, but with the transformation requested.
removeHeaderRefs($filenamebak, $filename);
}