/*----- File hashing ------------------------------------------------------*/
+typedef struct fhashstate {
+ const gchash *gch;
+ unsigned f;
+} fhashstate;
+
+#define FHF_BINARY 0x100u
+#define FHF_PROGRESS 0x200u
+
+#define FHF_MASK 0xff00u
+
+/* --- @gethash@ --- *
+ *
+ * Arguments: @const char *name@ = pointer to name string
+ *
+ * Returns: Pointer to appropriate hash class.
+ *
+ * Use: Chooses a hash function by name.
+ */
+
+extern const gchash *gethash(const char */*name*/);
+
+/* --- @fhash_init@ ---*
+ *
+ * Arguments: @fhashstate *fh@ = pointer to fhash state to initialize
+ * @const gchash *gch@ = hash class to set
+ * @unsigned f@ initial flags to set
+ *
+ * Returns: ---
+ *
+ * Use: Initializes an @fhashstate@ structure.
+ */
+
+extern void fhash_init(fhashstate */*fh*/,
+ const gchash */*gch*/, unsigned /*f*/);
+
+/* --- @fhash_free@ --- *
+ *
+ * Arguments: @fhashstate *fh@ = pointer to fhash state to free
+ *
+ * Returns: ---
+ *
+ * Use: Frees an fhash state.
+ */
+
+extern void fhash_free(fhashstate */*fh*/);
+
/* --- @fhash@ --- *
*
- * Arguments: @const gchash *gch@ = pointer to hash function to use
- * @unsigned f@ = flags to set
+ * Arguments: @fhashstate *fh@ = pointer to fhash state
* @const char *file@ = file name to be hashed (null for stdin)
* @void *buf@ = pointer to hash output buffer
*
* Use: Hashes a file.
*/
-#define FHF_BINARY 256u
-#define FHF_PROGRESS 512u
+extern int fhash(fhashstate */*fh*/, const char */*file*/, void */*buf*/);
-#define FHF_MASK 3840
+/* --- @hfparse@ --- *
+ *
+ * Arguments: @hfpctx *hfp@ = pointer to the context structure
+ *
+ * Returns: A code indicating what happened.
+ *
+ * Use: Parses a line from the input file.
+ */
+
+enum { /* Meaning and members set */
+ HF_FILE, /* File hash: @dline@ and @hbuf@ */
+ HF_ENC, /* Encoding: @ee@ */
+ HF_HASH, /* Hash function: @gch@ */
+ HF_ESC, /* Name escape: @f@ */
+ HF_EOF, /* End of file */
+ HF_BAD /* Unrecognized line */
+};
-extern int fhash(const gchash */*gch*/, unsigned /*f*/,
- const char */*file*/, void */*buf*/);
+typedef struct hfpctx {
+ unsigned f; /* Flags to read */
+#define HFF_ESCAPE 1u /* File names are escaped */
+ FILE *fp; /* Input file to read */
+ dstr *dline; /* Line contents, corrupted */
+ const gchash *gch; /* Hash function to use */
+ const encodeops *ee; /* Encoding to apply to hashes */
+ dstr *dfile; /* File name for @HF_FILE@ lines */
+ octet *hbuf; /* Output buffer for hash data */
+} hfpctx;
+
+extern int hfparse(hfpctx */*hfp*/);
/*----- String I/O --------------------------------------------------------*/