!*************************** AMUS Program Label ******************************
! Filename: DBFOPN.BAS                                      Date: 01/31/90
! Category: UTIL         Hash Code: 651-515-471-461      Version: 89.11A(15)
! Initials: MKE/AM       Name: DAVID W. BARROW III
! Company: STONEWALL COMPUTER CENTER               Telephone #: 4143752667
! Related Files: DBFOPN.DOC, DBFCLS.BAS, DBFCLS.DOC
! Min. Op. Sys.:                               Expertise Level: BEG
! Special:
! Description: Utility to open all your FOLDER (from Soft Machines) files.
!
!
!*****************************************************************************
!***************************************************************************
! SHAREWARE NOTICE:
!      The author of this program has requested a monetary contribution,
! if you find the program beneficial, in return for his/her programming
! effort. This type of software is referred to as shareware. Please note
! that this contribution is strictly voluntary and there are no
! obligations to pay the amount requested.
!***************************************************************************
!       This is "Shareware".  The program is published for everyone to look
!       at and try.  If you like it and can use it PLEASE send $5.00 to:
!                       DAVID W. BARROW III
!                       1894 Elm Drive
!                       West Bend, WI 53095
!       If you have questions or problems with this program you may call
!       (414) 375-AMOS.
!
!       DBFOPN.BAS - Dave Barrow's Folder OPeN
!
!       This program will:
!         1.  Produce a directory of all of the FOLDERs (TM Soft Machines).
!         2.  Open all of those folders.
!
!       Assumptions:
!         1.  That all FOLDER files have the extention .FLD.
!         2.  That you have enough FOLDERs enabled to open all of them.
!         3.  That the first three letters of the .FLD file are unique
!               so that they can be used as the Logical Device name.
!         4.  That each FOLDER filename is at least three letters long.
!
!       Copyright @1989 by David W. Barrow III
!
! Date          Who     S What
!--------       ---     - ---------------------------------------------------
! 11-15-86      DWB     A Original coding.
!

PROGRAM DBFOPN,89.11A(15)

MAP1    DIR'REC, S, 50, ""      ! Produced by DIR/D/ DBFOP1.DIR=ALL:.FLD[]
MAP1    EXIST,F,6,0             ! answer from lookup
MAP1    CONTINUE,S,1,"N"        ! Answer to continue
MAP1    Q$,S,1,CHR$(34)         ! Puts a quote in output file
MAP1    T$,S,1,CHR$(9)          ! Puts a tab in output file

! HOUSEKEEPING:
       ! Standard Error Routine
