Mercurial > hg > sidinfo
annotate sidinfo.c @ 409:5a27c0fbbf20 default tip
Added tag rel-1_0_1 for changeset f18129e65b6f
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 20 Dec 2023 08:08:38 +0200 |
parents | f18129e65b6f |
children |
rev | line source |
---|---|
2 | 1 /* |
2 * SIDInfo - PSID/RSID information displayer | |
171
d86ade7d0dfd
Change copyright blurbs slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
169
diff
changeset
|
3 * Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
404 | 4 * (C) Copyright 2014-2023 Tecnic Software productions (TNSP) |
2 | 5 */ |
0 | 6 #include "th_args.h" |
2 | 7 #include "th_string.h" |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
8 #include "th_file.h" |
176
2e890e3d5684
Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
9 #include "th_datastruct.h" |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
10 #include "sidlib.h" |
313
b3d46806787d
Move a number of more or less generic helper functions into a separate sidutil.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
11 #include "sidutil.h" |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
12 #include <sys/types.h> |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
13 #include <dirent.h> |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
14 |
0 | 15 |
229 | 16 // |
28 | 17 // Some constants |
229 | 18 // |
112
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
19 enum |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
20 { |
157
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
21 OFMT_QUOTED = 0x0001, |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
22 OFMT_FORMAT = 0x0002, |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
23 }; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
24 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
25 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
26 enum |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
27 { |
112
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
28 OTYPE_OTHER = 0, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
29 OTYPE_STR = 1, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
30 OTYPE_INT = 2, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
31 }; |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
32 |
0 | 33 |
34 typedef struct | |
35 { | |
63 | 36 int cmd; |
37 char *str; | |
38 char chr; | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
39 int flags; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
40 char *fmt; |
63 | 41 } PSFStackItem; |
42 | |
43 | |
44 typedef struct | |
45 { | |
46 int nitems, nallocated; | |
47 PSFStackItem *items; | |
48 } PSFStack; | |
49 | |
50 | |
51 typedef struct | |
52 { | |
2 | 53 char *name; |
54 char *lname; | |
112
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
55 int type; |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
56 char *dfmt; |
2 | 57 } PSFOption; |
58 | |
59 | |
314
71139ed7e43f
Rename #define HEX_ADDR to more informative SET_FMT_HEX_ADDR.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
60 #define SET_FMT_HEX_ADDR "%d ($%04x)" |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
61 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
62 static const PSFOption optPSOptions[] = |
2 | 63 { |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
64 { "Filename" , NULL , OTYPE_STR , NULL }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
65 { "Type" , NULL , OTYPE_STR , NULL }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
66 { "Version" , NULL , OTYPE_STR , NULL }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
67 { "PlayerType" , "Player type" , OTYPE_STR , NULL }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
68 { "PlayerCompat" , "Player compatibility" , OTYPE_STR , NULL }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
69 { "VideoClock" , "Video clock speed" , OTYPE_STR , NULL }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
70 { "SIDModel" , "SID model" , OTYPE_STR , NULL }, |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
71 |
314
71139ed7e43f
Rename #define HEX_ADDR to more informative SET_FMT_HEX_ADDR.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
72 { "DataOffs" , "Data offset" , OTYPE_INT , SET_FMT_HEX_ADDR }, |
71139ed7e43f
Rename #define HEX_ADDR to more informative SET_FMT_HEX_ADDR.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
73 { "DataSize" , "Data size" , OTYPE_INT , SET_FMT_HEX_ADDR }, |
71139ed7e43f
Rename #define HEX_ADDR to more informative SET_FMT_HEX_ADDR.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
74 { "LoadAddr" , "Load address" , OTYPE_INT , SET_FMT_HEX_ADDR }, |
71139ed7e43f
Rename #define HEX_ADDR to more informative SET_FMT_HEX_ADDR.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
75 { "InitAddr" , "Init address" , OTYPE_INT , SET_FMT_HEX_ADDR }, |
71139ed7e43f
Rename #define HEX_ADDR to more informative SET_FMT_HEX_ADDR.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
76 { "PlayAddr" , "Play address" , OTYPE_INT , SET_FMT_HEX_ADDR }, |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
77 { "Songs" , "Songs" , OTYPE_INT , "%d" }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
78 { "StartSong" , "Start song" , OTYPE_INT , "%d" }, |
28 | 79 |
376
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
80 { "StartPage" , "Start page" , OTYPE_INT , SET_FMT_HEX_ADDR }, |
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
81 { "PageLength" , "Page length" , OTYPE_INT , SET_FMT_HEX_ADDR }, |
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
82 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
83 { "SID2Model" , "2nd SID model" , OTYPE_STR , NULL }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
84 { "SID3Model" , "3rd SID model" , OTYPE_STR , NULL }, |
314
71139ed7e43f
Rename #define HEX_ADDR to more informative SET_FMT_HEX_ADDR.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
85 { "SID2Addr" , "2nd SID address" , OTYPE_INT , SET_FMT_HEX_ADDR }, |
71139ed7e43f
Rename #define HEX_ADDR to more informative SET_FMT_HEX_ADDR.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
86 { "SID3Addr" , "3rd SID address" , OTYPE_INT , SET_FMT_HEX_ADDR }, |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
87 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
88 { "Name" , NULL , OTYPE_STR , NULL }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
89 { "Author" , NULL , OTYPE_STR , NULL }, |
385
1049033c6bbd
Backwards-incompatible change in UX: renamed the 'Copyright'
Matti Hamalainen <ccr@tnsp.org>
parents:
384
diff
changeset
|
90 { "Released" , NULL , OTYPE_STR , NULL }, |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
91 { "Hash" , NULL , OTYPE_STR , NULL }, |
112
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
92 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
93 { "Songlengths" , "Song lengths" , OTYPE_OTHER , NULL }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
94 { "STIL" , "STIL information" , OTYPE_OTHER , NULL }, |
2 | 95 }; |
96 | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
97 static const int noptPSOptions = sizeof(optPSOptions) / sizeof(optPSOptions[0]); |
2 | 98 |
99 | |
28 | 100 // Option variables |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
101 char *setHVSCPath = NULL, |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
102 *setSLDBPath = NULL, |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
103 *setSTILDBPath = NULL; |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
104 bool optParsable = false, |
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
105 optFieldNamePrefix = true, |
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
106 optHexadecimal = false, |
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
107 optFieldOutput = true, |
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
108 optRecurseDirs = false, |
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
109 optShowHelp = false; |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
110 char *optOneLineFieldSep = NULL, |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
111 *optEscapeChars = NULL; |
388
c96448875797
Change "new SLDB" boolean to a flags int.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
112 int optNFiles = 0, |
c96448875797
Change "new SLDB" boolean to a flags int.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
113 setSIDLibFlags = 0; |
c96448875797
Change "new SLDB" boolean to a flags int.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
114 |
2 | 115 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
116 PSFStack optFormat; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
117 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
118 SIDLibSLDB *sidSLDB = NULL; |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
119 SIDLibSTILDB *sidSTILDB = NULL; |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
120 |
313
b3d46806787d
Move a number of more or less generic helper functions into a separate sidutil.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
121 SIDUtilChConvCtx setChConv; |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
122 |
2 | 123 |
28 | 124 // Define option arguments |
121 | 125 static const th_optarg optList[] = |
2 | 126 { |
327
b6f88c150573
Use the newly added (in th-libs th_args module) option argument name field.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
127 { 0, '?', "help" , NULL , "Show this help", OPT_NONE }, |
b6f88c150573
Use the newly added (in th-libs th_args module) option argument name field.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
128 { 1, 0, "license" , NULL , "Print out this program's license agreement", OPT_NONE }, |
328
04ed43ef97e7
Oops, restore the long --verbose option.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
129 { 2, 'v', "verbose" , NULL , "Be more verbose", OPT_NONE }, |
177 | 130 |
351 | 131 { 10, 'p', "parsable" , NULL , "Output in script-parsable format", OPT_NONE }, |
132 { 12, 'x', "hex" , NULL , "Use hexadecimal values", OPT_NONE }, | |
133 { 14, 'n', "noprefix" , NULL , "Output without field name prefix", OPT_NONE }, | |
134 { 16, 'l', "line" , "sep" , "Output in one line format, -l <field sep str>", OPT_ARGREQ }, | |
135 { 18, 'e', "escape" , "chars" , "Escape these characters in fields (see note)", OPT_ARGREQ }, | |
136 { 20, 'f', "fields" , "fields" , "Show only specified field(s)", OPT_ARGREQ }, | |
137 { 22, 'F', "format" , "fmt" , "Use given format string (see below)", OPT_ARGREQ }, | |
138 { 24, 'R', "recurse" , NULL , "Recurse into sub-directories", OPT_NONE }, | |
139 { 30, 'H', "hvsc" , "path" , "Specify path to HVSC root directory", OPT_ARGREQ }, | |
140 { 32, 'S', "sldb" , "file" , "Specify Songlengths.(txt|md5) file", OPT_ARGREQ }, | |
141 { 34, 'T', "stildb" , "file" , "Specify STIL.txt file", OPT_ARGREQ }, | |
2 | 142 }; |
143 | |
44
7b137e4e817c
Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
144 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
2 | 145 |
146 | |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
147 void siArgShowHelp(void) |
2 | 148 { |
330 | 149 int index, width; |
2 | 150 |
313
b3d46806787d
Move a number of more or less generic helper functions into a separate sidutil.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
151 th_print_banner(stdout, th_prog_name, "[options] <sid file|path> [file|path #2 ..]"); |
329
14a91c998d96
Adjust help output cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
152 th_args_help(stdout, optList, optListN, 0, 80 - 2); |
14a91c998d96
Adjust help output cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
153 |
2 | 154 printf( |
155 "\n" | |
156 "Available fields:\n"); | |
3 | 157 |
330 | 158 for (width = index = 0; index < noptPSOptions; index++) |
2 | 159 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
160 const PSFOption *opt = &optPSOptions[index]; |
330 | 161 int len = strlen(opt->name) + 2; |
162 width += len; | |
163 if (width >= 80 - 2) | |
2 | 164 { |
165 printf("\n"); | |
330 | 166 width = len; |
2 | 167 } |
330 | 168 printf("%s%s", |
169 opt->name, | |
170 (index < noptPSOptions - 1) ? ", " : "\n"); | |
2 | 171 } |
58 | 172 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
173 printf( |
330 | 174 "\n" |
385
1049033c6bbd
Backwards-incompatible change in UX: renamed the 'Copyright'
Matti Hamalainen <ccr@tnsp.org>
parents:
384
diff
changeset
|
175 "Example: %s -x -p -f hash,released somesidfile.sid\n" |
61 | 176 "\n" |
330 | 177 "Format strings for '-F' option are composed of @fields@ that get expanded\n" |
178 "to their value. Also, escape sequences \\r, \\n and \\t can be used:\n" | |
385
1049033c6bbd
Backwards-incompatible change in UX: renamed the 'Copyright'
Matti Hamalainen <ccr@tnsp.org>
parents:
384
diff
changeset
|
179 " -F \"hash=@hash@\\ncopy=@released@\\n\"\n" |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
180 "\n" |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
181 "The -F fields can be further formatted via printf-style specifiers:\n" |
385
1049033c6bbd
Backwards-incompatible change in UX: renamed the 'Copyright'
Matti Hamalainen <ccr@tnsp.org>
parents:
384
diff
changeset
|
182 " -F \"@released:'%%-30s'@\"\n" |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
183 "\n" |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
184 "NOTE: One line output (-l <field separator>) also sets escape characters\n" |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
185 "(option -e <chars>), if escape characters have NOT been separately set.\n" |
234 | 186 "\n" |
187 "TIP: When specifying HVSC paths, it is preferable to use -H/--hvsc option,\n" | |
188 "as STIL.txt and Songlengths.(txt|md5) will be automatically used from there.\n" | |
287
41bde08182ce
Add a line about HVSC_BASE in the --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
285
diff
changeset
|
189 "You can also set it via HVSC_BASE environment variable, see README.\n" |
234 | 190 "\n" |
337
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
191 "HVSC path : %s\n" |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
192 "SLDB file : %s\n" |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
193 "STIL file : %s\n" |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
194 "\n", |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
195 th_prog_name, |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
196 setHVSCPath != NULL ? setHVSCPath : "[not set]", |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
197 setSLDBPath != NULL ? setSLDBPath : "[not set]", |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
198 setSTILDBPath != NULL ? setSTILDBPath : "[not set]" |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
199 ); |
2 | 200 } |
201 | |
202 | |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
203 int siArgMatchPSField(const char *field) |
2 | 204 { |
205 int index, found = -1; | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
206 for (index = 0; index < noptPSOptions; index++) |
2 | 207 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
208 const PSFOption *opt = &optPSOptions[index]; |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
209 if (th_strcasecmp(opt->name, field) == 0) |
2 | 210 { |
211 if (found >= 0) | |
212 return -2; | |
213 found = index; | |
214 } | |
215 } | |
216 | |
217 return found; | |
218 } | |
219 | |
220 | |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
221 int siArgMatchPSFieldError(const char *field) |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
222 { |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
223 int found = siArgMatchPSField(field); |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
224 switch (found) |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
225 { |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
226 case -1: |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
227 THERR("No such field '%s'.\n", field); |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
228 break; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
229 |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
230 case -2: |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
231 THERR("Field '%s' is ambiguous.\n", field); |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
232 break; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
233 } |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
234 return found; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
235 } |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
236 |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
237 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
238 bool siStackAddItem(PSFStack *stack, const PSFStackItem *item) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
239 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
240 if (stack->items == NULL || stack->nitems + 1 >= stack->nallocated) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
241 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
242 stack->nallocated += 16; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
243 if ((stack->items = th_realloc(stack->items, stack->nallocated * sizeof(PSFStackItem))) == NULL) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
244 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
245 THERR("Could not allocate memory for format item stack.\n"); |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
246 return false; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
247 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
248 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
249 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
250 memcpy(stack->items + stack->nitems, item, sizeof(PSFStackItem)); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
251 stack->nitems++; |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
252 return true; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
253 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
254 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
255 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
256 void siClearStack(PSFStack *stack) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
257 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
258 if (stack != NULL) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
259 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
260 if (stack->nitems > 0 && stack->items != NULL) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
261 { |
246
f50947e8ff93
Move two index variables from block scope to loop scope.
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
262 for (int n = 0; n < stack->nitems; n++) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
263 { |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
264 PSFStackItem *item = &stack->items[n]; |
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
265 th_free(item->str); |
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
266 th_free(item->fmt); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
267 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
268 th_free(stack->items); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
269 } |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
270 |
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
271 // Clear the stack data |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
272 memset(stack, 0, sizeof(PSFStack)); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
273 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
274 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
275 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
276 |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
277 bool siArgParsePSFields(PSFStack *stack, const char *fmt) |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
278 { |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
279 const char *start = fmt; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
280 siClearStack(stack); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
281 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
282 while (*start) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
283 { |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
284 const char *end = strchr(start, ','); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
285 char *field = (end != NULL) ? |
116
d062312ea850
Fix th_strndup_trim() usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
286 th_strndup_trim(start, end - start, TH_TRIM_BOTH) : |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
287 th_strdup_trim(start, TH_TRIM_BOTH); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
288 |
118 | 289 if (field != NULL) |
290 { | |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
291 PSFStackItem item; |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
292 int found = siArgMatchPSFieldError(field); |
118 | 293 th_free(field); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
294 |
118 | 295 if (found < 0) |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
296 return false; |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
297 |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
298 memset(&item, 0, sizeof(item)); |
118 | 299 item.cmd = found; |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
300 item.fmt = th_strdup(optPSOptions[found].dfmt); |
294
c9cc62e7f221
Oops. Better remember to properly always initialize PSFStackItem fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
301 |
118 | 302 if (!siStackAddItem(stack, &item)) |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
303 return false; |
118 | 304 } |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
305 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
306 if (!end) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
307 break; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
308 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
309 start = end + 1; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
310 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
311 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
312 return true; |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
313 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
314 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
315 |
283 | 316 static int siItemFormatStrPutInt(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
317 const int value, const int f_radix, int f_flags, int f_width, int f_prec, |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
318 const bool f_unsig, th_vprintf_altfmt_func f_alt) |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
319 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
320 char buf[64]; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
321 int f_len = 0, vret; |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
322 bool f_neg = false; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
323 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
324 vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, value, |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
325 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
326 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
327 if (vret == EOF) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
328 return 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
329 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
330 return th_vprintf_put_int_format(ctx, vputch, buf, f_flags, f_width, f_prec, f_len, vret, f_neg, f_unsig, f_alt); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
331 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
332 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
333 |
283 | 334 static int siItemFormatStrPrintDo(th_vprintf_ctx *ctx, |
335 th_vprintf_putch vputch, const char *fmt, | |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
336 const int otype, const char *d_str, const int d_int) |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
337 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
338 int ret = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
339 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
340 while (*fmt) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
341 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
342 if (*fmt != '%') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
343 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
344 if ((ret = vputch(ctx, *fmt)) == EOF) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
345 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
346 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
347 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
348 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
349 int f_width = -1, f_prec = -1, f_flags = 0; |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
350 bool end = false; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
351 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
352 fmt++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
353 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
354 // Check for flags |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
355 while (!end) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
356 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
357 switch (*fmt) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
358 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
359 case '#': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
360 f_flags |= TH_PF_ALT; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
361 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
362 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
363 case '+': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
364 f_flags |= TH_PF_SIGN; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
365 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
366 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
367 case '0': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
368 f_flags |= TH_PF_ZERO; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
369 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
370 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
371 case '-': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
372 f_flags |= TH_PF_LEFT; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
373 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
374 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
375 case ' ': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
376 f_flags |= TH_PF_SPACE; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
377 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
378 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
379 case '\'': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
380 f_flags |= TH_PF_GROUP; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
381 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
382 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
383 default: |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
384 end = true; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
385 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
386 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
387 if (!end) fmt++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
388 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
389 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
390 // Get field width |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
391 if (*fmt == '*') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
392 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
393 return -101; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
394 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
395 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
396 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
397 f_width = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
398 while (th_isdigit(*fmt)) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
399 f_width = f_width * 10 + (*fmt++ - '0'); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
400 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
401 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
402 // Check for field precision |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
403 if (*fmt == '.') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
404 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
405 fmt++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
406 if (*fmt == '*') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
407 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
408 return -102; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
409 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
410 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
411 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
412 // If no digit after '.', precision is to be 0 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
413 f_prec = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
414 while (th_isdigit(*fmt)) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
415 f_prec = f_prec * 10 + (*fmt++ - '0'); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
416 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
417 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
418 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
419 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
420 // Check for length modifiers (only some are supported currently) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
421 switch (*fmt) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
422 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
423 case 0: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
424 return -104; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
425 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
426 case 'o': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
427 if (otype != OTYPE_INT) return -120; |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
428 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 8, f_flags, f_width, f_prec, true, th_vprintf_altfmt_oct)) == EOF) |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
429 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
430 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
431 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
432 case 'u': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
433 case 'i': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
434 case 'd': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
435 if (otype != OTYPE_INT) return -120; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
436 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 10, f_flags, f_width, f_prec, *fmt == 'u', NULL)) == EOF) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
437 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
438 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
439 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
440 case 'x': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
441 case 'X': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
442 if (otype != OTYPE_INT) return -120; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
443 if (*fmt == 'X') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
444 f_flags |= TH_PF_UPCASE; |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
445 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 16, f_flags, f_width, f_prec, true, th_vprintf_altfmt_hex)) == EOF) |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
446 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
447 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
448 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
449 case 's': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
450 if (otype != OTYPE_STR) return -121; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
451 if ((ret = th_vprintf_put_str(ctx, vputch, d_str, f_flags, f_width, f_prec)) == EOF) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
452 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
453 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
454 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
455 //case '%': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
456 default: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
457 if ((ret = vputch(ctx, *fmt)) == EOF) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
458 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
459 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
460 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
461 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
462 fmt++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
463 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
464 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
465 out: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
466 return ret == EOF ? ret : ctx->ipos; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
467 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
468 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
469 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
470 static int siItemFormatStrPutCH(th_vprintf_ctx *ctx, const char ch) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
471 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
472 if (ctx->pos + 1 >= ctx->size) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
473 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
474 ctx->size += 64; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
475 if ((ctx->buf = th_realloc(ctx->buf, ctx->size)) == NULL) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
476 return EOF; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
477 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
478 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
479 ctx->buf[ctx->pos] = ch; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
480 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
481 ctx->pos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
482 ctx->ipos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
483 return ch; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
484 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
485 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
486 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
487 char * siItemFormatStrPrint(const char *fmt, const int otype, const char *d_str, const int d_int) |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
488 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
489 th_vprintf_ctx ctx; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
490 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
491 ctx.size = 128; |
320 | 492 ctx.pos = 0; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
493 ctx.ipos = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
494 |
320 | 495 if ((ctx.buf = th_malloc(ctx.size)) == NULL) |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
496 return NULL; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
497 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
498 if (siItemFormatStrPrintDo(&ctx, siItemFormatStrPutCH, fmt, otype, d_str, d_int) <= 0) |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
499 goto err; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
500 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
501 if (siItemFormatStrPutCH(&ctx, 0) < 0) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
502 goto err; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
503 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
504 return ctx.buf; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
505 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
506 err: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
507 th_free(ctx.buf); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
508 return NULL; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
509 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
510 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
511 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
512 static int siItemFormatStrPutCHNone(th_vprintf_ctx *ctx, const char ch) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
513 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
514 ctx->pos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
515 ctx->ipos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
516 return ch; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
517 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
518 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
519 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
520 static bool siItemFormatStrCheck(const char *fmt, const PSFOption *opt) |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
521 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
522 th_vprintf_ctx ctx; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
523 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
524 memset(&ctx, 0, sizeof(ctx)); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
525 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
526 return siItemFormatStrPrintDo(&ctx, siItemFormatStrPutCHNone, fmt, opt->type, NULL, 0) >= 0; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
527 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
528 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
529 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
530 // |
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
531 // Parse a format string into a PSFStack structure |
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
532 // |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
533 static bool siArgParsePSFormatStr(PSFStack *stack, const char *fmt) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
534 { |
83 | 535 const char *start = NULL; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
536 int mode = 0; |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
537 bool rval = true; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
538 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
539 siClearStack(stack); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
540 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
541 while (mode != -1) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
542 switch (mode) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
543 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
544 case 0: |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
545 if (*fmt == '@') |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
546 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
547 start = fmt + 1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
548 mode = 1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
549 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
550 else |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
551 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
552 start = fmt; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
553 mode = 2; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
554 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
555 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
556 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
557 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
558 case 1: |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
559 if (*fmt != '@') |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
560 { |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
561 if (*fmt == 0) |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
562 mode = -1; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
563 fmt++; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
564 break; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
565 } |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
566 |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
567 if (fmt - start == 0) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
568 { |
177 | 569 // "@@" sequence, just print out @ |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
570 PSFStackItem item; |
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
571 memset(&item, 0, sizeof(item)); |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
572 item.cmd = -2; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
573 item.chr = '@'; |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
574 |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
575 if (!siStackAddItem(stack, &item)) |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
576 return false; |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
577 } |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
578 else |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
579 { |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
580 char *fopt = NULL, *pfield, *field = th_strndup_trim(start, fmt - start, TH_TRIM_BOTH); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
581 if ((pfield = strchr(field, ':')) != NULL) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
582 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
583 *pfield = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
584 fopt = th_strdup_trim(pfield + 1, TH_TRIM_BOTH); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
585 } |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
586 |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
587 int ret = siArgMatchPSFieldError(field); |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
588 if (ret >= 0) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
589 { |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
590 PSFStackItem item; |
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
591 memset(&item, 0, sizeof(item)); |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
592 item.cmd = ret; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
593 |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
594 if (fopt != NULL) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
595 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
596 if (siItemFormatStrCheck(fopt, &optPSOptions[item.cmd])) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
597 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
598 item.flags |= OFMT_FORMAT; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
599 item.fmt = th_strdup(fopt); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
600 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
601 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
602 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
603 THERR("Invalid field format specifier '%s' in '%s'.\n", fopt, field); |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
604 rval = false; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
605 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
606 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
607 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
608 if (!siStackAddItem(stack, &item)) |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
609 rval = false; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
610 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
611 else |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
612 rval = false; |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
613 |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
614 th_free(fopt); |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
615 th_free(field); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
616 } |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
617 |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
618 mode = 0; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
619 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
620 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
621 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
622 case 2: |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
623 if (*fmt == 0 || *fmt == '@') |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
624 { |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
625 PSFStackItem item; |
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
626 memset(&item, 0, sizeof(item)); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
627 item.cmd = -1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
628 item.str = th_strndup(start, fmt - start); |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
629 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
630 if (!siStackAddItem(stack, &item)) |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
631 return false; |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
632 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
633 mode = (*fmt == 0) ? -1 : 0; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
634 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
635 else |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
636 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
637 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
638 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
639 |
113
cd97e7517e21
Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
640 return rval; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
641 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
642 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
643 |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
644 static bool siArgHandleOpt(const int optN, char *optArg, char *currArg) |
2 | 645 { |
646 switch (optN) | |
647 { | |
648 case 0: | |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
649 optShowHelp = true; |
2 | 650 break; |
651 | |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
652 case 1: |
313
b3d46806787d
Move a number of more or less generic helper functions into a separate sidutil.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
653 sidutil_print_license(); |
173
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
654 exit(0); |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
655 break; |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
656 |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
657 case 2: |
172
6dcf4ca1dce7
Change to match th-libs' verbosity level changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
658 th_verbosity++; |
2 | 659 break; |
660 | |
351 | 661 case 10: |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
662 optParsable = true; |
2 | 663 break; |
664 | |
351 | 665 case 12: |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
666 optHexadecimal = true; |
2 | 667 break; |
668 | |
351 | 669 case 14: |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
670 optFieldNamePrefix = false; |
7 | 671 break; |
672 | |
351 | 673 case 16: |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
674 optOneLineFieldSep = optArg; |
29 | 675 break; |
676 | |
351 | 677 case 18: |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
678 optEscapeChars = optArg; |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
679 break; |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
680 |
351 | 681 case 20: |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
682 if (!siArgParsePSFields(&optFormat, optArg)) |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
683 return false; |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
684 break; |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
685 |
351 | 686 case 22: |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
687 optFieldOutput = false; |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
688 if (!siArgParsePSFormatStr(&optFormat, optArg)) |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
689 return false; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
690 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
691 |
351 | 692 case 24: |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
693 optRecurseDirs = true; |
351 | 694 break; |
695 | |
696 case 30: | |
252
9e45cb6f12a5
Use th_pstr_cpy() for setting certain variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
697 th_pstr_cpy(&setHVSCPath, optArg); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
698 break; |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
699 |
351 | 700 case 32: |
252
9e45cb6f12a5
Use th_pstr_cpy() for setting certain variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
701 th_pstr_cpy(&setSLDBPath, optArg); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
702 break; |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
703 |
351 | 704 case 34: |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
705 th_pstr_cpy(&setSTILDBPath, optArg); |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
706 break; |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
707 |
2 | 708 default: |
709 THERR("Unknown option '%s'.\n", currArg); | |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
710 return false; |
2 | 711 } |
712 | |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
713 return true; |
2 | 714 } |
715 | |
716 | |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
717 static void siPrintFieldPrefixName(FILE *outfh, const char *name, const bool multifield) |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
718 { |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
719 if (optFieldNamePrefix) |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
720 { |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
721 if (optFieldOutput && optOneLineFieldSep == NULL) |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
722 fprintf(outfh, optParsable ? "%s=" : "%-20s : ", name); |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
723 else |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
724 if (multifield) |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
725 fprintf(outfh, "[%s] ", name); |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
726 } |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
727 } |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
728 |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
729 |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
730 static void siPrintFieldPrefix(FILE *outfh, const PSFOption *opt) |
2 | 731 { |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
732 siPrintFieldPrefixName(outfh, |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
733 (optParsable || opt->lname == NULL) ? opt->name : opt->lname, |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
734 false); |
2 | 735 } |
736 | |
737 | |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
738 static void siPrintFieldSeparator(FILE *outfh, const bool multifield, const bool last) |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
739 { |
111 | 740 if (optFieldOutput) |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
741 fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : "\n", outfh); |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
742 else |
301
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
743 if (multifield && !last) |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
744 fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : ", ", outfh); |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
745 } |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
746 |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
747 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
748 static const char *siGetInfoFormat(const PSFStackItem *item, const int otype) |
2 | 749 { |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
750 switch (otype) |
146 | 751 { |
752 case OTYPE_INT: | |
347
3b922a79aa2d
Don't use predefined format strings for one-line output.
Matti Hamalainen <ccr@tnsp.org>
parents:
345
diff
changeset
|
753 if (!optParsable && optOneLineFieldSep == NULL && item->fmt != NULL) |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
754 return item->fmt; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
755 else |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
756 return optHexadecimal ? "$%04x" : "%d"; |
146 | 757 |
758 case OTYPE_STR: | |
347
3b922a79aa2d
Don't use predefined format strings for one-line output.
Matti Hamalainen <ccr@tnsp.org>
parents:
345
diff
changeset
|
759 if (!optParsable && optOneLineFieldSep == NULL && item->fmt != NULL) |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
760 return item->fmt; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
761 else |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
762 return "%s"; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
763 |
155
de75385f75e2
Simplify by removing few lines of duplicate code.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
764 default: |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
765 return NULL; |
146 | 766 } |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
767 } |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
768 |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
769 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
770 static void siPrintPSIDInfoLine(FILE *outfh, bool *shown, |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
771 const char *fmt, const int otype, |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
772 const char *d_str, const int d_int, |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
773 const bool convert) |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
774 { |
341
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
775 char *formatted, *escaped; |
2 | 776 |
341
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
777 escaped = sidutil_escape_string(d_str, optEscapeChars); |
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
778 |
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
779 if ((formatted = siItemFormatStrPrint(fmt, otype, escaped, d_int)) != NULL) |
176
2e890e3d5684
Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
780 { |
341
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
781 char *converted; |
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
782 if (setChConv.enabled && convert && |
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
783 (converted = sidutil_chconv_convert(&setChConv, formatted)) != NULL) |
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
784 { |
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
785 fputs(converted, outfh); |
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
786 th_free(converted); |
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
787 } |
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
788 else |
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
789 fputs(formatted, outfh); |
176
2e890e3d5684
Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
790 } |
196
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
791 |
341
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
792 th_free(formatted); |
fe061ead51cc
Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
793 th_free(escaped); |
157
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
794 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
795 *shown = true; |
2 | 796 } |
797 | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
798 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
799 #define PRS(d_str, d_conv) do { \ |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
800 siPrintFieldPrefix(outfh, opt); \ |
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
801 siPrintPSIDInfoLine(outfh, shown, siGetInfoFormat(item, opt->type), opt->type, d_str, -1, d_conv); \ |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
802 siPrintFieldSeparator(outfh, false, true); \ |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
803 } while (0) |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
804 |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
805 #define PRI(d_int) do { \ |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
806 siPrintFieldPrefix(outfh, opt); \ |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
807 siPrintPSIDInfoLine(outfh, shown, siGetInfoFormat(item, opt->type), opt->type, NULL, d_int, false); \ |
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
808 siPrintFieldSeparator(outfh, false, true); \ |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
809 } while (0) |
9
c1fba4abf56f
Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
810 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
811 |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
812 static void siPrintPSIDInformationField(FILE *outfh, const char *filename, |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
813 const SIDLibPSIDHeader *psid, bool *shown, const PSFStackItem *item) |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
814 { |
114 | 815 const PSFOption *opt = &optPSOptions[item->cmd]; |
150
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
816 char tmp[128]; |
146 | 817 |
114 | 818 switch (item->cmd) |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
819 { |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
820 case 0: PRS(filename, false); break; |
371
22e8ee2df9ac
Check for RSID validity, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
367
diff
changeset
|
821 case 1: |
22e8ee2df9ac
Check for RSID validity, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
367
diff
changeset
|
822 snprintf(tmp, sizeof(tmp), "%s%s", |
22e8ee2df9ac
Check for RSID validity, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
367
diff
changeset
|
823 psid->magic, |
22e8ee2df9ac
Check for RSID validity, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
367
diff
changeset
|
824 psid->isInvalidRSID ? " (INVALID RSID!)" : ""); |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
825 PRS(tmp, false); |
371
22e8ee2df9ac
Check for RSID validity, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
367
diff
changeset
|
826 break; |
146 | 827 case 2: |
828 snprintf(tmp, sizeof(tmp), "%d.%d", (psid->version & 0xff), (psid->version >> 8)); | |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
829 PRS(tmp, false); |
146 | 830 break; |
831 case 3: | |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
832 PRS((psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in", false); |
146 | 833 break; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
834 case 4: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
835 if (psid->version >= 2) |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
836 PRS((psid->flags & PSF_PLAYSID_TUNE) ? (psid->isRSID ? "C64 BASIC" : "PlaySID") : "C64 compatible", false); |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
837 break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
838 case 5: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
839 if (psid->version >= 2) |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
840 PRS(sidlib_get_sid_clock_str((psid->flags >> 2) & PSF_CLOCK_MASK), false); |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
841 break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
842 case 6: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
843 if (psid->version >= 2) |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
844 PRS(sidlib_get_sid_model_str((psid->flags >> 4) & PSF_MODEL_MASK), false); |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
845 break; |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
846 |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
847 case 7: PRI(psid->dataOffset); break; |
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
848 case 8: PRI(psid->dataSize); break; |
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
849 case 9: PRI(psid->loadAddress); break; |
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
850 case 10: PRI(psid->initAddress); break; |
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
851 case 11: PRI(psid->playAddress); break; |
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
852 case 12: PRI(psid->nSongs); break; |
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
853 case 13: PRI(psid->startSong); break; |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
854 |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
855 case 14: |
376
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
856 PRI(psid->startPage); |
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
857 break; |
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
858 |
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
859 case 15: |
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
860 PRI(psid->pageLength); |
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
861 break; |
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
862 |
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
863 case 16: |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
864 if (psid->version >= 3) |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
865 { |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
866 int flags = (psid->flags >> 6) & PSF_MODEL_MASK; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
867 if (flags == PSF_MODEL_UNKNOWN) |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
868 flags = (psid->flags >> 4) & PSF_MODEL_MASK; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
869 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
870 PRS(sidlib_get_sid_model_str(flags), false); |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
871 } |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
872 break; |
376
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
873 case 17: |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
874 if (psid->version >= 4) |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
875 { |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
876 int flags = (psid->flags >> 8) & PSF_MODEL_MASK; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
877 if (flags == PSF_MODEL_UNKNOWN) |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
878 flags = (psid->flags >> 4) & PSF_MODEL_MASK; |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
879 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
880 PRS(sidlib_get_sid_model_str(flags), false); |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
881 } |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
882 break; |
376
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
883 case 18: |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
884 if (psid->version >= 3) |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
885 PRI(0xD000 | (psid->sid2Addr << 4)); |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
886 break; |
376
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
887 case 19: |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
888 if (psid->version >= 4) |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
889 PRI(0xD000 | (psid->sid3Addr << 4)); |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
890 break; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
891 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
892 case 20: PRS(psid->sidName, true); break; |
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
893 case 21: PRS(psid->sidAuthor, true); break; |
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
894 case 22: PRS(psid->sidReleased, true); break; |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
895 |
376
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
896 case 23: |
140
9f96b37c4f75
Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
897 { |
150
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
898 size_t i, k; |
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
899 for (i = k = 0; i < TH_MD5HASH_LENGTH && k < sizeof(tmp) - 1; i++, k += 2) |
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
900 sprintf(&tmp[k], "%02x", psid->hash[i]); |
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
901 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
902 PRS(tmp, false); |
140
9f96b37c4f75
Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
903 } |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
904 break; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
905 |
376
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
906 case 24: |
142
da29f147afcb
Better check for number of songlengths.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
907 if (psid->lengths != NULL && psid->lengths->nlengths > 0) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
908 { |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
909 siPrintFieldPrefix(outfh, opt); |
246
f50947e8ff93
Move two index variables from block scope to loop scope.
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
910 for (int i = 0; i < psid->lengths->nlengths; i++) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
911 { |
114 | 912 int len = psid->lengths->lengths[i]; |
279
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
913 |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
914 snprintf(tmp, sizeof(tmp), "%d:%02d%s", |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
915 len / 60, len % 60, |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
916 (i < psid->lengths->nlengths - 1) ? ", " : ""); |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
917 |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
918 siPrintPSIDInfoLine(outfh, shown, |
279
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
919 siGetInfoFormat(item, OTYPE_STR), |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
920 OTYPE_STR, |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
921 tmp, |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
922 -1, false); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
923 } |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
924 siPrintFieldSeparator(outfh, false, true); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
925 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
926 break; |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
927 |
376
a2da68ae083d
Display StartPage and PageLength information from the header as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
374
diff
changeset
|
928 case 25: |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
929 if (psid->stil != NULL) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
930 { |
301
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
931 int nfieldn = 0, nfieldcount = 0; |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
932 |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
933 // We need to count the number of fields to be outputted |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
934 // beforehand, so we can know when we are at the last one |
311
ee56f1f2b528
Change how the STIL subtune are handled internally. Also fix a bug that
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
935 for (size_t nsubtune = 0; nsubtune < psid->stil->nsubtunes; nsubtune++) |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
936 { |
311
ee56f1f2b528
Change how the STIL subtune are handled internally. Also fix a bug that
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
937 SIDLibSTILSubTune *subtune = &psid->stil->subtunes[nsubtune]; |
301
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
938 for (int nfield = 0; nfield < STF_LAST; nfield++) |
303
c2f0e8fbcac3
Oops, forgot NULL checks for STIL subtunes. Should not be coding tired, deserve much spanking.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
939 nfieldcount += subtune->fields[nfield].ndata; |
301
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
940 } |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
941 |
311
ee56f1f2b528
Change how the STIL subtune are handled internally. Also fix a bug that
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
942 for (size_t nsubtune = 0; nsubtune < psid->stil->nsubtunes; nsubtune++) |
301
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
943 { |
311
ee56f1f2b528
Change how the STIL subtune are handled internally. Also fix a bug that
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
944 SIDLibSTILSubTune *subtune = &psid->stil->subtunes[nsubtune]; |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
945 int maxdata = 0; |
301
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
946 |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
947 // For each subtune we need to check the max number of field data items |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
948 for (int nfield = 0; nfield < STF_LAST; nfield++) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
949 { |
303
c2f0e8fbcac3
Oops, forgot NULL checks for STIL subtunes. Should not be coding tired, deserve much spanking.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
950 SIDLibSTILField *fld = &subtune->fields[nfield]; |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
951 if (fld->ndata > maxdata) |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
952 maxdata = fld->ndata; |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
953 } |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
954 |
301
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
955 // Now output the items in field order |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
956 for (int nitem = 0; nitem < maxdata; nitem++) |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
957 for (int nfield = 0; nfield < STF_LAST; nfield++) |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
958 { |
303
c2f0e8fbcac3
Oops, forgot NULL checks for STIL subtunes. Should not be coding tired, deserve much spanking.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
959 SIDLibSTILField *fld = &subtune->fields[nfield]; |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
960 if (nitem < fld->ndata) |
279
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
961 { |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
962 if (nsubtune > 0) |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
963 { |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
964 snprintf(tmp, sizeof(tmp), "STIL#%d/%s", |
352
4978ff445572
Add lowercase versions of the STIL field names array as
Matti Hamalainen <ccr@tnsp.org>
parents:
351
diff
changeset
|
965 subtune->tune, sidlib_stil_fields_uc[nfield]); |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
966 } |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
967 else |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
968 { |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
969 snprintf(tmp, sizeof(tmp), "STIL/%s", |
352
4978ff445572
Add lowercase versions of the STIL field names array as
Matti Hamalainen <ccr@tnsp.org>
parents:
351
diff
changeset
|
970 sidlib_stil_fields_uc[nfield]); |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
971 } |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
972 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
973 siPrintFieldPrefixName(outfh, tmp, true); |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
974 siPrintPSIDInfoLine(outfh, shown, |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
975 siGetInfoFormat(item, OTYPE_STR), |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
976 OTYPE_STR, |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
977 fld->data[nitem], |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
978 -1, true); |
301
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
979 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
980 siPrintFieldSeparator(outfh, true, |
301
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
981 ++nfieldn >= nfieldcount); |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
982 } |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
983 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
984 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
985 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
986 break; |
29 | 987 } |
2 | 988 } |
989 | |
0 | 990 |
402
95a8e05dae27
Sync with th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
991 void siPSIDError(th_ioctx_t *fh, const int err, const char *msg) |
187 | 992 { |
993 (void) err; | |
269
cea4a7df9efd
Rename siError() to siPSIDError() and make the printed output more logical.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
994 THERR("%s - %s\n", msg, fh->filename); |
187 | 995 } |
996 | |
997 | |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
998 bool siHandleSIDFile(const char *filename) |
19 | 999 { |
226
c32015f4969e
Rename PSIDHeader struct to SIDLibPSIDHeader to conform with the SIDLib
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
1000 SIDLibPSIDHeader *psid = NULL; |
402
95a8e05dae27
Sync with th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
1001 th_ioctx_t *infh = NULL; |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1002 FILE *outfh; |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
1003 bool shown = false; |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
1004 int res; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1005 |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1006 outfh = stdout; |
19 | 1007 |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1008 if ((res = th_io_fopen(&infh, &th_stdio_io_ops, filename, "rb")) != THERR_OK) |
19 | 1009 { |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
1010 THERR("Could not open file '%s': %s\n", |
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
1011 filename, th_error_str(res)); |
126
c1462b7880e8
Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
1012 goto error; |
19 | 1013 } |
1014 | |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1015 th_io_set_handlers(infh, siPSIDError, NULL); |
187 | 1016 |
19 | 1017 // Read PSID data |
388
c96448875797
Change "new SLDB" boolean to a flags int.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
1018 if ((res = sidlib_read_sid_file_alloc(infh, &psid, setSIDLibFlags, NULL)) != THERR_OK) |
19 | 1019 goto error; |
1020 | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1021 // Get songlength information, if any |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1022 if (sidSLDB != NULL) |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1023 psid->lengths = sidlib_sldb_get_by_hash(sidSLDB, psid->hash); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1024 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1025 // Get STIL information, if any |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1026 if (sidSTILDB != NULL) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1027 { |
313
b3d46806787d
Move a number of more or less generic helper functions into a separate sidutil.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
1028 psid->stil = sidlib_stildb_get_node(sidSTILDB, |
b3d46806787d
Move a number of more or less generic helper functions into a separate sidutil.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
1029 sidutil_strip_hvsc_path(setHVSCPath, filename)); |
b3d46806787d
Move a number of more or less generic helper functions into a separate sidutil.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
1030 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1031 if (psid->stil != NULL) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1032 psid->stil->lengths = psid->lengths; |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1033 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1034 |
19 | 1035 // Output |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
1036 for (int index = 0; index < optFormat.nitems; index++) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1037 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1038 PSFStackItem *item = &optFormat.items[index]; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1039 switch (item->cmd) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1040 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1041 case -1: |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1042 sidutil_print_string_escaped(outfh, item->str); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1043 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1044 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1045 case -2: |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1046 fputc(item->chr, outfh); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1047 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1048 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1049 default: |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1050 siPrintPSIDInformationField(outfh, filename, psid, &shown, item); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1051 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1052 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1053 } |
153
e3be2ae6120e
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
1054 |
188
489eb428cf65
Add separator empty line between "files" when in normal output mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
1055 if (optFieldOutput && shown) |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1056 { |
340
6f8c431a3040
Rename some variables and function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1057 fprintf(outfh, "\n"); |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1058 } |
19 | 1059 |
1060 // Shutdown | |
1061 error: | |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1062 sidlib_free_sid_file(psid); |
355
9924d4518932
Adjust to th-libs ioctx API change.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1063 th_io_close(infh); |
19 | 1064 |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
1065 return true; |
19 | 1066 } |
1067 | |
1068 | |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
1069 bool siArgHandleFileDir(const char *path, const char *filename, const char *pattern) |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1070 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1071 th_stat_data sdata; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1072 char *npath; |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
1073 bool ret = true; |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1074 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1075 if (filename != NULL) |
250
cf8c31ed13ad
TH_DIR_SEPARATOR define was renamed to TH_DIR_SEPARATOR_CHR in th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
1076 npath = th_strdup_printf("%s%c%s", path, TH_DIR_SEPARATOR_CHR, filename); |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1077 else |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1078 npath = th_strdup(path); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1079 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1080 if (!th_stat_path(npath, &sdata)) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1081 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1082 THERR("File or path '%s' does not exist.\n", npath); |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
1083 ret = false; |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1084 goto out; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1085 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1086 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1087 optNFiles++; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1088 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1089 if (sdata.flags & TH_IS_DIR) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1090 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1091 DIR *dirh; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1092 struct dirent *entry; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1093 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1094 // Check if recursion is disabled |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1095 if (!optRecurseDirs && optNFiles > 1) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1096 goto out; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1097 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1098 if ((dirh = opendir(npath)) == NULL) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1099 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1100 int err = th_get_error(); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1101 THERR("Could not open directory '%s': %s\n", |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1102 path, th_error_str(err)); |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
1103 ret = false; |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1104 goto out; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1105 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1106 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1107 while ((entry = readdir(dirh)) != NULL) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1108 if (entry->d_name[0] != '.') |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1109 { |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
1110 if (!siArgHandleFileDir(npath, entry->d_name, pattern)) |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1111 { |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
1112 ret = false; |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1113 goto out; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1114 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1115 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1116 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1117 closedir(dirh); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1118 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1119 else |
401
600bd0c3dd83
Update to match changes in th-libs API. Also use case-insensitive
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
1120 if (pattern == NULL || |
600bd0c3dd83
Update to match changes in th-libs API. Also use case-insensitive
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
1121 #ifdef TH_FS_CASE_INSENSITIVE |
600bd0c3dd83
Update to match changes in th-libs API. Also use case-insensitive
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
1122 th_strcasematch(filename, pattern, true) |
600bd0c3dd83
Update to match changes in th-libs API. Also use case-insensitive
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
1123 #else |
600bd0c3dd83
Update to match changes in th-libs API. Also use case-insensitive
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
1124 th_strmatch(filename, pattern, true) |
600bd0c3dd83
Update to match changes in th-libs API. Also use case-insensitive
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
1125 #endif |
600bd0c3dd83
Update to match changes in th-libs API. Also use case-insensitive
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
1126 ) |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1127 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1128 siHandleSIDFile(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1129 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1130 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1131 out: |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1132 th_free(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1133 return ret; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1134 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1135 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1136 |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
1137 bool siArgHandleOther(char *path) |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1138 { |
339 | 1139 char *pattern, *filename, *pt, *npath; |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
1140 bool ret; |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1141 |
238 | 1142 if ((npath = th_strdup(path)) == NULL) |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
1143 return false; |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1144 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1145 // Check if we have path separators |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1146 if ((pt = strrchr(npath, '/')) != NULL || |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1147 (pt = strrchr(npath, '\\')) != NULL) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1148 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1149 *pt++ = 0; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1150 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1151 else |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1152 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1153 th_free(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1154 npath = th_strdup("."); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1155 pt = strcmp(path, npath) != 0 ? path : NULL; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1156 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1157 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1158 // Check if we have glob pattern chars |
339 | 1159 pattern = filename = NULL; |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1160 if (pt != NULL && *pt != 0) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1161 { |
400
b095a35a0848
Use strpbrk() instead of strchr() twice.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
1162 if (strpbrk(pt, "*?")) |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1163 pattern = th_strdup(pt); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1164 else |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1165 filename = th_strdup(pt); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1166 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1167 |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
1168 ret = siArgHandleFileDir(npath, filename, pattern); |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1169 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1170 th_free(pattern); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1171 th_free(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1172 th_free(filename); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1173 return ret; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1174 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1175 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1176 |
0 | 1177 int main(int argc, char *argv[]) |
1178 { | |
313
b3d46806787d
Move a number of more or less generic helper functions into a separate sidutil.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
1179 char *setLang = getenv("LANG"); |
349
a6153837c138
Split HVSC SLDB and STILDB reading boilerplate code from sidinfo to sidutil.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
1180 int res; |
196
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
1181 |
259
4df54600633a
Add support for "HVSC_BASE" environment variable as used by STILView by LaLa
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
1182 // Get HVSC_BASE env variable if it is set |
4df54600633a
Add support for "HVSC_BASE" environment variable as used by STILView by LaLa
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
1183 th_pstr_cpy(&setHVSCPath, getenv("HVSC_BASE")); |
4df54600633a
Add support for "HVSC_BASE" environment variable as used by STILView by LaLa
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
1184 |
0 | 1185 // Initialize |
408 | 1186 th_init("SIDInfo", "PSID/RSID information displayer", "1.0.1", |
404 | 1187 "By Matti 'ccr' Hamalainen (C) Copyright 2014-2023 TNSP", |
173
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
1188 "This program is distributed under a 3-clause BSD -style license."); |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
1189 |
172
6dcf4ca1dce7
Change to match th-libs' verbosity level changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
1190 th_verbosity = 0; |
0 | 1191 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1192 memset(&optFormat, 0, sizeof(optFormat)); |
336
5c2e77ec45e8
Initialize setChConv structure with memset().
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
1193 memset(&setChConv, 0, sizeof(setChConv)); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1194 |
337
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1195 // Parse command line arguments |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1196 if (!th_args_process(argc, argv, optList, optListN, |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
1197 siArgHandleOpt, NULL, OPTH_ONLY_OPTS)) |
337
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1198 goto exit; |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1199 |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1200 // Check if HVSC path is set |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1201 if (setHVSCPath != NULL) |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1202 { |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1203 // Ensure that there is a path separator at the end |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1204 if (th_strrcasecmp(setHVSCPath, TH_DIR_SEPARATOR_STR) == NULL) |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1205 th_pstr_printf(&setHVSCPath, "%s%c", setHVSCPath, TH_DIR_SEPARATOR_CHR); |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1206 |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1207 // If SLDB path is not set, autocheck for .md5 and .txt |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1208 if (setSLDBPath == NULL) |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1209 setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".md5"); |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1210 |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1211 if (setSLDBPath == NULL) |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1212 setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".txt"); |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1213 |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1214 if (setSTILDBPath == NULL) |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1215 setSTILDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_STILDB_FILENAME, NULL); |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1216 } |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1217 |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1218 // Check if help is requested |
360
522c8a77ad54
If no arguments given, show help anyway.
Matti Hamalainen <ccr@tnsp.org>
parents:
355
diff
changeset
|
1219 if (optShowHelp || argc < 2) |
337
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1220 { |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
1221 siArgShowHelp(); |
337
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1222 goto exit; |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1223 } |
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1224 |
324 | 1225 // Initialize character set conversion |
349
a6153837c138
Split HVSC SLDB and STILDB reading boilerplate code from sidinfo to sidutil.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
1226 if ((res = sidutil_chconv_init(&setChConv, setLang)) != THERR_OK) |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1227 { |
313
b3d46806787d
Move a number of more or less generic helper functions into a separate sidutil.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
1228 THERR("Could not initialize character set conversion (LANG='%s'): %s\n", |
349
a6153837c138
Split HVSC SLDB and STILDB reading boilerplate code from sidinfo to sidutil.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
1229 setLang, th_error_str(res)); |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1230 } |
196
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
1231 |
273
2437436b6129
Inform user of the character set conversion in use (or not in use) with verbosity level of 2.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
1232 THMSG(2, "Requested output LANG='%s', use charset conversion=%s\n", |
313
b3d46806787d
Move a number of more or less generic helper functions into a separate sidutil.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
1233 setChConv.outLang, setChConv.enabled ? "yes" : "no"); |
273
2437436b6129
Inform user of the character set conversion in use (or not in use) with verbosity level of 2.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
1234 |
337
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1235 // Check operation mode |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1236 if (optOneLineFieldSep != NULL || |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1237 (!optFieldOutput && optFormat.nitems > 0)) |
29 | 1238 { |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1239 // For one-line format and formatted output (-F), disable parsable |
393
db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
1240 optParsable = false; |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1241 |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1242 // If no escape chars have been set, use the field separator(s) |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1243 if (optEscapeChars == NULL) |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1244 optEscapeChars = optOneLineFieldSep; |
29 | 1245 } |
153
e3be2ae6120e
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
1246 |
161 | 1247 if (optFieldOutput && optFormat.nitems == 0) |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1248 { |
161 | 1249 // For standard field output, push standard items to format stack |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1250 siClearStack(&optFormat); |
127
1786b9d77782
Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
1251 |
161 | 1252 for (int i = 0; i < noptPSOptions; i++) |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1253 { |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1254 PSFStackItem item; |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1255 memset(&item, 0, sizeof(item)); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1256 item.cmd = i; |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1257 item.fmt = th_strdup(optPSOptions[i].dfmt); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1258 siStackAddItem(&optFormat, &item); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1259 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1260 } |
29 | 1261 |
337
7ad937740139
Change how --help option is handled and show currently set HVSC/SLDB/STIL
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
1262 // Read SLDB and STILDB |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1263 if (setSLDBPath != NULL) |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1264 { |
388
c96448875797
Change "new SLDB" boolean to a flags int.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
1265 if (th_strrcasecmp(setSLDBPath, ".md5") != NULL) |
c96448875797
Change "new SLDB" boolean to a flags int.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
1266 setSIDLibFlags |= SIDLIB_FLG_NEW_SLDB; |
208
5cdcebad7342
Autodetect which version of Songlength database file is available (.md5 or .txt), prefer .md5 version.
Matti Hamalainen <ccr@tnsp.org>
parents:
205
diff
changeset
|
1267 |
215
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1268 THMSG(1, "Reading SLDB (%s format [%s]): %s\n", |
388
c96448875797
Change "new SLDB" boolean to a flags int.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
1269 (setSIDLibFlags & SIDLIB_FLG_NEW_SLDB) ? "new" : "old", |
c96448875797
Change "new SLDB" boolean to a flags int.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
1270 (setSIDLibFlags & SIDLIB_FLG_NEW_SLDB) ? ".md5" : ".txt", |
215
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1271 setSLDBPath); |
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1272 |
349
a6153837c138
Split HVSC SLDB and STILDB reading boilerplate code from sidinfo to sidutil.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
1273 if ((res = sidutil_read_sldb_file(setSLDBPath, &sidSLDB)) != THERR_OK) |
a6153837c138
Split HVSC SLDB and STILDB reading boilerplate code from sidinfo to sidutil.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
1274 goto exit; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1275 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1276 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1277 if (setSTILDBPath != NULL) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1278 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1279 THMSG(1, "Reading STIL database: %s\n", |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1280 setSTILDBPath); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1281 |
349
a6153837c138
Split HVSC SLDB and STILDB reading boilerplate code from sidinfo to sidutil.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
1282 if ((res = sidutil_read_stildb_file(setSTILDBPath, &sidSTILDB, NULL)) != THERR_OK) |
a6153837c138
Split HVSC SLDB and STILDB reading boilerplate code from sidinfo to sidutil.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
1283 goto exit; |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1284 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1285 |
23 | 1286 // Process files |
1287 if (!th_args_process(argc, argv, optList, optListN, | |
398
9f9cf5c4b474
Rename functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
1288 NULL, siArgHandleOther, OPTH_ONLY_OTHER)) |
335 | 1289 goto exit; |
23 | 1290 |
19 | 1291 if (optNFiles == 0) |
2 | 1292 { |
141
71725be55ed1
Do not show full help if no filenames are specified.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
1293 THERR("No filename(s) specified. Try --help.\n"); |
2 | 1294 } |
1 | 1295 |
335 | 1296 exit: |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1297 |
313
b3d46806787d
Move a number of more or less generic helper functions into a separate sidutil.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
1298 sidutil_chconv_close(&setChConv); |
273
2437436b6129
Inform user of the character set conversion in use (or not in use) with verbosity level of 2.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
1299 |
257
41fe5ec24726
Plug some minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
252
diff
changeset
|
1300 siClearStack(&optFormat); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1301 th_free(setHVSCPath); |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1302 th_free(setSLDBPath); |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1303 th_free(setSTILDBPath); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1304 |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1305 sidlib_sldb_free(sidSLDB); |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1306 sidlib_stildb_free(sidSTILDB); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1307 |
19 | 1308 return 0; |
0 | 1309 } |