comparison sidinfo.c @ 230:1e860046a4cc

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 03 Jan 2020 13:11:29 +0200
parents 080219f105ce
children 1c004e74d0ad
comparison
equal deleted inserted replaced
229:080219f105ce 230:1e860046a4cc
1188 { 1188 {
1189 th_stat_data sdata; 1189 th_stat_data sdata;
1190 char *npath = th_strdup_printf("%s%c%s%c%s%s", 1190 char *npath = th_strdup_printf("%s%c%s%c%s%s",
1191 setHVSCPath, TH_DIR_SEPARATOR, 1191 setHVSCPath, TH_DIR_SEPARATOR,
1192 SET_HVSC_DOCUMENTS, TH_DIR_SEPARATOR, 1192 SET_HVSC_DOCUMENTS, TH_DIR_SEPARATOR,
1193 filebase, fext); 1193 filebase, fext != NULL ? fext : "");
1194 1194
1195 if (npath != NULL && 1195 if (npath != NULL &&
1196 th_stat_path(npath, &sdata) && 1196 th_stat_path(npath, &sdata) &&
1197 (sdata.flags & TH_IS_READABLE) && 1197 (sdata.flags & TH_IS_READABLE) &&
1198 (sdata.flags & TH_IS_DIR) == 0) 1198 (sdata.flags & TH_IS_DIR) == 0)
1204 1204
1205 1205
1206 int main(int argc, char *argv[]) 1206 int main(int argc, char *argv[])
1207 { 1207 {
1208 char *setLang = th_strdup(getenv("LANG")); 1208 char *setLang = th_strdup(getenv("LANG"));
1209 th_ioctx *inFile = NULL;
1209 1210
1210 // Initialize 1211 // Initialize
1211 th_init("SIDInfo", "PSID/RSID information displayer", "0.8.0", 1212 th_init("SIDInfo", "PSID/RSID information displayer", "0.8.0",
1212 "By Matti 'ccr' Hamalainen (C) Copyright 2014-2020 TNSP", 1213 "By Matti 'ccr' Hamalainen (C) Copyright 2014-2020 TNSP",
1213 "This program is distributed under a 3-clause BSD -style license."); 1214 "This program is distributed under a 3-clause BSD -style license.");
1278 if (setHVSCPath != NULL) 1279 if (setHVSCPath != NULL)
1279 { 1280 {
1280 // If SLDB path is not set, autocheck for .md5 and .txt 1281 // If SLDB path is not set, autocheck for .md5 and .txt
1281 if (setSLDBPath == NULL) 1282 if (setSLDBPath == NULL)
1282 setSLDBPath = siCheckHVSCFilePath(SET_SLDB_FILEBASE, ".md5"); 1283 setSLDBPath = siCheckHVSCFilePath(SET_SLDB_FILEBASE, ".md5");
1284
1283 if (setSLDBPath == NULL) 1285 if (setSLDBPath == NULL)
1284 setSLDBPath = siCheckHVSCFilePath(SET_SLDB_FILEBASE, ".txt"); 1286 setSLDBPath = siCheckHVSCFilePath(SET_SLDB_FILEBASE, ".txt");
1285 } 1287 }
1286 1288
1287 if (setSLDBPath != NULL) 1289 if (setSLDBPath != NULL)
1288 { 1290 {
1289 // Initialize SLDB 1291 // Initialize SLDB
1290 int ret = THERR_OK; 1292 int ret = THERR_OK;
1291 th_ioctx *inFile = NULL;
1292 1293
1293 setSLDBNewFormat = th_strrcasecmp(setSLDBPath, ".md5") != NULL; 1294 setSLDBNewFormat = th_strrcasecmp(setSLDBPath, ".md5") != NULL;
1294 1295
1295 if ((ret = th_io_fopen(&inFile, &th_stdio_io_ops, setSLDBPath, "r")) != THERR_OK) 1296 if ((ret = th_io_fopen(&inFile, &th_stdio_io_ops, setSLDBPath, "r")) != THERR_OK)
1296 { 1297 {
1314 { 1315 {
1315 THERR("Error parsing SLDB: %d, %s\n", 1316 THERR("Error parsing SLDB: %d, %s\n",
1316 ret, th_error_str(ret)); 1317 ret, th_error_str(ret));
1317 goto err; 1318 goto err;
1318 } 1319 }
1319 th_io_close(inFile);
1320 1320
1321 if ((ret = sidlib_sldb_build_index(sidSLDB)) != THERR_OK) 1321 if ((ret = sidlib_sldb_build_index(sidSLDB)) != THERR_OK)
1322 { 1322 {
1323 THERR("Error building SLDB index: %d, %s.\n", 1323 THERR("Error building SLDB index: %d, %s.\n",
1324 ret, th_error_str(ret)); 1324 ret, th_error_str(ret));
1325 goto err; 1325 goto err;
1326 } 1326 }
1327 1327
1328 err: 1328 err:
1329 th_io_close(inFile); 1329 th_io_close(inFile);
1330 inFile = NULL;
1330 } 1331 }
1331 1332
1332 // Process files 1333 // Process files
1333 if (!th_args_process(argc, argv, optList, optListN, 1334 if (!th_args_process(argc, argv, optList, optListN,
1334 NULL, argHandleFile, OPTH_ONLY_OTHER)) 1335 NULL, argHandleFile, OPTH_ONLY_OTHER))