 REM Ver 6.7b
 CLS
 PRINT "This program will search through all new backup and/or all history files"
 PRINT "to extract the latest position of each station.  It outputs these summaries"
 PRINT "to the ALLBAKS.hst and ALLHSTS.hst files."
 PRINT
 PRINT "These files are saved as HISTORY files.  This is so that they"
 PRINT "can be REPLAYED at any time to find out where someone is without"
 PRINT "destroying data on the P or L list."
 PRINT
 PRINT "To use them, just select FILE-REPLAY and after selecting the ALLBAKS.hst or"
 PRINT "the ALLHSTS.hst file, then select the callsign of the station you are looking"
 PRINT "for.  If that station is in the file, APRS will draw the map with that"
 PRINT "station on it."
 PRINT
 PRINT "Or you can use these files to see everyone in a given area.  Just choose"
 PRINT "the map area you are interested in, and replay the file.  Every call in "
 PRINT "the file that is in that area will appear on the map!"
 PRINT
 LOCATE 25, 1: INPUT "Hit ENTER to continue..."; a$
 CLS
 PRINT "Once you run this program ONCE, it saves the two summary files in your HSTS"
 PRINT "Directory where you can find it easliy.  From then on, whenever you want to "
 PRINT "clean up your normal APRS\HSTS directory, just run this program instead of "
 PRINT "just deleting all the old TKxxxxx.HST files.  Unless told otherwise, this"
 PRINT "program will look through all new TKxxxxx.HST files and combine any new calls"
 PRINT "with the existing ALLHSTS.HST or ALLBAKS.HST files."
 PRINT
 PRINT "Once this is done, you can delete all of the old TKxxxxx.HST files if"
 PRINT "you no longer need them."
 PRINT
 DIM P$(800)

 INPUT "Search all BK (B) or HST files (H)"; a$
 IF LEFT$(UCASE$(a$), 1) = "B" THEN GOTO BAKS

HSTS: HSTpath$ = "\APRS\HSTS"
  PRINT "Enter path to your APRS\HSTS directory if not "; HSTpath$;
  INPUT a$: IF a$ <> "" THEN HSTpath$ = a$
  INPUT "Search ALL files or just new TK files (T)"; Ans$: Ans$ = UCASE$(Ans$)
     
  SHELL "dir " + HSTpath$ + " >temp.hst"
     
  OPEN "temp.hst" FOR INPUT AS #1
  DO UNTIL EOF(1)
     LINE INPUT #1, a$: REM PRINT a$
     IF LEN(a$) > 38 AND LEFT$(a$, 1) <> "." AND LEFT$(a$, 1) <> " " THEN
        IF Ans$ = "A" OR LEFT$(a$, 2) = "TK" OR LEFT$(a$, 7) = "ALLHSTS" THEN
           F$ = LEFT$(a$, 8) + "." + MID$(a$, 10, 3)
           LOCATE 24, 1: PRINT "Opening "; F$
           OPEN HSTpath$ + "\" + F$ FOR INPUT AS #2
           GOSUB Do25th
           IF INKEY$ = CHR$(27) THEN EXIT DO
           DO UNTIL EOF(2)
              LINE INPUT #2, a$
              PRINT ".";
              IF LEN(a$) > 40 THEN
                 NxPosC$ = MID$(a$, 1, 9)
                 NxPosT$ = MID$(a$, 19, 6)
                 REM PRINT LEFT$("        Found " + a$, 79)
                 Haveit = 0
                 FOR i = 1 TO NumPos
                     IF NxPosC$ = LEFT$(P$(i), 9) THEN
                        Haveit = -1
                        REM now compare times
                        IF NxPosT$ > MID$(P$(i), 12, 6) THEN 'it is later so swap
                           P$(i) = a$: LOCATE 24, 1
                           PRINT LEFT$("      NEWER POSIT: " + P$(i), 79)
                           GOSUB Do25th
                        END IF 'if it was newer
                     END IF' if it is the same callsign
                 NEXT i ' compare to all existing P$(i)
                 IF Haveit = 0 THEN
                    NumPos = NumPos + 1
                    P$(NumPos) = a$: LOCATE 24, 1
                    PRINT NumPos; LEFT$("      Add pos: " + P$(NumPos), 73)
                    GOSUB Do25th
                 END IF
              END IF' if it was a POSITION (p,)
           LOOP 'read the next line in the BK file
           CLOSE #2 ' Finished all of that file
        END IF 'if it was a valid file name
     END IF
  LOOP 'to the next BK file
  CLOSE #1 ' Finished that all files in that directory

  F$ = "ALLHSTS.hst"
  PRINT "Enter name of OUTPUT file if other than "; F$;
  INPUT a$: IF a$ <> "" THEN F$ = a$
  OPEN F$ FOR OUTPUT AS #3: PRINT "OPENING OUTPUT FILE..."; F$
  FOR i = 1 TO NumPos: PRINT #3, P$(i): NEXT i
  CLOSE #3
  STOP
    
