ea65038032707bf22d3ea6396221d19cba6ab0ef
[compress.git] / compress.c
1 /* depend: */
2 /* cflags: */
3 /* linker: atoi.o code.o debug.o fprintf.o */
4
5 #include <fcntl.h>
6 #include <unistd.h>
7 #include <stddef.h>
8 #include "atoi.h"
9 #include "code.h"
10 #include "debug.h"
11 #include "fprintf.h"
12
13 /* constants */
14
15 #define BUFFER_SIZE 4096
16
17 #define COMPRESS 1
18 #define DECOMPRESS 2
19
20 /* macros */
21
22 /* gobal variables */
23
24 char *progname = NULL;
25
26 /* help function */
27
28 int usage (int ret)
29 {
30 //int fd = ret ? STDERR_FILENO : STDOUT_FILENO;
31 int fd = ret ? _fderr : _fdout;
32 fdprintf (fd, "usage: %s\n", progname);
33 fdprintf (fd, " -h : help message\n");
34 fdprintf (fd, " -i <file>: input file\n");
35 fdprintf (fd, " -o <file>: output file\n");
36 fdprintf (fd, " -v : verbose level (%d)\n", verbose);
37
38 return ret;
39 }
40
41 void blkcpy (void *dst, const void *src, int len)
42 {
43 while (len--) {
44 *((char *)dst++) = *((char *)src++);
45 }
46 }
47
48 /* create occurence table */
49 int *create_table (char *filename)
50 {
51 byte_t buffer[BUFFER_SIZE] = {0};
52 int nbread;
53 static int table[NB_BYTES] = {0};
54 int fid = 0;
55
56 VERBOSE (DEBUG, PRINTOUT ("start creating occurence table\n"));
57
58 /* open file */
59 fid = open (filename, O_RDONLY|O_RAW);
60 if (fid == -1) {
61 VERBOSE (ERROR, PRINTERR ("can't open file '%s'\n", filename/);
62 return NULL;
63 }
64 VERBOSE (INFO, PRINTOUT ("file '%s' opened\n", filename));
65
66 /* read file */
67 while ((nbread = read (fid, buffer, BUFFER_SIZE)) > 0) {
68 VERBOSE (DEBUG, PRINTOUT ("nbread: %d\n", nbread));
69 while (nbread--) {
70 table[(int)buffer[nbread]]++;
71 }
72 }
73
74 /* close file */
75 close (fid);
76
77 VERBOSE (DEBUG, PRINTOUT ("end creating occurence table\n"));
78
79 return table;
80 }
81
82 /* print occurence table */
83
84 void print_occ_table (int *table)
85 {
86 int i;
87
88 PRINTOUT ("Occurence table\n");
89 for (i = 0; i < NB_BYTES; i++) {
90 if (table[i]) {
91 PRINTOUT ("0x%02x '%c': %d\n", i, ((i < 32) || (i > 127)) ? '.' : i, table[i]);
92 }
93 }
94 }
95
96 /* initialize forest */
97
98 leaf_t **init_forest (int *table)
99 {
100 static leaf_t *leafs[NB_BYTES] = {0};
101 int nb_leafs = 0;
102 int i, l;
103
104 VERBOSE (DEBUG, PRINTOUT ("start initiliazing forest\n"));
105
106 /* count number of leafs */
107 for (i = 0; i < NB_BYTES; i++) {
108 if (table[i] > 0) {
109 nb_leafs++;
110 }
111 }
112
113 /* initialize leafs */
114 for (i = 0, l = 0; i < NB_BYTES; i++) {
115 if (table[i] > 0) {
116 leafs[l] = getleaf (1);
117 if (leafs[l] == NULL) {
118 VERBOSE (ERROR, PRINTERR ("can't allocate memory\n"));
119 return NULL;
120 }
121 leafs[l]->occ = table[i];
122 leafs[l]->c = i;
123 l++;
124 }
125 }
126
127 VERBOSE (DEBUG, PRINTOUT ("end initiliazing forest\n"));
128
129 return leafs;
130 }
131
132 /* create tree */
133
134 leaf_t *create_tree (leaf_t **leafs)
135 {
136 leaf_t *branch = NULL;
137 int nb_leafs = 0;
138 int last = -1;
139 int ante;
140 int i, j;
141
142 VERBOSE (DEBUG, PRINTOUT ("start creating tree\n"));
143
144 /* count number of leafs */
145 while (leafs[nb_leafs] != NULL) {
146 nb_leafs++;
147 }
148
149 /* create tree */
150 for (j = 0; j < nb_leafs - 1; j++) {
151
152 /* look for leatest occurence */
153 last = -1;
154 for (i = 0; i < nb_leafs; i++) {
155 if (leafs[i] == NULL) {
156 continue;
157 }
158 if ((last == -1) || (leafs[i]->occ < leafs[last]->occ)) {
159 last = i;
160 }
161 }
162
163 /* look for ante leatest occurence */
164 ante = -1;
165 for (i = 0; i < nb_leafs; i++) {
166 if ((i == last) || (leafs[i] == NULL)) {
167 continue;
168 }
169 if ((ante == -1) || (leafs[i]->occ < leafs[ante]->occ)) {
170 ante = i;
171 }
172 }
173
174 /* create branch */
175 if ((last == -1) || (ante == -1)) {
176 VERBOSE (ERROR, PRINTERR ("error during tree building\n"));
177 return NULL;
178 }
179 branch = getleaf (1);
180 if (branch == NULL) {
181 VERBOSE (ERROR, PRINTERR ("can't allocate memory\n"));
182 return NULL;
183 }
184 branch->left = leafs[last];
185 branch->right = leafs[ante];
186 branch->occ = branch->left->occ + branch->right->occ;
187 leafs[last] = branch;
188 leafs[ante] = NULL;
189 }
190
191 VERBOSE (DEBUG, PRINTOUT ("end creating tree\n"));
192
193 return (last != -1) ? leafs[last] : NULL;
194 }
195
196 /* explore tree */
197
198 void explore_tree (code_t *table, leaf_t *root, char *code, int index)
199 {
200
201 VERBOSE (DEBUG, PRINTOUT ("start exploring code tree\n"));
202
203 if ((root->left == NULL) && (root->right == NULL)) {
204 codcpy ((char *)(table + (int)(root->c)), sizeof (code_t), code);
205 }
206 else {
207 codcpy (code + index, sizeof (code_t), "1");
208 explore_tree (table, root->left, code, index + 1);
209 codcpy (code + index, sizeof (code_t), "0");
210 explore_tree (table, root->right, code, index + 1);
211 }
212
213 VERBOSE (DEBUG, PRINTOUT ("end exploring code tree\n"));
214 }
215
216 /* create code table */
217 code_t *create_code (leaf_t *root)
218 {
219 static code_t table[NB_BYTES] = {0};
220 code_t code = {0};
221
222 VERBOSE (DEBUG, PRINTOUT ("start creating code table\n"));
223
224 explore_tree (table, root, (char *)&code, 0);
225
226 VERBOSE (DEBUG, PRINTOUT ("end creating code table\n"));
227
228 return table;
229 }
230
231 /* print code table */
232
233 void print_code_table (code_t *codes)
234 {
235 char *code;
236 int i;
237
238 PRINTOUT ("Code table\n");
239 for (i = 0; i < NB_BYTES; i++) {
240 code = (char *)(codes + i);
241 if (codlen (code) == 0) {
242 continue;
243 }
244 PRINTOUT ("0x%02x '%c': %s\n", i, ((i < 32) || (i > 127)) ? '.' : i, code);
245 }
246 }
247
248 /* encode header and code table */
249
250 byte_t *encode_header_table (code_t *codes, int *occ)
251 {
252 static byte_t buffer[NB_BYTES * (NB_BYTES - 1) / 2 / 8 + NB_BYTES + 6] = {0};
253 char bits[(NB_BYTES - 1) + 8 + 1] = {0};
254 char *code;
255 byte_t *header = buffer;
256 int i, j, length, mode;
257 int nb = 0;
258 int size = 0;
259
260 VERBOSE (DEBUG, PRINTOUT ("start encoding header and code table\n"));
261
262 /* mode 1 or 2 */
263 for (i = 0; i < NB_BYTES; i++) {
264 code = (char *)(codes + i);
265 if (codlen (code) > 0) {
266 nb++;
267 size += codlen (code) * occ[i];
268 }
269 }
270 mode = (NB_BYTES < 2 * nb + 1) ? 1 : 2;
271 VERBOSE (DEBUG, PRINTOUT ("nb chars: %d\n", nb));
272 VERBOSE (DEBUG, PRINTOUT ("mode: %d\n", mode));
273 VERBOSE (DEBUG, PRINTOUT ("size: %d\n", size));
274 VERBOSE (DEBUG, PRINTOUT ("rem: %d\n", size % 256));
275
276 /* header */
277 codcpy ((char *)header, sizeof (buffer), (mode == 1) ? "MZ1 " : "MZ2 ");
278 header += 6;
279
280 /* size */
281 switch (mode) {
282 case 1:
283 for (i = 0; i < NB_BYTES; i++) {
284 code = (char *)(codes + i);
285 *(header++) = (byte_t) codlen (code);
286 }
287 break;
288 case 2:
289 *(header++) = (byte_t)(nb - 1);
290 for (i = 0; i < NB_BYTES; i++) {
291 code = (char *)(codes + i);
292 if (codlen (code) > 0) {
293 *(header++) = (byte_t) i;
294 *(header++) = (byte_t) codlen (code);
295 }
296 }
297 break;
298 }
299
300 /* bits */
301 for (i = 0; i < NB_BYTES; i++) {
302 code = (char *)(codes + i);
303 if (codlen (code) > 0) {
304 codcat (bits, sizeof (code_t), code);
305 while (codlen (bits) > (8 - 1)) {
306 for (j = 0; j < 8; j++) {
307 *header <<= 1;
308 if (bits[j] == '1') {
309 (*header)++;
310 }
311 }
312 codcpy (bits, sizeof (code_t), bits + 8);
313 header++;
314 }
315 }
316 }
317 if (codlen (bits) > 0) {
318 for (j = 0; j < (int)codlen (bits); j++) {
319 *header <<= 1;
320 if (bits[j] == '1') {
321 (*header)++;
322 }
323 }
324 for (j = (int)codlen (bits); j < 8; j++) {
325 *header <<= 1;
326 }
327 header++;
328 }
329
330 /* length */
331 length = (int)(header - buffer - 6);
332 VERBOSE (DEBUG, PRINTOUT ("lengh: %d %02x %02x\n", length, length >> 8, length & 0xff));
333 buffer[3] = (byte_t)(length >> 8);
334 buffer[4] = (byte_t)(length & 0xff);
335 buffer[5] = (byte_t)(size % 256);
336 header = buffer;
337
338 VERBOSE (DEBUG, PRINTOUT ("end encoding header and code table\n"));
339
340 return header;
341 }
342
343 /* print header */
344
345 void print_header (byte_t *header)
346 {
347 int length, i;
348
349 length = (header[3] << 8) + header[4];
350 VERBOSE (DEBUG, PRINTOUT ("lengh: %d\n", length));
351 for (i = 0; i < length + 6; i++) {
352 PRINTOUT ("%02x", header[i]);
353 }
354 PRINTOUT ("\n");
355 }
356
357 /* write crompressed file */
358
359 int write_compress (char *output, char *input, code_t *codes, byte_t *header)
360 {
361 byte_t bufin[BUFFER_SIZE] = {0};
362 byte_t bufout[BUFFER_SIZE] = {0};
363 char bits[(NB_BYTES - 1) + 8 + 1] = {0};
364 int fin, fout;
365 int length = 0;
366 int i, j, nbread;
367 byte_t *pt;
368
369 VERBOSE (DEBUG, PRINTOUT ("start writting compressed file\n"));
370
371 /* open input file */
372 fin = open (input, O_RDONLY|O_RAW);
373 if (fin == -1) {
374 VERBOSE (ERROR, PRINTERR ("can't open file '%s' for reading\n", input));
375 return 1;
376 }
377 VERBOSE (INFO, PRINTOUT ("file '%s' opened\n", input));
378
379 /* open output file */
380 fout = open (output, O_WRONLY|O_CREAT|O_RAW, 0700);
381 if (fout == -1) {
382 VERBOSE (ERROR, PRINTERR ("can't open file '%s' for writing\n", output));
383 close (fin);
384 return 1;
385 }
386 VERBOSE (INFO, PRINTOUT ("file '%s' opened\n", output));
387
388 /* write header */
389 length = (header[3] << 8) + header[4];
390 VERBOSE (DEBUG, PRINTOUT ("lengh: %d\n", length));
391 write (fout, header, length + 6);
392
393 /* write file */
394 pt = bufout;
395 while ((nbread = read (fin, bufin, BUFFER_SIZE)) > 0) {
396 VERBOSE (DEBUG, PRINTOUT ("nbread: %d\n", nbread));
397 for (i = 0; i < nbread; i++) {
398 codcat (bits, sizeof (code_t), (char *)(codes + bufin[i]));
399 while (codlen (bits) > (8 - 1)) {
400 for (j = 0; j < 8; j++) {
401 *pt <<= 1;
402 if (bits[j] == '1') {
403 (*pt)++;
404 }
405 }
406 codcpy (bits, sizeof (code_t), bits + 8);
407 if (pt - bufout == BUFFER_SIZE - 1) {
408 write (fout, bufout, BUFFER_SIZE);
409 pt = bufout;
410 } else {
411 pt++;
412 }
413 }
414 }
415 }
416 VERBOSE (DEBUG, PRINTOUT ("lastest bits : %d\n", codlen (bits)));
417 if (codlen (bits) > 0) {
418 for (j = 0; j < (int)codlen (bits); j++) {
419 *pt <<= 1;
420 if (bits[j] == '1') {
421 (*pt)++;
422 }
423 }
424 for (j = (int)codlen (bits); j < 8; j++) {
425 *pt <<= 1;
426 }
427 pt++;
428 }
429 if (pt != bufout) {
430 VERBOSE (DEBUG, PRINTOUT ("last partial buffer written: %u\n", pt - bufout));
431 write (fout, bufout, pt - bufout);
432 }
433
434 /* closing */
435 close (fin);
436 close (fout);
437
438 VERBOSE (DEBUG, PRINTOUT ("end writting compressed file\n"));
439
440 return 0;
441 }
442
443 /* read header */
444
445 code_t *read_header (char *filename) {
446 static code_t table[NB_BYTES] = {0};
447 byte_t buffer[NB_BYTES * (NB_BYTES - 1) / 2 / 8 + NB_BYTES + 6] = {0};
448 byte_t *codes = NULL;
449 byte_t cur;
450 int lengths[NB_BYTES] = {0};
451 int fid;
452 int mode = 0;
453 int i, j, l, nb, size;
454
455 VERBOSE (DEBUG, PRINTOUT ("start reading header\n"));
456
457 /* open file */
458 fid = open (filename, O_RDONLY|O_RAW);
459 if (fid == -1) {
460 VERBOSE (ERROR, PRINTERR ("can't open file '%s'\n", filename));
461 return NULL;
462 }
463 VERBOSE (INFO, PRINTOUT ("file '%s' opened\n", filename));
464
465 /* read magic number */
466 nb = read (fid, buffer, 6);
467 VERBOSE (DEBUG, PRINTOUT ("nb, buffer: %d 0x%02x 0x%02x\n", nb, buffer[0], buffer[1]));
468 if ((nb == 6) && (buffer[0] == 'M') && (buffer[1] == 'Z')) {
469 mode = (buffer[2] == '1') ? 1 : (buffer[2] == '2') ? 2 : 0;
470 size = (buffer[3] << 8) + buffer[4];
471 VERBOSE (DEBUG, PRINTOUT ("mode, size: %d %d\n", mode, size));
472 if (size > NB_BYTES * (NB_BYTES - 1) / 2 / 8 + NB_BYTES) {
473 mode = 0;
474 } else {
475 nb = read (fid, buffer, size);
476 VERBOSE (DEBUG, PRINTOUT ("nb read: %d/%d\n", nb, size));
477 if (nb != size) {
478 mode = 0;
479 }
480 }
481 }
482 close (fid);
483 if (mode == 0) {
484 VERBOSE (ERROR, PRINTERR ("incorrect file\n"));
485 return NULL;
486 }
487
488 /* analyse header */
489 codes = buffer;
490 switch (mode) {
491 case 1:
492 for (i = 0; i < NB_BYTES; i++) {
493 lengths[i] = *(codes++);
494 }
495 break;
496 case 2:
497 nb = *(codes++) + 1;
498 VERBOSE (DEBUG, PRINTOUT ("nb codes: %d\n", nb));
499 for (i = 0; i < nb; i++) {
500 j = *(codes++);
501 lengths[j] = *(codes++);
502 }
503 break;
504 }
505 VERBOSE (DEBUG, for (i = 0; i < NB_BYTES; i++) if (lengths[i]) PRINTOUT ("%d: %d\n", i, lengths[i]));
506
507 /* check lengths */
508 for (i = 0, l = 0; i < NB_BYTES; i++) {
509 l += lengths[i];
510 }
511 if (((mode == 1) && (size - 256 != (l + 7) / 8)) ||
512 ((mode == 2) && (size - 2 * nb - 1 != (l + 7) / 8))) {
513 VERBOSE (ERROR, PRINTERR ("incorrect code table length: %d %d %d\n", size, nb, l));
514 return NULL;
515 }
516
517 /* decode code */
518 cur = *(codes++);
519 l = 8;
520 for (i = 0; i < NB_BYTES; i++) {
521 if (lengths[i] == 0) {
522 continue;
523 }
524 while (lengths[i]--) {
525 codcat ((char *)(table + i), sizeof (code_t), ((cur & 0x80) == 0) ? "0" : "1");
526 l--;
527 cur <<= 1;
528 if (l == 0) {
529 cur = *(codes++);
530 l = 8;
531 }
532 }
533 }
534
535 VERBOSE (DEBUG, PRINTOUT ("end reading header\n"));
536
537 return table;
538 }
539
540 /* write decompressed file */
541
542 int write_decompress (char *output, char *input, code_t *codes)
543 {
544 byte_t bufin[BUFFER_SIZE] = {0};
545 byte_t bufout[BUFFER_SIZE] = {0};
546 byte_t bufhea[MAX(NB_BYTES * (NB_BYTES - 1) / 2 / 8 + NB_BYTES + 6, BUFFER_SIZE)] = {0};
547 char bits[(NB_BYTES - 1) + 1] = {0};
548 int fin, fout;
549 int i, j, k, nb, size, rem;
550 int is_found;
551 int l = 0;
552 byte_t *pt;
553
554 VERBOSE (DEBUG, PRINTOUT ("start writing decompressed file\n"));
555
556 /* open file for reading */
557 fin = open (input, O_RDONLY|O_RAW);
558 if (fin == -1) {
559 VERBOSE (ERROR, PRINTERR ("can't open file '%s' for reading\n", input));
560 return 1;
561 }
562 VERBOSE (INFO, PRINTOUT ("file '%s' opened\n", input));
563
564 /* read magic number */
565 nb = read (fin, bufhea, 6);
566 if (nb != 6) {
567 VERBOSE (ERROR, PRINTERR ("can't read file\n"));
568 close (fin);
569 return 1;
570 }
571 size = (bufhea[3] << 8) + bufhea[4];
572 VERBOSE (DEBUG, PRINTOUT ("table size: %d\n", size));
573 rem = bufhea[5];
574 VERBOSE (DEBUG, PRINTOUT ("remainder: %d\n", rem));
575 nb = read (fin, bufhea, size);
576 if (nb != size) {
577 VERBOSE (ERROR, PRINTERR ("can't read file\n"));
578 close (fin);
579 return 1;
580 }
581
582 /* open file for writing */
583 fout = open (output, O_WRONLY|O_CREAT|O_RAW, 0700);
584 if (fout == -1) {
585 VERBOSE (ERROR, PRINTERR ("can't open file '%s' for writing\n", output));
586 close (fin);
587 return 2;
588 }
589 VERBOSE (INFO, PRINTOUT ("file '%s' opened\n", output));
590
591 /* write file */
592 pt = bufout;
593 while ((nb = read (fin, bufin, BUFFER_SIZE)) > 0) {
594 VERBOSE (DEBUG, PRINTOUT ("nbread: %d\n", nb));
595 for (i = 0; i < nb; i++) {
596 for (j = 0; j < 8; j++) {
597 codcat (bits, sizeof (bits), ((bufin[i] & 0x80) == 0) ? "0" : "1");
598 bufin[i] <<= 1;
599 l++;
600 VERBOSE (DEBUG, PRINTOUT ("bits: %d - %s\n", codlen (bits), bits));
601
602 /* look for correct code */
603 is_found = 0;
604 for (k = 0; (k < NB_BYTES) && (!is_found); k++) {
605 if (codcmp ((char *)(codes + k), bits) == 0) {
606 is_found = 1;
607 VERBOSE (DEBUG, PRINTOUT ("found: %d\n", k));
608 *pt= k;
609 bits[0] = 0;
610 if (pt - bufout == BUFFER_SIZE - 1) {
611 VERBOSE (DEBUG, PRINTOUT ("nb buffer out: %u\n", (pt - bufout)));
612 write (fout, bufout, BUFFER_SIZE);
613 pt = bufout;
614 } else {
615 pt++;
616 }
617 }
618 }
619 if ((i == nb - 1) && (l % 256 == rem) && (nb != BUFFER_SIZE)) {
620 VERBOSE (DEBUG, PRINTOUT ("break\n"));
621 break;
622 }
623 }
624 }
625 }
626 if (pt != bufout) {
627 VERBOSE (DEBUG, PRINTOUT ("nb buffer out: %u\n", (pt - bufout)));
628 write (fout, bufout, pt - bufout);
629 }
630
631 /* close files */
632 close (fin);
633 close (fout);
634
635 VERBOSE (DEBUG, PRINTOUT ("end writing decompressed file\n"));
636
637 return 0;
638 }
639
640 /* main function */
641
642 int main (int argc, char *argv[])
643 {
644 char *input = NULL;
645 char *output = NULL;
646 int *table = NULL;
647 leaf_t **leafs = NULL;
648 leaf_t *root = NULL;
649 code_t *codes = NULL;
650 byte_t *header = NULL;
651 int mode = COMPRESS;
652 int rc = 1;
653
654 progname = argv[0];
655
656 int c;
657 char * arg;
658 VERBOSE (DEBUG, PRINTOUT ("start processing arguments\n"));
659 while (argc-- > 1) {
660 arg = *(++argv);
661 if (arg[0] != '-') {
662 PRINTERR ("%s: invalid option -- %s\n", progname, arg);
663 return usage (1);
664 }
665 c = arg[1];
666 VERBOSE (DEBUG, PRINTOUT ("option: %c\n", c));
667 switch (c) {
668 case 'c':
669 mode = COMPRESS;
670 break;
671 case 'd':
672 mode = DECOMPRESS;
673 break;
674 case 'i':
675 input = (arg[2]) ? arg + 2 : (--argc > 0 ) ? *(++argv) : NULL;
676 VERBOSE (DEBUG, PRINTOUT ("input: %s\n", input));
677 break;
678 case 'o':
679 output = (arg[2]) ? arg + 2 : (--argc > 0 ) ? *(++argv) : NULL;
680 VERBOSE (DEBUG, PRINTOUT ("output: %s\n", output));
681 break;
682 case 'v':
683 arg = (arg[2]) ? arg + 2 : (--argc > 0 ) ? *(++argv) : NULL;
684 if (arg == NULL) {
685 PRINTERR ("%s: missing verbose level\n", progname);
686 return usage (1);
687 }
688 verbose = myatoi (arg);
689 VERBOSE (INFO, PRINTOUT ("verbose: %d\n", verbose));
690 break;
691 case 'h':
692 default:
693 return usage (c != 'h');
694 }
695 }
696 if ((input == NULL) || (output == NULL)) {
697 PRINTERR ("%s: missing file\n", progname);
698 return usage (1);
699 }
700 VERBOSE (DEBUG, PRINTOUT ("end processing arguments\n"));
701
702 switch (mode) {
703 case COMPRESS:
704 table = create_table (input);
705 if (table == NULL) break;
706 VERBOSE (INFO, print_occ_table (table));
707
708 leafs = init_forest (table);
709 if (leafs == NULL) break;
710 root = create_tree (leafs);
711 if (root == NULL) break;
712 codes = create_code (root);
713 if (codes == NULL) break;
714 VERBOSE (INFO, print_code_table (codes));
715 header = encode_header_table (codes, table);
716 if (header == NULL) break;
717 VERBOSE (INFO, print_header (header));
718 rc = write_compress (output, input, codes, header);
719 break;
720 case DECOMPRESS:
721 codes = read_header (input);
722 if (codes == NULL) break;
723 VERBOSE (INFO, print_code_table (codes));
724 rc = write_decompress (output, input, codes);
725 break;
726 }
727
728 return rc;
729 }
730
731 // test: compress.exe -h
732 // test: compress.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
733 // test: compress.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
734 // test: compress.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
735 // test: compress.exe -c -i compress.c -o compress.mz
736 // test: ls -sS1 compress.c compress.mz | tail -1 | grep compress.mz
737 // test: compress.exe -d -i compress.mz -o tmp.c
738 // test: cmp compress.c tmp.c
739 // test: rm compress.mz tmp.c
740
741 /* vim: set ts=4 sw=4 et: */