# HG changeset patch # User Matti Hamalainen # Date 1578614689 -7200 # Node ID 04502257ccdf1b61bbcb7b8beef2e1a749145f02 # Parent 696e93dd7ecc5e4d309f0199f6b205a168097f80 Add default formats for certain fields, but use them only for the standard output and not for parsable output. diff -r 696e93dd7ecc -r 04502257ccdf sidinfo.c --- a/sidinfo.c Thu Jan 09 23:29:15 2020 +0200 +++ b/sidinfo.c Fri Jan 10 02:04:49 2020 +0200 @@ -75,40 +75,42 @@ char *name; char *lname; int type; + char *dfmt; } PSFOption; +#define HEX_ADDR "%d ($%04x)" + static const PSFOption optPSOptions[] = { - { "Filename" , NULL , OTYPE_STR }, - { "Type" , NULL , OTYPE_STR }, - { "Version" , NULL , OTYPE_STR }, - { "PlayerType" , "Player type" , OTYPE_STR }, - { "PlayerCompat" , "Player compatibility" , OTYPE_STR }, - { "VideoClock" , "Video clock speed" , OTYPE_STR }, - { "SIDModel" , "SID model" , OTYPE_STR }, + { "Filename" , NULL , OTYPE_STR , NULL }, + { "Type" , NULL , OTYPE_STR , NULL }, + { "Version" , NULL , OTYPE_STR , NULL }, + { "PlayerType" , "Player type" , OTYPE_STR , NULL }, + { "PlayerCompat" , "Player compatibility" , OTYPE_STR , NULL }, + { "VideoClock" , "Video clock speed" , OTYPE_STR , NULL }, + { "SIDModel" , "SID model" , OTYPE_STR , NULL }, - { "DataOffs" , "Data offset" , OTYPE_INT }, - { "DataSize" , "Data size" , OTYPE_INT }, - { "LoadAddr" , "Load address" , OTYPE_INT }, - { "InitAddr" , "Init address" , OTYPE_INT }, - { "PlayAddr" , "Play address" , OTYPE_INT }, - { "Songs" , "Songs" , OTYPE_INT }, - { "StartSong" , "Start song" , OTYPE_INT }, + { "DataOffs" , "Data offset" , OTYPE_INT , HEX_ADDR }, + { "DataSize" , "Data size" , OTYPE_INT , HEX_ADDR }, + { "LoadAddr" , "Load address" , OTYPE_INT , HEX_ADDR }, + { "InitAddr" , "Init address" , OTYPE_INT , HEX_ADDR }, + { "PlayAddr" , "Play address" , OTYPE_INT , HEX_ADDR }, + { "Songs" , "Songs" , OTYPE_INT , "%d" }, + { "StartSong" , "Start song" , OTYPE_INT , "%d" }, - { "SID2Model" , "2nd SID model" , OTYPE_STR }, - { "SID3Model" , "3rd SID model" , OTYPE_STR }, - { "SID2Addr" , "2nd SID address" , OTYPE_INT }, - { "SID3Addr" , "3rd SID address" , OTYPE_INT }, + { "SID2Model" , "2nd SID model" , OTYPE_STR , NULL }, + { "SID3Model" , "3rd SID model" , OTYPE_STR , NULL }, + { "SID2Addr" , "2nd SID address" , OTYPE_INT , HEX_ADDR }, + { "SID3Addr" , "3rd SID address" , OTYPE_INT , HEX_ADDR }, - { "Name" , NULL , OTYPE_STR }, - { "Author" , NULL , OTYPE_STR }, - { "Copyright" , NULL , OTYPE_STR }, - { "Hash" , NULL , OTYPE_STR }, + { "Name" , NULL , OTYPE_STR , NULL }, + { "Author" , NULL , OTYPE_STR , NULL }, + { "Copyright" , NULL , OTYPE_STR , NULL }, + { "Hash" , NULL , OTYPE_STR , NULL }, - { "Songlengths" , "Song lengths" , OTYPE_OTHER }, - - { "STIL" , "STIL information" , OTYPE_OTHER }, + { "Songlengths" , "Song lengths" , OTYPE_OTHER , NULL }, + { "STIL" , "STIL information" , OTYPE_OTHER , NULL }, }; static const int noptPSOptions = sizeof(optPSOptions) / sizeof(optPSOptions[0]); @@ -378,6 +380,7 @@ memset(&item, 0, sizeof(item)); item.cmd = found; + item.fmt = th_strdup(optPSOptions[found].dfmt); if (!siStackAddItem(stack, &item)) return FALSE; @@ -885,6 +888,7 @@ case 7: optFieldOutput = FALSE; + optParsable = FALSE; if (!argParsePSFormatStr(&optFormat, optArg)) return FALSE; break; @@ -1012,13 +1016,13 @@ switch (otype) { case OTYPE_INT: - if (item->flags & OFMT_FORMAT) + if (!optParsable && item->fmt != NULL) return item->fmt; else return optHexadecimal ? "$%04x" : "%d"; case OTYPE_STR: - if (item->flags & OFMT_FORMAT) + if (!optParsable && item->fmt != NULL) return item->fmt; else return "%s"; @@ -1488,9 +1492,10 @@ THMSG(2, "Requested output LANG='%s', use charset conversion=%s\n", setLang, setUseOutConv ? "yes" : "no"); - if (optOneLineFieldSep != NULL) + if (optOneLineFieldSep != NULL || + (!optFieldOutput && optFormat.nitems > 0)) { - // For one-line format, disable parsable and prefixes + // For one-line format and formatted output (-F), disable parsable optParsable = FALSE; // If no escape chars have been set, use the field separator(s) @@ -1501,14 +1506,14 @@ if (optFieldOutput && optFormat.nitems == 0) { // For standard field output, push standard items to format stack - PSFStackItem item; - - memset(&item, 0, sizeof(item)); siClearStack(&optFormat); for (int i = 0; i < noptPSOptions; i++) { + PSFStackItem item; + memset(&item, 0, sizeof(item)); item.cmd = i; + item.fmt = th_strdup(optPSOptions[i].dfmt); siStackAddItem(&optFormat, &item); } }