/[projet1]/public/pc/tools/osdk/main/Ym2Mym/sources/lzhlib.txt
Defence Force logotype

Contents of /public/pc/tools/osdk/main/Ym2Mym/sources/lzhlib.txt

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1075 - (show annotations)
Sun Jan 12 20:13:41 2014 UTC (5 years, 11 months ago) by dbug
File MIME type: text/plain
File size: 4641 byte(s)
PictConv 0.016
- New option to skip the conversion if the target file is more recent than the source file (-u)
- New option to enable/disable information about what happens (-v)

Ym2Mym 1.1
- The tool is now able to extract LHA compressed YM files directly, should make the process much easier :)
1 LZHLIB.TXT
2
3 Copyright(c) 1996 Kerwin F. Medina
4 Kerwin F. Medina
5 kerwin@infoserve.net
6 kerwin@digi.co.jp
7
8 I took the source of Haruhiko Okumura's "ar" and extracted only the
9 necessary codes to create a compression library so an application can
10 make use of compression through a function call and without having to
11 spawn an external compression program.
12
13 The library has only two API functions: "lzh_freeze" (to compress) and
14 "lzh_melt" (to decompress). In both cases, the caller only has to
15 provide the I/O functions and memory allocation functions. The
16 following is an example of a minimal compressor and decompressor.
17
18 Sample Compressor:
19
20 #ifdef __TURBOC__
21 #include <io.h>
22 #include <fcntl.h>
23 #else
24 #include <stdio.h>
25 #endif
26 #include <stdlib.h>
27
28 /* My I/O functions */
29 int read0 (void far *p, int n) {return read (0, p, n);}
30 int write1 (void far *p, int n) {return write (1, p, n);}
31
32 /* My Memory functions */
33 void *mymalloc (unsigned n) {return malloc (n);}
34 void myfree (void far *p) {free (p);}
35
36 void main (void)
37 {
38 long n;
39 #ifdef __TURBOC__
40 setmode (0, O_BINARY); setmode (1, O_BINARY);
41 #endif
42 /* Get the length of the input file */
43 n = lseek (0, 0, 2);
44 lseek (0, 0, 0);
45
46 /* Write this length to the output file */
47 write (1, &n, sizeof (n));
48
49 /* Now, Call the compression function */
50 lzh_freeze (read0, write1, mymalloc, myfree);
51 }
52
53 Sample Decompressor:
54
55 #ifdef __TURBOC__
56 #include <io.h>
57 #include <fcntl.h>
58 #else
59 #include <stdio.h>
60 #endif
61 #include <stdlib.h>
62
63 /* My I/O functions */
64 int read0 (void far *p, int n) {return read (0, p, n);}
65 int write1 (void far *p, int n) {return write (1, p, n);}
66
67 /* My Memory functions */
68 void *mymalloc (unsigned n) {return malloc (n);}
69 void myfree (void far *p) {free (p);}
70
71 void main (void)
72 {
73 long n;
74 #ifdef __TURBOC__
75 setmode (0, O_BINARY); setmode (1, O_BINARY);
76 #endif
77 /* Get the original file length */
78 read (0, &n, sizeof (n));
79
80 /* Now, Call the decompression function */
81 lzh_melt (read0, write1, malloc, free, n);
82 }
83
84 The description of the library API is given in more detail below:
85
86 Prototypes:
87
88 int lzh_freeze (type_fnc_read pfnc_read,
89 type_fnc_write pfnc_write,
90 type_fnc_malloc pfnc_malloc,
91 type_fnc_free pfnc_free);
92
93 int lzh_melt (type_fnc_read pfnc_read,
94 type_fnc_write pfnc_write,
95 type_fnc_malloc pfnc_malloc,
96 type_fnc_free pfnc_free,
97 unsigned long origsize);
98
99 Remarks: "lzh_freeze" will perform an LZH compression on input
100 data that the caller provides through the
101 "fnc_read" callback function, and will output the
102 compressed result through a call to "fnc_write".
103
104 "lzh_melt" will perform decompression of input
105 data that the caller provides through the
106 "fnc_read" callback function, and will output the
107 decompressed result through a call to "fnc_write".
108
109 Argumets What it does
110 -------- ------------
111
112 fnc_read a callback function that library will call when
113 needing input data. "fnc_read" must return the
114 number of input bytes or -1 if there is an error.
115
116 fnc_write a callback function that library will call when
117 needing to output data. "fnc_write" must return
118 the number of outputed bytes (or -1 if there is an
119 error).
120
121 fnc_malloc a callback function that library will call when
122 needing to allocate memory. "fnc_malloc" must
123 return the address of the allocated memory or NULL
124 if there is an error.
125
126 fnc_free a callback function that library will call when
127 needing to free a memory that was allocated using
128 "fnc_malloc".
129
130 origsize the original number of bytes of the uncompressed
131 data.
132

  ViewVC Help
Powered by ViewVC 1.1.26