# HG changeset patch # User Matti Hamalainen # Date 1578440269 -7200 # Node ID 514d861516b03df36471d61bbd9bdc772cadbcb3 # Parent 08695f046565871721606abadceadf8a204df36e Further work on the STIL fields output format. It's not perfect, nor controllable, but I believe it is better now. Some further formatting control of multi-field and sub-tune STIL information is available now via -l and -n options when -F format string is being used. diff -r 08695f046565 -r 514d861516b0 sidinfo.c --- a/sidinfo.c Tue Jan 07 12:28:48 2020 +0200 +++ b/sidinfo.c Wed Jan 08 01:37:49 2020 +0200 @@ -120,7 +120,7 @@ *setSTILDBPath = NULL; BOOL setSLDBNewFormat = FALSE, optParsable = FALSE, - optNoNamePrefix = FALSE, + optFieldNamePrefix = TRUE, optHexadecimal = FALSE, optFieldOutput = TRUE, optRecurseDirs = FALSE; @@ -867,7 +867,7 @@ break; case 5: - optNoNamePrefix = TRUE; + optFieldNamePrefix = FALSE; break; case 6: @@ -967,24 +967,34 @@ } -static void siPrintFieldPrefixName(FILE *outFile, const char *name) +static void siPrintFieldPrefixName(FILE *outFile, const char *name, const BOOL multifield) { - if (!optNoNamePrefix && optFieldOutput) - fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name); + if (optFieldNamePrefix) + { + if (optFieldOutput && optOneLineFieldSep == NULL) + fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name); + else + if (multifield) + fprintf(outFile, "[%s] ", name); + } } static void siPrintFieldPrefix(FILE *outFile, const PSFOption *opt) { siPrintFieldPrefixName(outFile, - (optParsable || opt->lname == NULL) ? opt->name : opt->lname); + (optParsable || opt->lname == NULL) ? opt->name : opt->lname, + FALSE); } -static void siPrintFieldSeparator(FILE *outFile) +static void siPrintFieldSeparator(FILE *outFile, const BOOL multifield) { if (optFieldOutput) fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : "\n", outFile); + else + if (multifield) + fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : ", ", outFile); } @@ -1039,13 +1049,13 @@ #define PRS(d_str, d_conv) do { \ siPrintFieldPrefix(outFile, opt); \ siPrintPSIDInfoLine(outFile, shown, siGetInfoFormat(item, opt->type), opt->type, d_str, -1, d_conv); \ - siPrintFieldSeparator(outFile); \ + siPrintFieldSeparator(outFile, FALSE); \ } while (0) #define PRI(d_int) do { \ siPrintFieldPrefix(outFile, opt); \ siPrintPSIDInfoLine(outFile, shown, siGetInfoFormat(item, opt->type), opt->type, NULL, d_int, FALSE); \ - siPrintFieldSeparator(outFile); \ + siPrintFieldSeparator(outFile, FALSE); \ } while (0) @@ -1148,7 +1158,7 @@ tmp, -1, FALSE); } - siPrintFieldSeparator(outFile); + siPrintFieldSeparator(outFile, FALSE); } break; @@ -1159,27 +1169,39 @@ SIDLibSTILSubTune *node = psid->stil->subtunes[nsubtune]; if (node != NULL) { + int maxdata = 0; for (int nfield = 0; nfield < STF_LAST; nfield++) - for (int nitem = 0; nitem < node->fields[nfield].ndata; nitem++) { - if (nsubtune > 0) - { - snprintf(tmp, sizeof(tmp), "STIL#%d/%s", - nsubtune, sidlib_stil_fields[nfield]); - } - else + SIDLibSTILField *fld = &node->fields[nfield]; + if (fld->ndata > maxdata) + maxdata = fld->ndata; + } + + for (int nitem = 0; nitem < maxdata; nitem++) + for (int nfield = 0; nfield < STF_LAST; nfield++) + { + SIDLibSTILField *fld = &node->fields[nfield]; + if (nitem < fld->ndata) { - snprintf(tmp, sizeof(tmp), "STIL/%s", - sidlib_stil_fields[nfield]); - } + if (nsubtune > 0) + { + snprintf(tmp, sizeof(tmp), "STIL#%d/%s", + nsubtune, sidlib_stil_fields[nfield]); + } + else + { + snprintf(tmp, sizeof(tmp), "STIL/%s", + sidlib_stil_fields[nfield]); + } - siPrintFieldPrefixName(outFile, tmp); - siPrintPSIDInfoLine(outFile, shown, - siGetInfoFormat(item, OTYPE_STR), - OTYPE_STR, - node->fields[nfield].data[nitem], - -1, TRUE); - siPrintFieldSeparator(outFile); + siPrintFieldPrefixName(outFile, tmp, TRUE); + siPrintPSIDInfoLine(outFile, shown, + siGetInfoFormat(item, OTYPE_STR), + OTYPE_STR, + fld->data[nitem], + -1, TRUE); + siPrintFieldSeparator(outFile, TRUE); + } } } } @@ -1442,9 +1464,8 @@ if (optOneLineFieldSep != NULL) { - // For one-line format, disable parsing and prefixes + // For one-line format, disable parsable and prefixes optParsable = FALSE; - optNoNamePrefix = TRUE; // If no escape chars have been set, use the field separator(s) if (optEscapeChars == NULL)