changeset 230:1e860046a4cc

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 03 Jan 2020 13:11:29 +0200
parents 080219f105ce
children bb8ce494267b
files sidinfo.c sidlib.c sidlib.h
diffstat 3 files changed, 15 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/sidinfo.c	Fri Jan 03 12:04:51 2020 +0200
+++ b/sidinfo.c	Fri Jan 03 13:11:29 2020 +0200
@@ -1190,7 +1190,7 @@
     char *npath = th_strdup_printf("%s%c%s%c%s%s",
         setHVSCPath, TH_DIR_SEPARATOR,
         SET_HVSC_DOCUMENTS, TH_DIR_SEPARATOR,
-        filebase, fext);
+        filebase, fext != NULL ? fext : "");
 
     if (npath != NULL &&
         th_stat_path(npath, &sdata) &&
@@ -1206,6 +1206,7 @@
 int main(int argc, char *argv[])
 {
     char *setLang = th_strdup(getenv("LANG"));
+    th_ioctx *inFile = NULL;
 
     // Initialize
     th_init("SIDInfo", "PSID/RSID information displayer", "0.8.0",
@@ -1280,6 +1281,7 @@
         // If SLDB path is not set, autocheck for .md5 and .txt
         if (setSLDBPath == NULL)
             setSLDBPath = siCheckHVSCFilePath(SET_SLDB_FILEBASE, ".md5");
+
         if (setSLDBPath == NULL)
             setSLDBPath = siCheckHVSCFilePath(SET_SLDB_FILEBASE, ".txt");
     }
@@ -1288,7 +1290,6 @@
     {
         // Initialize SLDB
         int ret = THERR_OK;
-        th_ioctx *inFile = NULL;
 
         setSLDBNewFormat = th_strrcasecmp(setSLDBPath, ".md5") != NULL;
 
@@ -1316,7 +1317,6 @@
                 ret, th_error_str(ret));
             goto err;
         }
-        th_io_close(inFile);
 
         if ((ret = sidlib_sldb_build_index(sidSLDB)) != THERR_OK)
         {
@@ -1327,6 +1327,7 @@
 
 err:
         th_io_close(inFile);
+        inFile = NULL;
     }
 
     // Process files
--- a/sidlib.c	Fri Jan 03 12:04:51 2020 +0200
+++ b/sidlib.c	Fri Jan 03 13:11:29 2020 +0200
@@ -8,8 +8,8 @@
 #include "th_string.h"
 
 
-#define SIDLIB_DB_MAGIC "SIDLibDB"
-#define SIDLIB_DB_VERSION 0x0100
+#define SIDLIB_DB_MAGIC     "SIDLibDB"
+#define SIDLIB_DB_VERSION   0x0100
 
 
 typedef struct
@@ -54,18 +54,18 @@
     BOOL ret = FALSE, first = TRUE;
     size_t read;
 
-    if ((data = (uint8_t *) th_malloc(SIDLIB_PSID_BUFFER_SIZE)) == NULL)
+    if ((data = (uint8_t *) th_malloc(SIDLIB_BUFFER_SIZE)) == NULL)
     {
         th_io_error(ctx, THERR_MALLOC,
             "Error allocating temporary data buffer of %d bytes.\n",
-            SIDLIB_PSID_BUFFER_SIZE);
+            SIDLIB_BUFFER_SIZE);
         goto error;
     }
 
     psid->dataSize = 0;
     do
     {
-        read = thfread(data, sizeof(uint8_t), SIDLIB_PSID_BUFFER_SIZE, ctx);
+        read = thfread(data, sizeof(uint8_t), SIDLIB_BUFFER_SIZE, ctx);
         psid->dataSize += read;
 
         // If load address is 0 in header and we have the first block, grab it
@@ -443,15 +443,15 @@
 {
     char *line = NULL;
 
-    if ((line = th_malloc(SIDLIB_PSID_BUFFER_SIZE)) == NULL)
+    if ((line = th_malloc(SIDLIB_BUFFER_SIZE)) == NULL)
     {
         th_io_error(ctx, THERR_MALLOC,
             "Error allocating temporary data buffer of %d bytes.\n",
-            SIDLIB_PSID_BUFFER_SIZE);
+            SIDLIB_BUFFER_SIZE);
         return ctx->status;
     }
 
-    while (thfgets(line, SIDLIB_PSID_BUFFER_SIZE, ctx) != NULL)
+    while (thfgets(line, SIDLIB_BUFFER_SIZE, ctx) != NULL)
     {
         SIDLibSLDBNode *tmnode;
         size_t pos = 0;
--- a/sidlib.h	Fri Jan 03 12:04:51 2020 +0200
+++ b/sidlib.h	Fri Jan 03 13:11:29 2020 +0200
@@ -20,9 +20,9 @@
 //
 // Some constants
 //
-#define SIDLIB_PSID_MAGIC_LEN    4
-#define SIDLIB_PSID_STR_LEN      32
-#define SIDLIB_PSID_BUFFER_SIZE  (1024 * 16)
+#define SIDLIB_PSID_MAGIC_LEN    (4)
+#define SIDLIB_PSID_STR_LEN      (32)
+#define SIDLIB_BUFFER_SIZE       (1024 * 16)
 
 
 enum