Merge branch 'master' of https://secure.softndesign.org/git/compress
[compress.git] / compress.c
index f92393a47102e56e227cdfd9b2d6a86a4c9c3f5c..d8842b472c3c56df515105f6070e398e9aac1690 100644 (file)
@@ -33,6 +33,8 @@ int usage (int ret)
 {
     int fd = ret ? stdfderr : stdfdout;
     fdprintf (fd, "usage: %s\n", progname);
+    fdprintf (fd, " -c : mode compress\n");
+    fdprintf (fd, " -d : mode decompress\n");
     fdprintf (fd, " -h : help message\n");
     fdprintf (fd, " -i <file>: input file\n");
     fdprintf (fd, " -o <file>: output file\n");
@@ -271,7 +273,7 @@ byte_t *encode_header_table (code_t *codes, int *occ)
     VERBOSE (DEBUG, PRINTOUT ("rem: %d\n", size % 256));
 
     /* header */
-    codcpy ((char *)header, sizeof (buffer), (mode == 1) ? "MZ1   " : "MZ2   ");
+    codcpy ((char *)header, sizeof (buffer), (mode == 1) ? "M1Z   " : "M2Z   ");
     header += 6;
 
     /* size */
@@ -481,8 +483,8 @@ code_t *read_header (char *filename) {
     /* read magic number */
     nb = read (fid, buffer, 6);
     VERBOSE (DEBUG, PRINTOUT ("nb, buffer: %d 0x%02x 0x%02x\n", nb, buffer[0], buffer[1]));
-    if ((nb == 6) && (buffer[0] == 'M') && (buffer[1] == 'Z')) {
-        mode = (buffer[2] == '1') ? 1 : (buffer[2] == '2') ? 2 : 0;
+    if ((nb == 6) && (buffer[0] == 'M') && (buffer[2] == 'Z')) {
+        mode = (buffer[1] == '1') ? 1 : (buffer[1] == '2') ? 2 : 0;
         size = (buffer[3] << 8) + buffer[4];
         VERBOSE (DEBUG, PRINTOUT ("mode, size: %d %d\n", mode, size));
         if (size > NB_BYTES * (NB_BYTES - 1) / 2 / 8 + NB_BYTES) {
@@ -764,10 +766,10 @@ int main (int argc, char *argv[])
 // test: compress.exe -c -i compress.c 2>&1 | grep -q 'missing file'
 // test: compress.exe -c -v 4 -i compress.c -o compress.mz | grep -q "Occurence table"
 // test: compress.exe -c -i compress.c -o compress.mz
-// test: ls -sS1 compress.c compress.mz | tail -1 | grep compress.mz
+// test: ls -sS1 compress.c compress.mz | tail -1 | grep -q compress.mz
 // test: compress.exe -d -i compress.mz -o tmp.c
 // test: cmp compress.c tmp.c; x=$?; rm compress.mz tmp.c; test x$x = x0
-// test: compress.exe -c -i test/compress.c -o compress.mz 2>&1 | grep "can't open file"
-// test: compress.exe -c -i compress.c -o test/compress.mz 2>&1 | grep "can't open file"
+// test: compress.exe -c -i test/compress.c -o compress.mz 2>&1 | grep -q "can't open file"
+// test: compress.exe -c -i compress.c -o test/compress.mz 2>&1 | grep -q "can't open file"
 
 /* vim: set ts=4 sw=4 et: */