BAKS: BKpath$ = "\APRS\BAKS"
  PRINT "Enter path to your APRS\BAKS directory if not "; BKpath$;
  INPUT a$: IF a$ <> "" THEN BKpath$ = a$
  SHELL "dir " + BKpath$ + " >temp.bk"

  OPEN "temp.bk" FOR INPUT AS #1
  DO UNTIL EOF(1)
     LINE INPUT #1, a$: REM print a$
     IF LEN(a$) > 38 AND LEFT$(a$, 1) <> "." AND LEFT$(a$, 1) <> " " THEN
        IF Ans$ = "A" OR LEFT$(a$, 2) = "BK" OR LEFT$(a$, 7) = "ALLBAKS" THEN
           F$ = LEFT$(a$, 8) + "." + MID$(a$, 10, 3)
           PRINT "Opening "; F$
           OPEN BKpath$ + "\" + F$ FOR INPUT AS #2
           GOSUB Do25th
           DO UNTIL EOF(2)
              LINE INPUT #2, a$
              PRINT ".";
              IF LEFT$(a$, 1) = "p" THEN
                 NxPosC$ = MID$(a$, 3, 9)
                 NxPosT$ = MID$(a$, 21, 6)
                 REM PRINT LEFT$("        Found " + a$, 79)
                 Haveit = 0
                 FOR i = 1 TO NumPos
                     IF NxPosC$ = LEFT$(P$(i), 9) THEN
                        Haveit = -1
                        REM now compare times
                        IF NxPosT$ > MID$(P$(i), 12, 6) THEN 'it is later so swap
                           P$(i) = MID$(a$, 3): LOCATE 24, 1
                           PRINT LEFT$("      NEWER POSIT: " + P$(i), 79)
                           GOSUB Do25th
                        END IF 'if it was newer
                     END IF' if it is the same callsign
                 NEXT i ' compare to all existing P$(i)
                 IF Haveit = 0 THEN
                    NumPos = NumPos + 1
                    P$(NumPos) = MID$(a$, 3): LOCATE 24, 1
                    PRINT NumPos; LEFT$("      Add pos: " + P$(NumPos), 73)
                    GOSUB Do25th
                 END IF
              END IF' if it was a POSITION (p,)
           LOOP 'read the next line in the BK file
           CLOSE #2 ' Finished all of that file
        END IF 'if it was a valid file name
     END IF
  LOOP 'to the next BK file
  CLOSE #1 ' Finished all files in that directory

  F$ = "ALLBAKS.hst"
  PRINT "Enter output file if other than "; F$;
  INPUT a$: IF a$ <> "" THEN F$ = a$
  OPEN F$ FOR OUTPUT AS #3: PRINT "OPENING OUTPUT FILE..."; F$
  FOR i = 1 TO NumPos: PRINT #3, P$(i): NEXT i
  CLOSE #3
  STOP

Do25th: LOCATE 25, 1: PRINT SPACE$(80);
        LOCATE 25, 1
        RETURN


  END






