home *** CD-ROM | disk | FTP | other *** search
- *****************************************************************
- * * 01/12/93 DOCUMENT.PRG 12:22:12 *
- *****************************************************************
- * * Author's Name: Jeb Long *
- * * *
- * * Description: *
- * * This program illustrates memo field compression *
- * * using FOXTOOLS and edilzssa.dll *
- * * *
- * * This program maintains DOCUMENT.DBF which stores *
- * * documents as compressed database files *
- *****************************************************************
- USE DOCUMENT
- SET LIBRARY TO (SYS(2004)+"FOXTOOLS") ADDITIVE
- Stopit=.F.
- IF RECCOUNT() = 0 && Is file empty?
- DO ADDNEW
- ENDIF
- IF RECCOUNT() > 0
- DO DOCUMENT.SPR
- ENDIF
- CLEAR ALL
- RETURN
- *****************************************************************
- * Procedure ADDMEMO - Compresses document file and adds it to a
- * memo field
- PROCEDURE ADDNEW
- docfile = GETFILE() && Open file dialog box
- IF COMPRESS(docfile)
- APPEND BLANK
- REPL filename with docfile
- REPLACE DATE WITH DATE()
- APPEND MEMO Document FROM crunch.txt
- DELETE FILE crunch.txt
- ENDIF
- RETURN
- *****************************************************************
- * Function: COMPRESS(Source) - Compresses Source file
- *
- FUNCTION COMPRESS
- PARAMETER NameFile
- Regno = RegFN( "LZSSPACKFILE", "CC", "I", "edilzssa.dll" )
- Success = .F.
- IF Regno = -1
- WAIT WINDOW "Unable to register edilzssa.dll file"
- ELSE
- *
- * LZSSPackFile(Source, Destination) - Compresses source file
- * and writes compressed destination file
- *
- DELETE FILE crunch.txt
- ErrCode = CallFN(Regno, NameFile, "crunch.txt" )
- IF ErrCode = 0
- WAIT WINDOW STR(100-(100*FileSize("crunch.txt") ;
- /FileSize(NameFile) ),5,2);
- +"% Compression" TIMEOUT 10
- Success = .T.
- ELSE
- WAIT WINDOW "Error Number "+LTRIM(STR(ErrCode));
- +"... Compression not performed"
- ENDIF
- ENDIF
- RETURN Success
- *****************************************************************
- * Procedure: DECOMP
- *
- PROCEDURE DECOMP
- PARAMETER Target
- *
- * LZSSUnPackFile(Source, Destination) - Decompresses source file
- * and writes destination file
- *
- Regno = RegFN( "LZSSUnPACKFILE", "CC", "I", "edilzssa.dll" )
- IF FILE(Target)
- WAIT WINDOW Target+" already exists."
- ELSE
- Regno = RegFN( "LZSSUnPACKFILE", "CC", "I", "edilzssa.dll" )
- IF Regno = -1
- WAIT WINDOW "Unable to register edilzssa.dll file"
- ELSE
- ErrCode = CallFN(Regno, "crunch.txt", Target )
- IF ErrCode <> 0
- WAIT WINDOW "Error Number "+LTRIM(STR(ErrCode));
- +" Occurred"
- ENDIF
- ENDIF
- ENDIF
- ERASE crunch.txt
- RETURN
- ****************************************************************
- * File positioning functions
- *
- ***************
- FUNCTION Button
- PARAMETER Choice
- DO CASE
- CASE Choice = 1 && NEXT
- IF RECNO() < RECCOUNT()
- SKIP
- ENDIF
- CASE Choice = 2 && PREVIOUS
- IF RECNO()>1
- SKIP -1
- ENDIF
- CASE Choice = 3 && TOP (First record)
- GO TOP
- CASE Choice = 4 && BOTTOM (Last record)
- GO BOTTOM
- CASE Choice = 5 && Add new memo
- DO ADDNEW
- CASE Choice = 6 && Unpack a memo
- COPY MEMO Document TO crunch.txt
- DO DECOMP WITH Filename
- RETURN .T.
- CASE Choice = 7 && VIEW
- ERASE crunch.txt
- COPY MEMO Document TO crunch.txt
- RELEASE WINDOW VIEW.TMP
- ERASE VIEW.TMP
- DO DECOMP WITH "VIEW.TMP"
- IF ".BMP"$upper(filename)
- DEFINE WINDOW BITMAP FROM 20,1 TO 40,20 FILL FILE VIEW.TMP
- SHOW WINDOW BITMAP
- WAIT WINDOW
- RELEASE WINDOW BITMAP
- ELSE
- MODI FILE VIEW.TMP NOWAIT
- ENDIF
- CASE Choice = 8
- Stopit = .F. && EXIT
- CLEAR READ
- RETURN .T.
- ENDCASE
- SHOW GETS
- @ 1.000,89.200 SAY document.date ;
- SIZE 1.000,9.400 ;
- FONT "MS Sans Serif", 8
- RETURN .T.
- ***********************************************************************
- * Procedure: FileSize(<file>) - Returns size of <file> in bytes
- * If you don't pass it any parameters, it returns -2.
- * If the file cannot be found, the UDF returns -1.
- * (This function was derived from FSEEK() HELP example.)
- *
- PROCEDURE FileSize
- PARAMETERS cfile && File to be checked
- PRIVATE mhandle,fsize
-
- IF PARAMETERS( ) = 0
- RETURN -2 && Return -2 if no parameter passed
- ELSE
- IF !FILE(cfile)
- RETURN -1 && Return -1 if file does not exist
- ENDIF
- ENDIF
- mhandle = FOPEN(cfile) && Open file
- fsize = FSEEK(mhandle,0,2) && Determine file size, assign to fsize
- =FCLOSE(mhandle) && Close file
- RETURN fsize && Return value
-
-