!       ON ERROR GOTO ERR'ROUTINE

       ! Announce program
       PRINT TAB(-1,0)                         ! Clear the screen
       PRINT TAB(03,17); "DBFOPN - Dave Barrow's Folder OPeN program"
       PRINT TAB(05,01); "This program takes a directory file "        &
               "produced by DIR/F DBFOP1.DIR=ALL:*.FLD[]"
       PRINT TAB(06,01); "and will then open all those FOLDERs using "; &
                               "the first three letters"
       PRINT TAB(07,01); "of the folder file name as the device."
       PRINT TAB(09,01); "FOLDER is a TM of Soft Machines, Inc."

       ! Check to see if this is the right program to run
       PRINT TAB(11,10); "Do you really want to run THIS program (Y/N) ";
       INPUT CONTINUE
               IF      ( UCS(CONTINUE) # "Y" )                         &
               THEN    GOTO EXIT

       LOOKUP "DBFOP1.DIR", EXIST
               IF      ( EXIST <> 0 )                                  &
               THEN    KILL "DBFOP1.DIR"

! Phase 1 - Create a directory of all the FOLDERs
       OPEN #111, "DBFOP1.CMD", OUTPUT         ! Set up a command file
       PRINT #111; ";  DBFOP1.CMD"
       PRINT #111; ";  This is a temporary file created by DBFOPN.BAS"
       PRINT #111; ";  You may erase it at any time"
       PRINT #111; ":T"
       PRINT #111; "DIR/D DBFOP1.DIR=ALL:*.FLD[]"
       PRINT #111; "COMPIL DBFOP2"
       PRINT #111; "RUN DBFOP2"
       CLOSE #111

! Phase 2 - Create a command file to open all of the FOLDERs
       OPEN #112, "DBFOP2.BAS", OUTPUT         ! Set up a basic file
       PRINT #112; "!  DBFOP2.BAS"
       PRINT #112; "!  This is a temporary file created by DBFOPN.BAS"
       PRINT #112; "!  You may erase it at any time"
       PRINT #112
       PRINT #112; T$; "PROGRAM DBFOP2,89.11A(15)"
       PRINT #112
       PRINT #112; "MAP1"; T$; "COLON, F, 6, 0"
       PRINT #112; "MAP1"; T$; "COLON1, F, 6, 0"
       PRINT #112; "MAP1"; T$; "DIR'REC, S, 50, SPACE$(50)"
       PRINT #112; "MAP1"; T$; "F'NAM, S, 3, SPACE$(3)"
       PRINT #112; "MAP1"; T$; "L'BRAK, F, 6, 0"
       PRINT #112
       PRINT #112; "!HOUSEKEEPING:"
       PRINT #112; T$; "OPEN #111, "; Q$; "DBFOP1.DIR"; Q$; ", INPUT"

       PRINT #112; T$; "! Put a header on DBFOP3.CMD file"
       PRINT #112; T$; "OPEN #113, "; Q$; "DBFOP3.CMD"; Q$;            &
                       ", OUTPUT"; T$; T$; "! Set up a command file"
       PRINT #112; T$; "PRINT #113; "; Q$; ";  DBFOP3.CMD"; Q$
       PRINT #112; T$; "PRINT #113; "; Q$; ";  This is a temporary ";  &
                       "file created by DBFOPN.BAS"; Q$
       PRINT #112; T$; "PRINT #113; "; Q$; ";  You may erase it at ";  &
                       "any time"; Q$
       PRINT #112; T$; "PRINT #113; "; Q$; ":T"; Q$
       PRINT #112; T$; "PRINT #113; "; Q$; "ERASE DBFOP1.*"; Q$
       PRINT #112; T$; "PRINT #113; "; Q$; "ERASE DBFOP2.*"; Q$
       PRINT #112; T$; "CLOSE #113"
       PRINT #112
       PRINT #112; "! MAINLINE:"
       PRINT #112; T$; "FOR COUNTER = 1 TO 100"
       PRINT #112; T$; T$; "! Blank directory record to avoid carryover"
       PRINT #112; T$; T$; "DIRECTORY'RECORD = SPACE$(50)"
       PRINT #112; T$; T$; "! Get another .FLD file from the directory"
       PRINT #112; T$; T$; "INPUT LINE #111, DIR'REC"
       PRINT #112; T$; T$; "! Check for end of file"
       PRINT #112; T$; T$; T$; "IF"; T$; "( EOF(111) = 1 )"; T$; T$;   &
                               T$; "&"
       PRINT #112; T$; T$; T$; "THEN"; T$; "COUNTER = 100"; T$; T$;    &
                               T$; T$; "&"
       PRINT #112; T$; T$; T$; T$; ": GOTO EXIT"
       PRINT #112; T$; T$; "! Parse the directory record"
       PRINT #112; T$; T$; "L'BRAK = INSTR(1,DIR'REC,"; Q$; "["; Q$; ")"
       PRINT #112; T$; T$; "COLON1 = INSTR(1,DIR'REC,"; Q$; ":"; Q$; ")"
       PRINT #112; T$; T$; "! Check for second colon"
       PRINT #112; T$; T$; T$; "IF"; T$; "( (L'BRAK - COLON1) > 10 )"; &
                               T$; T$; "&"
       PRINT #112; T$; T$; T$; "THEN"; T$; "COLON = INSTR((COLON1+1),";&
                               "DIR'REC,"; Q$; ":"; Q$; ")"; T$; "&"
       PRINT #112; T$; T$; T$; T$; ": COLON = COLON + COLON1"
       PRINT #112; T$; T$; "! We want to start with the letter after " &
                               "the (2nd) colon"
       PRINT #112; T$; T$; "COLON = COLON MAX COLON1 + 1"
       PRINT #112; T$; T$; "F'NAM = DIR'REC[COLON,(COLON+2)]"
       PRINT #112; T$; T$; "! Add this folder to the list"
       PRINT #112; T$; T$; "OPEN #113, "; Q$; "DBFOP3.CMD"; Q$; ", APPEND"
       PRINT #112; T$; T$; "PRINT #113; "; Q$; "FOLDER/O "; Q$;        &
                       "; F'NAM; "; Q$; ":="; Q$; "; DIR'REC"
       PRINT #112; T$; T$; "CLOSE #113"
       PRINT #112; T$; "NEXT COUNTER"; T$; T$; "! Go get another"
       PRINT #112
       PRINT #112; "EXIT:"
       PRINT #112; T$; "CHAIN "; Q$; "DBFOP3.CMD"; Q$
       PRINT #112; T$; "END"

EXIT:
       CHAIN "DBFOP1.CMD"
       END

                       !!!!!!!!!!!!!!!!!!!!!!!!
                       ! STANDARD SUBROUTINES !
                       !!!!!!!!!!!!!!!!!!!!!!!!
ERR'ROUTINE:
       ! Check for AlphaBASIC error
               IF      ( ERR(0) = 0 )                                  &
               THEN    GOTO ISAM'ERROR
       ! Display Basic error
       PRINT TAB(16,15); "?? Fatal AlphaBASIC Error "; STR$(ERR(0))
               IF      ( ERR(1) )                                      &
               THEN    PRINT " at line "; STR$(ERR(1))
               IF      ( ERR(2) )                                      &
               THEN    PRINT " on Channel "; STR$(ERR(2))
       GOTO ERROR'ABORT

ISAM'ERROR:
!               IF      (

ERROR'ABORT:
       PRINT
       PRINT CHR$(7) : PRINT CHR$(7)
       PRINT "!! Contact System Operator Immediately !!"
       PRINT
       GOTO EXIT

!       *       **      ***     END OF DBFOPN.BAS       ***     **      *