home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c019 / 3.ddi / LZWLIB11 / LZW.DOC next >
Encoding:
Text File  |  1992-03-23  |  13.5 KB  |  416 lines

  1.                                LZW Lib 1.1
  2.  
  3.                                   by
  4.  
  5.                               Doug Hurst
  6.                             8912 Spur Road
  7.                         Springfield, VA 22153
  8.  
  9. <<<General>>>
  10.  
  11.      LZW Lib is a library of functions that will allow you to 
  12. do, in your C programs, some of the things you can do from the 
  13. DOS commandline with such programs as PKZIP and PKUNZIP, ARC, 
  14. LHARC, etc.  While I've titled the library LZW, your files can 
  15. have any extension you desire.  In fact, there is no default
  16. extension.  You should be aware that these files will probably 
  17. (read that assuredly) not be structurally compatible with the 
  18. files created by any of the programs mentioned above.
  19.  
  20.      This library uses a fairly generic LZW data encoding 
  21. algorithm, downloaded from a bulletin board, and allows you to 
  22. create and manipulate files of encoded files.
  23.  
  24.  
  25. <<<The Theory of Operation>>>
  26.  
  27.     The encoded files created by LZW Lib functions have the 
  28. following structure:
  29.  
  30.                         ┌─────────────┐
  31.                         │ File Header │
  32.                         ├─────────────┤
  33.                         │             │
  34.                         │             │
  35.                         │             │
  36.                         │             │
  37.                         │             │
  38.                         │ Encoded     │
  39.                         │ File        │
  40.                         │ Data        │
  41.                         │             │
  42.                         │             │
  43.                         │             │
  44.                         │             │
  45.                         │             │
  46.                         │             │
  47.                         │             │
  48.                         │             │
  49.                         │             │
  50.                         │             │
  51.                         │             │
  52.                         │             │
  53.                         │             │
  54.                         │             │
  55.                         │             │
  56.                         ├─────────────┤
  57.                         │ File        │
  58.                         │ Directory   │
  59.                         │             │
  60.                         │(linked list)│
  61.                         │             │
  62.                         │             │
  63.                         │             │
  64.                         └─────────────┘
  65.  
  66.  
  67.      The File Header is made up of the following structure:
  68.  
  69.                         typedef struct
  70.                         {
  71.                           char lzwid;
  72.                           unsigned int num_files;
  73.                           unsigned long linkpos;
  74.                         }LZW_HDR;
  75.  
  76.      When an existing file is opened, two steps occur 
  77. immediately.  The header structure is read from the top of the 
  78. file and the lzwid member of this structure is checked.  If 
  79. lzwid is not 0x1A, an error is returned.  If the file is 
  80. determined to be a valid LZW Lib file, the second step 
  81. is a seek to file position contained in the linkpos 
  82. member, then the file directory is read and a linked list 
  83. developed.  The num_files is maintained all the time the file 
  84. is open.  The linked list fields are as follows:
  85.  
  86.                         typedef struct
  87.                         {
  88.                           char marked;
  89.                           char path[60];
  90.                           char name[13];
  91.                           unsigned long filepos;
  92.                           unsigned long size;
  93.                           unsigned long length;
  94.                           unsigned int date;
  95.                           unsigned int time;
  96.                         }FIELDS,*FIELDSPTR;
  97.  
  98. This is almost self-explanatory.  The structure member 'marked'
  99. is used to speed up file operations.  When a new file is added 
  100. to the encoded file, the linked list is searched for files 
  101. of the same name.  If found, marked member is changed from 
  102. a ' ' (0x20) to an '*' 0x42 for those files and the new file 
  103. added to the end.  These files are then ignored by other 
  104. operations.  The LZW_HDR structure member linkpos is then 
  105. updated so the program knows where to go to write the file 
  106. directory when operations have been completed.
  107.  
  108.      You may be thinking if you only mark the old file and add 
  109. the new file, doesn't the encoded file get bigger?  Well, 
  110. yes it does.  There is a function called lzwpurge() that handles 
  111. this at a more opportune time for the program, such as when 
  112. exiting.  I don't know if this is the best way to handle this,
  113. but it's the way I handled it.  I'm open to suggestions.
  114.  
  115.      Additional explanation of the theory of operation is contained 
  116. int the functions Reference section below.
  117.  
  118.  
  119. <<<The Files>>>
  120.  
  121.      The following files are provided in the .ZIP file:
  122.  
  123.        LZW.DOC        This document
  124.        LZWIN.C        Source for an LZW encoding program
  125.        LZWIN.PRJ      Borland C++ 2.0 project file
  126.        LZWINB.MAK     Borland C++ 2.0 make file
  127.        LZWIN6.MAK     Microsoft C make file
  128.        LZWIN.LNK      Microsoft C link response file
  129.        LZWOUT.C       Source for an LZW decoding program
  130.        LZWOUT.PRJ     Borland C++ 2.0 project file
  131.        LZWOUTB.MAK    Borland C++ 2.0 make file
  132.        LZWOUT6.MAK    Microsoft C make file
  133.        LZWOUT.LNK     Microsoft C link response file
  134.        LZW.SRC        A PDQHelp(tm) (see below) file
  135.        LZW.H          A required header file when using the library
  136.                       functions
  137.        LZWLBC.LIB     Large code library for Borland C 2.0 and 
  138.                       above
  139.        LZWMBC.LIB     Medium code library for Borland C 2.0 and 
  140.                       above
  141.        LZWSBC.LIB     Small code library for Borland C 2.0 and 
  142.                       above
  143.        LZWLC6.LIB     Large code library for Microsoft C 5.1 and 
  144.                       above
  145.        LZWMC6.LIB     Medium code library for Microsoft C 5.1 and 
  146.                       above
  147.        LZWSC6.LIB     Small code library for Microsoft C 5.1 and 
  148.                       above
  149.  
  150. <<<The Functions>>>
  151.  
  152.    lzw_init()       A must call before calling any other functions
  153.    lzw_deinit()     A must call beore exiting the program
  154.    lzw()            The encoding (in) function
  155.    unlzw()          The decoding (out) function
  156.    lzwpurge()       The tidy up function
  157.  
  158. <<<The Future>>>
  159.  
  160.      I think this library will be useful for some applications.
  161. It is my intention to go through and speed things up with some
  162. in-line assembly wherever I can.  It is also my intention to 
  163. add to the library to allow encoded files to be decoded 
  164. and placed directly into memory.  Currently, you simply create 
  165. a full-sized file, which you then have to open and read.  
  166. I'm not sure how I'm going to do this yet, and again, 
  167. I'm open to suggestions.
  168.  
  169. <<<The Money>>>
  170.  
  171.      If you find this program useful and would like to donate
  172. to its contined life, I think a contribution of $10.00 would
  173. be sufficient for now.  You can send it to the address 
  174. contained at the top of this document.
  175.  
  176.  
  177. <<<The PDQHelp(tm) file>>>
  178.  
  179.      I'm sure most of you don't know about PDQHelp(tm).  
  180. PDQHelp(tm) is the greatest on-line help program for 
  181. programmer's ever.  It's available from:
  182.  
  183.                           Leverage Software
  184.                        2241-R Tacketts Mill Rd
  185.                          WoodBridge, VA 22192
  186.                             1-703-643-0818
  187.  
  188.      It's a TSR but is very well behaved and takes up only 
  189. 29K, and can be loaded high on 286's with QRAM or 386's 
  190. with just about any high memory manager.  Remember the The 
  191. Norton Guides?  It took up 70K.
  192.  
  193.      You can block/cut/paste into your editor or send to a 
  194. printer.  You can search by keyword, string within keyword, 
  195. or scan the help text itself.  You can also pick keywords 
  196. off the screen.
  197.  
  198.      Help files can be as large as available disk space up
  199. to 100000 keywords and 1200 lines per keyword.
  200.  
  201.      Various help files can merged together to make 
  202. consolidated help files.  One I have consists of all the 
  203. Vermont Views(tm), Greenleaf Comm, Advanced DOS, C 6.00A
  204. and Essential Graphics functions and other reference
  205. material.  Very handy indeed.
  206.  
  207.      Greenleaf Software thinks enough of it to supply 
  208. PDQHelp(tm) files for all their libraries
  209.  
  210.      I swear to you if you ever use this program, you'll never
  211. want to be without it.
  212.  
  213.      Enough of my swearings.
  214.  
  215.  
  216. <<<Miscellaneous>>>
  217.  
  218. Since I use both Borland C++ and Microsoft C, I use a directory
  219. called \OTHERINC to hold the header files for third party 
  220. libraries so I don't have to have duplicate copies.
  221.  
  222. You will likely have to change the paths in the make files for 
  223. LZWIN.C and LZWOUT.C to get them to compile and link properly.
  224.  
  225.  
  226.  
  227. Doug Hurst
  228.  
  229. =================================================================
  230.  
  231.                            <<<Reference>>>
  232.  
  233. -----------------------------------------------------------------
  234.                               LZW_INIT()
  235.  
  236.  
  237. lzw_init()
  238.  
  239. Initializes the LZW library
  240.  
  241. #include <lzw.h>
  242.  
  243. void lzw_init();
  244.  
  245. Returns       None
  246.  
  247. Description
  248.  
  249. This routine initializes certain global variables
  250.  
  251. Cautions
  252.  
  253. This function MUST called before calling any other LZW library 
  254. functions.
  255.  
  256. Related Functions
  257.  
  258. -----------------------------------------------------------------
  259.                              LZW_DEINIT()
  260.  
  261.  
  262. lzw_deinit()
  263.  
  264. Deinitializes the LZW library
  265.  
  266. #include <lzw.h>
  267.  
  268. void lzw_deinit();
  269.  
  270. Returns        None
  271.  
  272. Description
  273.  
  274. This function clears the linked list.
  275.  
  276. Cautions
  277.  
  278. This functions must only be called after a call to lzw_init()
  279.  
  280. Related Functions
  281.  
  282. lzw_init()
  283.  
  284. -----------------------------------------------------------------
  285.                                 LZW()
  286.  
  287.  
  288. lzw()
  289.  
  290. Encodes file(s) into an LZW file
  291.  
  292. #include <lzw.h>
  293.  
  294. int lzw(char *lzw_pathfile, unsigned long ops,
  295.                                      char *infile_pathmask);
  296.  
  297. Returns      0  Success
  298.             -1  Could not open or create LZW file
  299.             -2  Not an appropriate LZW file 
  300.             -3  Could not read in file directory (linked list)
  301.             -4  Nothing to do.  _dos_findfirst on mask 
  302.                 unsuccessful
  303.             -5  Could not open input file
  304.             -6  Encoding error
  305.             -7  Could not save file directory (linked list)
  306.  
  307. Description
  308.  
  309. This function acts on the lzw_pathfile to perform the specified 
  310. ops:
  311.  
  312.  PATHNAMES - May be used to insert the entire pathname of the file 
  313.              into the LZW header.
  314.  
  315. The infile_pathmask parameter is the mask of files that are to be 
  316. encoded and may include a valid DOS path.
  317.  
  318. A pass is made through the entire .LZW file, skipping from header
  319. to header, for each file to be encoded.  If that file already 
  320. exists, the header structure member 'marked' is filled with the 
  321. '*' character, then the new file is appended to the end of the 
  322. file.  This can cause the .LZW file to grow fairly rapidly in 
  323. size because the old files are not automatically purged.  
  324. The lzwpurge() function may be used to physically purge all 
  325. marked files.
  326.  
  327. Related Functions
  328.  
  329. unlzw(), lzwpurge()
  330.  
  331. -----------------------------------------------------------------
  332.                                UNLZW()
  333.  
  334.  
  335. unlzw()
  336.  
  337.  
  338. Decodes file(s) from an LZW file
  339.  
  340.  
  341. #include <lzw.h>
  342.  
  343.  
  344. int unlzw(char *lzw_pathfile, unsigned long ops, char *mask);
  345.  
  346. Returns         0  Success
  347.                -1  Could not open LZW file
  348.                -2  LZW file is empty or corrupted
  349.                -3  Not an LZW file
  350.                -4  Could not load file directory (linked list)
  351.                -5  Could not create output file
  352.                -6  Decoding error    
  353.                -7  Could not save file directory (linked list);
  354.  
  355. Description
  356.  
  357. This function acts on the lzw_pathfile to perform the specified 
  358. ops:
  359.  
  360.  EXTRACT     - Extracts the files designated by the parameter 
  361.                mask.
  362.  VIEW        - Not currently implemented, but will allow the 
  363.                passing of a function pointer to give the 
  364.                programmer access to file information designated 
  365.                by the parameter mask.  Cannot be used in 
  366.                conjunction with any other operation. 
  367.  CREATEDIRS  - Can be used in conjunction with the EXTRACT 
  368.                operation to 
  369.                create the directory specified in the path 
  370.                structure
  371.                member, if such a path exists.
  372.  NOOVERWRITE - Can be used in conjunction with EXTRACT and/or 
  373.                CREATEDIRS so existing files will not be 
  374.                overwritten.  Otherwise, they will be.
  375.  
  376. Only files matching the mask parameter will be extracted.
  377.  
  378. Caution
  379.  
  380. Ops may be or'd together for this call, except that the VIEW 
  381. option MAY NOT be used in conjunction with any other call.
  382.  
  383.  
  384. Related Functions
  385.  
  386. lzw()
  387.  
  388. -----------------------------------------------------------------
  389.                               LZWPURGE()
  390.  
  391.  
  392. lzwpurge()
  393.  
  394. Purges marked and specified files from an LZW file
  395.  
  396. #include <lzw.h>
  397.  
  398. int lzwpurge(char *lzw_pathfile,char *mask);
  399.  
  400. Returns      0  Success
  401.             -1  Could not LZW file
  402.             -2  Not an appropriate LZW file 
  403.             -3  Could not open temporary file
  404.  
  405. Description
  406.  
  407. This call will purge all 'marked' files from lzw_pathfile.  
  408. Specifiying a mask will also cause files matching the mask to 
  409. be purged even if they have not been previously marked.  Pass 
  410. NULL in the mask parameter position if no additional files are 
  411. to be purged.
  412.  
  413. Related functions
  414.  
  415. lzw()
  416.