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