Mercurial > hg > sidinfo
annotate sidinfo.c @ 333:f8a133d0b703
Oops, -H option index was incorrect. Fixed.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 13 Jan 2020 13:37:25 +0200 |
parents | c8f52ea74803 |
children | 293fce53b5f9 |
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> |
227 | 4 * (C) Copyright 2014-2020 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 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
80 { "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
|
81 { "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
|
82 { "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
|
83 { "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
|
84 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
85 { "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
|
86 { "Author" , 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
|
87 { "Copyright" , 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
|
88 { "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
|
89 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
90 { "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
|
91 { "STIL" , "STIL information" , OTYPE_OTHER , NULL }, |
2 | 92 }; |
93 | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
94 static const int noptPSOptions = sizeof(optPSOptions) / sizeof(optPSOptions[0]); |
2 | 95 |
96 | |
28 | 97 // Option variables |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
98 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
|
99 *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
|
100 *setSTILDBPath = NULL; |
163
179ffe97599c
Implement support for the "new" MD5 format of SLDB.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
101 BOOL setSLDBNewFormat = FALSE, |
179ffe97599c
Implement support for the "new" MD5 format of SLDB.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
102 optParsable = FALSE, |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
103 optFieldNamePrefix = TRUE, |
29 | 104 optHexadecimal = FALSE, |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
105 optFieldOutput = TRUE, |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
106 optRecurseDirs = FALSE; |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
107 char *optOneLineFieldSep = NULL, |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
108 *optEscapeChars = NULL; |
19 | 109 int optNFiles = 0; |
2 | 110 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
111 PSFStack optFormat; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
112 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
113 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
|
114 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
|
115 |
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
|
116 SIDUtilChConvCtx setChConv; |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
117 |
2 | 118 |
28 | 119 // Define option arguments |
121 | 120 static const th_optarg optList[] = |
2 | 121 { |
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
|
122 { 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
|
123 { 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
|
124 { 2, 'v', "verbose" , NULL , "Be more verbose", OPT_NONE }, |
177 | 125 |
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
|
126 { 3, 'p', "parsable" , NULL , "Output in script-parsable format", 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
|
127 { 4, 'x', "hex" , NULL , "Use hexadecimal values", 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 { 5, 'n', "noprefix" , NULL , "Output without field name prefix", 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
|
129 { 6, 'l', "line" , "sep" , "Output in one line format, -l <field sep str>", OPT_ARGREQ }, |
b6f88c150573
Use the newly added (in th-libs th_args module) option argument name field.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
130 { 7, 'e', "escape" , "chars" , "Escape these characters in fields (see note)", OPT_ARGREQ }, |
b6f88c150573
Use the newly added (in th-libs th_args module) option argument name field.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
131 { 8, 'f', "fields" , "fields" , "Show only specified field(s)", OPT_ARGREQ }, |
b6f88c150573
Use the newly added (in th-libs th_args module) option argument name field.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
132 { 9, 'F', "format" , "fmt" , "Use given format string (see below)", OPT_ARGREQ }, |
333
f8a133d0b703
Oops, -H option index was incorrect. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
133 { 10, 'H', "hvsc" , "path" , "Specify path to HVSC root directory", OPT_ARGREQ }, |
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
|
134 { 11, 'S', "sldb" , "file" , "Specify Songlengths.(txt|md5) file", OPT_ARGREQ }, |
b6f88c150573
Use the newly added (in th-libs th_args module) option argument name field.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
135 { 12, 'T', "stildb" , "file" , "Specify STIL.txt file", OPT_ARGREQ }, |
b6f88c150573
Use the newly added (in th-libs th_args module) option argument name field.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
136 { 13, 'R', "recurse" , NULL , "Recurse into sub-directories", OPT_NONE }, |
2 | 137 }; |
138 | |
44
7b137e4e817c
Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
139 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
2 | 140 |
141 | |
142 void argShowHelp(void) | |
143 { | |
330 | 144 int index, width; |
2 | 145 |
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
|
146 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
|
147 th_args_help(stdout, optList, optListN, 0, 80 - 2); |
14a91c998d96
Adjust help output cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
148 |
2 | 149 printf( |
150 "\n" | |
151 "Available fields:\n"); | |
3 | 152 |
330 | 153 for (width = index = 0; index < noptPSOptions; index++) |
2 | 154 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
155 const PSFOption *opt = &optPSOptions[index]; |
330 | 156 int len = strlen(opt->name) + 2; |
157 width += len; | |
158 if (width >= 80 - 2) | |
2 | 159 { |
160 printf("\n"); | |
330 | 161 width = len; |
2 | 162 } |
330 | 163 printf("%s%s", |
164 opt->name, | |
165 (index < noptPSOptions - 1) ? ", " : "\n"); | |
2 | 166 } |
58 | 167 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
168 printf( |
330 | 169 "\n" |
61 | 170 "Example: %s -x -p -f hash,copyright somesidfile.sid\n" |
171 "\n" | |
330 | 172 "Format strings for '-F' option are composed of @fields@ that get expanded\n" |
173 "to their value. Also, escape sequences \\r, \\n and \\t can be used:\n" | |
174 " -F \"hash=@hash@\\ncopy=@copyright@\\n\"\n" | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
175 "\n" |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
176 "The -F fields can be further formatted via printf-style specifiers:\n" |
330 | 177 " -F \"@copyright:'%%-30s'@\"\n" |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
178 "\n" |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
179 "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
|
180 "(option -e <chars>), if escape characters have NOT been separately set.\n" |
234 | 181 "\n" |
182 "TIP: When specifying HVSC paths, it is preferable to use -H/--hvsc option,\n" | |
183 "as STIL.txt and Songlengths.(txt|md5) will be automatically used from there.\n" | |
287
41bde08182ce
Add a line about HVSC_BASE in the --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
285
diff
changeset
|
184 "You can also set it via HVSC_BASE environment variable, see README.\n" |
234 | 185 "\n" |
61 | 186 , th_prog_name); |
2 | 187 } |
188 | |
189 | |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
190 int argMatchPSField(const char *field) |
2 | 191 { |
192 int index, found = -1; | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
193 for (index = 0; index < noptPSOptions; index++) |
2 | 194 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
195 const PSFOption *opt = &optPSOptions[index]; |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
196 if (th_strcasecmp(opt->name, field) == 0) |
2 | 197 { |
198 if (found >= 0) | |
199 return -2; | |
200 found = index; | |
201 } | |
202 } | |
203 | |
204 return found; | |
205 } | |
206 | |
207 | |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
208 int argMatchPSFieldError(const char *field) |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
209 { |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
210 int found = argMatchPSField(field); |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
211 switch (found) |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
212 { |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
213 case -1: |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
214 THERR("No such field '%s'.\n", field); |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
215 break; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
216 |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
217 case -2: |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
218 THERR("Field '%s' is ambiguous.\n", field); |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
219 break; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
220 } |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
221 return found; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
222 } |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
223 |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
224 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
225 BOOL siStackAddItem(PSFStack *stack, const PSFStackItem *item) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
226 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
227 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
|
228 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
229 stack->nallocated += 16; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
230 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
|
231 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
232 THERR("Could not allocate memory for format item stack.\n"); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
233 return FALSE; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
234 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
235 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
236 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
237 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
|
238 stack->nitems++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
239 return TRUE; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
240 } |
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 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
243 void siClearStack(PSFStack *stack) |
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 if (stack != NULL) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
246 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
247 if (stack->nitems > 0 && stack->items != NULL) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
248 { |
246
f50947e8ff93
Move two index variables from block scope to loop scope.
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
249 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
|
250 { |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
251 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
|
252 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
|
253 th_free(item->fmt); |
59
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 th_free(stack->items); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
256 } |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
257 |
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
258 // Clear the stack data |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
259 memset(stack, 0, sizeof(PSFStack)); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
260 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
261 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
262 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
263 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
264 BOOL argParsePSFields(PSFStack *stack, const char *fmt) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
265 { |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
266 const char *start = fmt; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
267 siClearStack(stack); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
268 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
269 while (*start) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
270 { |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
271 const char *end = strchr(start, ','); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
272 char *field = (end != NULL) ? |
116
d062312ea850
Fix th_strndup_trim() usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
273 th_strndup_trim(start, end - start, TH_TRIM_BOTH) : |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
274 th_strdup_trim(start, TH_TRIM_BOTH); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
275 |
118 | 276 if (field != NULL) |
277 { | |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
278 PSFStackItem item; |
118 | 279 int found = argMatchPSFieldError(field); |
280 th_free(field); | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
281 |
118 | 282 if (found < 0) |
283 return FALSE; | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
284 |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
285 memset(&item, 0, sizeof(item)); |
118 | 286 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
|
287 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
|
288 |
118 | 289 if (!siStackAddItem(stack, &item)) |
290 return FALSE; | |
291 } | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
292 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
293 if (!end) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
294 break; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
295 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
296 start = end + 1; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
297 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
298 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
299 return TRUE; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
300 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
301 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
302 |
283 | 303 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
|
304 const int value, const int f_radix, int f_flags, int f_width, int f_prec, |
225
15a51252b73a
Adjust to fit th-libs API change for th_vprintf_altfmt_func.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
305 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
|
306 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
307 char buf[64]; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
308 int f_len = 0, vret; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
309 BOOL f_neg = FALSE; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
310 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
311 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
|
312 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
|
313 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
314 if (vret == EOF) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
315 return 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
316 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
317 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
|
318 } |
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 |
283 | 321 static int siItemFormatStrPrintDo(th_vprintf_ctx *ctx, |
322 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
|
323 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
|
324 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
325 int ret = 0; |
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 while (*fmt) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
328 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
329 if (*fmt != '%') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
330 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
331 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
|
332 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
333 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
334 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
335 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
336 int f_width = -1, f_prec = -1, f_flags = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
337 BOOL end = FALSE; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
338 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
339 fmt++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
340 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
341 // Check for flags |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
342 while (!end) |
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 switch (*fmt) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
345 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
346 case '#': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
347 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
|
348 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
349 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
350 case '+': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
351 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
|
352 break; |
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 case '0': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
355 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
|
356 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
357 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
358 case '-': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
359 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
|
360 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
361 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
362 case ' ': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
363 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
|
364 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
365 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
366 case '\'': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
367 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
|
368 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
369 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
370 default: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
371 end = TRUE; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
372 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
373 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
374 if (!end) fmt++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
375 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
376 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
377 // Get field width |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
378 if (*fmt == '*') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
379 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
380 return -101; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
381 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
382 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
383 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
384 f_width = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
385 while (th_isdigit(*fmt)) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
386 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
|
387 } |
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 // Check for field precision |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
390 if (*fmt == '.') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
391 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
392 fmt++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
393 if (*fmt == '*') |
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 return -102; |
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 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
398 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
399 // 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
|
400 f_prec = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
401 while (th_isdigit(*fmt)) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
402 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
|
403 } |
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 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
406 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
407 // 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
|
408 switch (*fmt) |
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 case 0: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
411 return -104; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
412 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
413 case 'o': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
414 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
|
415 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 8, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_oct)) == EOF) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
416 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
417 break; |
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 case 'u': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
420 case 'i': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
421 case 'd': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
422 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
|
423 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
|
424 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
425 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
426 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
427 case 'x': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
428 case 'X': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
429 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
|
430 if (*fmt == 'X') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
431 f_flags |= TH_PF_UPCASE; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
432 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex)) == EOF) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
433 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
434 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
435 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
436 case 's': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
437 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
|
438 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
|
439 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
440 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
441 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
442 //case '%': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
443 default: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
444 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
|
445 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
446 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
447 } |
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 fmt++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
450 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
451 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
452 out: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
453 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
|
454 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
455 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
456 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
457 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
|
458 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
459 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
|
460 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
461 ctx->size += 64; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
462 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
|
463 return EOF; |
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 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
466 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
|
467 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
468 ctx->pos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
469 ctx->ipos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
470 return 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 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
473 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
474 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
|
475 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
476 th_vprintf_ctx ctx; |
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 ctx.size = 128; |
320 | 479 ctx.pos = 0; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
480 ctx.ipos = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
481 |
320 | 482 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
|
483 return NULL; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
484 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
485 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
|
486 goto err; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
487 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
488 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
|
489 goto err; |
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 return ctx.buf; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
492 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
493 err: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
494 th_free(ctx.buf); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
495 return NULL; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
496 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
497 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
498 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
499 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
|
500 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
501 ctx->pos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
502 ctx->ipos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
503 return ch; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
504 } |
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 |
283 | 507 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
|
508 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
509 th_vprintf_ctx ctx; |
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 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
|
512 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
513 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
|
514 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
515 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
516 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
517 // |
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
518 // Parse a format string into a PSFStack structure |
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
519 // |
283 | 520 static BOOL argParsePSFormatStr(PSFStack *stack, const char *fmt) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
521 { |
83 | 522 const char *start = NULL; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
523 int mode = 0; |
113
cd97e7517e21
Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
524 BOOL rval = TRUE; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
525 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
526 siClearStack(stack); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
527 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
528 while (mode != -1) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
529 switch (mode) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
530 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
531 case 0: |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
532 if (*fmt == '@') |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
533 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
534 start = fmt + 1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
535 mode = 1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
536 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
537 else |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
538 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
539 start = fmt; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
540 mode = 2; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
541 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
542 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
543 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
544 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
545 case 1: |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
546 if (*fmt != '@') |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
547 { |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
548 if (*fmt == 0) |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
549 mode = -1; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
550 fmt++; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
551 break; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
552 } |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
553 |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
554 if (fmt - start == 0) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
555 { |
177 | 556 // "@@" 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
|
557 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
|
558 memset(&item, 0, sizeof(item)); |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
559 item.cmd = -2; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
560 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
|
561 |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
562 if (!siStackAddItem(stack, &item)) |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
563 return FALSE; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
564 } |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
565 else |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
566 { |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
567 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
|
568 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
|
569 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
570 *pfield = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
571 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
|
572 } |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
573 |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
574 int ret = argMatchPSFieldError(field); |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
575 if (ret >= 0) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
576 { |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
577 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
|
578 memset(&item, 0, sizeof(item)); |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
579 item.cmd = ret; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
580 |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
581 if (fopt != 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 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
|
584 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
585 item.flags |= OFMT_FORMAT; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
586 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
|
587 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
588 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
589 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
590 THERR("Invalid field format specifier '%s' in '%s'.\n", fopt, field); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
591 rval = FALSE; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
592 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
593 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
594 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
595 if (!siStackAddItem(stack, &item)) |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
596 rval = FALSE; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
597 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
598 else |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
599 rval = FALSE; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
600 |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
601 th_free(fopt); |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
602 th_free(field); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
603 } |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
604 |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
605 mode = 0; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
606 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
607 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
608 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
609 case 2: |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
610 if (*fmt == 0 || *fmt == '@') |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
611 { |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
612 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
|
613 memset(&item, 0, sizeof(item)); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
614 item.cmd = -1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
615 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
|
616 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
617 if (!siStackAddItem(stack, &item)) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
618 return FALSE; |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
619 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
620 mode = (*fmt == 0) ? -1 : 0; |
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 else |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
623 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
624 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
625 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
626 |
113
cd97e7517e21
Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
627 return rval; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
628 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
629 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
630 |
283 | 631 static BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
2 | 632 { |
633 switch (optN) | |
634 { | |
635 case 0: | |
636 argShowHelp(); | |
637 exit(0); | |
638 break; | |
639 | |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
640 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
|
641 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
|
642 exit(0); |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
643 break; |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
644 |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
645 case 2: |
172
6dcf4ca1dce7
Change to match th-libs' verbosity level changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
646 th_verbosity++; |
2 | 647 break; |
648 | |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
649 case 3: |
2 | 650 optParsable = TRUE; |
651 break; | |
652 | |
653 case 4: | |
654 optHexadecimal = TRUE; | |
655 break; | |
656 | |
7 | 657 case 5: |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
658 optFieldNamePrefix = FALSE; |
7 | 659 break; |
660 | |
29 | 661 case 6: |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
662 optOneLineFieldSep = optArg; |
29 | 663 break; |
664 | |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
665 case 7: |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
666 optEscapeChars = optArg; |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
667 break; |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
668 |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
669 case 8: |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
670 if (!argParsePSFields(&optFormat, optArg)) |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
671 return FALSE; |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
672 break; |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
673 |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
674 case 9: |
111 | 675 optFieldOutput = FALSE; |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
676 if (!argParsePSFormatStr(&optFormat, optArg)) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
677 return FALSE; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
678 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
679 |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
680 case 10: |
252
9e45cb6f12a5
Use th_pstr_cpy() for setting certain variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
681 th_pstr_cpy(&setHVSCPath, optArg); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
682 break; |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
683 |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
684 case 11: |
252
9e45cb6f12a5
Use th_pstr_cpy() for setting certain variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
685 th_pstr_cpy(&setSLDBPath, optArg); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
686 break; |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
687 |
322
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
688 case 12: |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
689 th_pstr_cpy(&setSTILDBPath, optArg); |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
690 break; |
5dfce66cc390
Reorder / clean up the commandline option indices.
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
691 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
692 case 13: |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
693 optRecurseDirs = TRUE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
694 break; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
695 |
2 | 696 default: |
697 THERR("Unknown option '%s'.\n", currArg); | |
698 return FALSE; | |
699 } | |
700 | |
701 return TRUE; | |
702 } | |
703 | |
704 | |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
705 static void siPrintFieldPrefixName(FILE *outFile, 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
|
706 { |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
707 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
|
708 { |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
709 if (optFieldOutput && optOneLineFieldSep == NULL) |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
710 fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name); |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
711 else |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
712 if (multifield) |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
713 fprintf(outFile, "[%s] ", name); |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
714 } |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
715 } |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
716 |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
717 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
718 static void siPrintFieldPrefix(FILE *outFile, const PSFOption *opt) |
2 | 719 { |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
720 siPrintFieldPrefixName(outFile, |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
721 (optParsable || opt->lname == NULL) ? opt->name : opt->lname, |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
722 FALSE); |
2 | 723 } |
724 | |
725 | |
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
|
726 static void siPrintFieldSeparator(FILE *outFile, const BOOL multifield, const BOOL last) |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
727 { |
111 | 728 if (optFieldOutput) |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
729 fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : "\n", outFile); |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
730 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
|
731 if (multifield && !last) |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
732 fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : ", ", outFile); |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
733 } |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
734 |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
735 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
736 static const char *siGetInfoFormat(const PSFStackItem *item, const int otype) |
2 | 737 { |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
738 switch (otype) |
146 | 739 { |
740 case OTYPE_INT: | |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
741 if (!optParsable && 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
|
742 return item->fmt; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
743 else |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
744 return optHexadecimal ? "$%04x" : "%d"; |
146 | 745 |
746 case OTYPE_STR: | |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
747 if (!optParsable && 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
|
748 return item->fmt; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
749 else |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
750 return "%s"; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
751 |
155
de75385f75e2
Simplify by removing few lines of duplicate code.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
752 default: |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
753 return NULL; |
146 | 754 } |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
755 } |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
756 |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
757 |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
758 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
759 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
|
760 const char *d_str, const int d_int, |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
761 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
|
762 { |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
763 char *str, *tmp; |
2 | 764 |
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
|
765 if (d_str != NULL && setChConv.enabled && convert) |
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
|
766 { |
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
|
767 char *tmp2 = sidutil_chconv_convert(&setChConv, d_str); |
316
b0c844b39516
Move and rename siEscapeString() to sidutil_escape_string() and
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
768 tmp = sidutil_escape_string(tmp2, optEscapeChars); |
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
|
769 th_free(tmp2); |
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
|
770 } |
157
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
771 else |
316
b0c844b39516
Move and rename siEscapeString() to sidutil_escape_string() and
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
772 tmp = sidutil_escape_string(d_str, optEscapeChars); |
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
|
773 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
774 if ((str = siItemFormatStrPrint(fmt, otype, tmp, d_int)) != NULL) |
146 | 775 fputs(str, outFile); |
3 | 776 |
146 | 777 th_free(str); |
157
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
778 th_free(tmp); |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
779 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
780 *shown = TRUE; |
2 | 781 } |
782 | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
783 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
784 #define PRS(d_str, d_conv) do { \ |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
785 siPrintFieldPrefix(outFile, opt); \ |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
786 siPrintPSIDInfoLine(outFile, shown, siGetInfoFormat(item, opt->type), opt->type, d_str, -1, d_conv); \ |
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
|
787 siPrintFieldSeparator(outFile, FALSE, TRUE); \ |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
788 } while (0) |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
789 |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
790 #define PRI(d_int) do { \ |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
791 siPrintFieldPrefix(outFile, opt); \ |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
792 siPrintPSIDInfoLine(outFile, shown, siGetInfoFormat(item, opt->type), opt->type, NULL, d_int, FALSE); \ |
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
|
793 siPrintFieldSeparator(outFile, FALSE, TRUE); \ |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
794 } while (0) |
9
c1fba4abf56f
Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
795 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
796 |
226
c32015f4969e
Rename PSIDHeader struct to SIDLibPSIDHeader to conform with the SIDLib
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
797 static void siPrintPSIDInformationField(FILE *outFile, const char *filename, |
c32015f4969e
Rename PSIDHeader struct to SIDLibPSIDHeader to conform with the SIDLib
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
798 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
|
799 { |
114 | 800 const PSFOption *opt = &optPSOptions[item->cmd]; |
150
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
801 char tmp[128]; |
146 | 802 |
114 | 803 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
|
804 { |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
805 case 0: PRS(filename, FALSE); break; |
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
806 case 1: PRS(psid->magic, FALSE); break; |
146 | 807 case 2: |
808 snprintf(tmp, sizeof(tmp), "%d.%d", (psid->version & 0xff), (psid->version >> 8)); | |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
809 PRS(tmp, FALSE); |
146 | 810 break; |
811 case 3: | |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
812 PRS((psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in", FALSE); |
146 | 813 break; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
814 case 4: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
815 if (psid->version >= 2) |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
816 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
|
817 break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
818 case 5: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
819 if (psid->version >= 2) |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
820 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
|
821 break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
822 case 6: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
823 if (psid->version >= 2) |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
824 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
|
825 break; |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
826 |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
827 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
|
828 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
|
829 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
|
830 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
|
831 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
|
832 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
|
833 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
|
834 |
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
|
835 case 14: |
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
|
836 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
|
837 { |
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
|
838 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
|
839 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
|
840 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
|
841 |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
842 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
|
843 } |
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
|
844 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
|
845 case 15: |
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
|
846 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
|
847 { |
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
|
848 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
|
849 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
|
850 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
|
851 |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
852 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
|
853 } |
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 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
|
855 case 16: |
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
|
856 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
|
857 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
|
858 break; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
859 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
|
860 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
|
861 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
|
862 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
|
863 |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
864 case 18: PRS(psid->sidName, TRUE); break; |
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
865 case 19: PRS(psid->sidAuthor, TRUE); break; |
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
866 case 20: PRS(psid->sidCopyright, 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
|
867 |
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 case 21: |
140
9f96b37c4f75
Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
869 { |
150
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
870 size_t i, k; |
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
871 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
|
872 sprintf(&tmp[k], "%02x", psid->hash[i]); |
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
873 |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
874 PRS(tmp, FALSE); |
140
9f96b37c4f75
Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
875 } |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
876 break; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
877 |
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
|
878 case 22: |
142
da29f147afcb
Better check for number of songlengths.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
879 if (psid->lengths != NULL && psid->lengths->nlengths > 0) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
880 { |
140
9f96b37c4f75
Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
881 siPrintFieldPrefix(outFile, opt); |
246
f50947e8ff93
Move two index variables from block scope to loop scope.
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
882 for (int i = 0; i < psid->lengths->nlengths; i++) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
883 { |
114 | 884 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
|
885 |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
886 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
|
887 len / 60, len % 60, |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
888 (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
|
889 |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
890 siPrintPSIDInfoLine(outFile, shown, |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
891 siGetInfoFormat(item, OTYPE_STR), |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
892 OTYPE_STR, |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
893 tmp, |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
894 -1, FALSE); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
895 } |
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
|
896 siPrintFieldSeparator(outFile, FALSE, TRUE); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
897 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
898 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
|
899 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
900 case 23: |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
901 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
|
902 { |
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
|
903 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
|
904 |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
905 // 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
|
906 // 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
|
907 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
|
908 { |
311
ee56f1f2b528
Change how the STIL subtune are handled internally. Also fix a bug that
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
909 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
|
910 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
|
911 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
|
912 } |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
913 |
311
ee56f1f2b528
Change how the STIL subtune are handled internally. Also fix a bug that
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
914 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
|
915 { |
311
ee56f1f2b528
Change how the STIL subtune are handled internally. Also fix a bug that
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
916 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
|
917 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
|
918 |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
919 // 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
|
920 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
|
921 { |
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
|
922 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
|
923 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
|
924 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
|
925 } |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
926 |
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
|
927 // 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
|
928 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
|
929 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
|
930 { |
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
|
931 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
|
932 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
|
933 { |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
934 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
|
935 { |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
936 snprintf(tmp, sizeof(tmp), "STIL#%d/%s", |
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 subtune->tune, sidlib_stil_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
|
938 } |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
939 else |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
940 { |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
941 snprintf(tmp, sizeof(tmp), "STIL/%s", |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
942 sidlib_stil_fields[nfield]); |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
943 } |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
944 |
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 siPrintFieldPrefixName(outFile, tmp, TRUE); |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
946 siPrintPSIDInfoLine(outFile, shown, |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
947 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
|
948 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
|
949 fld->data[nitem], |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
950 -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
|
951 |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
952 siPrintFieldSeparator(outFile, TRUE, |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
953 ++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
|
954 } |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
955 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
956 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
957 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
958 break; |
29 | 959 } |
2 | 960 } |
961 | |
0 | 962 |
269
cea4a7df9efd
Rename siError() to siPSIDError() and make the printed output more logical.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
963 void siPSIDError(th_ioctx *fh, const int err, const char *msg) |
187 | 964 { |
965 (void) err; | |
269
cea4a7df9efd
Rename siError() to siPSIDError() and make the printed output more logical.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
966 THERR("%s - %s\n", msg, fh->filename); |
187 | 967 } |
968 | |
969 | |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
970 void siSTILError(th_ioctx *fh, const int err, const char *msg) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
971 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
972 (void) err; |
293
c3ebab7f9094
Fix one more format string to use proper PRIu_SIZE_T.
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
973 THERR("[%s:%" PRIu_SIZE_T "] %s\n", fh->filename, fh->line, msg); |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
974 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
975 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
976 |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
977 BOOL siHandleSIDFile(const char *filename) |
19 | 978 { |
226
c32015f4969e
Rename PSIDHeader struct to SIDLibPSIDHeader to conform with the SIDLib
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
979 SIDLibPSIDHeader *psid = NULL; |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
980 th_ioctx *inFile = NULL; |
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
981 FILE *outFile; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
982 BOOL shown = FALSE; |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
983 int res; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
984 |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
985 outFile = stdout; |
19 | 986 |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
987 if ((res = th_io_fopen(&inFile, &th_stdio_io_ops, filename, "rb")) != THERR_OK) |
19 | 988 { |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
989 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
|
990 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
|
991 goto error; |
19 | 992 } |
993 | |
269
cea4a7df9efd
Rename siError() to siPSIDError() and make the printed output more logical.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
994 th_io_set_handlers(inFile, siPSIDError, NULL); |
187 | 995 |
19 | 996 // Read PSID data |
319
6d0143e43edf
Add functionality and API changes for doing on-the-fly character set
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
997 if ((res = sidlib_read_sid_file_alloc(inFile, &psid, setSLDBNewFormat, NULL)) != THERR_OK) |
19 | 998 goto error; |
999 | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1000 // Get songlength information, if any |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1001 if (sidSLDB != NULL) |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1002 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
|
1003 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1004 // 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
|
1005 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
|
1006 { |
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
|
1007 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
|
1008 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
|
1009 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1010 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
|
1011 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
|
1012 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1013 |
19 | 1014 // Output |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
1015 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
|
1016 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1017 PSFStackItem *item = &optFormat.items[index]; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1018 switch (item->cmd) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1019 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1020 case -1: |
316
b0c844b39516
Move and rename siEscapeString() to sidutil_escape_string() and
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
1021 sidutil_print_string_escaped(outFile, item->str); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1022 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1023 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1024 case -2: |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1025 fputc(item->chr, outFile); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1026 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1027 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1028 default: |
126
c1462b7880e8
Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
1029 siPrintPSIDInformationField(outFile, filename, psid, &shown, item); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1030 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1031 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1032 } |
153
e3be2ae6120e
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
1033 |
188
489eb428cf65
Add separator empty line between "files" when in normal output mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
1034 if (optFieldOutput && shown) |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1035 { |
188
489eb428cf65
Add separator empty line between "files" when in normal output mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
1036 fprintf(outFile, "\n"); |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1037 } |
19 | 1038 |
1039 // Shutdown | |
1040 error: | |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1041 sidlib_free_sid_file(psid); |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
1042 th_io_free(inFile); |
19 | 1043 |
1044 return TRUE; | |
1045 } | |
1046 | |
1047 | |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1048 BOOL argHandleFileDir(const char *path, const char *filename, const char *pattern) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1049 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1050 th_stat_data sdata; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1051 char *npath; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1052 BOOL ret = TRUE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1053 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1054 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
|
1055 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
|
1056 else |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1057 npath = th_strdup(path); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1058 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1059 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
|
1060 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1061 THERR("File or path '%s' does not exist.\n", npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1062 ret = FALSE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1063 goto out; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1064 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1065 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1066 optNFiles++; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1067 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1068 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
|
1069 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1070 DIR *dirh; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1071 struct dirent *entry; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1072 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1073 // Check if recursion is disabled |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1074 if (!optRecurseDirs && optNFiles > 1) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1075 goto out; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1076 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1077 if ((dirh = opendir(npath)) == NULL) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1078 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1079 int err = th_get_error(); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1080 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
|
1081 path, th_error_str(err)); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1082 ret = FALSE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1083 goto out; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1084 } |
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 while ((entry = readdir(dirh)) != NULL) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1087 if (entry->d_name[0] != '.') |
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 (!argHandleFileDir(npath, entry->d_name, pattern)) |
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 ret = FALSE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1092 goto out; |
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 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1095 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1096 closedir(dirh); |
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 else |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1099 if (pattern == NULL || th_strmatch(filename, pattern)) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1100 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1101 siHandleSIDFile(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1102 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1103 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1104 out: |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1105 th_free(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1106 return ret; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1107 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1108 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1109 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1110 BOOL argHandleFile(char *path) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1111 { |
238 | 1112 char *pattern = NULL, *filename = NULL, *pt, *npath; |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1113 BOOL ret; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1114 |
238 | 1115 if ((npath = th_strdup(path)) == NULL) |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1116 return FALSE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1117 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1118 // 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
|
1119 if ((pt = strrchr(npath, '/')) != NULL || |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1120 (pt = strrchr(npath, '\\')) != NULL) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1121 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1122 *pt++ = 0; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1123 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1124 else |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1125 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1126 th_free(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1127 npath = th_strdup("."); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1128 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
|
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 // Check if we have glob pattern chars |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1132 if (pt != NULL && *pt != 0) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1133 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1134 if (strchr(pt, '*') || strchr(pt, '?')) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1135 pattern = th_strdup(pt); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1136 else |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1137 filename = th_strdup(pt); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1138 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1139 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1140 ret = argHandleFileDir(npath, filename, pattern); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1141 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1142 th_free(pattern); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1143 th_free(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1144 th_free(filename); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1145 return ret; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1146 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1147 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1148 |
0 | 1149 int main(int argc, char *argv[]) |
1150 { | |
230 | 1151 th_ioctx *inFile = NULL; |
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
|
1152 char *setLang = getenv("LANG"); |
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
|
1153 int ret; |
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
|
1154 |
259
4df54600633a
Add support for "HVSC_BASE" environment variable as used by STILView by LaLa
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
1155 // 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
|
1156 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
|
1157 |
0 | 1158 // Initialize |
309 | 1159 th_init("SIDInfo", "PSID/RSID information displayer", "0.9.2", |
227 | 1160 "By Matti 'ccr' Hamalainen (C) Copyright 2014-2020 TNSP", |
173
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
1161 "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
|
1162 |
172
6dcf4ca1dce7
Change to match th-libs' verbosity level changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
1163 th_verbosity = 0; |
0 | 1164 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1165 memset(&optFormat, 0, sizeof(optFormat)); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1166 |
324 | 1167 // Initialize character set conversion |
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
|
1168 if ((ret = sidutil_chconv_init(&setChConv, setLang)) != THERR_OK) |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1169 { |
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
|
1170 THERR("Could not initialize character set conversion (LANG='%s'): %s\n", |
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
|
1171 setLang, th_error_str(ret)); |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1172 } |
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
|
1173 |
2 | 1174 // Parse command line arguments |
1175 if (!th_args_process(argc, argv, optList, optListN, | |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1176 argHandleOpt, NULL, OPTH_ONLY_OPTS)) |
247
8c6f0a3afc43
"goto out" instead of "return -1" when commandline argument parsing fails.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
1177 goto out; |
2 | 1178 |
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
|
1179 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
|
1180 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
|
1181 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1182 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
|
1183 (!optFieldOutput && optFormat.nitems > 0)) |
29 | 1184 { |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1185 // For one-line format and formatted output (-F), disable parsable |
29 | 1186 optParsable = FALSE; |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1187 |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1188 // 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
|
1189 if (optEscapeChars == NULL) |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1190 optEscapeChars = optOneLineFieldSep; |
29 | 1191 } |
153
e3be2ae6120e
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
1192 |
161 | 1193 if (optFieldOutput && optFormat.nitems == 0) |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1194 { |
161 | 1195 // 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
|
1196 siClearStack(&optFormat); |
127
1786b9d77782
Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
1197 |
161 | 1198 for (int i = 0; i < noptPSOptions; i++) |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1199 { |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1200 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
|
1201 memset(&item, 0, sizeof(item)); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1202 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
|
1203 item.fmt = th_strdup(optPSOptions[i].dfmt); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1204 siStackAddItem(&optFormat, &item); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1205 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1206 } |
29 | 1207 |
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
|
1208 // Check if HVSC path is set |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1209 if (setHVSCPath != NULL) |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1210 { |
270 | 1211 // Ensure that there is a path separator at the end |
251
1e7c2c87e1e0
Oops, missed some lines from previous commit "TH_DIR_SEPARATOR define was renamed to TH_DIR_SEPARATOR_CHR in th-libs."
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
1212 if (th_strrcasecmp(setHVSCPath, TH_DIR_SEPARATOR_STR) == NULL) |
1e7c2c87e1e0
Oops, missed some lines from previous commit "TH_DIR_SEPARATOR define was renamed to TH_DIR_SEPARATOR_CHR in th-libs."
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
1213 th_pstr_printf(&setHVSCPath, "%s%c", setHVSCPath, TH_DIR_SEPARATOR_CHR); |
244
1beaad0d5219
Ensure that the specified HVSC path has '/' path separator at the end.
Matti Hamalainen <ccr@tnsp.org>
parents:
243
diff
changeset
|
1214 |
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
|
1215 // If SLDB path is not set, autocheck for .md5 and .txt |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1216 if (setSLDBPath == NULL) |
318
f3ba2ba894b1
Rename few HVSC related #defines to have SIDUTIL_ prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
1217 setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".md5"); |
230 | 1218 |
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
|
1219 if (setSLDBPath == NULL) |
318
f3ba2ba894b1
Rename few HVSC related #defines to have SIDUTIL_ prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
1220 setSLDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_SLDB_FILEBASE, ".txt"); |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1221 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1222 if (setSTILDBPath == NULL) |
318
f3ba2ba894b1
Rename few HVSC related #defines to have SIDUTIL_ prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
1223 setSTILDBPath = sidutil_check_hvsc_file(setHVSCPath, SIDUTIL_STILDB_FILENAME, NULL); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1224 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1225 |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1226 if (setSLDBPath != NULL) |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1227 { |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1228 // Initialize 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
|
1229 setSLDBNewFormat = th_strrcasecmp(setSLDBPath, ".md5") != NULL; |
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
|
1230 |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
1231 if ((ret = th_io_fopen(&inFile, &th_stdio_io_ops, setSLDBPath, "r")) != THERR_OK) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1232 { |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
1233 THERR("Could not open SLDB '%s': %s\n", |
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
1234 setSLDBPath, th_error_str(ret)); |
235 | 1235 goto err1; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1236 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1237 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1238 th_io_set_handlers(inFile, siSTILError, NULL); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1239 |
215
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1240 THMSG(1, "Reading SLDB (%s format [%s]): %s\n", |
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1241 setSLDBNewFormat ? "new" : "old", |
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1242 setSLDBNewFormat ? ".md5" : ".txt", |
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1243 setSLDBPath); |
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1244 |
236
609bfc1bd628
Change sidlib_sldb_new() API to int sidlib_sldb_new(SIDLibSLDB **pdbh).
Matti Hamalainen <ccr@tnsp.org>
parents:
235
diff
changeset
|
1245 if ((ret = sidlib_sldb_new(&sidSLDB)) != THERR_OK) |
110 | 1246 { |
236
609bfc1bd628
Change sidlib_sldb_new() API to int sidlib_sldb_new(SIDLibSLDB **pdbh).
Matti Hamalainen <ccr@tnsp.org>
parents:
235
diff
changeset
|
1247 THERR("Could not allocate SLDB database structure: %s\n", |
609bfc1bd628
Change sidlib_sldb_new() API to int sidlib_sldb_new(SIDLibSLDB **pdbh).
Matti Hamalainen <ccr@tnsp.org>
parents:
235
diff
changeset
|
1248 th_error_str(ret)); |
235 | 1249 goto err1; |
110 | 1250 } |
1251 | |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1252 if ((ret = sidlib_sldb_read(inFile, sidSLDB)) != THERR_OK) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1253 { |
285 | 1254 THERR("Error parsing SLDB: %s\n", |
1255 th_error_str(ret)); | |
235 | 1256 goto err1; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1257 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1258 |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1259 if ((ret = sidlib_sldb_build_index(sidSLDB)) != THERR_OK) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1260 { |
285 | 1261 THERR("Error building SLDB index: %s\n", |
1262 th_error_str(ret)); | |
235 | 1263 goto err1; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1264 } |
110 | 1265 |
235 | 1266 err1: |
257
41fe5ec24726
Plug some minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
252
diff
changeset
|
1267 th_io_free(inFile); |
230 | 1268 inFile = NULL; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1269 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1270 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1271 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
|
1272 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1273 // Initialize STILDB |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1274 if ((ret = th_io_fopen(&inFile, &th_stdio_io_ops, setSTILDBPath, "r")) != THERR_OK) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1275 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1276 THERR("Could not open STIL database '%s': %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
|
1277 setSTILDBPath, th_error_str(ret)); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1278 goto err2; |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1279 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1280 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1281 th_io_set_handlers(inFile, siSTILError, NULL); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1282 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1283 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
|
1284 setSTILDBPath); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1285 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1286 if ((ret = sidlib_stildb_new(&sidSTILDB)) != THERR_OK) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1287 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1288 THERR("Could not allocate STIL database structure: %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
|
1289 th_error_str(ret)); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1290 goto err2; |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1291 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1292 |
319
6d0143e43edf
Add functionality and API changes for doing on-the-fly character set
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
1293 if ((ret = sidlib_stildb_read(inFile, sidSTILDB, NULL)) != THERR_OK) |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1294 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1295 THERR("Error parsing STIL: %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
|
1296 th_error_str(ret)); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1297 goto err2; |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1298 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1299 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1300 if ((ret = sidlib_stildb_build_index(sidSTILDB)) != THERR_OK) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1301 { |
285 | 1302 THERR("Error building STIL index: %s\n", |
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_error_str(ret)); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1304 goto err2; |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1305 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1306 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1307 err2: |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1308 th_io_free(inFile); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1309 inFile = NULL; |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1310 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1311 |
23 | 1312 // Process files |
1313 if (!th_args_process(argc, argv, optList, optListN, | |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1314 NULL, argHandleFile, OPTH_ONLY_OTHER)) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1315 goto out; |
23 | 1316 |
19 | 1317 if (optNFiles == 0) |
2 | 1318 { |
141
71725be55ed1
Do not show full help if no filenames are specified.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
1319 THERR("No filename(s) specified. Try --help.\n"); |
2 | 1320 } |
1 | 1321 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1322 out: |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1323 |
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
|
1324 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
|
1325 |
257
41fe5ec24726
Plug some minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
252
diff
changeset
|
1326 siClearStack(&optFormat); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1327 th_free(setHVSCPath); |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1328 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
|
1329 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
|
1330 |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1331 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
|
1332 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
|
1333 |
19 | 1334 return 0; |
0 | 1335 } |