"Program Code - System2"
By Ron Stultz
4 July 2006
At 60 years of age, my mind is not what it used to be or more specifically, my memory or ability to
solve problems of one kind or another but no, I have not lost my mind but neither am I the
engineer I once was.
Computer programming. When I started programming computers in 1970 or there abouts,
computers were just then beginning to appear outside the huge mainframe complexes controlled
by IBM. With the invent of the minicomputer, computers began to appear everywhere and thus the
need for programmers to program them. I was never a business application programmer, instead I
did scientific programming or the interface programming for some device, known as a device
driver. When I started computer programming, there were around 50,000 "registered" computer
programmers in the United States. Since that time, many, many people like to call themselves
programmers but by examining the quality or reliability of their code, most are not true
programmers in the traditional sense.
Funny how I did so poorly in Latin in high school but took so naturally to computer languages.
Over the span of my engineering career, I must have worked in at least 5 or more different
computer languages. New job, new language? No problem.
Below is a sample of some of the code I have written over the years. As most of the code I wrote was
for defense agencies, most was or still could be, classified and thus I cannot show it here, but I can
show some utility software I developed for my own use.
The following software is only part of a larger software function, which allows a user to backup
critical data files across multiple floppy disk volumes. Anyone who has programmed will realize,
multiple volume backup is not a simple programming task.
To those that have never programmed, I hope the following has enough "comments" and "notes" in
it to maybe allow you to see the workings, wheels, of the program.
I have always used a lot of comments and notes in my code as I have found that if I didn't, one
month, one year, anytime later, I might not be able to follow my own programming and a program
which cannot be maintained or modified easily is not a good program.
If you like puzzles, you should like the following.
* PROGRAM: SYSTEM2
******************
******************
* DESCRIPTION: BACKUP OF SYSTEM
STORED DATA TO REMOVABLE MEDIA
*.
*
* COPYRIGHT @ 2001 RON STULTZ
* LAST REVISION: OCTOBER 2001
*
*
* INPUT: MDRIVE && USER DEFINED
REMOVABLE MEDIA DRIVE
*
* RETURNS: MHALT && ON ERROR = .T.
*
*
NOTE: NEW MEDIA ASKED FOR WHEN
MEDIA IN DRIVE HAS LESS THAN 20K BYTES.
*
*
* BEGIN: DECLARE MEM VARIABLES
PUBLIC WHICH ARE UNIQUE TO THIS SYSTEM2
**********************************************************************
**********************************************************************
PUBLIC MOPERATION
*
PUBLIC MDRIVE
*
PUBLIC MMEDIA_USED_IN_BACKUP
*
PUBLIC MBACKUP_DATE
PUBLIC MBACKUP_TIME
*
PUBLIC MINFO_DBF_SIZE
*
PUBLIC MDBF_NAME
PUBLIC MDBF_SIZE
*
PUBLIC MMEDIA_FREE_SPACE
*
*
*
* BEGIN: EXECUTE FORM
*********************
*********************
DO FORM SYSTEM2
READ EVENTS
RETURN
PROCEDURE MRELEASE
******************
******************
* DESCRIPTION: RELEASES ALL PUBLIC
MEM VARIABLES DECLARED IN SYSTEM2
*
*
RELEASE MOPERATION
*
RELEASE MDRIVE
*
RELEASE MMEDIA_USED_IN_BACKUP
*
*
RELEASE MINFO_DBF_SIZE
*
RELEASE MDBF_NAME
RELEASE MDBF_SIZE
*
RELEASE MMEDIA_FREE_SPACE
*
RELEASE MBACKUP_DATE
RELEASE MBACKUP_TIME
*
*
RETURN
*
* EOF() MRELEASE
****************
****************
PROCEDURE BACKUP
****************
****************
* DESCRIPTION: BACKUP OF ALL SYSTEM
STORED DATA TO DEFINED REMOVABLE MEDIA.
*
*
* INPUT: MOWNER
* INPUT: MDRIVE
*
* RETURNS: MHALT
* RETURNS: MMEDIA_USED_IN_BACKUP
*
*
*
* BEGIN: INITIALIZE MEM
VARIABLES
*********************************
*********************************
MHALT = .F. && INITIALIZE ERROR FLAG
*
MDBF_NAME = "" && DBF NAME BEING
COPIED
MDBF_SIZE = 0 && # BYTES IN SYSTEM
DBF BEING COPIED
*
MMEDIA_USED_IN_BACKUP = 0 && # BACKUP MEDIA USED
MMEDIA_FREE_SPACE = 0
&& # FREE BYTES ON REMOVAVLE
MEDIA
*
*
*
* BEGIN: GET & HOLD BACKUP
DATE & TIME
**************************************
**************************************
MBACKUP_DATE = DTOC( DATE() ) && CURRENT DATE IN CHARACTER FORMAT
MBACKUP_TIME = TIME() && CURRENT TIME IN
CHARACTER FORMAT
*
*
*
* BEGIN: CREATE INFO.DBF TO USE
*******************************
*******************************
NOTE: FOR RESTORE OPERATION, NEED
EACH RESTORE MEDIA TO HAVE:
* NAME OF INVESTOR (BLANK OR SPACES)
* DATE OF BACKUP
* TIME OF BACKUP
* ID OF MEDIA
*
NOTE: ON RESTORE MEDIA, OWNER =
SPACES
NOTE: ON IMPORT MEDIA, OWNER =
ACTUAL INVESTOR NAME
*
NOTE: TIME & DATE CAPTURED
HERE & STORED.
* ALLOWS RESTORE TO DETECT USEAGE OF MEDIA NOT ASSOCIATED WITH
RESTORE.
* THAT IS, USER COULD HAVE PERFORMED SEVERAL BACKUPS & WITH
OUT
* INVESTOR NAME & DATE & TIME, USER COULD INSERT WRONG
SECOND MEDIA
* AS PART OF AN RESTORE OPERATION.
*
NOTE: AS CONFIG.DBF ALWAYS OPEN,
NEED NEW WORK AREA HERE
*
*
IF FILE("INFO.DBF") && MAY STILL BE ON HARD DISK FROM
PREVIOUS BACKUP
ERASE INFO.DBF
ELSE
ENDIF
*
*
MBACKUP_DATE = DTOC( DATE() )
MBACKUP_TIME = TIME()
SELECT SELECT(1)
CREATE TABLE INFO.DBF
;
( OWNER C(15), ;
DATE C(10), ;
TIME C(8) , ;
ID I(4) )
*
APPEND BLANK
REPLACE OWNER WITH SPACE(15) && FOR BACKUP = SPACES
REPLACE DATE WITH MBACKUP_DATE && CURRENT DATE IN CHARACTER
FORMAT
REPLACE TIME WITH MBACKUP_TIME && TIME IN CHARACTER FORMAT
REPLACE ID WITH 0 && BACKUP MEDIA ID,
INTEGER
*
*
*
* BEGIN: GET SIZE, IN BYTES, OF
INFO.DBF
****************************************
****************************************
NOTE: FOR FSIZE() TO RETURN FILE
SIZE, FILE MUST BE OPEN AND
* SET COMPATIBLE ON.
*
SET COMPATIBLE ON
MINFO_DBF_SIZE =
FSIZE("INFO.DBF")
USE
SET COMPATIBLE OFF
*
*
*
* BEGIN: CREATE DISKS.DBF TO
USE
********************************
********************************
NOTE: DISKS.DBF HOLDS TOTAL #
BACKUP MEDIA USED IN BACKUP PROCESS.
*
NOTE: ON USE OF DISKS.DBF:
* ‑ AS EACH BACKUP MEDIA IS USED, INFO.DBF IS COPIED TO
BACKUP MEDIA
* WHICH INCLUDES ID FIELD WHICH IS ID OF MEDIA USED.
* ‑ ON LAST BACKUP MEDIA USED, IN ADDITION TO INFO.DBF,
* DISKS.DBF IS STORED WHICH SHOWS TOTAL # OF BACKUP MEDIA
USED.
*
IF FILE("DISKS.DBF")
ERASE DISKS.DBF
ELSE
ENDIF
SELECT SELECT(1)
CREATE TABLE DISKS.DBF (COUNT I(4))
APPEND BLANK
REPLACE COUNT WITH 0 && COUNT IS TOTAL # OF BACKUP
MEDIA USED.
USE
*
*
*
* BEGIN: GET 1ST BACKUP MEDIA
*****************************
*****************************
NOTE: THIS ROUTINE DOES THE
FOLLOWING:
*
* (1) GETS USER TO INSERT BLANK MEDIA INTO REMOVABLE MEDIA
DRIVE.
*
* (2) CHECKS TO SEE IF INSERTED DISK IS ONE PREVIOUSLY
WRITTEN
* THIS SAME SESSION.
I.E. USER DID NOT REMOVE FROM DRIVE
* WHEN TOLD TO.
*
* (2) CHECKS THAT THERE IS FREE SPACE ON MEDIA FOR BACKUP
USE
* AFTER INFO.DBF WRITTEN.
*
* (3) WRITES INFO.DBF TO MEDIA
*
NOTE: IF HALT = .T. DO NOT CONTINUE WITH BACKUP.
*
*
* INPUTS: MDBF_NAME, MDRIVE,
INFO.DBF, MINFO_DBF_SIZE
* RETURNS: MHALT
NOTE: RETURNS WITH DEFAULT
DRIVE/PATH SET TO STORED DATA.
NOTE: ON ERROR, RETURNS WITH
DEFAULT DRIVE/PATH SET TO STORED DATA.
*
MDBF_NAME = ""
DO GNEW_BACKUP_MEDIA
IF MHALT
RETURN
ELSE
ENDIF
*
*
*
NOTE: DEFAULT DRIVE/PATH SET TO
STORED DATA.
*
*
*
* BEGIN: COPY ACQUIRE
TRANSACTIONS (ACQUIRE.DBF) TO REMOVABLE MEDIA
*******************************************************************
*******************************************************************
NOTE: CONFIG.DBF ALWAYS OPEN IN
MMAIN. NEED NEW DBF SPACE
*
MDBF_NAME = "ACQUIRE.DBF"
SELECT SELECT(1)
USE ACQUIRE
SET INDEX TO
SET FILTER TO
GO TOP
COPY TO SYS2
USE SYS2
*
* BEGIN: WRITE FILE TO
REMOVABLE MEDIA
**************************************
**************************************
* INPUTS: OPEN DBF, MDBF_NAME
* RETURNS: MHALT
NOTE: RETURNS WITH DEFAULT DRIVE/PATH
SET TO STORED DATA.
NOTE; ON ERROR, RETURNS WITH DEFAULT
DRIVE/PATH SET TO STORED DATA.
DO FCOPY
IF MHALT
*
SELECT SYS2
USE
*
RETURN
*
ELSE
ENDIF
SELECT SYS2
USE
ERASE SYS2.FPT
*
*
*
* BEGIN: COPY SYSTEM
CONFIGURATION (CONFIG.DBF) TO REMOVABLE MEDIA
******************************************************************
******************************************************************
NOTE: CONFIG.DBF OPEN IN MMAIN
& LEFT OPEN
*
MDBF_NAME = "CONFIG.DBF"
SELECT CONFIG
SET INDEX TO
SET FILTER TO
GO TOP
COPY TO SYS2
*
SELECT SELECT(1)
USE SYS2
*
DO FCOPY
IF MHALT
*
SELECT SYS2
USE
*
RETURN
*
ELSE
ENDIF
SELECT SYS2
USE
&& CLOSE SYS2.DBF
ERASE SYS2.FPT
*
*
*
* BEGIN: COPY SYSTEM DATES
(DATES.DBF) TO REMOVABLE MEDIA
*********************************************************
*********************************************************
MDBF_NAME = "DATES.DBF"
SELECT SELECT(1)
USE DATES
SET INDEX TO
*
NOTE: IF 1ST UPDATE, NEED TO ADD
RECORD FOR UPDATE
* OR AT USE OF SYS AFTER 1ST UPDATE
* WILL STILL GET MESSAGE TO PERFORM UPDATE
*
SET FILTER TO TYPE =
"BACKUP"
GO TOP
IF EOF()
APPEND BLANK
REPLACE TYPE WITH "BACKUP"
REPLACE DATE WITH DATE()
&& CURRENT DATE
ELSE
ENDIF
SET FILTER TO
GO TOP
*
COPY TO SYS2
USE SYS2
*
DO FCOPY
IF MHALT
*
SELECT SYS2
USE
*
RETURN
*
ELSE
ENDIF
SELECT SYS2
USE
ERASE SYS2.FPT
*
*
*
* BEGIN: COPY DISPOSE
TRANSACTIONS (DISPOSE.DBF) TO REMOVABLE MEDIA
*******************************************************************
*******************************************************************
MDBF_NAME = "DISPOSE.DBF"
SELECT SELECT(1)
USE DISPOSE
SET INDEX TO
SET FILTER TO
GO TOP
COPY TO SYS2
USE SYS2
*
DO FCOPY
IF MHALT
*
SELECT SYS2
USE
*
RETURN
*
ELSE
ENDIF
SELECT SYS2
USE
ERASE SYS2.FPT
*
*
*
* BEGIN: COPY INVESTMENT
HISTORY (HISTORY.DBF) TO REMOVABLE MEDIA
*****************************************************************
*****************************************************************
MDBF_NAME = "HISTORY.DBF"
SELECT SELECT(1)
USE HISTORY
SET INDEX TO
SET FILTER TO
GO TOP
COPY TO SYS2
USE SYS2
*
DO FCOPY
IF MHALT
*
SELECT SYS2
USE
*
RETURN
*
ELSE
ENDIF
SELECT SYS2
USE
ERASE SYS2.FPT
*
*
*
* BEGIN: COPY INVESTMENT SHARE
PRICE HISTORY (HISTORY2.DBF) TO REMOVABLE MEDIA
******************************************************************************
******************************************************************************
MDBF_NAME = "HISTORY2.DBF"
SELECT SELECT(1)
USE HISTORY2
SET INDEX TO
SET FILTER TO
GO TOP
COPY TO SYS2
USE SYS2
*
DO FCOPY
IF MHALT
*
SELECT SYS2
USE
*
RETURN
*
ELSE
ENDIF
SELECT SYS2
USE
ERASE SYS2.FPT
*
*
*
* BEGIN: COPY INVESTOR
INFORMATION (INVEST.DBF) TO REMOVABLE MEDIA
******************************************************************
******************************************************************
MDBF_NAME = "INVEST.DBF"
SELECT SELECT(1)
USE INVEST
SET INDEX TO
SET FILTER TO
GO TOP
COPY TO SYS2
USE SYS2
*
DO FCOPY
IF MHALT
SELECT SYS2
USE
*
RETURN
*
ELSE
ENDIF
SELECT SYS2
USE
ERASE SYS2.FPT
*
*
*
* BEGIN: COPY INVESTMENT
INFORMATION (PORT.DBF) TO REMOVABLE MEDIA
******************************************************************
******************************************************************
MDBF_NAME = "PORT.DBF"
SELECT SELECT(1)
USE PORT
SET INDEX TO
SET FILTER TO
GO TOP
COPY TO SYS2
USE SYS2
*
DO FCOPY
IF MHALT
*
SELECT SYS2
USE
*
RETURN
*
ELSE
ENDIF
SELECT SYS2
USE
ERASE SYS2.FPT
*
*
*
* BEGIN: COPY SYSTEM TAX RATES
TABLE (TAXRATES.DBF) TO REMOVAVLE MEDIA
**********************************************************************
**********************************************************************
MDBF_NAME = "TAXRATES.DBF"
SELECT SELECT(1)
USE TAXRATES
SET INDEX TO
SET FILTER TO
GO TOP
COPY TO SYS2
USE SYS2
*
DO FCOPY
IF MHALT
*
SELECT SYS2
USE
*
RETURN
*
ELSE
ENDIF
SELECT SYS2
USE
ERASE SYS2.FPT
*
*
*
* BEGIN: COPY SYSTEM SHARE
PRICE TABLE (WORTH.DBF) TO REMOVABLE MEDIA
*********************************************************************
*********************************************************************
MDBF_NAME = "WORTH.DBF"
SELECT SELECT(1)
USE WORTH
SET INDEX TO
SET FILTER TO
GO TOP
COPY TO SYS2
USE SYS2
*
DO FCOPY
IF MHALT
*
SELECT SYS2
USE
*
RETURN
*
ELSE
ENDIF
SELECT SYS2
USE
ERASE SYS2.FPT
*
*
*
* BEGIN: ALL DONE WITH SYSTEM
STORED DATA,
* WRITE DISKS.DBF TO REMOVAVLE MEDIA
*******************************************
*******************************************
MDBF_NAME = "DISKS.DBF"
SELECT SELECT(1)
USE DISKS
SET INDEX TO
SET FILTER TO
GO TOP
*
NOTE: REPLACE "COUNT"
FIELD IN DISKS.DBF TO REFLECT TOTAL # MEDIA USED
* IN THIS BACKUP.
REPLACE COUNT WITH
MMEDIA_USED_IN_BACKUP && UPDATE
TOTAL # MEDIA USED IN BACKUP PROCESS
*
DO FCOPY
IF MHALT
*
SELECT DISKS
USE
*
RETURN
*
ELSE
ENDIF
SELECT DISKS
USE && CLOSE DISKS.DBF
*
*
MHALT = .F.
RETURN
*
*
* EOF() BACKUP
**************
**************
PROCEDURE GNEW_BACKUP_MEDIA
***************************
***************************
* DESCRIPTION: GETS NEW BACKUP MEDIA
TO USE.
*
*
NOTE: THIS ROUTINE CALLED AT
BACKUP START (BEFORE ANY STARTING TO COPY FILES)
* & THEN, WHENEVER FCOPY DETERMINES CURRENT MEDIA IS FULL
* & NEEDS NEW MEDIA INSERTED.
*
*
* PROCESSING DETAILS:
*
* 1. USED BY BACKUP ONLY.
*
* 2. INSTRUCTS USER TO INSERT MEDIA INTO REMOVABLE
MEDIA DRIVE.
*
* 3. CHECKS THAT REMOVABLE MEDIA DRIVE IS READY.
*
* 4. CHECKS TO SEE IF MEDIA IN DRIVE HAS INFO.DBF.
* IF INFO.DBF, READS IT TO SEE IF CURRENT BACKUP
SESSION
* WHICH MEANS USER DID NOT REMOVE FROM DRIVE WHEN
TOLD TO.
*
* 5. ERASES FROM BACKUP MEDIA ANY EXISTING DBF &
FPT FILES.
*
* 5. CHECKS THAT BACKUP MEDIA HAS AT LEAST 100,000 FREE
BYTES
* AFTER INFO.DBF WRITTEN TO MEDIA.
* IF NOT 100,000 BYTES FREE, ASKS FOR NEW BACKUP
MEDIA.
*
IF 100,0000
BYTES FREE, INCREMENTS # BACKUP MEDIA USED.
*
* 6. WRITES INFO.DBF TO BACKUP MEDIA.
*
* 7. RETURNS WITH DEFAULT DRIVE/PATH SET TO SYSTEM
STORED DATA.
*
NOTE: THIS ROUTINE RETURNS WITH
DRIVE/PATH SET TO STORED SYSTEM DATA.
*
NOTE: IF ERROR, RETURNS WITH
DEFAULT DRIVE/PATH SET TO STORED DATA.
*
* INPUT: MINFO_DBF_SIZE
* INPUT: MDRIVE
*
* RETURNS: MHALT
*
*
* BEGIN: GET NEW BACKUP MEDIA
LOOP
**********************************
**********************************
DO WHILE .T. && IS A LOOP
*
*
* BEGIN: INSTRUCT USER TO INSERT MEDIA INTO REMOVABLE DRIVE
***********************************************************
***********************************************************
_VFP.ACTIVEFORM.MOUSEPOINTER = 0
*
NOTE: MMEDIA_USED BEGINS WITH 0 SO ADD 1 HERE
MMEDIA_TO_BE_USED = MMEDIA_USED_IN_BACKUP+1
*
MESSAGEBOX("Insert media NUMBER
"+LTRIM(STR(MMEDIA_TO_BE_USED))+" into removable media drive
now.",0,"Alert!")
*
_VFP.ACTIVEFORM.MOUSEPOINTER = 11
*
*
*
* BEGIN: SET DEFAULT DRIVE/PATH TO REMOVABLE MEDIA DRIVE
********************************************************
********************************************************
NOTE: RETURNS WITH DEFAULT DRIVE/PATH SET TO REMOVALE MEDIA
NOTE: IF ERROR, RETURNS WITH DEFAULT DRIVE/PATH SET TO STORED
DATA.
*
* INPUT: MDRIVE
* RETURN: MHALT
DO SET_REMOVABLE_DRIVE
IF MHALT
RETURN
ELSE
ENDIF
*
*
*
NOTE: DEFAULT DRIVE/PATH SET TO REMOVABLE DRIVE
*
*
*
* BEGIN: USER FORGOT TO REMOVE LAST MEDIA WRITTEN THIS SESSION
**************************************************************
**************************************************************
DO WHILE .T.
&& NOT A
LOOP
*
IF .NOT. FILE("INFO.DBF")
NOTE: CURRENT MEDIA NOT USED IN ANY PREVIOUS BACKUP OR RESTORE.
*
MDUMMY = 7 && FLAG: NEED
NEW MEDIA. 7 = "NO"
EXIT
*
ELSE
ENDIF
*
*
*
NOTE: INFO.DBF ON INSERTED REMOVABLE MEDIA
* COULD ONLY BE THERE FROM
EITHER BACKUP OR EXPORT OPERATION.
*
*
NOTE: DEFAULT DRIVE/PATH IS REMOVABLE MEDIA.
*
*
*
* BEGIN: READ INFO.DBF ON INSERTED REMOVABLE MEDIA
**************************************************
**************************************************
SELECT SELECT(1)
USE INFO
SET INDEX TO
SET FILTER TO
GO TOP
*
*
*
* BEGIN: INFO.DBF DATA DOES MATCH CURRENT BACKUP SESSION VALUES
***************************************************************
***************************************************************
IF DATE <> MBACKUP_DATE
.OR. ;
;
TIME <> MBACKUP_TIME
*
NOTE: INSERTED MEDIA IS NOT MEDIA WRITTEN IN CURRENT BACKUP SESSION.
*
USE
MDUMMY = 7 && FLAG: NEED
NEW MEDIA, 7 = "NO"
EXIT
*
ELSE
ENDIF
USE
*
*
*
* BEGIN: MEDIA USED IN THIS BACKUP SESSION. USER WANT TO CONTINUE
?
*******************************************************************
*******************************************************************
_VFP.ACTIVEFORM.MOUSEPOINTER = 0
*
MDUMMY = MESSAGEBOX("Media in drive is one just
written."+CHR(13)+CHR(13)+"Try to continue with BACKUP ?",4,"Error!")
*
IF MDUMMY <> 6
&& 6 = "YES"
NOTE: USER SAYS ABORT BACKUP.
*
DO SET_DBF_HD_PATH IN SUPPORT
MHALT = .T.
RETURN
*
ELSE
ENDIF
_VFP.ACTIVEFORM.MOUSEPOINTER = 11
*
*
NOTE: USER WANTS TO CONTINUE WITH THIS BACKUP
*
EXIT
*
*
ENDDO && END: USER
FORGOT TO REMOVE MEDIA USE USED
****************************************************
****************************************************
*
*
*
NOTE: DEFAULT DRIVE/PATH SET TO REMOVABLE MEDIA
*
*
*
* BEGIN: NEED NEW MEDIA INSERTED ?
**********************************
**********************************
IF MDUMMY = 6 &&
6 = "YES"
DO SET_DBF_HD_PATH IN SUPPORT
DO MEDIA_REMOVE
LOOP
ELSE
ENDIF
*
*
*
NOTE: DEFAULT DRIVE/PATH IS REMOVABLE MEDIA
*
*
*
* BEGIN: ERASE ALL DBF & FPT ON INSERTED BACKUP MEDIA
*****************************************************
*****************************************************
ERASE *.DBF
ERASE *.FPT
*
*
*
* BEGIN: GET FREE SPACE, IN BYTES, ON INSERTED MEDIA
****************************************************
****************************************************
* INPUTS: MDRIVE
* RETURNS: MMEDIA_FREE_SPACE
* RETURNS: MHALT
NOTE: RETURNS WITH DRIVE/PATH SET TO SYSTEM STORED DATA.
NOTE: IF ERROR, RETURNS WITH DRIVE/PATH SET TO STORED DATA.
*
DO GMEDIA_SIZE
IF MHALT
RETURN
ELSE
ENDIF
*
*
*
NOTE: DEFAULT DRIVE/PATH SET TO STORED DATA.
*
*
*
* BEGIN: ENOUGH FREE SPACE ON INSERTED MEDIA ?
**********************************************
**********************************************
NOTE: CHECK FREE SPACE LEFT AFTER INFO.DBF SPACE SUBTRACTED
IF MMEDIA_FREE_SPACE >= (100000 + MINFO_DBF_SIZE)
NOTE: AT LEAST 1000,000 BYTES FREEE ON INSERTED MEDIA.
*
EXIT
*
ELSE
ENDIF
*
*
*
NOTE: HERE BECAUSE INSTALLED MEDIA HAS INSUFFICENT STORAGE SPACE
*
*
*
* BEGIN: FORCE USER TO INSERT ANOTHER BACKUP MEDIA
**************************************************
**************************************************
_VFP.ACTIVEFORM.MOUSEPOINTER = 0
*
MDUM = MESSAGEBOX("INSUFFICENT free SPACE on inserted media
!"+chr(13)+chr(13)+"Try to CONTINUE with this BACKUP
?",4,"Error!")
*
_VFP.ACTIVEFORM.MOUSEPOINTER = 11
*
IF MDUM = 6 && 6
= "YES"
NOTE: USER WANTS TO TRY TO CONTINUE WITH THIS BACKUP
*
DO MEDIA_REMOVE
LOOP
*
ELSE
ENDIF
*
NOTE: USER SAYS ABORT THIS BACKUP
MHALT = .T.
RETURN
*
*
*
ENDDO && END: GET NEW BACKUP MEDIA LOOP
*****************************************
*****************************************
*
*
*
NOTE: HERE BACKUP MEDIA INSERTED:
* (1) NOT MEDIA JUST USED IN THIS BACKUP SESSION.
* (2) HAS >= 100,000 BYTES FREE AFTER INFO.DBF ADDED.
*
*
NOTE; DEFAULT DRIVE/PATH SET TO
STORED DATA
*
*
*
* BEGIN: INCREMENT BACKUP MEDIA
USED COUNT
******************************************
******************************************
NOTE: MMEDIA_USED_IN_BACKUP = 0
INITIALLY
*
MMEDIA_USED_IN_BACKUP =
MMEDIA_USED_IN_BACKUP + 1
*
*
*
* BEGIN: COPY INFO.DBF TO
BACKUP MEDIA
**************************************
**************************************
NOTE: INFO.DBF COPIED TO EACH
BACKUP MEDIA CREATED.
*
SELECT SELECT(1)
USE INFO
SET INDEX TO
SET FILTER TO
GO TOP
*
NOTE: UPDATE ID FIELD TO REFLECT
ID OF MEDIA BEING WRITTEN.
REPLACE ID WITH MMEDIA_USED_IN_BACKUP
GO TOP
*
*
MHALT = .F.
IF MDRIVE = "A"
COPY TO A:\INFO.DBF
ELSE
COPY TO B:\INFO.DBF
ENDIF
IF MHALT
NOTE: IF WRITE ERROR
*
USE
RETURN
*
ELSE
ENDIF
USE
*
*
*
* BEGIN: RETURN TO DBF BEING COPIED BEFORE NEED FOR
NEW MEDIA
**************************************************************
**************************************************************
DO CASE
*
CASE MDBF_NAME = "DISKS.DBF"
SELECT DISKS
*
*
CASE MDBF_NAME = ""
NOTE: ON GETTING 1ST BACKUP MEDIA TO USE, MDBF_NAME = ""
*
*
OTHERWISE
*
SELECT SYS2
*
ENDCASE
*
*
*
MHALT = .F. && MHALT = .F. = "SUCCESSFULLY GOT NEW BACKUP
MEDIA"
RETURN
*
*
* EOF() GNEW_BACKUP_MEDIA
*************************
*************************
PROCEDURE GMEDIA_SIZE
*********************
*********************
* DESCRIPTION: GETS FREE SPACE, IN
BYTES, ON INSERTED REMOVABLE MEDIA.
*
*
* INPUT: MDRIVE
*
* RETURNS: MMEDIA_FREE_SPACE
* RETURNS: MHALT
*
*
NOTE: RETURNS WITH DRIVE/PATH SET
TO SYSTEM STORED DATA.
NOTE: IF ERROR, RETURNS WITH
DRIVE/PATH SET TO STORED DATA.
*
*
*
* BEGIN: INITIALIZE FREE SPACE
******************************
******************************
MMEDIA_FREE_SPACE = 0.0
*
*
*
* BEGIN: SET DEFAULT DRIVE/PATH
TO REMOVABLE MEDIA DRIVE
********************************************************
********************************************************
NOTE: SETTING TO DRIVE WILL CHECK
IF DRIVE READY
NOTE: RETURNS WITH DEFAULT
DRIVE/PATH SET TO REMOVABLE MEDIA
NOTE: IF ERROR, RETURNS WITH
DEFAULT DRIVE/PATH SET TO STORED DATA.
*
* INPUT: MDRIVE
* RETURNS: MHALT
DO SET_REMOVABLE_DRIVE
IF MHALT
RETURN
*
ELSE
ENDIF
*
*
*
NOTE: DEFAULT DRIVE/PATH SET TO
REMOVAVLE MEDIA.
*
*
*
* BEGIN: GET FREE SPACE ON
INSERTED BACKUP MEDIA, IN BYTES
**********************************************************
**********************************************************
MMEDIA_FREE_SPACE = DISKSPACE()
*
*
*
NOTE: DEFAULT DRIVE/PATH SET TO
REMOVABLE MEDIA
*
*
*
* BEGIN: SET DEFAULT DRIVE/PATH
TO STORED DATA
**********************************************
**********************************************
DO SET_DBF_HD_PATH IN SUPPORT
*
*
MHALT = .F.
RETURN
*
*
* EOF() GMEDIA_SIZE
*******************
*******************
PROCEDURE GDBF_SIZE
*******************
*******************
* DESCRIPTION: GETS SIZE, IN BYTES,
OF OPEN DBF.
*
* INPUT: OPEN DBF
* RETURNS: MDBF_SIZE
*
*
*
NOTE: MDBF_SIZE INCLUDES COMBINED
SIZE OF DBF & ANY ASSOCIATED .FPT.
*
NOTE: RETURNS WITH DEFAULT
DRIVE/PATH SET TO SYSTEM STORED DATA.
*
*
*
* BEGIN: GET SIZE OF OPEN DBF
BEGIN COPIED
******************************************
******************************************
IF MDBF_NAME = ""
NOTE: 1ST TIME AS FOR NEW MEDIA
MDBF_SIZE = 0
*
RETURN
*
ELSE
ENDIF
*
*
*
* BEGIN: SET COMPATIBLE ON
**************************
**************************
NOTE: FOR FSIZE TO RETURN SIZE OF
FILE & NOT SIZE OF A FIELD,
* MUST HAVE COMPATIBLE "ON" & FILE MUST BE OPEN.
*
SET COMPATIBLE ON
*
*
* BEGIN: GET SIZE OF DEFINED
DBF & ANY ASSOCIATED .FPT
******************************************************
******************************************************
IF MDBF_NAME = "DISKS"
*
MDBF_SIZE = FSIZE('DISKS.DBF')
*
ELSE
*
MDBF_SIZE = FSIZE('SYS2.DBF')
*
NOTE: IF MEMO FIELD ASSICATED WITH DEFINED DBF.
IF FILE('SYS2.FPT')
MDBF_SIZE = MDBF_SIZE + FSIZE('SYS2.FPT')
ELSE
ENDIF
*
ENDIF
*
SET COMPATIBLE OFF && NORMAL SETTING
*
*
RETURN
*
* EOF() GDBF_SIZE
*****************
*****************
PROCEDURE FCOPY
***************
***************
* DESCRIPTION: ADDS A FILE TO THE
BACKUP MEDIA
*
* INPUT: MDBF_NAME
* INPUT: MDRIVE
*
* RETURN: MHALT
*
*
NOTE: USED BY BACKUP.
*
NOTE: CALLED WHEN READY TO ADD A
SYSTEM DBF TO REMOVABLE MEDIA.
*
NOTE: AT THIS POINT HAVE WRITTEN
INFO.DBF TO BACKUP MEDIA
*
NOTE: RETURNS WITH DRIVE/PATH SET
TO SYSTEM STORED DATA.
NOTE: IF ERROR, RETURNS WTIH
DRIVE/PATH SET TO STORED DATA.
*
*
*
* BEGIN: GET CURRENT FREE SPACE
ON INSERTED MEDIA
*************************************************
*************************************************
* INPUT: MDRIVE
* RETURNS: MHALT
* RETURNS: MMEDIA_FREE_SPACE
NOTE: RETURNS WITH DRIVE/PATH SET
TO SYSTEM STORED DATA.
NOTE: IF ERROR, RETURNS WITH
DRIVE/PATH SET TO STORED DATA.
*
DO GMEDIA_SIZE
IF MHALT
RETURN
ELSE
ENDIF
*
*
*
* BEGIN: GET SIZE OF DBF BEING
COPIED
*************************************
*************************************
* INPUT: OPEN DBF
* INPUT: MDBF_NAME
* RETURNS: MDBF_SIZE
NOTE: MDBF_SIZE INCLUDES SIZE OF
ANY ASSOCIATED MEMO (.FPT) FILE.
NOTE: RETURNS WITH DRIVE/PATH SET
TO SYSTEM STORED DATA.
DO GDBF_SIZE
*
*
*
* BEGIN: ENTIRE, DEFINED DBF,
WILL FIT ON CURRENT BACKUP MEDIA?
* WITH 20K BYTES TO SPARE
********************************
********************************
IF MMEDIA_FREE_SPACE > MDBF_SIZE +
20000
*
* BEGIN: COPY OPEN DBF TO REMOVABLE DRIVE MEDIA
***********************************************
***********************************************
* INPUT: OPEN DBF
* INPUT: MDRIVE
* RETURNS: MHALT
NOTE: RETURNS WITH DEFAULT DRIVE/PATH SET TO STORED DATA.
NOTE; IF ERROR, RETURNS WITH DEFAULT DRIVE/PATH SET TO STORED
DATA.
*
DO WRITE_MEDIA
IF MHALT
RETURN
ELSE
ENDIF
*
MHALT = .F.
RETURN
*
ELSE
ENDIF
*
*
*
NOTE: DEFINED DBF WILL NOT FIT ON
DEFINED MEDIA
* AS A SINGLE "COPY" TO MEDIA.
NOTE: BECAUSE A MEMO FIELD CAN
GROW AS LARGE AS NEEDED
* AND NO WAY TO DETERMINE AVERAGE RECORD SIZE &
* THEN DETERMINE # RECORDS TO COPY.
*
* WRITING ONE RECORD AT A TIME TO REMOVALE MEDIA
* IS SAFE METHOD BUT TOO SLOW.
*
* THUS NEED TO DETERMINE ACTUAL CHUCK OF FILE
* WHICH WILL FIT ON REMOVALE MEDIA
* COPY IT AND THEN GET NEW MEDIA.
*
*
* BEGIN: GET RECORD COUNT OF
DEFINED DBF
****************************************
****************************************
MRECORD_COUNT = RECCOUNT()
*
*
*
* BEGIN: INITIALIZE
MFIRST_RECORD
*********************************
*********************************
NOTE: 1 IS FIRST RECORD # OF ANY
DBF
MFIRST_RECORD = 1
*
*
*
* BEGIN: INITIALIZE
MLAST_RECORD
********************************
********************************
NOTE: INITIALLY SET TO RECCOUNT OF
FILE BEING COPIED
* THEN DECREMENTED UNTIL MFIRST_RECORD, MLAST_RECORD CHUCK
* IF FIT REMOVABLE MEDIA FREE SPACE
MLAST_RECORD = MRECORD_COUNT
*
*
*
* BEGIN: ADD DEFINED DBF TO
REMOVABLE MEDIA
*******************************************
*******************************************
DO WHILE .T. && A LOOP
*
IF MDBF_NAME = "DISKS.DBF"
SELECT DISKS
ELSE
SELECT SYS2
ENDIF
*
*
*
* BEGIN: BASED ON FIRST & LAST RECORD, DEFINE A CHUCK OF FILE
*************************************************************
*************************************************************
SET FILTER TO RECNO() >= MFIRST_RECORD .AND. ;
;
RECNO() <= MLAST_RECORD
GO TOP
*
COPY TO SYS2T
SELECT SELECT(1)
USE SYS2T
*
*
*
* BEGIN: GET SIZE, IN BYTES, OF DEFINED DBF CHUCK
*************************************************
*************************************************
NOTE: FOR FSIZE TO WORK SET COMPATIBLE MUST BE ON &
* FILE MUST BE OPEN.
SET COMPATIBLE ON
*
MDBF_SIZE = FSIZE('SYS2T.DBF')
IF FILE('SYS2T.FPT')
MDBF_SIZE = MDBF_SIZE + FSIZE('SYS2T.FPT')
ELSE
ENDIF
*
SET COMPATIBLE OFF
*
*
*
* BEGIN: GET CURRENT FREE SPACE ON REMOVABLE MEDIA
**************************************************
**************************************************
* RETURNS: MMEDIA_FREE_SPACE
* RETURNS: MHALT
NOTE: RETURNS WITH DEFAULT DRIVE/PATH SET TO STORED DATA
NOTE: IF ERROR, RETURNS WITH DEFAULT DRIVE/PATH SET TO STORED
DATA.
*
DO GMEDIA_SIZE
IF MHALT
*
SELECT SYS2T
USE
ERASE SYS2T.DBF
ERASE SYS2T.FPT
RETURN
*
ELSE
ENDIF
*
*
*
* BEGIN: NEED NEW MEDIA ?
*************************
*************************
IF MMEDIA_FREE_SPACE <= 20000
*
NOTE: NEED NEW MEDIA
DO MEDIA_REMOVE && INSTRUCT USER TO REMOVE
CURRENT MEDIA
*
DO GNEW_BACKUP_MEDIA
&& GET NEW MEDIA
WITH AT LEAST 100,000 BYTES
IF MHALT
*
SELECT SYS2T
USE
ERASE SYS2T.DBF
ERASE SYS2T.FPT
RETURN
ELSE
ENDIF
NOTE: KNOW NEW MEDIA HAS >= 100,000 BYTES FREE
*
*
* BEGIN: GET FREE SPACE OF NEW MEDIA
************************************
************************************
DO GMEDIA_SIZE
IF MHALT
*
SELECT SYS2T
USE
ERASE SYS2T.DBF
ERASE SYS2T.FPT
RETURN
ELSE
ENDIF
*
ELSE
ENDIF
*
*
*
* BEGIN: DEFINED FILE CHUCK FIT ON REMOVABLE DRIVE ?
****************************************************
****************************************************
IF MMEDIA_FREE_SPACE ‑ MDBF_SIZE >= 20000
NOTE: DEFINED CHUCK OF FILE WILL FIT ON REMOVABLE MEDIA
*
*
* BEGIN: WRITE DEFINED FILE CHUCK TO REMOVABLE MEDIA
****************************************************
****************************************************
SELECT SYS2T
*
NOTE: RETURNS WITH DEFAULT DRIVE/PATH SET TO STORED DATA.
NOTE: IF ERROR, RETURNS WITH DEFAULT DRIVE/PATH SET TO STORED DATA.
DO WRITE_MEDIA
IF MHALT
*
SELECT SYS2T
USE
ERASE SYS2T.DBF
ERASE SYS2T.FPT
*
RETURN
*
ELSE
ENDIF
*
*
*
* BEGIN: CLOSE SYS2T
********************
********************
SELECT SYS2T
USE
*
*
*
* BEGIN: ALL DONE WITH THIS FILE ?
**********************************
**********************************
IF MLAST_RECORD = MRECORD_COUNT
NOTE: ALL RECORDS COPIED OF DEFINED FILE
*
ERASE SYS2T.DBF
ERASE SYS2T.FPT
*
MHALT = .F.
*
RETURN
*
*
ELSE
*
NOTE: NOT ALL DONE WITH DEFINED FILE
*
*
* BEGIN: GET NEW REMOVABLE MEDIA
********************************
********************************
NOTE: FILE AS WHOLE WOULD NOT FIT. FOUND CHUCK WHICH WOULD
* & WROTE IT. MEDIA MAY NOT BE FULL, I.E. < 20000 BYTES
* BUT AS CLOSE AS CAN GET.
DO MEDIA_REMOVE
DO GNEW_BACKUP_MEDIA
IF MHALT
RETURN
ELSE
ENDI
*
*
*
* BEGIN: ADJUST MFIRST_RECORD
*****************************
*****************************
MFIRST_RECORD = MLAST_RECORD+1
*
*
*
* BEGIN: RESET LAST_RECORD TO RECORD_COUNT
******************************************
******************************************
MLAST_RECORD = MRECORD_COUNT
*
*
* BEGIN: CREATE NEXT CHUCK TO WRITE TO DISK
*******************************************
*******************************************
LOOP
*
ENDIF
*
*
*
ENDIF
*
*
*
NOTE: CURRENTLY DEFINED FILE CHUCK WILL NOT FIT ON REMOVABLE MEDIA
*
*
*
* BEGIN: CLOSE SYS2T
********************
********************
SELECT SYS2T
USE
*
*
*
* BEGIN: DECREMENT MLAST_RECORD
*******************************
*******************************
IF MLAST_RECORD - 50 <= 0
NOTE: LESS THAN 49 RECORDS LEFT TO COPY
* BEGIN TO DECREMENT BY 1
MLAST_RECORD = MLAST_RECORD - 1
*
ELSE
MLAST_RECORD = MLAST_RECORD ‑ 50
*
ENDIF
*
*
*
NOTE: IF HERE, READY TO TRY TO DEFINE A FILE CHUCK WHICH WILL FIT
* ON INSERTED REMOVABLE
MEDIA.
*
*
*
ENDDO && END: ADD RECORDS TO REMOVABLE MEDIA
*********************************************
*********************************************
*
* EOF() FCOPY
*************
*************
PROCEDURE WRITE_MEDIA
*********************
*********************
* DESCRIPTION: COPIES OPEN DBF TO
REMOVABLE MEDIA WITH APPROPRIATE DBF NAME
*
*
* INPUT: MDRIVE
* INPUT: MDBF_NAME
* INPUT: OPEN DBF
*
* RETURNS: MHALT
*
*
NOTE: THIS ROUTINE DOES WRITE
DISKS.DBF TO BACKUP DEVICE
*
NOTE: RETURNS WITH DRIVE/PATH SET
TO SYSTEM STORED DATA
*
NOTE: ON ERROR, RETURNS WITH
DEFAULT DRIVE/PATH SET TO STORED DATA.
*
*
*
* BEGIN: INITIALIZE ERROR
FLAG. MHALT = .T. = ERROR
****************************************************
****************************************************
MHALT = .F.
*
*
*
* BEGIN: COPY OPEN DBF TO
REMOVABLE MEDIA
*****************************************
*****************************************
DO CASE
*
*
CASE MDBF_NAME = "ACQUIRE.DBF"
IF MDRIVE = "A"
COPY TO A:\ACQUIRE.DBF
ELSE
COPY TO B:\ACQUIRE.DBF
ENDIF
*
*
CASE MDBF_NAME = "CONFIG.DBF"
IF MDRIVE = "A"
COPY TO A:\CONFIG.DBF
ELSE
COPY TO B:\CONFIG.DBF
ENDIF
*
*
CASE MDBF_NAME = "DATES.DBF"
IF MDRIVE = "A"
COPY TO A:\DATES.DBF
ELSE
COPY TO B:\DATES.DBF
ENDIF
*
*
CASE MDBF_NAME = "DISKS.DBF"
IF MDRIVE = "A"
COPY TO A:\DISKS.DBF
ELSE
COPY TO B:\DISKS.DBF
ENDIF
*
*
CASE MDBF_NAME = "DISPOSE.DBF"
IF MDRIVE = "A"
COPY TO A:\DISPOSE.DBF
ELSE
COPY TO B:\DISPOSE.DBF
ENDIF
*
*
CASE MDBF_NAME = "HISTORY.DBF"
IF MDRIVE = "A"
COPY TO A:\HISTORY.DBF
ELSE
COPY TO B:\HISTORY.DBF
ENDIF
*
*
CASE MDBF_NAME = "HISTORY2.DBF"
IF MDRIVE = "A"
COPY TO A:\HISTORY2.DBF
ELSE
COPY TO B:\HISTORY2.DBF
ENDIF
*
*
CASE MDBF_NAME = "INVEST.DBF"
IF MDRIVE = "A"
COPY TO A:\INVEST.DBF
ELSE
COPY TO B:\INVEST.DBF
ENDIF
*
*
CASE MDBF_NAME = "PORT.DBF"
IF MDRIVE = "A"
COPY TO A:\PORT.DBF
ELSE
COPY TO B:\PORT.DBF
ENDIF
*
*
CASE MDBF_NAME = "TAXRATES.DBF"
IF MDRIVE = "A"
COPY TO A:\TAXRATES.DBF
ELSE
COPY TO B:\TAXRATES.DBF
ENDIF
*
*
CASE MDBF_NAME = "WORTH.DBF"
IF MDRIVE = "A"
COPY TO A:\WORTH.DBF
ELSE
COPY TO B:\WORTH.DBF
ENDIF
*
*
ENDCASE
*
*
IF MHALT
NOTE: IF WRITE TO REMOVABLE ERROR
*
DO SET_DBF_HD_PATH IN SUPPORT
RETURN
ELSE
ENDIF
*
*
*
MHALT = .F.
*
RETURN
*
*
* EOF() WRITE_MEDIA
*******************
*******************
PROCEDURE CBACK
***************
***************
* DESCRIPTION: CLEANS UP TEMPORARY
DBFS AFTER SYSTEM BACKUP
*
NOTE: NEEDS TO BE SEPARATE ROUTINE
SO IT CAN BE CALLED IF
* ANYTHING TRIGGERS MHALT = .T.
*
*
*
ERASE DISKS.DBF
ERASE INFO.DBF
*
*
IF FILE("SYS2.DBF")
*
ERASE SYS2.DBF
*
ELSE
ENDIF
*
*
IF FILE("SYS2.FPT")
ERASE SYS2.FPT
ELSE
ENDIF
*
*
RETURN
*
* EOF() CBACK
*************
*************
PROCEDURE MEDIA_REMOVE
**********************
**********************
* DESCRIPTION: INSTRUCTS USER TO
REMOVE MEDIA FROM DRIVE
*
*
*
* BEGIN: DISPLAY INSTRUCTION TO
USER
************************************
************************************
*
_VFP.ACTIVEFORM.MOUSEPOINTER = 0
*
MESSAGEBOX("REMOVE media from
removable media drive now.",0,"Alert !")
*
_VFP.ACTIVEFORM.MOUSEPOINTER = 11
*
*
RETURN
*
* EOF() MEDIA_REMOVE
********************
********************
PROCEDURE SET_REMOVABLE_DRIVE
*****************************
*****************************
* DESCRIPTION: SETS SYSTEM DEFAULT
DRIVE/PATH TO REMOVABLE MEDIA DRIVE
*
* INPUT: MDRIVE && FROM FUNCTION FORM
*
* RETURN: MHALT
*
*
NOTE: RETURNS WITH DEFAULT
DRIVE/PATH SET TO REMOVABLE DRIVE.
*
NOTE: IF ERROR IN GETTING DRIVE,
RETURNS WITH DEFAULT DRIVE/PATH
* SET TO STORED DATA.
*
*
*
* BEGIN: SET SYSTEM DEFAULT
DRIVE/PATH TO REMOVABLE MEDIA DRIVE
***************************************************************
***************************************************************
DO CASE
*
CASE MDRIVE = "A"
SET DEFAULT TO A:\
*
CASE MDRIVE = "B"
SET DEFAULT TO B:\
*
ENDCASE
IF MHALT
*
DO SET_DBF_HD_PATH IN SUPPORT
RETURN
*
ELSE
ENDIF
*
*
SET PATH TO
*
RETURN
*
* EOF() SET_REMOVABLE_DRIVE
***************************
***************************
*
*
* EOF() SYSTEM2
***************
***************