home *** CD-ROM | disk | FTP | other *** search
- LZW Lib 1.1
-
- by
-
- Doug Hurst
- 8912 Spur Road
- Springfield, VA 22153
-
- <<<General>>>
-
- LZW Lib is a library of functions that will allow you to
- do, in your C programs, some of the things you can do from the
- DOS commandline with such programs as PKZIP and PKUNZIP, ARC,
- LHARC, etc. While I've titled the library LZW, your files can
- have any extension you desire. In fact, there is no default
- extension. You should be aware that these files will probably
- (read that assuredly) not be structurally compatible with the
- files created by any of the programs mentioned above.
-
- This library uses a fairly generic LZW data encoding
- algorithm, downloaded from a bulletin board, and allows you to
- create and manipulate files of encoded files.
-
-
- <<<The Theory of Operation>>>
-
- The encoded files created by LZW Lib functions have the
- following structure:
-
- ┌─────────────┐
- │ File Header │
- ├─────────────┤
- │ │
- │ │
- │ │
- │ │
- │ │
- │ Encoded │
- │ File │
- │ Data │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- ├─────────────┤
- │ File │
- │ Directory │
- │ │
- │(linked list)│
- │ │
- │ │
- │ │
- └─────────────┘
-
-
- The File Header is made up of the following structure:
-
- typedef struct
- {
- char lzwid;
- unsigned int num_files;
- unsigned long linkpos;
- }LZW_HDR;
-
- When an existing file is opened, two steps occur
- immediately. The header structure is read from the top of the
- file and the lzwid member of this structure is checked. If
- lzwid is not 0x1A, an error is returned. If the file is
- determined to be a valid LZW Lib file, the second step
- is a seek to file position contained in the linkpos
- member, then the file directory is read and a linked list
- developed. The num_files is maintained all the time the file
- is open. The linked list fields are as follows:
-
- typedef struct
- {
- char marked;
- char path[60];
- char name[13];
- unsigned long filepos;
- unsigned long size;
- unsigned long length;
- unsigned int date;
- unsigned int time;
- }FIELDS,*FIELDSPTR;
-
- This is almost self-explanatory. The structure member 'marked'
- is used to speed up file operations. When a new file is added
- to the encoded file, the linked list is searched for files
- of the same name. If found, marked member is changed from
- a ' ' (0x20) to an '*' 0x42 for those files and the new file
- added to the end. These files are then ignored by other
- operations. The LZW_HDR structure member linkpos is then
- updated so the program knows where to go to write the file
- directory when operations have been completed.
-
- You may be thinking if you only mark the old file and add
- the new file, doesn't the encoded file get bigger? Well,
- yes it does. There is a function called lzwpurge() that handles
- this at a more opportune time for the program, such as when
- exiting. I don't know if this is the best way to handle this,
- but it's the way I handled it. I'm open to suggestions.
-
- Additional explanation of the theory of operation is contained
- int the functions Reference section below.
-
-
- <<<The Files>>>
-
- The following files are provided in the .ZIP file:
-
- LZW.DOC This document
- LZWIN.C Source for an LZW encoding program
- LZWIN.PRJ Borland C++ 2.0 project file
- LZWINB.MAK Borland C++ 2.0 make file
- LZWIN6.MAK Microsoft C make file
- LZWIN.LNK Microsoft C link response file
- LZWOUT.C Source for an LZW decoding program
- LZWOUT.PRJ Borland C++ 2.0 project file
- LZWOUTB.MAK Borland C++ 2.0 make file
- LZWOUT6.MAK Microsoft C make file
- LZWOUT.LNK Microsoft C link response file
- LZW.SRC A PDQHelp(tm) (see below) file
- LZW.H A required header file when using the library
- functions
- LZWLBC.LIB Large code library for Borland C 2.0 and
- above
- LZWMBC.LIB Medium code library for Borland C 2.0 and
- above
- LZWSBC.LIB Small code library for Borland C 2.0 and
- above
- LZWLC6.LIB Large code library for Microsoft C 5.1 and
- above
- LZWMC6.LIB Medium code library for Microsoft C 5.1 and
- above
- LZWSC6.LIB Small code library for Microsoft C 5.1 and
- above
-
- <<<The Functions>>>
-
- lzw_init() A must call before calling any other functions
- lzw_deinit() A must call beore exiting the program
- lzw() The encoding (in) function
- unlzw() The decoding (out) function
- lzwpurge() The tidy up function
-
- <<<The Future>>>
-
- I think this library will be useful for some applications.
- It is my intention to go through and speed things up with some
- in-line assembly wherever I can. It is also my intention to
- add to the library to allow encoded files to be decoded
- and placed directly into memory. Currently, you simply create
- a full-sized file, which you then have to open and read.
- I'm not sure how I'm going to do this yet, and again,
- I'm open to suggestions.
-
- <<<The Money>>>
-
- If you find this program useful and would like to donate
- to its contined life, I think a contribution of $10.00 would
- be sufficient for now. You can send it to the address
- contained at the top of this document.
-
-
- <<<The PDQHelp(tm) file>>>
-
- I'm sure most of you don't know about PDQHelp(tm).
- PDQHelp(tm) is the greatest on-line help program for
- programmer's ever. It's available from:
-
- Leverage Software
- 2241-R Tacketts Mill Rd
- WoodBridge, VA 22192
- 1-703-643-0818
-
- It's a TSR but is very well behaved and takes up only
- 29K, and can be loaded high on 286's with QRAM or 386's
- with just about any high memory manager. Remember the The
- Norton Guides? It took up 70K.
-
- You can block/cut/paste into your editor or send to a
- printer. You can search by keyword, string within keyword,
- or scan the help text itself. You can also pick keywords
- off the screen.
-
- Help files can be as large as available disk space up
- to 100000 keywords and 1200 lines per keyword.
-
- Various help files can merged together to make
- consolidated help files. One I have consists of all the
- Vermont Views(tm), Greenleaf Comm, Advanced DOS, C 6.00A
- and Essential Graphics functions and other reference
- material. Very handy indeed.
-
- Greenleaf Software thinks enough of it to supply
- PDQHelp(tm) files for all their libraries
-
- I swear to you if you ever use this program, you'll never
- want to be without it.
-
- Enough of my swearings.
-
-
- <<<Miscellaneous>>>
-
- Since I use both Borland C++ and Microsoft C, I use a directory
- called \OTHERINC to hold the header files for third party
- libraries so I don't have to have duplicate copies.
-
- You will likely have to change the paths in the make files for
- LZWIN.C and LZWOUT.C to get them to compile and link properly.
-
-
-
- Doug Hurst
-
- =================================================================
-
- <<<Reference>>>
-
- -----------------------------------------------------------------
- LZW_INIT()
-
-
- lzw_init()
-
- Initializes the LZW library
-
- #include <lzw.h>
-
- void lzw_init();
-
- Returns None
-
- Description
-
- This routine initializes certain global variables
-
- Cautions
-
- This function MUST called before calling any other LZW library
- functions.
-
- Related Functions
-
- -----------------------------------------------------------------
- LZW_DEINIT()
-
-
- lzw_deinit()
-
- Deinitializes the LZW library
-
- #include <lzw.h>
-
- void lzw_deinit();
-
- Returns None
-
- Description
-
- This function clears the linked list.
-
- Cautions
-
- This functions must only be called after a call to lzw_init()
-
- Related Functions
-
- lzw_init()
-
- -----------------------------------------------------------------
- LZW()
-
-
- lzw()
-
- Encodes file(s) into an LZW file
-
- #include <lzw.h>
-
- int lzw(char *lzw_pathfile, unsigned long ops,
- char *infile_pathmask);
-
- Returns 0 Success
- -1 Could not open or create LZW file
- -2 Not an appropriate LZW file
- -3 Could not read in file directory (linked list)
- -4 Nothing to do. _dos_findfirst on mask
- unsuccessful
- -5 Could not open input file
- -6 Encoding error
- -7 Could not save file directory (linked list)
-
- Description
-
- This function acts on the lzw_pathfile to perform the specified
- ops:
-
- PATHNAMES - May be used to insert the entire pathname of the file
- into the LZW header.
-
- The infile_pathmask parameter is the mask of files that are to be
- encoded and may include a valid DOS path.
-
- A pass is made through the entire .LZW file, skipping from header
- to header, for each file to be encoded. If that file already
- exists, the header structure member 'marked' is filled with the
- '*' character, then the new file is appended to the end of the
- file. This can cause the .LZW file to grow fairly rapidly in
- size because the old files are not automatically purged.
- The lzwpurge() function may be used to physically purge all
- marked files.
-
- Related Functions
-
- unlzw(), lzwpurge()
-
- -----------------------------------------------------------------
- UNLZW()
-
-
- unlzw()
-
-
- Decodes file(s) from an LZW file
-
-
- #include <lzw.h>
-
-
- int unlzw(char *lzw_pathfile, unsigned long ops, char *mask);
-
- Returns 0 Success
- -1 Could not open LZW file
- -2 LZW file is empty or corrupted
- -3 Not an LZW file
- -4 Could not load file directory (linked list)
- -5 Could not create output file
- -6 Decoding error
- -7 Could not save file directory (linked list);
-
- Description
-
- This function acts on the lzw_pathfile to perform the specified
- ops:
-
- EXTRACT - Extracts the files designated by the parameter
- mask.
- VIEW - Not currently implemented, but will allow the
- passing of a function pointer to give the
- programmer access to file information designated
- by the parameter mask. Cannot be used in
- conjunction with any other operation.
- CREATEDIRS - Can be used in conjunction with the EXTRACT
- operation to
- create the directory specified in the path
- structure
- member, if such a path exists.
- NOOVERWRITE - Can be used in conjunction with EXTRACT and/or
- CREATEDIRS so existing files will not be
- overwritten. Otherwise, they will be.
-
- Only files matching the mask parameter will be extracted.
-
- Caution
-
- Ops may be or'd together for this call, except that the VIEW
- option MAY NOT be used in conjunction with any other call.
-
-
- Related Functions
-
- lzw()
-
- -----------------------------------------------------------------
- LZWPURGE()
-
-
- lzwpurge()
-
- Purges marked and specified files from an LZW file
-
- #include <lzw.h>
-
- int lzwpurge(char *lzw_pathfile,char *mask);
-
- Returns 0 Success
- -1 Could not LZW file
- -2 Not an appropriate LZW file
- -3 Could not open temporary file
-
- Description
-
- This call will purge all 'marked' files from lzw_pathfile.
- Specifiying a mask will also cause files matching the mask to
- be purged even if they have not been previously marked. Pass
- NULL in the mask parameter position if no additional files are
- to be purged.
-
- Related functions
-
- lzw()