# Routine to take missing.log entries and link to UGNT and ULB.KJV.Strongs use 5.12.0; use File::Slurp; $| = "\n"; use utf8; #use open IN => ":utf8", OUT => ":utf8"; use open IO => ":utf8"; binmode(STDOUT, ":utf8"); use File::Find ; use FindBin '$Bin'; use Cwd ; my ($pwd, $d, $textEditor, $repoPath, $browser) = ($Bin, "\\"); if ($^O eq "darwin" || $^O eq "linux") {$d = "/"} open LOG, ">:utf8", "Logs${d}mine_log.log" or die ("$!"); my ($udf) = "User_defaults.windows.txt"; if ($^O eq "linux") {$udf = "User_defaults.linux.txt"} elsif ($^O eq "darwin") {$udf = "User_defaults.mac.txt"} chdir $Bin; open (my $defaults, "<:utf8", "User${d}$udf") or die "User${d}$udf:\n$!"; GetUserDefaults(); my ($excFile, $topDir, $txtFile, $dataFile, $displayFile, $filePattern, $sn, $xfAbr, $thisULB) = ( "$Bin${d}Exceptions${d}Exceptions_tWs_from_OSHB.txt", "$repoPath${d}en_tw/bible", "$Bin${d}Temp${d}ULB_NASB_Strongs.txt", "$Bin${d}User${d}tW_work_NT.txt", "$Bin${d}Temp${d}mine_results.html", "*\.md" ); my ($missingLine, $bk, $ch, $vs, $ref, $strong, $word, $flag, $tNid, $abbr, $doFlag, $xmlFile, $outputFiles, $lbsBk, $url, $putative, $usfmFile); my (%bkAbr, %wa); my @tWfiles; find( sub { push @tWfiles, $File::Find::name if ( m/^(.*)$filePattern$/ ) }, $topDir) ; open OUT, ">:utf8", "$displayFile" or die; say OUT " "; ParseLine(); FindURL(); FindVerse($ref); ChecktWPages($word); Finish(); say OUT " "; close OUT; close LOG; print "\n\tDone.\n\n"; sub GetUserDefaults { open (my $defaults, "<:utf8", "$Bin${d}User${d}$udf") or die "$Bin${d}User${d}$udf:\n$!"; while (my $thisLine = <$defaults>) { chomp $thisLine; if ($thisLine =~ /^Text editor: (.*)$/) { $textEditor = "\"$1\""; } elsif ($thisLine =~ /^Repository directory: (.*)$/) { $repoPath = $1 } elsif ($thisLine =~ /^HTML browser: (.*)$/) { $browser = "\"$1\""; } } say LOG "\$textEditor: $textEditor\n\$repoPath: $repoPath\n\$browser: $browser"; die "No text editor found" if $textEditor eq ""; die "No path to repo found" if $repoPath eq ""; if ($^O eq "darwin") {$textEditor = "open -a $textEditor"; $browser = "open -a $browser"} close $defaults; } sub ParseLine { my ($sch, $svs); if ($^O eq "linux" || $^O eq "darwin") { say "\nEnter line from Entries_not_handled.txt:\n"; $missingLine = ; # I moved chomp to a new line to make it more readable chomp $missingLine; # Get rid of newline character at the end exit 0 if ($missingLine eq ""); # If empty string, exit. #$missingLine = "Zephaniah 1:2 5486"; } else { $missingLine = read_file ("Temp${d}temp.tmp"); } if ($missingLine =~ /^(([^:]*) (\d+):(\d+))\t([^\/]*\/([^\t]*))/) { ($ref, $bk, $ch, $vs, $url, $putative) = ($1, $2, $3, $4, $5, $6); $outputFiles .= "${url}.md "; say LOG "\$bk: $bk"; open (my $file, "<:utf8", "$dataFile") or die "$dataFile:\n$!"; while (my $line = <$file>) { chomp $line; if ($line =~ /^(# )?([^\t]*)\t([^\t]*)\t([^\t]*)$/) { my ($fullBk, $numBk, $abr) = ($2, $3, $4); say LOG "\$fullBk: |$fullBk|, \$numBk: $numBk, \$abr: $abr, \$bk: |$bk|"; if ($fullBk eq $bk) { say LOG "\$fullBk: |$fullBk|, \$bk: |$bk|"; $lbsBk = $abr; if ($numBk =~ /(\d\d)-(...)/) { $abbr = lc $2; say LOG "\$abbr: $abbr"; if ($^O eq "darwin") {system `open -a /Applications/Logos.app "logos4:TextComparison;ref=BibleESV.$lbsBk${ch}.$vs;res=esv,niv2011,niv,nasb95,nrsv,gs-netbible,nlt,leb,kjv1900"`} my $mxl; if ($bk eq "Psalms?") {$mxl = 3} else {$mxl = 2} while (length $ch < $mxl) {$ch =~ s/^/0/} while (length $vs < $mxl) {$vs =~ s/^/0/} } $usfmFile = "$repoPath${d}UGNT${d}${numBk}.usfm"; say LOG "\$abbr${d}\$ch${d}\$vs: $abbr${d}$ch${d}$vs"; if ($^O eq "darwin") {system `$textEditor $repoPath${d}en_tn${d}$abbr${d}$ch${d}$vs.md`} } } } close $file; } else { die "\n\tInput unreadable.\n" } say LOG "Looking for $putative in $usfmFile"; say LOG "\$missingLine: $missingLine, \$ref: $ref, \$bk: $bk, \$ch: $ch, \$vs: $vs, \$url: $url\n\n"; } sub FindURL { my ($thisChap, $thisVers); open (my $file, "<:utf8", "$usfmFile") or die "$usfmFile:\n$!"; while (my $line = <$file>) { chomp $line; if ($line =~ /\\mt (.*)$/) { my $thisBook = $1; if ($thisBook eq $bk) { say LOG "\$thisBook: $thisBook\t\$bk: $bk"; $doFlag = 1; } else { say LOG "\nThe wrong book is being searched.\n" } } elsif ($doFlag && $line =~ /^\\c (\d+)$/) { $thisChap = $1 } elsif ($doFlag && $line =~ /^\\v (\d+)$/) { $thisVers = $1 } elsif ($doFlag && $thisChap == $ch && $thisVers == $vs) { say LOG "\$thisChap:\$thisVers: $thisChap:$thisVers \$line: $line"; if ($line =~ /strong="([GH]....)(.).*$url/) { say OUT "

