changeset 231:bb8ce494267b

Remove currently dead code.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 04 Jan 2020 11:34:46 +0200
parents 1e860046a4cc
children 03b6f8604a7f
files sidlib.c sidlib.h
diffstat 2 files changed, 0 insertions(+), 188 deletions(-) [+]
line wrap: on
line diff
--- a/sidlib.c	Fri Jan 03 13:11:29 2020 +0200
+++ b/sidlib.c	Sat Jan 04 11:34:46 2020 +0200
@@ -8,24 +8,6 @@
 #include "th_string.h"
 
 
-#define SIDLIB_DB_MAGIC     "SIDLibDB"
-#define SIDLIB_DB_VERSION   0x0100
-
-
-typedef struct
-{
-    char magic[8];      // File magic ID
-    uint16_t version;   // Version
-    uint32_t nnodes;    // Number of song nodes
-//  struct {
-//      th_md5hash_t hash;         // Hash for this SID file
-//      uint16_t nlengths;         // Number of song (lengths)
-//      uint16_t length[nlengths]; // Length in seconds
-//  } * nnodes;
-    th_md5hash_t hash;
-} PSIDLibHdr;
-
-
 BOOL sidlib_fread_str(th_ioctx *ctx, char **str, const size_t len)
 {
     char *tmp = th_malloc(len + 1);
@@ -561,174 +543,6 @@
 }
 
 
