# HG changeset patch # User Matti Hamalainen # Date 1577437962 -7200 # Node ID 3a01518fffe0782fca8614fe9c78ee693c906a5a # Parent 8db9830e5d9772acdf8f013fe15f9ab36c3563cd Rename sidlib functions from si_* prefix to sidlib_*. diff -r 8db9830e5d97 -r 3a01518fffe0 sidinfo.c --- a/sidinfo.c Fri Dec 27 11:07:21 2019 +0200 +++ b/sidinfo.c Fri Dec 27 11:12:42 2019 +0200 @@ -927,11 +927,11 @@ break; case 5: if (psid->version >= 2) - PRS(si_get_sid_clock_str((psid->flags >> 2) & PSF_CLOCK_MASK), FALSE); + PRS(sidlib_get_sid_clock_str((psid->flags >> 2) & PSF_CLOCK_MASK), FALSE); break; case 6: if (psid->version >= 2) - PRS(si_get_sid_model_str((psid->flags >> 4) & PSF_MODEL_MASK), FALSE); + PRS(sidlib_get_sid_model_str((psid->flags >> 4) & PSF_MODEL_MASK), FALSE); break; case 7: PRI(psid->dataOffset); break; @@ -949,7 +949,7 @@ if (flags == PSF_MODEL_UNKNOWN) flags = (psid->flags >> 4) & PSF_MODEL_MASK; - PRS(si_get_sid_model_str(flags), FALSE); + PRS(sidlib_get_sid_model_str(flags), FALSE); } break; case 15: @@ -959,7 +959,7 @@ if (flags == PSF_MODEL_UNKNOWN) flags = (psid->flags >> 4) & PSF_MODEL_MASK; - PRS(si_get_sid_model_str(flags), FALSE); + PRS(sidlib_get_sid_model_str(flags), FALSE); } break; case 16: @@ -1031,12 +1031,12 @@ th_io_set_handlers(inFile, siError, NULL); // Read PSID data - if (!si_read_sid_file(inFile, &psid, setSLDBNewFormat)) + if (!sidlib_read_sid_file(inFile, &psid, setSLDBNewFormat)) goto error; // Get songlength information, if any if (sidSLDB != NULL) - psid->lengths = si_sldb_get_by_hash(sidSLDB, psid->hash); + psid->lengths = sidlib_sldb_get_by_hash(sidSLDB, psid->hash); // Output for (int index = 0; index < optFormat.nitems; index++) @@ -1065,7 +1065,7 @@ // Shutdown error: - si_free_sid_file(psid); + sidlib_free_sid_file(psid); th_io_free(inFile); return TRUE; @@ -1293,13 +1293,13 @@ setSLDBNewFormat ? ".md5" : ".txt", setSLDBPath); - if ((sidSLDB = si_sldb_new()) == NULL) + if ((sidSLDB = sidlib_sldb_new()) == NULL) { THERR("Could not allocate SLDB structure!\n"); goto err; } - if ((ret = si_sldb_read(inFile, sidSLDB)) != THERR_OK) + if ((ret = sidlib_sldb_read(inFile, sidSLDB)) != THERR_OK) { THERR("Error parsing SLDB: %d, %s\n", ret, th_error_str(ret)); @@ -1307,7 +1307,7 @@ } th_io_close(inFile); - if ((ret = si_sldb_build_index(sidSLDB)) != THERR_OK) + if ((ret = sidlib_sldb_build_index(sidSLDB)) != THERR_OK) { THERR("Error building SLDB index: %d, %s.\n", ret, th_error_str(ret)); @@ -1337,6 +1337,6 @@ th_free(setHVSCPath); th_free(setSLDBPath); - si_sldb_free(sidSLDB); + sidlib_sldb_free(sidSLDB); return 0; } diff -r 8db9830e5d97 -r 3a01518fffe0 sidlib.c --- a/sidlib.c Fri Dec 27 11:07:21 2019 +0200 +++ b/sidlib.c Fri Dec 27 11:12:42 2019 +0200 @@ -26,7 +26,7 @@ } PSIDLibHdr; -BOOL si_fread_str(th_ioctx *ctx, char **str, const size_t len) +BOOL sidlib_fread_str(th_ioctx *ctx, char **str, const size_t len) { char *tmp = th_malloc(len + 1); if (tmp == NULL) @@ -47,7 +47,7 @@ } -static BOOL si_read_hash_data(th_ioctx *ctx, PSIDHeader *psid, +static BOOL sidlib_read_hash_data(th_ioctx *ctx, PSIDHeader *psid, th_md5state_t *state, const BOOL newSLDB) { uint8_t *data = NULL; @@ -105,7 +105,7 @@ } -BOOL si_read_sid_file(th_ioctx *ctx, PSIDHeader **ppsid, const BOOL newSLDB) +BOOL sidlib_read_sid_file(th_ioctx *ctx, PSIDHeader **ppsid, const BOOL newSLDB) { PSIDHeader *psid = NULL; th_md5state_t state; @@ -152,9 +152,9 @@ psid->isRSID = psid->magic[0] == 'R'; - if (!si_fread_str(ctx, &psid->sidName, PSID_STR_LEN) || - !si_fread_str(ctx, &psid->sidAuthor, PSID_STR_LEN) || - !si_fread_str(ctx, &psid->sidCopyright, PSID_STR_LEN)) + if (!sidlib_fread_str(ctx, &psid->sidName, PSID_STR_LEN) || + !sidlib_fread_str(ctx, &psid->sidAuthor, PSID_STR_LEN) || + !sidlib_fread_str(ctx, &psid->sidCopyright, PSID_STR_LEN)) { th_io_error(ctx, ctx->status, "Error reading SID file header from '%s': %s.\n", @@ -190,7 +190,7 @@ // We just hash the whole file, so seek back to beginning .. thfseek(ctx, hdrStart, SEEK_SET); - if (!si_read_hash_data(ctx, psid, &state, FALSE)) + if (!sidlib_read_hash_data(ctx, psid, &state, FALSE)) goto error; psid->dataSize -= hdrEnd - hdrStart; @@ -199,7 +199,7 @@ { // "Old" Songlengths.txt style MD5 hash calculation // We need to separately hash data etc. - if (!si_read_hash_data(ctx, psid, &state, TRUE)) + if (!sidlib_read_hash_data(ctx, psid, &state, TRUE)) goto error; // Append header data to hash @@ -243,7 +243,7 @@ } -void si_free_sid_file(PSIDHeader *psid) +void sidlib_free_sid_file(PSIDHeader *psid) { if (psid != NULL) { @@ -254,7 +254,7 @@ } -const char *si_get_sid_clock_str(const int flags) +const char *sidlib_get_sid_clock_str(const int flags) { switch (flags) { @@ -267,7 +267,7 @@ } -const char *si_get_sid_model_str(const int flags) +const char *sidlib_get_sid_model_str(const int flags) { switch (flags) { @@ -282,7 +282,7 @@ // Free memory allocated for given SLDB node // -static void si_sldb_node_free(SIDLibSLDBNode *node) +static void sidlib_sldb_node_free(SIDLibSLDBNode *node) { if (node != NULL) { @@ -294,7 +294,7 @@ // Insert given node to db linked list // -static void si_sldb_node_insert(SIDLibSLDB *dbh, SIDLibSLDBNode *node) +static void sidlib_sldb_node_insert(SIDLibSLDB *dbh, SIDLibSLDBNode *node) { if (dbh->nodes != NULL) { @@ -313,7 +313,7 @@ // Parse a time-entry in SLDB format // -static int si_sldb_get_value(const char *str, size_t *pos) +static int sidlib_sldb_get_value(const char *str, size_t *pos) { int result = 0; @@ -324,7 +324,7 @@ } -static int si_sldb_gettime(const char *str, size_t *pos) +static int sidlib_sldb_gettime(const char *str, size_t *pos) { int result; @@ -332,14 +332,14 @@ if (th_isdigit(str[*pos])) { // Get minutes-field - result = si_sldb_get_value(str, pos) * 60; + result = sidlib_sldb_get_value(str, pos) * 60; // Check the field separator char if (str[*pos] == ':') { // Get seconds-field (*pos)++; - result += si_sldb_get_value(str, pos); + result += sidlib_sldb_get_value(str, pos); } else result = -2; @@ -357,7 +357,7 @@ // Parse one SLDB definition line, return SLDB node // -SIDLibSLDBNode *si_sldb_parse_entry(th_ioctx *ctx, const char *line) +SIDLibSLDBNode *sidlib_sldb_parse_entry(th_ioctx *ctx, const char *line) { SIDLibSLDBNode *node = NULL; size_t pos, tmpLen, savePos; @@ -400,7 +400,7 @@ { th_findnext(line, &pos); - if (si_sldb_gettime(line, &pos) >= 0) + if (sidlib_sldb_gettime(line, &pos) >= 0) node->nlengths++; else isOK = FALSE; @@ -425,7 +425,7 @@ int l; th_findnext(line, &pos); - l = si_sldb_gettime(line, &pos); + l = sidlib_sldb_gettime(line, &pos); if (l >= 0) node->lengths[i] = l; else @@ -435,12 +435,12 @@ return node; error: - si_sldb_node_free(node); + sidlib_sldb_node_free(node); return NULL; } -SIDLibSLDB * si_sldb_new(void) +SIDLibSLDB * sidlib_sldb_new(void) { return (SIDLibSLDB *) th_malloc0(sizeof(SIDLibSLDB)); } @@ -448,7 +448,7 @@ // Read SLDB database to memory // -int si_sldb_read(th_ioctx *ctx, SIDLibSLDB *dbh) +int sidlib_sldb_read(th_ioctx *ctx, SIDLibSLDB *dbh) { char *line = NULL; @@ -484,9 +484,9 @@ else { // Parse and add node to db - if ((tmnode = si_sldb_parse_entry(ctx, line)) != NULL) + if ((tmnode = sidlib_sldb_parse_entry(ctx, line)) != NULL) { - si_sldb_node_insert(dbh, tmnode); + sidlib_sldb_node_insert(dbh, tmnode); } else { @@ -515,7 +515,7 @@ // negative if hash1 < hash2 // positive if hash1 > hash2 // -static int si_sldb_compare_hash(th_md5hash_t hash1, th_md5hash_t hash2) +static int sidlib_sldb_compare_hash(th_md5hash_t hash1, th_md5hash_t hash2) { int i, delta; @@ -528,9 +528,9 @@ // Compare two nodes. // We assume here that we never ever get NULL-pointers. -static int si_sldb_compare_nodes(const void *node1, const void *node2) +static int sidlib_sldb_compare_nodes(const void *node1, const void *node2) { - return si_sldb_compare_hash( + return sidlib_sldb_compare_hash( (*(SIDLibSLDBNode **) node1)->hash, (*(SIDLibSLDBNode **) node2)->hash); } @@ -538,7 +538,7 @@ // (Re)create index // -int si_sldb_build_index(SIDLibSLDB * dbh) +int sidlib_sldb_build_index(SIDLibSLDB * dbh) { SIDLibSLDBNode *node; @@ -564,7 +564,7 @@ dbh->pindex[i++] = node; // Sort the indexes - qsort(dbh->pindex, dbh->nnodes, sizeof(SIDLibSLDBNode *), si_sldb_compare_nodes); + qsort(dbh->pindex, dbh->nnodes, sizeof(SIDLibSLDBNode *), sidlib_sldb_compare_nodes); } return THERR_OK; @@ -574,7 +574,7 @@ // // Read binary format SLDB // -int si_sldb_read_bin(th_ioctx *ctx, SIDLibSLDB *dbh) +int sidlib_sldb_read_bin(th_ioctx *ctx, SIDLibSLDB *dbh) { PSIDLibHdr hdr; th_md5state_t state; @@ -660,7 +660,7 @@ node->lengths[index] = tmpl; } - si_sldb_node_insert(dbh, node); + sidlib_sldb_node_insert(dbh, node); dbh->pindex[n] = node; } @@ -677,7 +677,7 @@ } -int si_sldb_write_bin(th_ioctx *ctx, const SIDLibSLDB *dbh) +int sidlib_sldb_write_bin(th_ioctx *ctx, const SIDLibSLDB *dbh) { th_md5state_t state; th_md5hash_t hash; @@ -740,7 +740,7 @@ // Free a given song-length database // -void si_sldb_free(SIDLibSLDB *dbh) +void sidlib_sldb_free(SIDLibSLDB *dbh) { if (dbh != NULL) { @@ -748,7 +748,7 @@ while (node != NULL) { SIDLibSLDBNode *next = node->next; - si_sldb_node_free(node); + sidlib_sldb_node_free(node); node = next; } @@ -761,13 +761,13 @@ } -SIDLibSLDBNode *si_sldb_get_by_hash(SIDLibSLDB *dbh, th_md5hash_t hash) +SIDLibSLDBNode *sidlib_sldb_get_by_hash(SIDLibSLDB *dbh, th_md5hash_t hash) { SIDLibSLDBNode keyItem, *key, **item; memcpy(&keyItem.hash, hash, sizeof(th_md5hash_t)); key = &keyItem; - item = bsearch(&key, dbh->pindex, dbh->nnodes, sizeof(dbh->pindex[0]), si_sldb_compare_nodes); + item = bsearch(&key, dbh->pindex, dbh->nnodes, sizeof(dbh->pindex[0]), sidlib_sldb_compare_nodes); return (item != NULL) ? *item : NULL; } diff -r 8db9830e5d97 -r 3a01518fffe0 sidlib.h --- a/sidlib.h Fri Dec 27 11:07:21 2019 +0200 +++ b/sidlib.h Fri Dec 27 11:12:42 2019 +0200 @@ -100,20 +100,20 @@ // // Functions // -BOOL si_read_sid_file(th_ioctx *ctx, PSIDHeader **ppsid, const BOOL newSLDB); -void si_free_sid_file(PSIDHeader *psid); +BOOL sidlib_read_sid_file(th_ioctx *ctx, PSIDHeader **ppsid, const BOOL newSLDB); +void sidlib_free_sid_file(PSIDHeader *psid); -const char * si_get_sid_clock_str(const int flags); -const char * si_get_sid_model_str(const int flags); +const char * sidlib_get_sid_clock_str(const int flags); +const char * sidlib_get_sid_model_str(const int flags); -SIDLibSLDB * si_sldb_new(void); -int si_sldb_read(th_ioctx *ctx, SIDLibSLDB *dbh); -int si_sldb_build_index(SIDLibSLDB *dbh); -void si_sldb_free(SIDLibSLDB *dbh); -SIDLibSLDBNode * si_sldb_get_by_hash(SIDLibSLDB *dbh, th_md5hash_t hash); +SIDLibSLDB * sidlib_sldb_new(void); +int sidlib_sldb_read(th_ioctx *ctx, SIDLibSLDB *dbh); +int sidlib_sldb_build_index(SIDLibSLDB *dbh); +void sidlib_sldb_free(SIDLibSLDB *dbh); +SIDLibSLDBNode * sidlib_sldb_get_by_hash(SIDLibSLDB *dbh, th_md5hash_t hash); -int si_sldb_read_bin(th_ioctx *ctx, SIDLibSLDB *dbh); -int si_sldb_write_bin(th_ioctx *ctx, const SIDLibSLDB *dbh); +int sidlib_sldb_read_bin(th_ioctx *ctx, SIDLibSLDB *dbh); +int sidlib_sldb_write_bin(th_ioctx *ctx, const SIDLibSLDB *dbh); #ifdef __cplusplus