]> git.lizzy.rs Git - zlib.git/blobdiff - example.c
zlib 1.2.0.1
[zlib.git] / example.c
index 8820e565729e7aaebb3e2c31177bfa35c80321c0..9fd13ce3ad227ba3d546a43a897859b186be5e12 100644 (file)
--- a/example.c
+++ b/example.c
@@ -1,6 +1,6 @@
 /* example.c -- usage example of the zlib compression library
  * Copyright (C) 1995-2003 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h 
+ * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
 /* @(#) $Id$ */
@@ -37,22 +37,22 @@ const char dictionary[] = "hello";
 uLong dictId; /* Adler32 value of the dictionary */
 
 void test_compress      OF((Byte *compr, uLong comprLen,
-                           Byte *uncompr, uLong uncomprLen));
-void test_gzio          OF((const char *out, const char *in, 
-                           Byte *uncompr, int uncomprLen));
+                            Byte *uncompr, uLong uncomprLen));
+void test_gzio          OF((const char *out, const char *in,
+                            Byte *uncompr, int uncomprLen));
 void test_deflate       OF((Byte *compr, uLong comprLen));
 void test_inflate       OF((Byte *compr, uLong comprLen,
-                           Byte *uncompr, uLong uncomprLen));
+                            Byte *uncompr, uLong uncomprLen));
 void test_large_deflate OF((Byte *compr, uLong comprLen,
-                           Byte *uncompr, uLong uncomprLen));
+                            Byte *uncompr, uLong uncomprLen));
 void test_large_inflate OF((Byte *compr, uLong comprLen,
-                           Byte *uncompr, uLong uncomprLen));
+                            Byte *uncompr, uLong uncomprLen));
 void test_flush         OF((Byte *compr, uLong *comprLen));
 void test_sync          OF((Byte *compr, uLong comprLen,
-                           Byte *uncompr, uLong uncomprLen));
+                            Byte *uncompr, uLong uncomprLen));
 void test_dict_deflate  OF((Byte *compr, uLong comprLen));
 void test_dict_inflate  OF((Byte *compr, uLong comprLen,
-                           Byte *uncompr, uLong uncomprLen));
+                            Byte *uncompr, uLong uncomprLen));
 int  main               OF((int argc, char *argv[]));
 
 /* ===========================================================================
@@ -75,7 +75,7 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
 
     if (strcmp((char*)uncompr, hello)) {
         fprintf(stderr, "bad uncompress\n");
-       exit(1);
+        exit(1);
     } else {
         printf("uncompress(): %s\n", (char *)uncompr);
     }
@@ -103,11 +103,11 @@ void test_gzio(out, in, uncompr, uncomprLen)
     gzputc(file, 'h');
     if (gzputs(file, "ello") != 4) {
         fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
-       exit(1);
+        exit(1);
     }
     if (gzprintf(file, ", %s!", "hello") != 8) {
         fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
-       exit(1);
+        exit(1);
     }
     gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
     gzclose(file);
@@ -121,36 +121,36 @@ void test_gzio(out, in, uncompr, uncomprLen)
     uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen);
     if (uncomprLen != len) {
         fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
-       exit(1);
+        exit(1);
     }
     if (strcmp((char*)uncompr, hello)) {
         fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
-       exit(1);
+        exit(1);
     } else {
         printf("gzread(): %s\n", (char *)uncompr);
     }
 
     pos = gzseek(file, -8L, SEEK_CUR);
     if (pos != 6 || gztell(file) != pos) {
-       fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
-               (long)pos, (long)gztell(file));
-       exit(1);
+        fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
+                (long)pos, (long)gztell(file));
+        exit(1);
     }
 
     if (gzgetc(file) != ' ') {
-       fprintf(stderr, "gzgetc error\n");
-       exit(1);
+        fprintf(stderr, "gzgetc error\n");
+        exit(1);
     }
 
     gzgets(file, (char*)uncompr, uncomprLen);
     uncomprLen = strlen((char*)uncompr);
     if (uncomprLen != 6) { /* "hello!" */
         fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
-       exit(1);
+        exit(1);
     }
     if (strcmp((char*)uncompr, hello+7)) {
         fprintf(stderr, "bad gzgets after gzseek\n");
-       exit(1);
+        exit(1);
     } else {
         printf("gzgets() after gzseek: %s\n", (char *)uncompr);
     }