-//
-// Read binary format SLDB
-//
-int sidlib_sldb_read_bin(th_ioctx *ctx, SIDLibSLDB *dbh)
-{
-    PSIDLibHdr hdr;
-    th_md5state_t state;
-    th_md5hash_t hash;
-    size_t n;
-
-    // Check pointers
-    if (ctx == NULL || dbh == NULL)
-        return THERR_NULLPTR;
-
-    if (!thfread_str(ctx, &hdr.magic, sizeof(hdr.magic)) ||
-        !thfread_le16(ctx, &hdr.version) ||
-        !thfread_le32(ctx, &hdr.nnodes))
-        return THERR_FREAD;
-
-    // Check magic and version
-    if (memcmp(hdr.magic, SIDLIB_DB_MAGIC, sizeof(hdr.magic)) != 0)
-        return THERR_NOT_SUPPORTED;
-
-    if (hdr.version != SIDLIB_DB_VERSION)
-        return THERR_NOT_SUPPORTED;
-
-    // Make some reasonable assumptions about validity
-    if (hdr.nnodes == 0 || hdr.nnodes > 256*1024)
-        return THERR_INVALID_DATA;
-
-    // Initialize MD5 state
-    th_md5_init(&state);
-    th_md5_append_ne16(&state, hdr.version);
-    th_md5_append_ne32(&state, hdr.nnodes);
-
-    // Allocate index
-    dbh->nnodes = hdr.nnodes;
-    dbh->pindex = (SIDLibSLDBNode **) th_malloc(sizeof(SIDLibSLDBNode *) * dbh->nnodes);
-    if (dbh->pindex == NULL)
-        return THERR_MALLOC;
-
-    // Read nodes
-    for (n = 0; n < dbh->nnodes; n++)
-    {
-        SIDLibSLDBNode *node;
-        th_md5hash_t mhash;
-        uint16_t tmpn;
-        int index;
-
-        // Read node hash and nlengths
-        if (!thfread_str(ctx, mhash, TH_MD5HASH_LENGTH) ||
-            !thfread_le16(ctx, &tmpn))
-            return THERR_FREAD;
-
-        // Sanity check
-        if (tmpn == 0 || tmpn > 2048)
-            return THERR_INVALID_DATA;
-
-        // Append to hash
-        th_md5_append(&state, mhash, TH_MD5HASH_LENGTH);
-        th_md5_append_ne16(&state, tmpn);
-
-        // Allocate node
-        node = (SIDLibSLDBNode *) th_malloc0(sizeof(SIDLibSLDBNode));
-        if (node == NULL)
-            return THERR_MALLOC;
-
-        node->nlengths = tmpn;
-        memcpy(node->hash, mhash, sizeof(mhash));
-
-        node->lengths = (int *) th_calloc(node->nlengths, sizeof(int));
-        if (node->lengths == NULL)
-        {
-            th_free(node);
-            th_io_error(ctx, THERR_MALLOC,
-                "Could not allocate memory for node.\n");
-            return ctx->status;
-        }
-
-        // Read node lenghts
-        for (index = 0; index < node->nlengths; index++)
-        {
-            uint16_t tmpl;
-            if (!thfread_le16(ctx, &tmpl))
-                return THERR_FREAD;
-
-            th_md5_append_ne16(&state, tmpl);
-            node->lengths[index] = tmpl;
-        }
-
-        th_llist_append_node((th_llist_t **) &dbh->nodes, (th_llist_t *) node);
-        dbh->pindex[n] = node;
-    }
-
-    // Read stored checksum hash
-    if (!thfread_str(ctx, hdr.hash, sizeof(hdr.hash)))
-        return THERR_FREAD;
-
-    // Compare to what we get
-    th_md5_finish(&state, hash);
-    if (memcmp(hash, hdr.hash, sizeof(hdr.hash)) != 0)
-        return THERR_INVALID_DATA;
-
-    return THERR_OK;
-}
-
-
-int sidlib_sldb_write_bin(th_ioctx *ctx, const SIDLibSLDB *dbh)
-{
-    th_md5state_t state;
-    th_md5hash_t hash;
-    size_t n;
-
-    // Check pointers
-    if (ctx == NULL || dbh == NULL)
-        return THERR_NULLPTR;
-
-    // Write header
-    if (!thfwrite_str(ctx, SIDLIB_DB_MAGIC, 8) ||
-        !thfwrite_le16(ctx, SIDLIB_DB_VERSION) ||
-        !thfwrite_le32(ctx, dbh->nnodes))
-        return THERR_FWRITE;
-
-    th_md5_init(&state);
-    th_md5_append_ne16(&state, SIDLIB_DB_VERSION);
-    th_md5_append_ne32(&state, dbh->nnodes);
-
-    // Write nodes
-    for (n = 0; n < dbh->nnodes; n++)
-    {
-        const SIDLibSLDBNode *node = dbh->pindex[n];
-        uint16_t tmpn;
-        int index;
-
-        // Sanity check
-        if (node->nlengths <= 0 || node->nlengths > 2048)
-            return THERR_INVALID_DATA;
-
-        tmpn = node->nlengths;
-        th_md5_append(&state, node->hash, TH_MD5HASH_LENGTH);
-        th_md5_append_ne16(&state, tmpn);
-
-        // Write node data
-        if (!thfwrite_str(ctx, node->hash, TH_MD5HASH_LENGTH) ||
-            !thfwrite_le16(ctx, tmpn))
-            return THERR_FWRITE;
-
-        for (index = 0; index < node->nlengths; index++)
-        {
-            if (node->lengths[index] > 16378)
-                return THERR_INVALID_DATA;
-
-            if (!thfwrite_le16(ctx, node->lengths[index]))
-                return THERR_FWRITE;
-
-            th_md5_append_ne16(&state, node->lengths[index]);
-        }
-    }
-
-    th_md5_finish(&state, hash);
-
-    if (!thfwrite_str(ctx, hash, sizeof(hash)))
-        return THERR_FWRITE;
-
-    return THERR_OK;
-}
-
-
 // Free a given song-length database
 //
 void sidlib_sldb_free(SIDLibSLDB *dbh)
--- a/sidlib.h	Fri Jan 03 13:11:29 2020 +0200
+++ b/sidlib.h	Sat Jan 04 11:34:46 2020 +0200
@@ -115,8 +115,6 @@
 void             sidlib_sldb_free(SIDLibSLDB *dbh);
 SIDLibSLDBNode * sidlib_sldb_get_by_hash(SIDLibSLDB *dbh, th_md5hash_t hash);
 
-int              sidlib_sldb_read_bin(th_ioctx *ctx, SIDLibSLDB *dbh);
-int              sidlib_sldb_write_bin(th_ioctx *ctx, const SIDLibSLDB *dbh);
 
 
 #ifdef __cplusplus