change magic number
[compress.git] / compress.c
index f92393a47102e56e227cdfd9b2d6a86a4c9c3f5c..916d8f8eac4bf297baaa8df598c78bffa4a2d6f7 100644 (file)
@@ -271,7 +271,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 +481,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 +764,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: */