Rem Sub Finddoc v1.0a for Dndbbs 4.7c PD 2001.
Rem $Include: 'qbx.bi'
Dim Variables(1024) As String
Dim InregsX As RegTypeX
Dim OutRegsX As RegTypeX
Color 15, 0
Print "Keyword finder v1.0a:"
' read command line from PSP
CommandLine$ = ""
InregsX.AX = &H6200
CALL InterruptX(&H21, InregsX, OutregsX)
PSPsegment = OutregsX.BX
PSPoffset = 128
DEF SEG = PSPsegment
FOR Count = 1 TO 127
   Command.Char = PEEK(PSPoffset + Count)
   SELECT CASE Command.Char
   CASE 0, 10, 13
      EXIT FOR
   CASE ELSE
      CommandLine$ = CommandLine$ + CHR$(Command.Char)
   END SELECT
NEXT
DEF SEG
CommandLine$ = LTRIM$(CommandLine$)
If Len(CommandLine$) Then
   Var=Instr(Ucase$(CommandLine$),"/X")
   If Var Then
      CommandLine$=Left$(CommandLine$,Var-1)+Mid$(CommandLine$,Var+2)
      OutputFile=-1
   Endif
Endif
If CommandLine$="/?" Or CommandLine$="-?" Then
   Color 14, 0
   Print "Finds keywords in Dndbbs text files;"
   Print "Specify variable to find on command line."
   Color 7, 0
   Print "Exiting to system:"
   End
Endif
If CommandLine$="" Then
   Color 15, 0
   Print "Enter keyword? ";
   Line Input CommandLine$
Endif
Print "Case sensitive(y/n)? ";
Locate ,,1
Do
   Var$=Inkey$
   If Len(Var$) Then
      Select Case Lcase$(Var$)
      Case "y"
         Print "y"
         Sensitive=-1
         Exit Do
      Case "n"
         Print "n"
         Sensitive=0
         Exit Do
      End Select
   Endif
Loop
Color 15, 0
Print "Finding: "; CHR$(34);
Color 14, 0
Print CommandLine$;
Color 15, 0
Print CHR$(34); " ";
VarF!=Timer
Variable1=0
CommandLine$=Ltrim$(CommandLine$)
CommandLine$=Rtrim$(CommandLine$)
If Sensitive=0 Then
   CommandLine$=Lcase$(CommandLine$)
Endif
For File.Types=1 To 2
   If File.Types=1 Then
      FileSpec$="*.txt"
   Else
      FileSpec$="*.doc"
   Endif
   Filename$=Dir$(FileSpec$)
   While Len(Filename$)
      Close
      Open Filename$ For Input As #1
      Variable3=Variable3+1
      Gosub Dot.Display
      ' go through file searching for variable
      Do While Not Eof(1)
         Line Input #1,InputLine$
         InputLine$=Ltrim$(InputLine$)
         InputLine$=Rtrim$(InputLine$)
         If Sensitive=0 Then
            InputLine$=Lcase$(InputLine$)
         Endif
         If Len(InputLine$)>0 Then
            If Instr(InputLine$,CommandLine$)>0 Then
               Variable1=Variable1+1
               Variable2=Variable2+1
               Variables(Variable1)=Filename$
               ' go through remaining file counting variables
               Do While Not Eof(1)
                  Line Input #1,InputLine$
                  InputLine$=Ltrim$(InputLine$)
                  InputLine$=Rtrim$(InputLine$)
                  If Sensitive=0 Then
                     InputLine$=Lcase$(InputLine$)
                  Endif
                  If Len(InputLine$)>0 Then
                     If Instr(InputLine$,CommandLine$)>0 Then
                        Variable2=Variable2+1
                     Endif
                  Endif
               Loop
            Endif
         Endif
      Loop
      Filename$=Dir$
   Wend
Next
Print
If Variable1>1 Then
   For Sort1=1 To Variable1
      For Sort2=Sort1+1 To Variable1
         If Variables(Sort1)>Variables(Sort2) Then
            Swap Variables(Sort1),Variables(Sort2)
         Endif
      Next
   Next
Endif
Color 15, 0
Print "Files counted:"; Variable3
If Variable2=1 Then
   Var$=" 1 keyword "
Else
   Var$=Str$(Variable2)+" keywords "
Endif
Select Case Variable1
Case 0
   Print "No keywords found in any files."
Case 1
   Print "Total of"+Var$+"found in 1 file."
Case Else
   Print "Total of"+Var$+"found in"+Str$(Variable1)+" files."
End Select
Page=2
Color 14, 0
If Variable1>0 Then
   If OutputFile Then
      Close
      Open "finddata.txt" For Output As #1
      Print #1,"Results for: "+CommandLine$
   Endif
   For Var=1 To Variable1
      Filename$=Variables(Var)
      Filename$=Filename$+Space$(15-Len(Filename$))
      If OutputFile Then
         Print #1, Filename$;
      Else
         Print Filename$;
      Endif
      Line1=Line1+1
      If Line1=5 Then
         If OutputFile Then
            Print #1,""
         Else
            Print
            Page=Page+1
            If Page=23 Then
               Page=0
               Color 15, 0
               Print "More:";
               While Inkey$=""
               Wend
               Print
               Color 14, 0
            Endif
         Endif
         Line1=0
      Endif
   Next
Endif
If OutputFile Then
   Print #1,""
Else
   Print
Endif
Color 7, 0
Print "Exiting to system:"
End

Dot.Display:
 VarG!=Timer-VarE!
 If VarG!<0! Then
    VarG!=Elapsed.Time!+86400!
 Endif
 If VarG!>=1! Then
    VarE!=Timer
    If VarD=0 Then
       VarC=VarC+1
       Print ".";
       If VarC=5 Then
          VarD=-1
          VarC=0
       Endif
    Else
       VarC=VarC+1
       Locate Csrlin,Pos(0)-1,0
       Print " ";
       Locate Csrlin,Pos(0)-1,1
       If VarC=5 Then
          VarD=0
          VarC=0
       Endif
    Endif
 Endif
 Return
