# 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"; use File::Find ; use Cwd ; my ($pwd, $^O, $d, $textEditor, $repoPath) = (cwd(), $^O, "\\"); if ($^O eq "darwin" || $^O eq "linux") {$d = "/"} open OUT, ">:utf8", "Temp${d}mine_results.html" or die; #binmode(STDOUT, "encoding(UTF-8)"); GetUserDefaults(); my ($outputFiles, $topDir, $usfmFile, $txtFile, $lbsBk, $dataFile, $doFlag) = ( "$repoPath${d}en_tw/bible${d}", "$repoPath${d}en_tw/bible", "", "Temp${d}ULB.NASB.Strongs.txt", "", "User${d}tW_work_NT.txt" ); my ($missingLine, $bk, $ch, $vs, $ref, $url, $strong, $word, $flag, $putative, $tNid, $abbr); open LOG, ">:utf8", "Logs${d}mine.log.log" or die; #open OUT, ">:utf8", $outputFile or die; ParseLine(); FindURL(); FindVerse($ref); ChecktWPages($word); Finish(); #close OUT; close LOG; print "\n\tDone.\n\n"; sub GetUserDefaults { open (my $defaults, "<:utf8", "data${d}UserDefaults") or die "data${d}UserDefaults:\n$!"; while (my $thisLine = <$defaults>) { chomp $thisLine; if ($thisLine =~ /^Text editor: (.*)$/) { $textEditor = $1; } elsif ($thisLine =~ /^Repository directory: (.*)$/) { $repoPath = $1 } } say LOG "\$textEditor: $textEditor, \$repoPath: $repoPath"; 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"} close $defaults; } sub ParseLine { say OUT "\n\n\033[0;1;31mEnter line from missing.log:\033[m\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 = "Mark 11:6 kt/command"; 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"; 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"; #system `open -a /Applications/Logos.app "logosres:esv;ref=BibleESV.$lbsBk${ch}.$vs"`; 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"} `; } 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 $line"; if ($line =~ /strong="([GH]....)(.).*$url/) { say OUT "\n\$line:\n$line\n"; $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 "\033[0;1;31m$strong\033[m\n"; last } } elsif ($line =~ /\\k-s[^\n]*$url/) { say OUT "\n\t$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"; } say "$ref$fore$preprecon\033[0;0;32m$word\033[m <\033[0;1;31m$strong\033[m$aft\n"; } else { say "\n\nThe Strong's code <<$strong>> is not found in $ref.\n\n"; if ($^O eq "darwin") {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\]\" {} \\;")} } } return $word; } sub ChecktWPages{ say LOG "<<$word>>"; die "\n\$word is empty.\n" if $word eq ""; my $topDir = "$repoPath${d}en_tw${d}bible"; my @filesToRun = (); my $filePattern = '*.md' ; find( sub { push @filesToRun, $File::Find::name if ( m/^(.*)$filePattern$/ ) }, $topDir) ; foreach my $file ( @filesToRun ) { 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 "\033[0;1;31m$abb\033[m"; $outputFiles .= "$file " } } } sub Finish { say "\nLooking for $strong."; # find $topDir -name "*.md" -exec grep -H '($strong[^\d]|$strong$)' {} + if ($^O eq "darwin") {system ("find $topDir -name \"*.md\" -exec grep -H --color \"$strong\[, \\n\\r\]\" {} \\;")} if ($^O eq "darwin") {system ("find $topDir -name \"*.md\" -exec grep -H --color \"$strong\$\" {} \\;")} #system ("find $topDir -name \"*.md\" -exec grep -H --color \"\($strong\[, \\n\\r\]\|$strong\$\)\" {} \\;"); say "\nLooking for $putative."; #system ("find $topDir -name \"*.md\" -exec grep -Hi --color \"^# $putative\[^A-Za-z\]\" {} \\;"); #system ("find $topDir -name \"*.md\" -exec grep -Hi --color \"^# .*\[^A-Za-z\]$putative\[^A-Za-z\]\" {} \\;"); if ($^O eq "darwin") {system ("find $topDir -name \"*.md\" -exec egrep -Hi --color \"^# (.*\[^A-Za-z\])?$putative\[^A-Za-z\]\" {} \\;")} say "\nLooking for $word."; #system ("find $topDir -name \"*.md\" -exec grep -Hi --color \"^#$word\[^A-Za-z\]\" {} \\;"); #system ("find $topDir -name \"*.md\" -exec grep -Hi --color \"^# .*\[^A-Za-z\]$word\[^A-Za-z\]\" {} \\;"); if ($^O eq "darwin") {system ("find $topDir -name \"*.md\" -exec egrep -Hi --color \"^# (.*\[^A-Za-z\])?$word\[^A-Za-z\]\" {} \\;")}; say "Opening .md files."; if ($^O eq "darwin") {system `open -a /Applications/Firefox.app https://www.blueletterbible.org/lang/lexicon/lexicon.cfm?strongs=$strong`} if ($^O eq "darwin") {system `open -a /Applications/BBEdit.app $outputFiles`} }