@@ -231,7 +231,7 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
 
     if (strcmp((char*)uncompr, hello)) {
         fprintf(stderr, "bad inflate\n");
-       exit(1);
+        exit(1);
     } else {
         printf("inflate(): %s\n", (char *)uncompr);
     }
@@ -266,7 +266,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
     CHECK_ERR(err, "deflate");
     if (c_stream.avail_in != 0) {
         fprintf(stderr, "deflate not greedy\n");
-       exit(1);
+        exit(1);
     }
 
     /* Feed in already compressed data and switch to no compression: */
@@ -286,7 +286,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
     err = deflate(&c_stream, Z_FINISH);
     if (err != Z_STREAM_END) {
         fprintf(stderr, "deflate should report Z_STREAM_END\n");
-       exit(1);
+        exit(1);
     }
     err = deflateEnd(&c_stream);
     CHECK_ERR(err, "deflateEnd");
@@ -316,7 +316,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
 
     for (;;) {
         d_stream.next_out = uncompr;            /* discard the output */
-       d_stream.avail_out = (uInt)uncomprLen;
+        d_stream.avail_out = (uInt)uncomprLen;
         err = inflate(&d_stream, Z_NO_FLUSH);
         if (err == Z_STREAM_END) break;
         CHECK_ERR(err, "large inflate");
@@ -327,7 +327,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
 
     if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
         fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
-       exit(1);
+        exit(1);
     } else {
         printf("large_inflate(): OK\n");
     }
@@ -407,7 +407,7 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
     if (err != Z_DATA_ERROR) {
         fprintf(stderr, "inflate should report DATA_ERROR\n");
         /* Because of incorrect adler32 */
-       exit(1);
+        exit(1);
     }
     err = inflateEnd(&d_stream);
     CHECK_ERR(err, "inflateEnd");
@@ -433,7 +433,7 @@ void test_dict_deflate(compr, comprLen)
     CHECK_ERR(err, "deflateInit");
 
     err = deflateSetDictionary(&c_stream,
-                              (const Bytef*)dictionary, sizeof(dictionary));
+                               (const Bytef*)dictionary, sizeof(dictionary));
     CHECK_ERR(err, "deflateSetDictionary");
 
     dictId = c_stream.adler;
@@ -446,7 +446,7 @@ void test_dict_deflate(compr, comprLen)
     err = deflate(&c_stream, Z_FINISH);
     if (err != Z_STREAM_END) {
         fprintf(stderr, "deflate should report Z_STREAM_END\n");
-       exit(1);
+        exit(1);
     }
     err = deflateEnd(&c_stream);
     CHECK_ERR(err, "deflateEnd");
@@ -480,14 +480,14 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
     for (;;) {
         err = inflate(&d_stream, Z_NO_FLUSH);
         if (err == Z_STREAM_END) break;
-       if (err == Z_NEED_DICT) {
-           if (d_stream.adler != dictId) {
-               fprintf(stderr, "unexpected dictionary");
-               exit(1);
-           }
-           err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
-                                      sizeof(dictionary));
-       }
+        if (err == Z_NEED_DICT) {
+            if (d_stream.adler != dictId) {
+                fprintf(stderr, "unexpected dictionary");
+                exit(1);
+            }
+            err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
+                                       sizeof(dictionary));
+        }
         CHECK_ERR(err, "inflate with dict");
     }
 
@@ -496,7 +496,7 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
 
     if (strcmp((char*)uncompr, hello)) {
         fprintf(stderr, "bad inflate with dict\n");
-       exit(1);
+        exit(1);
     } else {
         printf("inflate with dictionary: %s\n", (char *)uncompr);
     }
@@ -530,13 +530,13 @@ int main(argc, argv)
      */
     if (compr == Z_NULL || uncompr == Z_NULL) {
         printf("out of memory\n");
-       exit(1);
+        exit(1);
     }
     test_compress(compr, comprLen, uncompr, uncomprLen);
 
     test_gzio((argc > 1 ? argv[1] : TESTFILE),
               (argc > 2 ? argv[2] : TESTFILE),
-             uncompr, (int)uncomprLen);
+              uncompr, (int)uncomprLen);
 
     test_deflate(compr, comprLen);
     test_inflate(compr, comprLen, uncompr, uncomprLen);
@@ -554,6 +554,5 @@ int main(argc, argv)
     free(compr);
     free(uncompr);
 
-    exit(0);
-    return 0; /* to avoid warning */
+    return 0;
 }