From 8d36d5cfaeba7785c21006692f66889d5bba5f60 Mon Sep 17 00:00:00 2001
From: "Mirar (Pontus Hagland)" <pike@sort.mirar.org>
Date: Fri, 27 Feb 1998 21:21:27 +0100
Subject: [PATCH] crc32 added

Rev: src/modules/Gz/zlibmod.c:1.18
Rev: tutorial/tutorial.wmml:1.72
---
 src/modules/Gz/zlibmod.c | 33 +++++++++++++++++++++++++++++++--
 tutorial/tutorial.wmml   | 18 ++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/src/modules/Gz/zlibmod.c b/src/modules/Gz/zlibmod.c
index 1978cdeaf7..19b233fdec 100644
--- a/src/modules/Gz/zlibmod.c
+++ b/src/modules/Gz/zlibmod.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: zlibmod.c,v 1.17 1997/11/11 03:56:25 grubba Exp $");
+RCSID("$Id: zlibmod.c,v 1.18 1998/02/27 20:21:27 mirar Exp $");
 
 #include "zlib_machine.h"
 
@@ -167,7 +167,7 @@ static void gz_deflate(INT32 args)
     case Z_NO_FLUSH:
       break;
 
-    defualt:
+    default:
       error("Argument 2 to gz_deflate->deflate() out of range.\n");
     }
   }else{
@@ -343,6 +343,31 @@ static void exit_gz_inflate(struct object *o)
 /*   mt_unlock(& THIS->lock); */
 }
 
+
+static void gz_crc32(INT32 args)
+{
+   unsigned INT32 crc;
+   if (!args ||
+       sp[-args].type!=T_STRING)
+      error("Gz.crc32: illegal or missing argument 1 (expected string)\n");
+
+   if (args>1)
+      if (sp[1-args].type!=T_INT)
+	 error("Gz.crc32: illegal argument 2 (expected integer)\n");
+      else
+	 crc=(unsigned INT32)sp[1-args].u.integer;
+   else
+      crc=0;
+	 
+   crc=crc32(crc,
+	     (unsigned char*)sp[-args].u.string->str,
+	     sp[-args].u.string->len);
+
+   pop_n_elems(args);
+   push_int((INT32)crc);
+}
+
+
 #endif
 
 void pike_module_exit(void) {}
@@ -387,6 +412,10 @@ void pike_module_init(void)
   add_integer_constant("SYNC_FLUSH",Z_SYNC_FLUSH,0);
   add_integer_constant("FINISH",Z_FINISH,0);
 
+  add_function("crc32",gz_crc32,
+	       "function(string,void|int:int)",
+	       OPT_TRY_OPTIMIZE);
+
 #endif
 }
 
diff --git a/tutorial/tutorial.wmml b/tutorial/tutorial.wmml
index 241b596790..037a522617 100644
--- a/tutorial/tutorial.wmml
+++ b/tutorial/tutorial.wmml
@@ -6729,6 +6729,7 @@ Note that these functions use the same <i>algorithm</i> as gzip, they do
 not use the exact same format however, so you cannot directly unzip gzipped
 files with these routines. Support for this will be added in the future.
 <p>
+
 <class name=Gz.deflate title="string packer">
 <man_description>
 Gz.inflate is a builtin program written in C. It interfaces the
@@ -6845,6 +6846,23 @@ Gz.deflate-&gt;deflate
 </method>
 
 </section>
+
+<method name=Gz.crc32 title="calculate checksum">
+<man_syntax>
+string crc32(string <I>data</I>,void|int start_value);<br>
+</man_syntax>
+
+<man_description>
+This method is usable for calculating checksums, and presents
+the standard ISO3309 Cyclic Redundancy Check.
+</man_description>
+
+<man_see>
+Gz
+</man_see>
+</method>
+
+
 </module>
 
 <hr noshade size=1>
-- 
GitLab