C
C         ADDRESS / PHONE NO. LIST        by Bruce W. Roeckel
C       *--------------------------*                         
C
C
$STORAGE:2
C
C
      COMMON/MAIN1/ LAST,FIRST,ADD1,ADD2,CITY,STATE,ZIP,PH1,PH2
      CHARACTER LAST(12,200)*1,FIRST(200)*23,ADD1(200)*30,ADD2(200)*30
      CHARACTER CITY(200)*23,STATE(200)*2,ZIP(200)*5
      CHARACTER PH1(200)*14,PH2(200)*14
C
      COMMON/MAIN2/ STRID,SORT,MNUM
      INTEGER*4 STRID(200),SORT(200),MNUM
C
      COMMON /REVNO/ PGM,AUTHOR,YEAR,DATE,REV
      CHARACTER PGM*21,AUTHOR*21,YEAR*4,DATE*8,REV*2
C
      COMMON/LETT/ALPHA,ALPH2
      CHARACTER*1 ALPHA(26),ALPH2(26)
C
      CHARACTER OPTION*25,KEY*1,SEL*1
      LOGICAL*2 CHECK
C
C           SET UP COMMON BLOCK OF ALPHABET
C
      ALPHA(1)='A'
      ALPHA(2)='B'
      ALPHA(3)='C'
      ALPHA(4)='D'
      ALPHA(5)='E'
      ALPHA(6)='F'
      ALPHA(7)='G'
      ALPHA(8)='H'
      ALPHA(9)='I'
      ALPHA(10)='J'
      ALPHA(11)='K'
      ALPHA(12)='L'
      ALPHA(13)='M'
      ALPHA(14)='N'
      ALPHA(15)='O'
      ALPHA(16)='P'
      ALPHA(17)='Q'
      ALPHA(18)='R'
      ALPHA(19)='S'
      ALPHA(20)='T'
      ALPHA(21)='U'
      ALPHA(22)='V'
      ALPHA(23)='W'
      ALPHA(24)='X'
      ALPHA(25)='Y'
      ALPHA(26)='Z'
      ALPH2(1)='a'
      ALPH2(2)='b'
      ALPH2(3)='c'
      ALPH2(4)='d'
      ALPH2(5)='e'
      ALPH2(6)='f'
      ALPH2(7)='g'
      ALPH2(8)='h'
      ALPH2(9)='i'
      ALPH2(10)='j'
      ALPH2(11)='k'
      ALPH2(12)='l'
      ALPH2(13)='m'
      ALPH2(14)='n'
      ALPH2(15)='o'
      ALPH2(16)='p'
      ALPH2(17)='q'
      ALPH2(18)='r'
      ALPH2(19)='s'
      ALPH2(20)='t'
      ALPH2(21)='u'
      ALPH2(22)='v'
      ALPH2(23)='w'
      ALPH2(24)='x'
      ALPH2(25)='y'
      ALPH2(26)='z'
C
C           DISPLAY ROCKSOFT HEADER
C
      PGM='Address Book         '
      AUTHOR='Bruce W. Roeckel     '
      YEAR='1986'
      REV='07'
      CALL MHEAD(PGM,AUTHOR,YEAR,REV,DATE)
      CALL TOP(PGM,DATE)
C
C           READ THE DATABASE INTO CORE
C
      CALL RDMAST
      CALL SORTIT
C
C           CHECK FOR HELP DOCUMENT FILE
C
      IHLP=0
      INQUIRE(FILE='ADDRESS.HLP',EXIST=CHECK)
      IF(CHECK .EQV. .TRUE.) THEN
         IHLP=1
         OPEN(15,FILE='ADDRESS.HLP')
      ENDIF
