home *** CD-ROM | disk | FTP | other *** search
- <<* MSAPACK.INC *>>
- <<* Modified 6 January 1987 *>>
-
- <<procedure GenPackBody>>
- <<begin>>
- PARAMETER row,origFILE,tempFILE,origINDEX,IsFileOK
- PRIVATE origMEMO,tempMEMO,undelrecs
-
- <<shade>>
- *
- * ---Build MEMO filenames.
- origMEMO = TRIM( SUBSTR( origFILE,1,AT(".",origFILE)-1 ) ) + ".DBT"
- tempMEMO = TRIM( SUBSTR( tempFILE,1,AT(".",tempFILE)-1 ) ) + ".DBT"
- *
- * ---Delete old temporary file if it exists.
- IF FILE( tempFILE )
- DELETE FILE &tempFILE
- IF FILE( tempMEMO )
- DELETE FILE &tempMEMO
- ENDIF
- ENDIF
- *
- * ---Open original file and "PACK".
- USE &origFILE
- IF "" <> TRIM(origINDEX)
- SET INDEX TO &origINDEX
- ENDIF
- @ row,0 CLEAR
- @ row,0 SAY [Copying "] + origFILE + ["...]
- * ---Copy undeleted records in order of index.
- * ---The new database will be "SORTed" in index order.
- SET DELETED ON
- SET TALK ON
- COPY TO &tempFILE
- SET TALK OFF
- SET DELETED OFF
- * ---Turn off the index and count the number of undeleted records.
- SET INDEX TO
- COUNT FOR .NOT. DELETED() TO undelrecs
- * ---Close original file.
- USE
- *
- * ---Was COPY TO temporary file successful?
- IsFileOK = .F.
- IF FILE( tempFILE )
- USE &tempFILE
- * ---The undeleted records in both files must match.
- IF EOF()
- IsFileOK = (undelrecs = 0)
- ELSE
- GOTO BOTTOM
- IsFileOK = (undelrecs = RECNO())
- ENDIF
- USE
- ENDIF
- IF .NOT. IsFileOK
- * ---"tempFILE" was not created or has an incorrect record count.
- @ row,0 CLEAR
- @ row,0 SAY "The file could not be packed."
- WAIT
- * ---Delete original index and have calling program recreate it.
- DELETE FILE &origINDEX
- RETURN
- ENDIF
- *
- * ---Delete the original file, and
- * ---RENAME temporary to original.
- DELETE FILE &origFILE
- RENAME &tempFILE TO &origFILE
- IF FILE( origMEMO )
- DELETE FILE &origMEMO
- RENAME &tempMEMO TO &origMEMO
- ENDIF
- <<end>> <<*GenPackBody*>>
-
-
- <<procedure GenPackItBody>>
- <<begin>>
- PARAMETER row
- PRIVATE IsFileOK,filename
- @ row,0 CLEAR
- @ row,0 SAY "NOT UNDOABLE! - Remove all *DELETED* records? (y/n)"
- DO GetKey WITH choice,"YN"+Returnkey
- @ row,0 CLEAR
- IF choice <> "Y"
- RETURN
- ENDIF
- CLOSE DATABASES
- @ row,0 SAY "Removing all *DELETED* records..."
- IsFileOK = .T.
- filename = ""
- IF NdxOrder > "0"
- filename = NDXnam&NdxOrder
- ENDIF
- DO {fileprefix}_APAC WITH row,DBFname,DBFtemp,filename,IsFileOK
- IF IsFileOK
- * ---USE new original and recreate index files.
- USE &DBFname
- @ row,0 CLEAR
- @ row,0 SAY "Recreating index files..."
- SET TALK ON
- <<if ismultials>>
- DO CASE
- <<forall databases>>
- CASE dbfarea = {"}{dbfcount}{"}
- <<if ndxtotal = 0>>
- * ---<None>.
- <<else>>
- <<forall indexes>>
- INDEX ON &NDXkey{ndxcount} TO &NDXnam{ndxcount}
- <<endfor>>
- <<endif>>
- <<endfor>>
- ENDCASE
- <<else>>
- <<select database 1>>
- <<forall indexes>>
- INDEX ON &NDXkey{ndxcount} TO &NDXnam{ndxcount}
- <<endfor>>
- <<endif>>
- SET TALK OFF
- * ---Close the datafile and index.
- USE
- ENDIF
- DO {fileprefix}_OPEN
- <<end>> <<*GenPackItBody*>>
-
- <<* EOF: MSAPACK.INC *>>