comparison sidinfo.c @ 337:7ad937740139

Change how --help option is handled and show currently set HVSC/SLDB/STIL path information in --help.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 13 Jan 2020 13:52:43 +0200
parents 5c2e77ec45e8
children 923e63b9653b
comparison
equal deleted inserted replaced
336:5c2e77ec45e8 337:7ad937740139
101 BOOL setSLDBNewFormat = FALSE, 101 BOOL setSLDBNewFormat = FALSE,
102 optParsable = FALSE, 102 optParsable = FALSE,
103 optFieldNamePrefix = TRUE, 103 optFieldNamePrefix = TRUE,
104 optHexadecimal = FALSE, 104 optHexadecimal = FALSE,
105 optFieldOutput = TRUE, 105 optFieldOutput = TRUE,
106 optRecurseDirs = FALSE; 106 optRecurseDirs = FALSE,
107 optShowHelp = FALSE;
107 char *optOneLineFieldSep = NULL, 108 char *optOneLineFieldSep = NULL,
108 *optEscapeChars = NULL; 109 *optEscapeChars = NULL;
109 int optNFiles = 0; 110 int optNFiles = 0;
110 111
111 PSFStack optFormat; 112 PSFStack optFormat;
181 "\n" 182 "\n"
182 "TIP: When specifying HVSC paths, it is preferable to use -H/--hvsc option,\n" 183 "TIP: When specifying HVSC paths, it is preferable to use -H/--hvsc option,\n"
183 "as STIL.txt and Songlengths.(txt|md5) will be automatically used from there.\n" 184 "as STIL.txt and Songlengths.(txt|md5) will be automatically used from there.\n"
184 "You can also set it via HVSC_BASE environment variable, see README.\n" 185 "You can also set it via HVSC_BASE environment variable, see README.\n"
185 "\n" 186 "\n"
186 , th_prog_name); 187 "HVSC path : %s\n"
188 "SLDB file : %s\n"
189 "STIL file : %s\n"
190 "\n",
191 th_prog_name,
192 setHVSCPath != NULL ? setHVSCPath : "[not set]",
193 setSLDBPath != NULL ? setSLDBPath : "[not set]",
194 setSTILDBPath != NULL ? setSTILDBPath : "[not set]"
195 );
187 } 196 }
188 197
189 198
190 int argMatchPSField(const char *field) 199 int argMatchPSField(const char *field)
191 { 200 {
631 static BOOL argHandleOpt(const int optN, char *optArg, char *currArg) 640 static BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
632 { 641 {
633 switch (optN) 642 switch (optN)
634 { 643 {
635 case 0: 644 case 0:
636 argShowHelp(); 645 optShowHelp = TRUE;
637 exit(0);
638 break; 646 break;
639 647
640 case 1: 648 case 1:
641 sidutil_print_license(); 649 sidutil_print_license();
642 exit(0); 650 exit(0);
1163 th_verbosity = 0; 1171 th_verbosity = 0;
1164 1172
1165 memset(&optFormat, 0, sizeof(optFormat)); 1173 memset(&optFormat, 0, sizeof(optFormat));
1166 memset(&setChConv, 0, sizeof(setChConv)); 1174 memset(&setChConv, 0, sizeof(setChConv));
1167 1175
1168 // Initialize character set conversion
1169 if ((ret = sidutil_chconv_init(&setChConv, setLang)) != THERR_OK)
1170 {
1171 THERR("Could not initialize character set conversion (LANG='%s'): %s\n",
1172 setLang, th_error_str(ret));
1173 }
1174
1175 // Parse command line arguments 1176 // Parse command line arguments
1176 if (!th_args_process(argc, argv, optList, optListN, 1177 if (!th_args_process(argc, argv, optList, optListN,
1177 argHandleOpt, NULL, OPTH_ONLY_OPTS)) 1178 argHandleOpt, NULL, OPTH_ONLY_OPTS))
1178 goto exit; 1179 goto exit;
1179 1180
1181 // Check if HVSC path is set
1182 if (setHVSCPath != NULL)
1183 {
1184 // Ensure that there is a path separator at the end
1185 if (th_strrcasecmp(setHVSCPath, TH_DIR_SEPARATOR_STR) == NULL)
1186 th_pstr_printf(&setHVSCPath, "%s%c", setHVSCPath, TH_DIR_SEPARATOR_CHR);
1187
1188 // If SLDB path is not set, autocheck for .md5 and .txt
1189 if (setSLDBPath == NULL)
1190 setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".md5");
1191
1192 if (setSLDBPath == NULL)
1193 setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".txt");
1194
1195 if (setSTILDBPath == NULL)
1196 setSTILDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_STILDB_FILENAME, NULL);
1197 }
1198
1199 // Check if help is requested
1200 if (optShowHelp)
1201 {
1202 argShowHelp();
1203 goto exit;
1204 }
1205
1206 // Initialize character set conversion
1207 if ((ret = sidutil_chconv_init(&setChConv, setLang)) != THERR_OK)
1208 {
1209 THERR("Could not initialize character set conversion (LANG='%s'): %s\n",
1210 setLang, th_error_str(ret));
1211 }
1212
1180 THMSG(2, "Requested output LANG='%s', use charset conversion=%s\n", 1213 THMSG(2, "Requested output LANG='%s', use charset conversion=%s\n",
1181 setChConv.outLang, setChConv.enabled ? "yes" : "no"); 1214 setChConv.outLang, setChConv.enabled ? "yes" : "no");
1182 1215
1216 // Check operation mode
1183 if (optOneLineFieldSep != NULL || 1217 if (optOneLineFieldSep != NULL ||
1184 (!optFieldOutput && optFormat.nitems > 0)) 1218 (!optFieldOutput && optFormat.nitems > 0))
1185 { 1219 {
1186 // For one-line format and formatted output (-F), disable parsable 1220 // For one-line format and formatted output (-F), disable parsable
1187 optParsable = FALSE; 1221 optParsable = FALSE;
1204 item.fmt = th_strdup(optPSOptions[i].dfmt); 1238 item.fmt = th_strdup(optPSOptions[i].dfmt);
1205 siStackAddItem(&optFormat, &item); 1239 siStackAddItem(&optFormat, &item);
1206 } 1240 }
1207 } 1241 }
1208 1242
1209 // Check if HVSC path is set 1243 // Read SLDB and STILDB
1210 if (setHVSCPath != NULL)
1211 {
1212 // Ensure that there is a path separator at the end
1213 if (th_strrcasecmp(setHVSCPath, TH_DIR_SEPARATOR_STR) == NULL)
1214 th_pstr_printf(&setHVSCPath, "%s%c", setHVSCPath, TH_DIR_SEPARATOR_CHR);
1215
1216 // If SLDB path is not set, autocheck for .md5 and .txt
1217 if (setSLDBPath == NULL)
1218 setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".md5");
1219
1220 if (setSLDBPath == NULL)
1221 setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".txt");
1222
1223 if (setSTILDBPath == NULL)
1224 setSTILDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_STILDB_FILENAME, NULL);
1225 }
1226
1227 if (setSLDBPath != NULL) 1244 if (setSLDBPath != NULL)
1228 { 1245 {
1229 // Initialize SLDB 1246 // Initialize SLDB
1230 setSLDBNewFormat = th_strrcasecmp(setSLDBPath, ".md5") != NULL; 1247 setSLDBNewFormat = th_strrcasecmp(setSLDBPath, ".md5") != NULL;
1231 1248