C
C           NOW DISPLAY MAIN MENU
C
  100 CONTINUE
      OPTION='Main Menu'
      CALL HEADER(OPTION)
         WRITE(*,150)
  150    FORMAT(/,3X,'Total Entries in',
     A          /,3X,'Master File: ',\)
         CALL BOLD
         WRITE(*,'(I3)') MNUM
         CALL OFF
      WRITE(*,200) 
  200 FORMAT(/,
     A      //,20X,' 1. Add / Delete / Edit Master File Entries  ',
     B       /,20X,' 2. Browse Entire Master File                ',
     C       /,20X,' 3. Print Master Address & Phone No. List    ',
     D       /,20X,' 4. Print Wallet Size Address Booklet        ',
     E       /,20X,' 5. Print Phone Number Only Summary          ')
C
C            ASK FOR SELECTION, THEN BRANCH BASED ON INPUT
C
  300 CONTINUE
      IV=21
      IH=1
      CALL MOVEIT(IH,IV)
      WRITE(*,'(/,5X,A37,\)') 'Enter Menu Choice (H=Help, Q=Quit) : '
         READ(*,'(A1)',ERR=100) SEL 
         CALL OFF
         IF (SEL.EQ.' ') THEN
            GOTO 300
         ELSEIF((SEL.EQ.'H') .OR. (SEL.EQ.'h')) THEN
            KEY=' '
            LU=15
            CALL HELP(KEY,LU)
         ELSEIF(SEL.EQ.'1') THEN
            CALL UPDATE
         ELSEIF(SEL.EQ.'2') THEN
            CALL LOOK
         ELSEIF(SEL.EQ.'3') THEN
            CALL MLIST
         ELSEIF(SEL.EQ.'4') THEN
            CALL BKLT
         ELSEIF(SEL.EQ.'5') THEN
            CALL PHONE
         ELSEIF((SEL.EQ.'Q') .OR. (SEL.EQ.'q')) THEN
            IF(IHLP.EQ.1) CLOSE(15)
            CALL WRMAST
            CALL CLS
            STOP
         ENDIF
      GOTO 100
      END
C
C
C
      SUBROUTINE RDMAST
C
      COMMON/MAIN1/ LAST,FIRST,ADD1,ADD2,CITY,STATE,ZIP,PH1,PH2
      CHARACTER LAST(12,200)*1,FIRST(200)*23,ADD1(200)*30,ADD2(200)*30
      CHARACTER CITY(200)*23,STATE(200)*2,ZIP(200)*5
      CHARACTER PH1(200)*14,PH2(200)*14
C
      COMMON/MAIN2/ STRID,SORT,MNUM
      INTEGER*4 STRID(200),SORT(200),MNUM
C
      CHARACTER*25 OPTION
C
C            OPEN FILE FOR INPUT
C
      OPTION='Loading Master File .....'
      CALL HEADER(OPTION)
      CALL KEYOFF
      OPEN(20,FILE='ADDRESS.DAT')
C
C            READ ALL DATA FROM MASTER FILE
C
      I=0
  100 CONTINUE
      I=I+1
      IF(I.GT.200) THEN
         WRITE(*,'(A33)') 'Program Aborted Reading Master   '
         STOP
      ENDIF
      READ(20,200,END=300) (LAST(K,I),K=1,12),
     A                     FIRST(I),ADD1(I),ADD2(I),CITY(I),
     A                     STATE(I),ZIP(I),PH1(I),PH2(I),SORT(I),
     A                     STRID(I)
  200 FORMAT(12A1,A23,A30,A30,A23,A2,A5,A14,A14,I8,I3)
      GOTO 100
  300 CONTINUE
      MNUM=I-1
      CLOSE(20)
      CALL KEYON
      RETURN
      END
C
C
C
      SUBROUTINE WRMAST
C
      COMMON/MAIN1/ LAST,FIRST,ADD1,ADD2,CITY,STATE,ZIP,PH1,PH2
      CHARACTER LAST(12,200)*1,FIRST(200)*23,ADD1(200)*30,ADD2(200)*30
      CHARACTER CITY(200)*23,STATE(200)*2,ZIP(200)*5
      CHARACTER PH1(200)*14,PH2(200)*14
