home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
CLIPPER
/
RCMP20
/
RCMPLIB.DOC
< prev
next >
Wrap
Text File
|
1993-09-20
|
25KB
|
637 lines
┌─────────────────────────────────────────────────────────────────────────╖
│ ║
│ RCmpLib version 2.0 (20/09/93) ║
│ ║
│ ║
│ (c) 1993 Rolf van Gelder, EINDHOVEN - All rights reserved ║
│ ║
╘═════════════════════════════════════════════════════════════════════════╝
1 INTRODUCTION --------------------------------------------------------
RCmpLib is a CLIPPER LIBRARY with data compression functions.
Because RCmpLib is fully written in ASSEMBLER its functions are
VERY FAST !
Three libraries are enclosed :
RCmpExo.lib - ExoSpace compatible library for Clipper 5.xx & Sum '87
RCmpLib.lib - Library for Clipper version 5.xx
RCmpS87.lib - Library for Clipper Summer '87
RCmpLib is a Shareware product :
You have the opportunity to try the program at no charge to see if
it meets your needs.
If you continue to use the program after evaluation,
please complete the included registration form (RCmpLib.FRM)
and send it with the applicable registration fee to the author.
FEATURES :
* Functions to COMPRESS and DECOMPRESS files
* FAST & RELIABLE COMPRESSION with a GOOD COMPRESSION FACTOR
* A NORTON GUIDE with a description of all functions in the library
* EXOSPACE COMPATIBLE
* A DEMO PROGRAM with examples of the use of all functions in
RCmpLib.
2 COMPRESSION AND DECOMPRESSION ---------------------------------------
2.1 COMPRESSION ALGORITHM -----------------------------------------------
The compression and decompression functions of RCmpLib are based on
the so-called Lempel-Ziv principle, to be specific the LZW algorithm.
This base principle is used by almost all famous compression programs
(as LHARC, ARJ and PKZIP).
The principle works in short as follows :
(Sub-)Strings that appear often in the file to compress are being
replaced by numerical codes.
While decompressing these codes are replaced again by the original
strings.
2.2 THE USE OF COMPRESSION IN CLIPPER APPLICATIONS ----------------------
The most common use of compression function in Clipper applications
is the following scenario :
Decompress all Clipper data files (.DBF,.DBT,.NTX,.FRM,... etc.) at
the beginning of an application. While the application is running
all the files are accessible in their normal, uncompressed form.
Compress all the Clipper data files (.DBF,.DBT,.NTX,.FRM,... etc.)
at the termination of the application.
Advantages of this method :
- During the execution of the application all is normal
(all the files are uncompressed on the disk)
- After the termination of the program, the application will consume
much less disk space (the data files are compressed)
- Backups of the application consume much less floppy disk space
(data files are backupped in their compressed form)
- One of the greatest advantages is :
After the application is terminated all data files will be
UNACCESSIBLE to the user (or other persons).
A compressed file is also ENCRYPTED !!
Files with secret information can't be examined using an editor
or list program.
It will be IMPOSSIBLE to manipulate the files with for example
dBASE or any other .DBF viewer/editor :
The (compressed) database can't be corrupted doing that way.
2.3 QUALITY OF THE COMPRESSION ------------------------------------------
The compression method used by RCmpLib is fast, reliable and gives
a good compression factor.
In comparison with the commercial compression programs as PKZIP 2.04
and ARJ 2.41, RCmpLib will score a little less.
The comparison is not completely fair because PKZIP and ARJ standalone
programs are with only one goal : compression.
RCmpLib is a part of a complete Clipper application and has to deal
with less resources (as memory).
3 FUNCTIONS IN RCMPLIB ------------------------------------------------
3.1 Function R_Compress : Compresses a file using the Lempel-Ziv algorithm
Syntax
nRetCode := R_Compress ( cInFile [, cOutFile[, nCmpFact ] ] )
Arguments
cInFile File specification of the file to be compressed
(=input file)
Format : [drive:][\path\]filename[.ext]
Example : C:\INVOICE\INVOICE.DBF
cOutFile File specification of the compressed file
(=output file)
Format : [drive:][\path\]filename[.ext]
Example : C:\INVOICE\INVOICE.ZIP
If NO output file name is specified the output file
will be created on the default drive, in the default
directory, with the same name as the input file.
THE FIRST CHARACTER OF THE FILE NAME EXTENSION WILL
BE REPLACED BY THE '#' CHARACTER.
Examples:
R_Compress ( 'TEST.DBF', 'TEST.LZC' ) => TEST.LZC
R_Compress ( 'TEST.DBF' ) => TEST.#CP
(v2.0) nCmpFact Compression factor [1-5]
Higher numbers give a higher compression factor.
Default value is 5. In most cases this is the best
choice. If there are "not-enough-memory" problems
take a lower compression factor : this saves memory
(but the size of the compressed files will increase
a little bit ...).
Returns
nRetCode Numeric return code
The values and descriptions of this return code
are defined in RCmpLib.CH :
┌────┬────────────────────┬─────────────────────────────────╖
│Code│Constant │Description ║
├────┼────────────────────┼─────────────────────────────────╢
│ 0 │CP_OKAY │Everything okay ║
│ 1 │CP_INVALID_PARM │Invalid parameter(s) passed ║
│ 2 │CP_OPEN_INPUT │Error OPENING input file ║
│ 3 │CP_NOT_RCMPLIB │Not compressed by RCmpLib ║
│ 4 │CP_WRONG_VERSION │Wrong version of RCmpLib ║
│ 5 │CP_CREATE_OUTPUT │Error CREATING output file ║
│ 6 │CP_READ_INPUT │Error READING input file ║
│ 7 │CP_WRITE_OUTPUT │Error WRITING output file ║
│ 8 │CP_CLOSE_INPUT │Error CLOSING input file ║
│ 9 │CP_CLOSE_OUTPUT │Error CLOSING output file ║
│ 10 │CP_MEMORY_ERROR │Not enough memory ║
│ 11 │CP_ALLOCATE_ERROR │Error allocating buffer ║
╘════╧════════════════════╧═════════════════════════════════╝
Description
Compresses the input file using Lempel-Ziv compression.
┌────────────────────────────────────────────────────────────────╖
│ -+- CAUTION -+- ║
│ ║
│ IN THE UN-REGISTERED VERSION OF RCMPLIB THE FOLLOWING ║
│ REGISTRATION MESSAGE WILL BE DISPLAYED AT RANDOM TIMES ║
│ (WHILE EXECUTING THE R_COMPRESS() FUNCTION) : ║
│ ║
│ UN-Registered version of RCmpLib -+- Please wait for 8 seconds ║
│ ║
│ AFTER A 8 SECONDS DELAY THE PROGRAM WILL CONTINUE. ║
╘════════════════════════════════════════════════════════════════╝
Example
*-- Compresses the file INVOICE.DBF => INVOICE.#BF
*-- Header file of RCmpLib
#include "RCmpLib.CH"
LOCAL nRetCode && Return code R_Compress
LOCAL aCmpError := CP_ERRMSG && Array with error msgs
*-- Save the original file size
LOCAL nFSizeIn := R_FSize ( 'INVOICE.DBF' )
LOCAL nFSizeOut && Size of output file
LOCAL nFactor && Compression factor
[...]
nRetCode := R_Compress ( 'INVOICE.DBF', 'INVOICE.#BF' )
IF nRetCode = CP_OKAY
*-- Compression is okay :
*-- delete the original file
FErase ( 'INVOICE.DBF' )
*-- Determine the size of the compressed file
nFSizeOut := R_FSize ( 'INVOICE.#BF' )
*-- Calculate the compression factor
nFactor := 100*(nFSizeIn-nFSizeOut)/nFSizeIn
*-- Show the compression factor
ALERT ( 'Compression factor : '+Str(nFactor)+' %' )
ELSE
*-- Oops, error while compressing ...
*-- Display the error message
ALERT ( 'Error R_Compress() : ' + aCmpError [nRetCode] )
ENDIF
*-- Continuation of the program
[...]
More examples can be found in the demo program RCmpDemo.PRG.
3.2 Function R_CPName : Determines the original name of a compressed file
Syntax
cFileName := R_CPName ( cCmpFile )
Arguments
cCmpFile File specification of a compressed file
Format : [drive:][\path\]filename[.ext]
Example : C:\INVOICE\INVOICE.#BF
Returns
cFileName Original name of the compressed file.
If an error is detected (p.e. the specified input
file doesn't exist) a NIL pointer will be returned.
The error can be examined using the R_LastErr ()
function.
Description
Determines what the file name of a file was before it was
compressed by R_Compress ().
Example
*-- Compresses the file INVOICE.DBF => INVOICE.#BF and determines
*-- the original file name
*-- header file of RCmpLib
#include "RCmpLib.CH"
LOCAL nRetCode && Return code R_Compress
nRetCode := R_Compress ( 'INVOICE.DBF', 'INVOICE.#BF' )
IF nRetCode = CP_OKAY
*-- Compression okay : delete the original file
FErase ( 'INVOICE.DBF' )
?'The original name of INVOICE.#BF was : ', ;
R_CPName ( 'INVOICE.#BF' )
*-- Results to : 'INVOICE.DBF'
ENDIF
3.3 Function R_CPSize : Determines the original size of a compressed file
Syntax
nFileSize := R_CPSize ( cCmpFile )
Arguments
cCmpFile File specification of a compressed file
Format : [drive:][\path\]filename[.ext]
Example : C:\INVOICE\INVOICE.#BF
Returns
nFileSize Original (uncompressed) size of the compressed file.
If an error is detected (p.e. the specified input
file doesn't exist) the value -1 will be returned.
The error can be examined using the R_LastErr ()
function.
Description
Determines what the file size of a file was before it was
compressed by R_Compress ().
This information can be used to check if there is enough free
disk space before decompressing files.
Example
*-- Compresses the file INVOICE.DBF => INVOICE.#BF and determines
*-- the original file size
*-- header file of RCmpLib
#include "RCmpLib.CH"
LOCAL nRetCode && Return code R_Compress
nRetCode := R_Compress ( 'INVOICE.DBF', 'INVOICE.#BF' )
IF nRetCode = CP_OKAY
*-- Compression okay : delete the original file
FErase ( 'INVOICE.DBF' )
?'The original size of INVOICE.#BF was : ', ;
R_CPSize ( 'INVOICE.#BF' )
ENDIF
3.4 Function R_DeComp : Decompresses a by R_Compress() compressed file
Syntax
nRetCode := R_DeComp ( cInFile [, cOutFile] )
Arguments
cInFile File specification of the file to be decompressed
(=input file)
Format : [drive:][\path\]filename[.ext]
Example : C:\INVOICE\INVOICE.#BF
cOutFile File specification of the decompressed file
(=output file)
Format : [drive:][\path\]filename[.ext]
Example : C:\INVOICE\INVOICE.DBF
If NO output file name is specified the output file
will be created on the default drive, in the default
directory, with the same name as the ORIGINAL file.
Example :
R_Compress ( 'TEST.DBF', 'TEST.#BF' )
R_DeComp ( 'TEST.#BF' ) => 'TEST.DBF'
Returns
nRetCode Numeric return code
The values and descriptions of this return code
are defined in RCmpLib.CH :
┌────┬────────────────────┬─────────────────────────────────╖
│Code│Constant │Description ║
├────┼────────────────────┼─────────────────────────────────╢
│ 0 │CP_OKAY │Everything okay ║
│ 1 │CP_INVALID_PARM │Invalid parameter(s) passed ║
│ 2 │CP_OPEN_INPUT │Error OPENING input file ║
│ 3 │CP_NOT_RCMPLIB │Not compressed by RCmpLib ║
│ 4 │CP_WRONG_VERSION │Wrong version of RCmpLib ║
│ 5 │CP_CREATE_OUTPUT │Error CREATING output file ║
│ 6 │CP_READ_INPUT │Error READING input file ║
│ 7 │CP_WRITE_OUTPUT │Error WRITING output file ║
│ 8 │CP_CLOSE_INPUT │Error CLOSING input file ║
│ 9 │CP_CLOSE_OUTPUT │Error CLOSING output file ║
│ 10 │CP_MEMORY_ERROR │Not enough memory ║
│ 11 │CP_ALLOCATE_ERROR │Error allocating buffer ║
╘════╧════════════════════╧═════════════════════════════════╝
Description
Decompresses the input file. The input file should be compressed
by the R_Compress() function.
The timestamp of the original (uncompressed) file will be restored
after the decompression.
┌────────────────────────────────────────────────────────────────╖
│ -+- CAUTION -+- ║
│ ║
│ IN THE UN-REGISTERED VERSION OF RCMPLIB THE FOLLOWING ║
│ REGISTRATION MESSAGE WILL BE DISPLAYED AT RANDOM TIMES ║
│ (WHILE EXECUTING THE R_DECOMP() FUNCTION) : ║
│ ║
│ UN-Registered version of RCmpLib -+- Please wait for 8 seconds ║
│ ║
│ AFTER A 8 SECONDS DELAY THE PROGRAM WILL CONTINUE. ║
╘════════════════════════════════════════════════════════════════╝
Example
*-- Decompressed the file INVOICE.#BF
*-- Header file of RCmpLib
#include "RCmpLib.CH"
LOCAL nRetCode && Return code R_Compress
LOCAL aCmpError := CP_ERRMSG && Array with error msgs
[...]
nRetCode := R_DeComp ( 'INVOICE.#BF' )
IF nRetCode = CP_OKAY
*-- Decompression okay :
*-- original (compressed) file can be deleted !
FErase ( 'INVOICE.#BF' )
ELSE
*-- Oops, error while decompressing
*-- Display the error message
ALERT ( 'Error R_DeComp() : ' + aCmpError [nRetCode] )
ENDIF
&& Continuation of the program
[...]
More examples can be found in the demo program RCmpDemo.PRG.
3.5 Function R_FSize : Determines the size of a file
Syntax
nFileSize := R_FSize ( cInFile )
Arguments
cInFile File specification of the file to be examined
Format : [drive:][\path\]filename[.ext]
Example : C:\INVOICE\INVOICE.DBF
Returns
nFileSize Size of the input file (in bytes).
If an error is detected (p.e. the specified input
file doesn't exist) the value -1 will be returned.
Description
Determines the size of a file
Example
See the example of R_Compress()
3.6 Function R_IsRCmp : Determines if a file has been compressed
by R_Compress()
Syntax
lCompressed := R_IsRCmp ( cInFile )
Arguments
cInFile File specification of the file to be examined
Format : [drive:][\path\]filename[.ext]
Example : C:\INVOICE\INVOICE.DBF
Returns
lCompressed .T. : file IS compressed by R_Compress()
.F. : file IS NOT compressed by R_Compress()
-OR- error occurred while executing R_IsCmp()
(p.e. the input file doesn't exist)
The error can be examined using the
R_LastErr () function.
Description
Determines if a file has been compressed using the R_Compress()
function.
Using this function it is easy to determine which files in a
particular directory are compressed by R_Compress() and so can
be decompressed using the R_DeComp() function.
Example
*-- Decompressed all compressed file in the current directory
#include "Directry.CH"
AEval ( Directory ( '*.*' ), ;
{ |aFile| IF ( R_IsRCmp ( aFile [F_NAME] ), ;
R_DeComp ( aFile [F_NAME] ), ;
nil ;
) ;
} ;
)
See also the demo program RCmpDemo.PRG
3.6 Function R_LastErr : Retrieves the last occurred error code (v2.0)
Syntax
nErrCode := R_LastErr ()
Parameters
(None)
Returns
nErrCode Last occurred error code
The values and descriptions of this return code
are defined in RCmpLib.CH :
┌────┬────────────────────┬─────────────────────────────────╖
│Code│Constant │Description ║
├────┼────────────────────┼─────────────────────────────────╢
│ 0 │CP_OKAY │Everything okay ║
│ 1 │CP_INVALID_PARM │Invalid parameter(s) passed ║
│ 2 │CP_OPEN_INPUT │Error OPENING input file ║
│ 3 │CP_NOT_RCMPLIB │Not compressed by RCmpLib ║
│ 4 │CP_WRONG_VERSION │Wrong version of RCmpLib ║
│ 5 │CP_CREATE_OUTPUT │Error CREATING output file ║
│ 6 │CP_READ_INPUT │Error READING input file ║
│ 7 │CP_WRITE_OUTPUT │Error WRITING output file ║
│ 8 │CP_CLOSE_INPUT │Error CLOSING input file ║
│ 9 │CP_CLOSE_OUTPUT │Error CLOSING output file ║
│ 10 │CP_MEMORY_ERROR │Not enough memory ║
│ 11 │CP_ALLOCATE_ERROR │Error allocating buffer ║
╘════╧════════════════════╧═════════════════════════════════╝
Description
This function can be used in combination with one of the following
functions :
R_CPName(), R_CPSize() or R_IsRCmp().
After calling one of these functions you can use R_LastErr() to
determine which error did occur.
(The error code is not returned by these functions).
Example
#include "RCmpLib.CH"
LOCAL aCmpError := CP_ERRMSG && Array with messages
LOCAL cOrgName
LOCAL nOrgSize
cOrgName := R_CPName ( 'INVOICE.#BF' )
IF cOrgName = NIL
*-- Determine & display error
?'Error: ' + aCmpError [R_LastErr()]
ELSE
?'The original name is ', cOrgName
ENDIF
cOrgSize := R_CPSize ( 'INVOICE.#BF' )
IF cOrgSize < 0
*-- Determine & display error
?'Error: ' + aCmpError [R_LastErr()]
ELSE
?'The original size is ', nOrgSize, ' bytes.'
ENDIF
IF !R_IsRCmp ( 'INVOICE.#BF' )
*-- Determine & display error
?'Error: ' + aCmpError [R_LastErr()]
ELSE
?'File is compressed by RCmpLib !'
ENDIF
4 REGISTRATION --------------------------------------------------------
RCmpLib is a Shareware product. It is available through Users Groups,
Bulletin Boards, etc.
You have the opportunity to try the program at no charge to see
if it meets your needs. If you continue to use the program after
evaluation, please complete the included registration form
(RCmpLib.FRM) and send it to:
Ing. R.P.B. van Gelder
Binnenwiertzstraat 27
5615 HG EINDHOVEN
THE NETHERLANDS
The price for registration is :
If you want to receive the library by E-MAIL : US $ 10,00
If you want to receive the library by POST : US $ 15,00
Payment :
Just include the appropriate amount of money (in cash) with the
registration form and send it to the address as mentioned above.
4.1 BENEFITS OF REGISTRATION --------------------------------------------
1) A registered version of RCmpLib will be sent to you by E-MAIL or
by POST.
┌─────────────────────────────────────────────────────────────╖
│ THE REGISTERED VERSION DOESN'T DISPLAY THE REGISTRATION ║
│ MESSAGE AND DOESN'T HAVE THE 8 SECONDS DELAYS. ║
╘═════════════════════════════════════════════════════════════╝
2) You will receive a small utility called DCmpAll.EXE.
With DCmpAll you can decompress all files in a directory.
This is very useful for system developers.
3) Run-time royalty-free license. You will be free to integrate
RCmpLib functions into your Clipper applications without having
to pay any royalty or fee for doing so. You may also distribute
or market any such applications royalty-free.
4) Support through E-Mail
E-Mail addresses :
Internet: RCROLF@urc.tue.nl
Bitnet : RCROLF@heitue5
4.2 USER GROUPS / SHAREWARE DISTRIBUTORS --------------------------------
PC User Groups are welcome to add RCmpLib to their libraries under
the following conditions :
1) It must be completely unmodified
2) A diskette/copying fee of $5 of less is charged; and
3) This documentation file MUST be included.
I would appreciate notification that you have added RCmpLib
to your library.
IF YOU RECEIVED RCMPLIB THROUGH EITHER A USER GROUP OR A SHAREWARE
DISTRIBUTOR, PLEASE REMEMBER THAT THE DISKETTE FEE YOU PAYED DOES NOT
CONSTITUTE LICENSING THE SOFTWARE, AND YOU ARE STILL OBLIGATED TO
REGISTER IF YOU DECIDE TO USE RCMPLIB.
5 DISCLAIMER ----------------------------------------------------------
The copyright owner disclaims all warranties and is not liable for
damages of any kind. By using RCmpLib you agree to this.