program Hunt
* To hunt for a string in a series of files and records.
*
lower = "abcdefghijklmnopqrstuvwxyz"
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Search = trimf(trimb(field(@SENTENCE,' ',2,len(@SENTENCE))))
convert lower to upper in Search

if @(0,0) then null

gosub LoadFileList
MoreFiles = FileList ne ""
if not(MoreFiles) or (Search eq "") then
   crt "Usage:"
   crt '   SELECT VOC WITH TYPE EQ "F" ...'
   crt '   HUNT searchtext'
end
open "","VOC" to VocFile else
   stop "Unable to open the VOC file.  (hunt)"
end
SaveList = "PA"
loop while MoreFiles do
   remove FileName from FileList setting MoreFiles
   gosub ProcessFile
repeat
if SaveList ne "PA" then
   write SaveList to VocFile, "EDIT"
   crt "Edit paragraph written to voc file as EDIT."
end
return

ProcessFile:
open "",FileName to File else
   crt "Unable to open ":FileName:" file. (hunt)"
   return
end
select File
loop
   readnext RecordName else
      exit
   end
   if RecordName[1,1] eq "$" then continue
   read Record from File, RecordName else
      continue
   end
   Copy = Record
   convert lower to upper in Copy
   Idx = index(Copy,Search,1)
   if Idx then
      Field = dcount(Record[1,Idx], @FM)
      crt
      crt ("0000":Field)[4]:" ":Record<Field>[1,74]
      crt "    Found in ":FileName:" ":RecordName
      SaveList<-1> = "DISPLAY :ED ":FileName:" ":RecordName
      SaveList<-1> = "ED ":FileName:" ":RecordName
      SaveList<-1> = "DATA L ":Search
   end
repeat
close File
return

LoadFileList:
FileList = ""
loop
   readnext FileName else exit
   FileList<-1> = FileName
repeat
return
end