C
      COMMON/MAIN2/ STRID,SORT,MNUM
      INTEGER*4 STRID(200),SORT(200),MNUM
C
      CHARACTER*25 OPTION
C
C            OPEN FILE FOR OUTPUT
C
      OPTION='Storing Master File .....'
      CALL HEADER(OPTION)
      CALL KEYOFF
      OPEN(20,FILE='ADDRESS.DAT')
C
C            WRITE ALL DATA TO MASTER LOOKUP FILE
C
      DO 300 I=1,MNUM
      WRITE(20,200) (LAST(K,I),K=1,12),
     A              FIRST(I),ADD1(I),ADD2(I),CITY(I),
     A              STATE(I),ZIP(I),PH1(I),PH2(I),SORT(I),
     A              STRID(I)
  200 FORMAT(12A1,A23,A30,A30,A23,A2,A5,A14,A14,I8,I3)
  300 CONTINUE
      ENDFILE 20
      CLOSE(20)
      CALL KEYON
      RETURN
      END
C
C
C
      SUBROUTINE SORTIT
C
      COMMON/MAIN1/ LAST,FIRST,ADD1,ADD2,CITY,STATE,ZIP,PH1,PH2
      CHARACTER LAST(12,200)*1,FIRST(200)*23,ADD1(200)*30,ADD2(200)*30
      CHARACTER CITY(200)*23,STATE(200)*2,ZIP(200)*5
      CHARACTER PH1(200)*14,PH2(200)*14
C
      COMMON/MAIN2/ STRID,SORT,MNUM
      INTEGER*4 STRID(200),SORT(200),MNUM
C
      CHARACTER LLAST(12)*1,LFIRST*23,LADD1*30,LADD2*30,LCITY*23
      CHARACTER LSTATE*2,LZIP*5,LPH1*14,LPH2*14,OPTION*25
      INTEGER*4 LSORT,LSTID,KEEP,MIN
C
C         CALL OPTION HEADER
C
      OPTION='Sorting Master File .....'
      CALL HEADER(OPTION)
C
C         NOW SORT THE DATA
C
      K=0
  400 MIN=999999
      K=K+1
      IF(K.GE.MNUM) GOTO 500
      DO 450 I=K,MNUM
      IF(SORT(I).LT.MIN) THEN
         MIN=SORT(I)
         KEEP=I
      ENDIF
  450 CONTINUE
      DO 460 J=1,12
  460 LLAST(J)=LAST(J,K)
      LFIRST=FIRST(K)
      LADD1 =ADD1(K)
      LADD2 =ADD2(K)
      LCITY =CITY(K)
      LSTATE=STATE(K)
      LZIP  =ZIP(K)
      LPH1  =PH1(K)
      LPH2  =PH2(K)
      LSORT =SORT(K)
      LSTID =STRID(K)
         DO 470 J=1,12
  470    LAST(J,K)=LAST(J,KEEP)
         FIRST(K)=FIRST(KEEP)
         ADD1(K) =ADD1(KEEP)
         ADD2(K) =ADD2(KEEP)
         CITY(K) =CITY(KEEP)
         STATE(K)=STATE(KEEP)
         ZIP(K)  =ZIP(KEEP)
         PH1(K)  =PH1(KEEP)
         PH2(K)  =PH2(KEEP)
         SORT(K) =SORT(KEEP)
         STRID(K)=STRID(KEEP)
      DO 480 J=1,12
  480 LAST(J,KEEP)=LLAST(J)
      FIRST(KEEP)=LFIRST
      ADD1(KEEP) =LADD1
      ADD2(KEEP) =LADD2
      CITY(KEEP) =LCITY
      STATE(KEEP)=LSTATE
      ZIP(KEEP)  =LZIP
      PH1(KEEP)  =LPH1
      PH2(KEEP)  =LPH2
      SORT(KEEP) =LSORT
      STRID(KEEP)=LSTID
      GOTO 400
  500 CONTINUE
      RETURN
      END
