diff sidlib.h @ 319:6d0143e43edf

Add functionality and API changes for doing on-the-fly character set conversion of STIL data and PSID header string fields while reading them.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 11 Jan 2020 20:12:00 +0200
parents ee56f1f2b528
children 4978ff445572
line wrap: on
line diff
--- a/sidlib.h	Sat Jan 11 19:11:34 2020 +0200
+++ b/sidlib.h	Sat Jan 11 20:12:00 2020 +0200
@@ -84,7 +84,7 @@
 typedef struct
 {
     int ndata;
-    char **data;
+    char **data;  // Converted through SIDLibChConvCtx if conversion is used
 } SIDLibSTILField;
 
 
@@ -99,9 +99,11 @@
 {
     th_llist_t node;
 
-    char *filename; // HVSC path/filename
+    char *filename;    // HVSC path/filename (NOT converted through SIDLibChConvCtx)
     size_t nsubtunes;  // Number of subtune information structures
-    SIDLibSTILSubTune *subtunes;
+    SIDLibSTILSubTune *subtunes; // NOTE! Subtunes are in undefined order here
+        // (through with correct SIDLibSTILSubTune::tune number, of course)
+        // unless sidlib_stildb_build_index() has been run on the SIDLibSTILDB
 
     // Internal use only
     SIDLibSLDBNode *lengths;
@@ -127,8 +129,9 @@
         nSongs,          // Number of subsongs
         startSong;       // Default starting song
     uint32_t speed;      // Speed
+
     char *sidName;       // Descriptive text-fields, ASCIIZ
-    char *sidAuthor;
+    char *sidAuthor;     // Converted through SIDLibChConvCtx if conversion is used
     char *sidCopyright;
 
     // PSIDv2+ data
@@ -148,16 +151,24 @@
 } SIDLibPSIDHeader;
 
 
+typedef struct SIDLibChConvCtx
+{
+    void *data;
+    char* (*convert)(struct SIDLibChConvCtx *ctx, const char *str);
+} SIDLibChConvCtx;
+
+
 //
 // Globals
 //
-const char *sidlib_stil_fields[STF_LAST];
+const char *     sidlib_stil_fields[STF_LAST];
+
 
 //
 // Functions
 //
-int              sidlib_read_sid_file(th_ioctx *ctx, SIDLibPSIDHeader *psid, const BOOL newSLDB);
-int              sidlib_read_sid_file_alloc(th_ioctx *ctx, SIDLibPSIDHeader **ppsid, const BOOL newSLDB);
+int              sidlib_read_sid_file(th_ioctx *ctx, SIDLibPSIDHeader *psid, const BOOL newSLDB, SIDLibChConvCtx *chconv);
+int              sidlib_read_sid_file_alloc(th_ioctx *ctx, SIDLibPSIDHeader **ppsid, const BOOL newSLDB, SIDLibChConvCtx *chconv);
 void             sidlib_free_sid_file(SIDLibPSIDHeader *psid);
 
 const char *     sidlib_get_sid_clock_str(const int flags);
@@ -170,7 +181,7 @@
 SIDLibSLDBNode * sidlib_sldb_get_by_hash(SIDLibSLDB *dbh, th_md5hash_t hash);
 
 int              sidlib_stildb_new(SIDLibSTILDB **pdbh);
-int              sidlib_stildb_read(th_ioctx *ctx, SIDLibSTILDB *dbh);
+int              sidlib_stildb_read(th_ioctx *ctx, SIDLibSTILDB *dbh, SIDLibChConvCtx *chconv);
 int              sidlib_stildb_build_index(SIDLibSTILDB *dbh);
 void             sidlib_stildb_free(SIDLibSTILDB *dbh);
 SIDLibSTILNode * sidlib_stildb_get_node(SIDLibSTILDB *dbh, const char *filename);