… | |
… | |
69 | } |
69 | } |
70 | |
70 | |
71 | /* |
71 | /* |
72 | * Anatomy: an lzf file consists of any number of blocks in the following format: |
72 | * Anatomy: an lzf file consists of any number of blocks in the following format: |
73 | * |
73 | * |
|
|
74 | * \x00 EOF (optional) |
74 | * "ZV\0" 2-byte-usize <uncompressed data> |
75 | * "ZV\0" 2-byte-usize <uncompressed data> |
75 | * "ZV\1" 2-byte-csize 2-byte-usize <compressed data> |
76 | * "ZV\1" 2-byte-csize 2-byte-usize <compressed data> |
76 | * "ZV\2" 4-byte-crc32-0xdebb20e3 (NYI) |
77 | * "ZV\2" 4-byte-crc32-0xdebb20e3 (NYI) |
77 | * |
78 | * |
78 | */ |
79 | */ |
… | |
… | |
122 | header[4] = us & 0xff; |
123 | header[4] = us & 0xff; |
123 | |
124 | |
124 | fwrite (header, 3+2, 1, stdout); |
125 | fwrite (header, 3+2, 1, stdout); |
125 | fwrite (buff1, us, 1, stdout); |
126 | fwrite (buff1, us, 1, stdout); |
126 | } |
127 | } |
127 | } while (!feof (stdin)); |
128 | } |
128 | } |
129 | } |
129 | |
130 | |
130 | static void decompress (void) |
131 | static void decompress (void) |
131 | { |
132 | { |
132 | ssize_t us; |
133 | ssize_t us; |
… | |
… | |
134 | u8 buff1[64*1024]; |
135 | u8 buff1[64*1024]; |
135 | u8 buff2[64*1024]; |
136 | u8 buff2[64*1024]; |
136 | u8 header[3+2+2]; |
137 | u8 header[3+2+2]; |
137 | |
138 | |
138 | for(;;) { |
139 | for(;;) { |
139 | if (fread (header, 3+2, 1, stdin) != 1) |
140 | int hdrsize = fread (header, 1, 3+2, stdin); |
|
|
141 | |
|
|
142 | /* check for \0 record */ |
|
|
143 | if (hdrsize) |
|
|
144 | { |
|
|
145 | if (!header[0]) |
|
|
146 | break; |
|
|
147 | else if (hdrsize != 3+2) |
|
|
148 | { |
|
|
149 | if (feof (stdin)) |
|
|
150 | fprintf (stderr, "decompress: invalid stream - short header\n"); |
|
|
151 | else |
|
|
152 | perror ("decompress"); |
|
|
153 | |
|
|
154 | exit (1); |
|
|
155 | } |
|
|
156 | } |
|
|
157 | else |
140 | { |
158 | { |
141 | if (feof (stdin)) |
159 | if (feof (stdin)) |
142 | break; |
160 | break; |
143 | else |
161 | else |
144 | { |
162 | { |
… | |
… | |
201 | main (int argc, char *argv[]) |
219 | main (int argc, char *argv[]) |
202 | { |
220 | { |
203 | int c; |
221 | int c; |
204 | unsigned int blocksize = 64*1024-1; |
222 | unsigned int blocksize = 64*1024-1; |
205 | enum { m_compress, m_decompress } mode = m_compress; |
223 | enum { m_compress, m_decompress } mode = m_compress; |
206 | |
|
|
207 | if (!strcmp (argv[0] + strlen (argv[0] - 5), "unlzf")) |
|
|
208 | mode = m_decompress; |
|
|
209 | |
224 | |
210 | while ((c = getopt (argc, argv, "cdb:h")) != -1) |
225 | while ((c = getopt (argc, argv, "cdb:h")) != -1) |
211 | switch (c) |
226 | switch (c) |
212 | { |
227 | { |
213 | case 'c': |
228 | case 'c': |