* - FOG.CMD
* - CALLED FROM MENU.CMD
* - USES FOG1.DBF; FOG2.DBF; FOG3.DBF; ..... ETC.
ERASE
release all
SET TALK OFF
*continue permits entry of new set of string while n get next dbf file
store "1" to n
store 1 to records
store t to continue
store " " to print
ERASE
*allow user to say where data files are located
ACCEPT "ENTER Drive identifier A,B,C, etc. where data file is located " TO DI

*use only 1st char for drive; if 2nd char y then run short version for test 
*program treats all entries as if in uppercase for any comparisons

if len(di)  > 1
  store !($(di,2,1)) to test
else 
  store "N" to test
endif

store !($(di,1,1)) to di

*repeat until requested to end
do while continue
store t to help
store " " to again
set bell on
set inten off
*use data file 'n'
  if file ("&di"+":fog"+n+".dbf")
    store ("&di"+":fog"+n+".dbf") to journal1
    use &journal1
  else
    ? "No data base file present - Search Routine Canceled"
    Return
  endif
  do while help

*mtext and ntext will hold strings to be searched for 
erase
STORE "                      " TO MTEXT
store "                      " to ntext

@  5,10 SAY "Enter the exact character string you wish to search"
@  6,10 SAY "for, include spaces and punctuation as necessary.  You can use "
@  7,10 SAY "either upper or lower case.  The search is only for the entered "
@  8,10 say "characters. For a more confined search enter a second string:"
@ 10,10 say "    i.e. word and patch would limit the search to patches "
@ 11,10 say "    for wordprocessing programs or Wordstar patches.  While"
@ 12,10 say "    word alone would find every conceivable match for word."
*get the string or strings entered without trailing blanks and in uppercase
@ 14, 5 say "1st string: "GET MTEXT
@ 15, 5 say "2nd string: "get ntext
@ 17,10 SAY "Press Return twice without an entry to end processing."
@ 19,10 say "For HELP: Enter 'H' alone in 1st string and Press Return twice"  
read
*?
*? "Output can be directed to either the printer or the screen, not both."
*Accept "Enter 'P' if a printout is wanted else Return for screen" to print 

STORE !(TRIM(MTEXT)) TO MTEXT
store !(trim(ntext)) to ntext

*if no first string end run
 IF MTEXT = " "
  RELEASE ALL
  RETURN
  ENDIF

*if 1st string = H show help screen
 if "H" = mtext
   if .not. file("fog-help.cmd")
     erase
     store 1 to hc
do while hc < 30 
@ 19,10 say "The Help file is not on the logged disk"
     store hc +1 to hc
     enddo
else
     do fog-help
    endif
  else
    store f to help
  endif
enddo
?
? "Output can be directed to either the printer or the screen, not both."
Accept "Enter 'P' if a printout is wanted else Return for screen" to print 

*set up counters to display data found, line 0 is reserved to dbase
ERASE
STORE 1 TO LINE
STORE 0 TO COUNT

* search for every occurance while not eof, when eof switch to next file
* which fools dbase since new is not eof and continues search
DO WHILE .NOT. EOF
* message to show operation
if !(print) = "P"
@ 1,count say "Searching....."
else
@ line,count say "Searching....."
endif
if records = 20
  if !(print) = "P"
    @ 1,count+15 say #
    @ 1,count+20 say " Records searched"
    @ 1,count+38 say "in file &n"
    store 0 to records
else
@ line,count + 15 say #
  @ line,count + 20 say " Records searched"
  @ line,count + 38 say "in file &n"
  store 0 to records
endif
endif
* asterisk means deleted so skip record
do while * .and. .not. eof
 skip
 store records + 1 to records
enddo
set inten on

*  search for each string anywhere ($) in virtual uppercase (!) subject




 if (MTEXT)  $ (!(subject)) .and. (ntext)  $ (!(subject))
   do fog-sub 
endif
 

if test = "Y"
 skip 7
 store records + 7 to records
else
 skip
 store records + 1 to records
endif
*on eof go to next file if it exists after test 
if eof
  store 1 to records
  store str(val(n)+1,1) to n
  *test to see if there is another file
  if file ("&di"+":fog"+n+".dbf")
    store ("&di"+":fog"+n+".dbf") to journal1
    use &journal1
    endif
endif

ENDDO

*after search of 2nd file display message and allow to look for new string(s)
set bell off
set inten off
erase
@ line +4, 0 say "The string(s) had been:  &mtext, &ntext "  
@ line +5, 0 say "No more articles contain the Search String(s)."
@ line +6, 0 say "To search for different string(s) Type 'Y'."
@ line +7, 0 say "To end searching completely enter any other key: "
* read whether to do new search
@ line +6,50 get again picture "!"

read
set inten on
if again <> "Y"
	store f to continue
	endif
if again = "Y"
    store "1" to n
    store 1 to records
    erase
release oldpattern,newpattern, endstring, character, firstchar
release lastchar,nextchar,endstring,empty,isblank,isnumber,cpointer
release isupper,islower,makelower,makeupper,capfirst,startstr,addchar
release string

endif
enddo

RETURN