$line

"; $strong = $1; my $test = $2; if ($test ne "0") {die "\n\t\tStrong's number won't work.\n\n"} unless ($strong =~ /^.+$/) {die "\nThe Strong's number <$strong> is not found.\n"} while ($strong =~ s/([GH])0/$1/) {} if ($strong =~ /^.+$/) { say OUT "

$strong

\n"; last } } elsif ($line =~ /\\k-s[^\n]*$url/) { say OUT "

$url is part of a phrase

\n"; $flag = 1; } } elsif ($line =~ /\\mt (.*)$/) { $doFlag = 0 } } close $file; } sub FindVerse { my $fileText = read_file("$txtFile", binmode => 'utf8'); say LOG "FindVerse |$strong|."; if ($flag && $fileText =~ /$ref\t[^\n]*\n[^\n]*\n/) { say LOG "$ref\n$&"; say $&; exit 0; } else { if ($fileText =~ /$ref([^\n]*\n )([^\n]*<)$strong(.?>[^\n]*)/) { my ($fore, $precon, $aft) = ($1, $2, $3); say LOG "\$ref: $ref\n\$fore: $fore\n\$precon:\n$precon\n\$aft: $aft"; my $preprecon; if ($precon =~ /^(.*([,>\w\'\"\- —;] |['";\.\?\!]))([\w\-]+) (<[^<>]*> )?<$/) { ($preprecon, $word) = ($1, $3); say LOG "\$&: $&\n\$preprecon: $preprecon\n\$word: $word"; } $preprecon =~ s//>/g; $aft =~ s//>/g; say OUT "

