summaryrefslogtreecommitdiff
path: root/src/common/grfio.h
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-03-14 01:25:13 +0100
committerHaru <haru@dotalux.com>2016-07-12 20:58:44 +0200
commit5196ad065674b65b030d30793b611823e18f0560 (patch)
treee8d21f22ce9ea0320c593c97ac26bf172be2b2fb /src/common/grfio.h
parent92226422121a7f834fd69b0e67d41e144b2cefea (diff)
downloadhercules-5196ad065674b65b030d30793b611823e18f0560.tar.gz
hercules-5196ad065674b65b030d30793b611823e18f0560.tar.bz2
hercules-5196ad065674b65b030d30793b611823e18f0560.tar.xz
hercules-5196ad065674b65b030d30793b611823e18f0560.zip
Various changes to the grfio interface
Mostly stylistic changes. Cleaned up documentation. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/grfio.h')
-rw-r--r--src/common/grfio.h88
1 files changed, 84 insertions, 4 deletions
diff --git a/src/common/grfio.h b/src/common/grfio.h
index 72afad274..857bc507e 100644
--- a/src/common/grfio.h
+++ b/src/common/grfio.h
@@ -23,22 +23,102 @@
#include "common/hercules.h"
+/** @file
+ * GRF I/O library.
+ */
+
+/// The GRF I/O interface.
struct grfio_interface {
+ /**
+ * Interface initialization.
+ *
+ * @param fname Name of the configuration file.
+ */
void (*init) (const char *fname);
+
+ /// Interface finalization.
void (*final) (void);
+
+ /**
+ * Reads a file into a newly allocated buffer (from grf or data directory).
+ *
+ * @param[in] fname Name of the file to read.
+ * @param[out] size Buffer to return the size of the read file (optional).
+ * @return The file data.
+ * @retval NULL in case of error.
+ */
void *(*reads) (const char *fname, int *size);
- char *(*find_file) (const char *fname);
+ /**
+ * Finds a file in the grf or data directory
+ *
+ * @param fname The file to find.
+ * @return The original file name.
+ * @retval NULL if the file wasn't found.
+ */
+ const char *(*find_file) (const char *fname);
+
+ /**
+ * Calculates a CRC32 hash.
+ *
+ * @param buf The data to hash.
+ * @param len Data length.
+ *
+ * @return The CRC32 hash.
+ */
unsigned long (*crc32) (const unsigned char *buf, unsigned int len);
- int (*decode_zip) (void *dest, unsigned long *destLen, const void *source, unsigned long sourceLen);
- int (*encode_zip) (void *dest, unsigned long *destLen, const void *source, unsigned long sourceLen);
+
+ /**
+ * Decompresses ZIP data.
+ *
+ * Decompresses the source buffer into the destination buffer.
+ * source_len is the byte length of the source buffer. Upon entry,
+ * dest_len is the total size of the destination buffer, which must be
+ * large enough to hold the entire uncompressed data. (The size of the
+ * uncompressed data must have been saved previously by the compressor
+ * and transmitted to the decompressor by some mechanism outside the
+ * scope of this compression library.) Upon exit, dest_len is the
+ * actual size of the uncompressed buffer.
+ *
+ * @param[in,out] dest The destination (uncompressed) buffer.
+ * @param[in,out] dest_len Max length of the destination buffer, returns length of the decompressed data.
+ * @param[in] source The source (compressed) buffer.
+ * @param[in] source_len Source data length.
+ * @return error code.
+ * @retval Z_OK in case of success.
+ */
+ int (*decode_zip) (void *dest, unsigned long *dest_len, const void *source, unsigned long source_len);
+
+ /**
+ * Compresses data to ZIP format.
+ *
+ * Compresses the source buffer into the destination buffer.
+ * source_len is the byte length of the source buffer. Upon entry,
+ * dest_len is the total size of the destination buffer, which must be
+ * at least the value returned by compressBound(source_len). Upon
+ * exit, dest_len is the actual size of the compressed buffer.
+ *
+ * @param[in,out] dest The destination (compressed) buffer (if NULL, a new buffer will be created).
+ * @param[in,out] dest_len Max length of the destination buffer (if 0, it will be calculated).
+ * @param[in] source The source (uncompressed) buffer.
+ * @param[in] source_len Source data length.
+ */
+ int (*encode_zip) (void *dest, unsigned long *dest_len, const void *source, unsigned long source_len);
};
+/**
+ * Reads a file into a newly allocated buffer (from grf or data directory)
+ *
+ * @param fn The filename to read.
+ *
+ * @see grfio_interface::reads()
+ * @related grfio_interface
+ */
#define grfio_read(fn) grfio->reads((fn), NULL)
#ifdef HERCULES_CORE
void grfio_defaults(void);
#endif // HERCULES_CORE
-HPShared struct grfio_interface *grfio;
+HPShared struct grfio_interface *grfio; ///< Pointer to the grfio interface.
#endif /* COMMON_GRFIO_H */