REM MAGSAMRX 3.0 - MAGSAM/E FILE REORGANIZATION UTILITY
REM                        FOR CP/M AND CB80
REM 
REM CB80 VERSION - REAL RECORD NUMBERS
REM
REM PROPRIETARY SOFTWARE OF:
REM
REM  MICRO APPLICATIONS GROUP
REM  7300 CALDUS AVENUE
REM  VAN NUYS, CA 91406
REM
REM (C) COPYRIGHT 1980-1982 MAG
REM 
      DIM MAGSAM$(20),MAGSAM(20)
      PRINT:PRINT:PRINT
      PRINT "MAGSAMRX 3.0 - MAGSAM/E FILE REORGANIZATION UTILITY"
      PRINT "(C) COPYRIGHT 1980-1982 MICRO APPLICATIONS GROUP"
100   PRINT: INPUT "ENTER INDEX FILE NAME: ";I$
      MAGSAM(1)=1: REM INDEX FILE NUMBER
      MAGSAM(2)=2: REM DATA FILE NUMBER
      PRINT: INPUT "ENTER OVERFLOW FILE NAME: ";O$
      MAGSAM(3)=3: REM OVERFLOW FILE NUMBER
      PRINT: INPUT "ENTER KEY LENGTH: "; MAGSAM(4)
      PRINT: INPUT "ENTER PERCENT FREE SPACE FOR NEW INDEX: ";MAGSAM(7)
      PRINT: INPUT "PRESS RETURN TO BEGIN REORGANIZATION OR ENTER 'END': "; \
         LINE MAGSAM$(1)
      MAGSAM$(1)=UCASE$(MAGSAM$(1))
      IF MAGSAM$(1)="END" THEN GOTO 990
      IF MID$(I$,2,1)=":" THEN IP$=MID$(I$,1,2): REM SAVE FILE PREFIXES FOR
      IF MID$(O$,2,1)=":" THEN OP$=MID$(O$,1,2): REM   FILE REORGANIZATION
      OPEN I$ RECL 256 AS MAGSAM(1)
      OPEN O$ RECL 256 AS MAGSAM(3)
      GOSUB 1000
      CLOSE MAGSAM(1),MAGSAM(3)
990   PRINT: INPUT "DO YOU WISH TO REORGANIZE MORE FILES? (Y/N) ";X$
      X$=UCASE$(X$)
      IF X$="Y" THEN GOTO 100
      IF X$<>"N" THEN GOTO 990
      PRINT:PRINT"MAGSAMRX COMPLETE":PRINT
      STOP
1000  REM REORGANIZATION SUBROUTINE
      TI$=IP$+"TEMPI.$$$":TO$=OP$+"TEMPO.$$$"
      MAGSAM(5)=4:MAGSAM(6)=5
      MAGSAM$(1)="RO"
      CREATE TI$ RECL 256 AS MAGSAM(5)
      CREATE TO$ RECL 256 AS MAGSAM(6)
      GOSUB 64000
      IF MAGSAM(8)<>0 THEN \
         PRINT:PRINT">> ERROR: ";MAGSAM(8): \
         DELETE MAGSAM(5),MAGSAM(6): \
         GOTO 1090
      CLOSE MAGSAM(1),MAGSAM(3),MAGSAM(5),MAGSAM(6)
      BI$=IP$+"OLDI.BAK":BO$=OP$+"OLDO.BAK"
      IF END # 6 THEN 1050
      OPEN BI$ RECL 256 AS 6: DELETE 6
1050  IF END # 7 THEN 1060
      OPEN BO$ RECL 256 AS 7: DELETE 7
1060  DUM%=RENAME(BI$,I$): DUM%=RENAME(BO$,O$)
      DUM%=RENAME(I$,TI$): DUM%=RENAME(O$,TO$)
      OPEN I$ RECL 256 AS MAGSAM(1)
      OPEN O$ RECL 256 AS MAGSAM(3)
      PRINT:PRINT"FILE SUCCESSFULLY REORGANIZED"
1090  RETURN
%INCLUDE MAGSAMRO.CB8
      END
