summaryrefslogtreecommitdiffstats
path: root/chksum.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-07-09 15:10:12 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-07-09 15:10:12 -0700
commitcfe3269e978e06cf0fb3f27f248bfde0a77d0038 (patch)
tree042a9b463e383f280b014af54f3a035710376e07 /chksum.c
parentfeb8eefb2fc97e5f8ccc831f28ef10e67717ec22 (diff)
downloadtxr-cfe3269e978e06cf0fb3f27f248bfde0a77d0038.tar.gz
txr-cfe3269e978e06cf0fb3f27f248bfde0a77d0038.tar.bz2
txr-cfe3269e978e06cf0fb3f27f248bfde0a77d0038.zip
chksum: generate more with TXR.
* genchksum.txr, chksum.c: The declarations of the symbol variables, COBJ class handles, and most of the chksum_init function is also generated now. A comment is added explaining what parts of the file are generated, and what parts are scraped, and giving some advice to the maintainer.
Diffstat (limited to 'chksum.c')
-rw-r--r--chksum.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/chksum.c b/chksum.c
index fa7c5691..79b613ca 100644
--- a/chksum.c
+++ b/chksum.c
@@ -1,4 +1,4 @@
-/* This file is generated by genchksum.txr */
+/* This file is partially generated by genchksum.txr; see comment below. */
/* Copyright 2019-2023
* Kaz Kylheku <kaz@kylheku.com>
@@ -51,8 +51,29 @@
#include "chksums/md5.h"
#include "chksum.h"
-static val sha1_ctx_s, sha256_ctx_s, md5_ctx_s;
-static struct cobj_class *sha1_ctx_cls, *sha256_ctx_cls, *md5_ctx_cls;
+/* This file is not entirely generated. Parts of it are maintained by
+ * hand. The genchksum.txr program will extract the hand-maintained
+ * parts, and merge it with the generated parts.
+ *
+ * After working on this file, save your work (perhaps into a commit).
+ * Then run txr ./genchksum.txr and ensure that the updated
+ * chksum.c file is identical to your saved copy.
+ *
+ * The generated parts are these:
+ *
+ * - everything starting with the declaration "static val sha1_ctx_s ..."
+ * up to just before the crc32 section: the crc32_stream function.
+ *
+ * - the crc32 function section starting with the crc32_stream function,
+ * to just before the checksum_
+ *
+ * - a portion fo the chksum_init(void) function, up to the line
+ * which registers the crc32-stream function.
+ *
+ * Thus, material outside of these sections is editable; but edits
+ * must be validated to make sure they don't break the generation
+ * program.
+ */
static val chksum_ensure_buf(val self, val buf_in,
val len, unsigned char **phash,
@@ -70,6 +91,9 @@ static val chksum_ensure_buf(val self, val buf_in,
}
}
+static val sha1_ctx_s, sha256_ctx_s, md5_ctx_s;
+static struct cobj_class *sha1_ctx_cls, *sha256_ctx_cls, *md5_ctx_cls;
+
static void sha1_stream_impl(val stream, val nbytes,
unsigned char *hash, val self)
{
@@ -729,11 +753,11 @@ void chksum_init(void)
reg_fun(intern(lit("sha256-begin"), user_package), func_n0(sha256_begin));
reg_fun(intern(lit("sha256-hash"), user_package), func_n2(sha256_hash));
reg_fun(intern(lit("sha256-end"), user_package), func_n2o(sha256_end, 1));
- reg_fun(intern(lit("crc32-stream"), user_package), func_n3o(crc32_stream, 1));
- reg_fun(intern(lit("crc32"), user_package), func_n2o(crc32, 1));
reg_fun(intern(lit("md5-stream"), user_package), func_n3o(md5_stream, 1));
reg_fun(intern(lit("md5"), user_package), func_n2o(md5, 1));
reg_fun(intern(lit("md5-begin"), user_package), func_n0(md5_begin));
reg_fun(intern(lit("md5-hash"), user_package), func_n2(md5_hash));
reg_fun(intern(lit("md5-end"), user_package), func_n2o(md5_end, 1));
+ reg_fun(intern(lit("crc32-stream"), user_package), func_n3o(crc32_stream, 1));
+ reg_fun(intern(lit("crc32"), user_package), func_n2o(crc32, 1));
}