# HG changeset patch # User Matti Hamalainen # Date 1578916363 -7200 # Node ID 7ad937740139b845e932626932e7b961ec6f676b # Parent 5c2e77ec45e88af266d21cbbf795625260e5a683 Change how --help option is handled and show currently set HVSC/SLDB/STIL path information in --help. diff -r 5c2e77ec45e8 -r 7ad937740139 sidinfo.c --- a/sidinfo.c Mon Jan 13 13:40:49 2020 +0200 +++ b/sidinfo.c Mon Jan 13 13:52:43 2020 +0200 @@ -103,7 +103,8 @@ optFieldNamePrefix = TRUE, optHexadecimal = FALSE, optFieldOutput = TRUE, - optRecurseDirs = FALSE; + optRecurseDirs = FALSE, + optShowHelp = FALSE; char *optOneLineFieldSep = NULL, *optEscapeChars = NULL; int optNFiles = 0; @@ -183,7 +184,15 @@ "as STIL.txt and Songlengths.(txt|md5) will be automatically used from there.\n" "You can also set it via HVSC_BASE environment variable, see README.\n" "\n" - , th_prog_name); + "HVSC path : %s\n" + "SLDB file : %s\n" + "STIL file : %s\n" + "\n", + th_prog_name, + setHVSCPath != NULL ? setHVSCPath : "[not set]", + setSLDBPath != NULL ? setSLDBPath : "[not set]", + setSTILDBPath != NULL ? setSTILDBPath : "[not set]" + ); } @@ -633,8 +642,7 @@ switch (optN) { case 0: - argShowHelp(); - exit(0); + optShowHelp = TRUE; break; case 1: @@ -1165,6 +1173,36 @@ memset(&optFormat, 0, sizeof(optFormat)); memset(&setChConv, 0, sizeof(setChConv)); + // Parse command line arguments + if (!th_args_process(argc, argv, optList, optListN, + argHandleOpt, NULL, OPTH_ONLY_OPTS)) + goto exit; + + // Check if HVSC path is set + if (setHVSCPath != NULL) + { + // Ensure that there is a path separator at the end + if (th_strrcasecmp(setHVSCPath, TH_DIR_SEPARATOR_STR) == NULL) + th_pstr_printf(&setHVSCPath, "%s%c", setHVSCPath, TH_DIR_SEPARATOR_CHR); + + // If SLDB path is not set, autocheck for .md5 and .txt + if (setSLDBPath == NULL) + setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".md5"); + + if (setSLDBPath == NULL) + setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".txt"); + + if (setSTILDBPath == NULL) + setSTILDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_STILDB_FILENAME, NULL); + } + + // Check if help is requested + if (optShowHelp) + { + argShowHelp(); + goto exit; + } + // Initialize character set conversion if ((ret = sidutil_chconv_init(&setChConv, setLang)) != THERR_OK) { @@ -1172,14 +1210,10 @@ setLang, th_error_str(ret)); } - // Parse command line arguments - if (!th_args_process(argc, argv, optList, optListN, - argHandleOpt, NULL, OPTH_ONLY_OPTS)) - goto exit; - THMSG(2, "Requested output LANG='%s', use charset conversion=%s\n", setChConv.outLang, setChConv.enabled ? "yes" : "no"); + // Check operation mode if (optOneLineFieldSep != NULL || (!optFieldOutput && optFormat.nitems > 0)) { @@ -1206,24 +1240,7 @@ } } - // Check if HVSC path is set - if (setHVSCPath != NULL) - { - // Ensure that there is a path separator at the end - if (th_strrcasecmp(setHVSCPath, TH_DIR_SEPARATOR_STR) == NULL) - th_pstr_printf(&setHVSCPath, "%s%c", setHVSCPath, TH_DIR_SEPARATOR_CHR); - - // If SLDB path is not set, autocheck for .md5 and .txt - if (setSLDBPath == NULL) - setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".md5"); - - if (setSLDBPath == NULL) - setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".txt"); - - if (setSTILDBPath == NULL) - setSTILDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_STILDB_FILENAME, NULL); - } - + // Read SLDB and STILDB if (setSLDBPath != NULL) { // Initialize SLDB