$ref$fore

\n

$preprecon$word <$strong$aft

\n"; } else { say OUT "

The Strong's code <<$strong>> is not found in $ref.

"; say OUT "

${ref}\\t[^\\n]*\\n[^\\n]*

"; #system ("bbfind -g \"${ref}\\t[^\\n]*\\n[^\\n]*\" 'data${d}ULB_NASB_Strongs.txt'") or die "$!"; if ($^O eq "darwin") {system ("find $topDir -name \"*.md\" -exec grep -H --color \"$strong\[, \\n\\r\]\" {} \\;")} #system ("find $topDir -name \"*.md\" -exec grep -H --color \"$strong\$\" {} \\;"); } } return $word; } sub ChecktWPages{ say LOG "<<$word>>"; die "\n\$word is empty.\n" if $word eq ""; my $topDir = "$repoPath${d}en_tw${d}bible"; foreach my $file ( @tWfiles ) { my $fileText = read_file("$file", binmode => 'utf8'); # While finds entries and Strong's numbers while ($fileText =~ /($strong)[^\d]|^(# [^\n]*\b$word\b)/g) { #system `clear`; my $abb = $file; $abb =~ s/.md$//; say OUT "

$abb

\n"; $outputFiles .= "$file " } } } sub Finish { say "\nLooking for $strong."; # find $topDir -name "*.md" -exec grep -H '($strong[^\d]|$strong$)' {} + #system ("find $topDir -name \"*.md\" -exec grep -H --color \"$strong\[, \\n\\r\]\" {} \\;"); foreach my $file ( @tWfiles ) { my $fileText = read_file("$file", binmode => 'utf8'); # While finds entries and Strong's numbers if ($fileText =~ /([^\n]*)($strong)([^\n]*)/g) { my ($pre, $found, $post) = ($1, $2, $3); my $abb = $file; $abb =~ s/.md$//; say OUT "

$abb: $pre$found$post

\n"; $outputFiles .= "$file " } } say "\nLooking for $putative."; foreach my $file ( @tWfiles ) { my $fileText = read_file("$file", binmode => 'utf8'); # While finds entries and Strong's numbers if ($fileText =~ /#{1,1} ([^\n]*)(\b$putative\b)([^\n]*)/g) { my ($pre, $found, $post) = ($1, $2, $3); my $abb = $file; $abb =~ s/.md$//; say OUT "

$abb: $pre$found$post

\n"; $outputFiles .= "$file " } } say "\nLooking for $word."; foreach my $file ( @tWfiles ) { my $fileText = read_file("$file", binmode => 'utf8'); # While finds entries and Strong's numbers if ($fileText =~ /#{1,1} ([^\n]*)(\b$word\b)([^\n]*)/g) { my ($pre, $found, $post) = ($1, $2, $3); my $abb = $file; $abb =~ s/.md$//; say OUT "

$abb: $pre$found$post

\n"; $outputFiles .= "$file " } } say "Opening .md files."; if ($^O eq "darwin") { system `$browser https://www.blueletterbible.org/lang/lexicon/lexicon.cfm?strongs=$strong`; system `$textEditor $outputFiles`; system `$textEditor $excFile`;} if ($^O eq "linux") { system `$browser https://www.blueletterbible.org/lang/lexicon/lexicon.cfm?strongs=$strong &`; system `$textEditor $outputFiles &`; system `$textEditor $excFile &`;} if ($^O eq "MSWin32" || $^O eq "MSWin64" ) { system `START "" $browser https://www.blueletterbible.org/lang/lexicon/lexicon.cfm?strongs=$strong`; system `START "" $textEditor $outputFiles`; system `START "" $textEditor $excFile`; system `START "" $browser $displayFile`;} }