Mercurial > hg > sidinfo
changeset 301:86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 09 Jan 2020 22:44:58 +0200 |
parents | 85d92bcbebf3 |
children | c478b35ee388 |
files | sidinfo.c |
diffstat | 1 files changed, 24 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/sidinfo.c Thu Jan 09 22:44:20 2020 +0200 +++ b/sidinfo.c Thu Jan 09 22:44:58 2020 +0200 @@ -997,12 +997,12 @@ } -static void siPrintFieldSeparator(FILE *outFile, const BOOL multifield) +static void siPrintFieldSeparator(FILE *outFile, const BOOL multifield, const BOOL last) { if (optFieldOutput) fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : "\n", outFile); else - if (multifield) + if (multifield && !last) fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : ", ", outFile); } @@ -1058,13 +1058,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, FALSE); \ + siPrintFieldSeparator(outFile, FALSE, TRUE); \ } 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, FALSE); \ + siPrintFieldSeparator(outFile, FALSE, TRUE); \ } while (0) @@ -1167,18 +1167,30 @@ tmp, -1, FALSE); } - siPrintFieldSeparator(outFile, FALSE); + siPrintFieldSeparator(outFile, FALSE, TRUE); } break; case 23: if (psid->stil != NULL) - for (int nsubtune = 0; nsubtune < psid->stil->nsubtunes; nsubtune++) { - SIDLibSTILSubTune *node = psid->stil->subtunes[nsubtune]; - if (node != NULL) + int nfieldn = 0, nfieldcount = 0; + + // We need to count the number of fields to be outputted + // beforehand, so we can know when we are at the last one + for (int nsubtune = 0; nsubtune < psid->stil->nsubtunes; nsubtune++) { + SIDLibSTILSubTune *node = psid->stil->subtunes[nsubtune]; + for (int nfield = 0; nfield < STF_LAST; nfield++) + nfieldcount += node->fields[nfield].ndata; + } + + for (int nsubtune = 0; nsubtune < psid->stil->nsubtunes; nsubtune++) + { + SIDLibSTILSubTune *node = psid->stil->subtunes[nsubtune]; int maxdata = 0; + + // For each subtune we need to check the max number of field data items for (int nfield = 0; nfield < STF_LAST; nfield++) { SIDLibSTILField *fld = &node->fields[nfield]; @@ -1186,6 +1198,7 @@ maxdata = fld->ndata; } + // Now output the items in field order for (int nitem = 0; nitem < maxdata; nitem++) for (int nfield = 0; nfield < STF_LAST; nfield++) { @@ -1209,7 +1222,9 @@ OTYPE_STR, fld->data[nitem], -1, TRUE); - siPrintFieldSeparator(outFile, TRUE); + + siPrintFieldSeparator(outFile, TRUE, + ++nfieldn >= nfieldcount); } } }