Mercurial > hg > sidinfo
annotate sidinfo.c @ 311:ee56f1f2b528
Change how the STIL subtune are handled internally. Also fix a bug that
caused the _last_ STIL field of each subtune not to be printed at all :S
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 11 Jan 2020 14:25:23 +0200 |
parents | ff93c168c4aa |
children | b3d46806787d |
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" |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
11 #include <sys/types.h> |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
12 #include <dirent.h> |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
13 #ifdef HAVE_ICONV |
229 | 14 # include <iconv.h> |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
15 #endif |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
16 |
0 | 17 |
229 | 18 // |
28 | 19 // Some constants |
229 | 20 // |
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
|
21 |
229 | 22 // HVSC documents directory |
23 #define SET_HVSC_DOCUMENTS "DOCUMENTS" | |
24 | |
25 // Songlengths database filename prefix (.md5|.txt appended) | |
26 #define SET_SLDB_FILEBASE "Songlengths" | |
1 | 27 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
28 // STIL database file |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
29 #define SET_STILDB_FILENAME "STIL.txt" |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
30 |
121 | 31 |
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
|
32 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
|
33 { |
157
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
34 OFMT_QUOTED = 0x0001, |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
35 OFMT_FORMAT = 0x0002, |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
36 }; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
37 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
38 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
39 enum |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
40 { |
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
|
41 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
|
42 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
|
43 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
|
44 }; |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
45 |
0 | 46 |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
47 enum |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
48 { |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
49 TH_LANG_UTF8, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
50 TH_LANG_ISO88591, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
51 TH_LANG_CP850, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
52 TH_LANG_CP437, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
53 }; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
54 |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
55 |
0 | 56 typedef struct |
57 { | |
63 | 58 int cmd; |
59 char *str; | |
60 char chr; | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
61 int flags; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
62 char *fmt; |
63 | 63 } PSFStackItem; |
64 | |
65 | |
66 typedef struct | |
67 { | |
68 int nitems, nallocated; | |
69 PSFStackItem *items; | |
70 } PSFStack; | |
71 | |
72 | |
73 typedef struct | |
74 { | |
2 | 75 char *name; |
76 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
|
77 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
|
78 char *dfmt; |
2 | 79 } PSFOption; |
80 | |
81 | |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
82 #define HEX_ADDR "%d ($%04x)" |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
83 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
84 static const PSFOption optPSOptions[] = |
2 | 85 { |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
86 { "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
|
87 { "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
|
88 { "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
|
89 { "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
|
90 { "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
|
91 { "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
|
92 { "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
|
93 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
94 { "DataOffs" , "Data offset" , OTYPE_INT , HEX_ADDR }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
95 { "DataSize" , "Data size" , OTYPE_INT , HEX_ADDR }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
96 { "LoadAddr" , "Load address" , OTYPE_INT , HEX_ADDR }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
97 { "InitAddr" , "Init address" , OTYPE_INT , HEX_ADDR }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
98 { "PlayAddr" , "Play address" , OTYPE_INT , HEX_ADDR }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
99 { "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
|
100 { "StartSong" , "Start song" , OTYPE_INT , "%d" }, |
28 | 101 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
102 { "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
|
103 { "SID3Model" , "3rd 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
|
104 { "SID2Addr" , "2nd SID address" , OTYPE_INT , HEX_ADDR }, |
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
105 { "SID3Addr" , "3rd SID address" , OTYPE_INT , 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
|
106 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
107 { "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
|
108 { "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
|
109 { "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
|
110 { "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
|
111 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
112 { "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
|
113 { "STIL" , "STIL information" , OTYPE_OTHER , NULL }, |
2 | 114 }; |
115 | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
116 static const int noptPSOptions = sizeof(optPSOptions) / sizeof(optPSOptions[0]); |
2 | 117 |
118 | |
28 | 119 // Option variables |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
120 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
|
121 *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
|
122 *setSTILDBPath = NULL; |
163
179ffe97599c
Implement support for the "new" MD5 format of SLDB.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
123 BOOL setSLDBNewFormat = FALSE, |
179ffe97599c
Implement support for the "new" MD5 format of SLDB.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
124 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
|
125 optFieldNamePrefix = TRUE, |
29 | 126 optHexadecimal = FALSE, |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
127 optFieldOutput = TRUE, |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
128 optRecurseDirs = FALSE; |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
129 char *optOneLineFieldSep = NULL, |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
130 *optEscapeChars = NULL; |
19 | 131 int optNFiles = 0; |
2 | 132 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
133 PSFStack optFormat; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
134 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
135 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
|
136 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
|
137 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
138 |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
139 BOOL setUseOutConv; |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
140 #ifdef HAVE_ICONV |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
141 iconv_t setIConvCtx; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
142 #else |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
143 int setOutLang; |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
144 #endif |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
145 |
2 | 146 |
28 | 147 // Define option arguments |
121 | 148 static const th_optarg optList[] = |
2 | 149 { |
150 { 0, '?', "help", "Show this help", OPT_NONE }, | |
204
0327fe1d0686
Enable -v verbosity option.
Matti Hamalainen <ccr@tnsp.org>
parents:
200
diff
changeset
|
151 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
173
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
152 {10, 0, "license", "Print out this program's license agreement", OPT_NONE }, |
177 | 153 |
2 | 154 { 2, 'p', "parsable", "Output in script-parsable format", OPT_NONE }, |
7 | 155 { 5, 'n', "noprefix", "Output without field name prefix", OPT_NONE }, |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
156 { 6, 'l', "line", "Output in one line format, -l <field separator>", OPT_ARGREQ }, |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
157 {11, 'e', "escape", "Escape these characters in fields (see note)", OPT_ARGREQ }, |
2 | 158 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ }, |
159 { 4, 'x', "hex", "Use hexadecimal values", OPT_NONE }, | |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
160 { 7, 'F', "format", "Use given format string (see below)", OPT_ARGREQ }, |
212
90ff5dbee152
The HVSC path -H option now requires HVSC root directory, not HVSC/DOCUMENTS directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
209
diff
changeset
|
161 { 8, 'H', "hvsc", "Specify path to HVSC root directory", OPT_ARGREQ }, |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
162 { 9, 'S', "sldb", "Specify Songlengths.(txt|md5) file", OPT_ARGREQ }, |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
163 {13, 'T', "stildb", "Specify STIL.txt file", OPT_ARGREQ }, |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
164 {12, 'R', "recurse", "Recurse into sub-directories", OPT_NONE }, |
2 | 165 }; |
166 | |
44
7b137e4e817c
Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
167 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
2 | 168 |
169 | |
173
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
170 void argShowLicense(void) |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
171 { |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
172 printf("%s - %s\n%s\n", th_prog_name, th_prog_desc, th_prog_author); |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
173 printf( |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
174 "\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
175 "Redistribution and use in source and binary forms, with or without\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
176 "modification, are permitted provided that the following conditions\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
177 "are met:\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
178 "\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
179 " 1. Redistributions of source code must retain the above copyright\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
180 " notice, this list of conditions and the following disclaimer.\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
181 "\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
182 " 2. Redistributions in binary form must reproduce the above copyright\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
183 " notice, this list of conditions and the following disclaimer in\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
184 " the documentation and/or other materials provided with the\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
185 " distribution.\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
186 "\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
187 " 3. The name of the author may not be used to endorse or promote\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
188 " products derived from this software without specific prior written\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
189 " permission.\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
190 "\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
191 "THIS SOFTWARE IS PROVIDED BY THE AUTHOR \"AS IS\" AND ANY EXPRESS OR\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
192 "IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
193 "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
194 "ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
195 "INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
196 "(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
197 "SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
198 "HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
199 "STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
200 "IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
201 "POSSIBILITY OF SUCH DAMAGE.\n" |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
202 ); |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
203 } |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
204 |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
205 |
2 | 206 void argShowHelp(void) |
207 { | |
75
92a4065c41d0
Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
208 int index, len; |
2 | 209 |
20 | 210 th_print_banner(stdout, th_prog_name, "[options] <sid filename> [sid filename #2 ..]"); |
44
7b137e4e817c
Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
211 th_args_help(stdout, optList, optListN, 0); |
2 | 212 printf( |
213 "\n" | |
214 "Available fields:\n"); | |
3 | 215 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
216 for (len = index = 0; index < noptPSOptions; index++) |
2 | 217 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
218 const PSFOption *opt = &optPSOptions[index]; |
75
92a4065c41d0
Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
219 len += strlen(opt->name) + 3; |
92a4065c41d0
Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
220 if (len >= 72) |
2 | 221 { |
222 printf("\n"); | |
75
92a4065c41d0
Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
223 len = 0; |
2 | 224 } |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
225 printf("%s%s", opt->name, (index < noptPSOptions - 1) ? ", " : "\n\n"); |
2 | 226 } |
58 | 227 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
228 printf( |
61 | 229 "Example: %s -x -p -f hash,copyright somesidfile.sid\n" |
230 "\n" | |
231 "Format strings for '-F' option are composed of @fields@ that\n" | |
232 "are expanded to their value. Also, escape sequences \\r, \\n and \\t\n" | |
233 "can be used: -F \"hash=@hash@\\ncopy=@copyright@\\n\"\n" | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
234 "\n" |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
235 "The -F fields can be further formatted via printf-style specifiers:\n" |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
236 "-F \"@copyright:'%%-30s'@\"\n" |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
237 "\n" |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
238 "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
|
239 "(option -e <chars>), if escape characters have NOT been separately set.\n" |
234 | 240 "\n" |
241 "TIP: When specifying HVSC paths, it is preferable to use -H/--hvsc option,\n" | |
242 "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
|
243 "You can also set it via HVSC_BASE environment variable, see README.\n" |
234 | 244 "\n" |
61 | 245 , th_prog_name); |
2 | 246 } |
247 | |
248 | |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
249 int argMatchPSField(const char *field) |
2 | 250 { |
251 int index, found = -1; | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
252 for (index = 0; index < noptPSOptions; index++) |
2 | 253 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
254 const PSFOption *opt = &optPSOptions[index]; |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
255 if (th_strcasecmp(opt->name, field) == 0) |
2 | 256 { |
257 if (found >= 0) | |
258 return -2; | |
259 found = index; | |
260 } | |
261 } | |
262 | |
263 return found; | |
264 } | |
265 | |
266 | |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
267 int argMatchPSFieldError(const char *field) |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
268 { |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
269 int found = argMatchPSField(field); |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
270 switch (found) |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
271 { |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
272 case -1: |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
273 THERR("No such field '%s'.\n", field); |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
274 break; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
275 |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
276 case -2: |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
277 THERR("Field '%s' is ambiguous.\n", field); |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
278 break; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
279 } |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
280 return found; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
281 } |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
282 |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
283 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
284 const char *siStripHVSCPath(const char *filename) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
285 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
286 if (setHVSCPath != NULL) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
287 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
288 const char *hvsc = setHVSCPath, *fptr = filename; |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
289 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
290 // Compare until end of string(s) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
291 for (; *hvsc != 0 && *fptr != 0 && *hvsc == *fptr; hvsc++, fptr++); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
292 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
293 // Full match? |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
294 if (*hvsc == 0) |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
295 return fptr - 1; |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
296 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
297 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
298 return filename; |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
299 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
300 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
301 |
240 | 302 char *siCheckHVSCFilePath(const char *filebase, const char *fext) |
303 { | |
304 th_stat_data sdata; | |
305 char *npath = th_strdup_printf("%s%c%s%c%s%s", | |
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
|
306 setHVSCPath, TH_DIR_SEPARATOR_CHR, |
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
|
307 SET_HVSC_DOCUMENTS, TH_DIR_SEPARATOR_CHR, |
240 | 308 filebase, fext != NULL ? fext : ""); |
309 | |
310 if (npath != NULL && | |
311 th_stat_path(npath, &sdata) && | |
312 (sdata.flags & TH_IS_READABLE) && | |
313 (sdata.flags & TH_IS_DIR) == 0) | |
314 return npath; | |
315 | |
316 th_free(npath); | |
317 return NULL; | |
318 } | |
319 | |
320 | |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
321 BOOL siStackAddItem(PSFStack *stack, const PSFStackItem *item) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
322 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
323 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
|
324 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
325 stack->nallocated += 16; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
326 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
|
327 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
328 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
|
329 return FALSE; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
330 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
331 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
332 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
333 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
|
334 stack->nitems++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
335 return TRUE; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
336 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
337 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
338 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
339 void siClearStack(PSFStack *stack) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
340 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
341 if (stack != NULL) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
342 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
343 if (stack->nitems > 0 && stack->items != NULL) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
344 { |
246
f50947e8ff93
Move two index variables from block scope to loop scope.
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
345 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
|
346 { |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
347 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
|
348 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
|
349 th_free(item->fmt); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
350 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
351 th_free(stack->items); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
352 } |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
353 |
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
354 // Clear the stack data |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
355 memset(stack, 0, sizeof(PSFStack)); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
356 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
357 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
358 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
359 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
360 BOOL argParsePSFields(PSFStack *stack, const char *fmt) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
361 { |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
362 const char *start = fmt; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
363 siClearStack(stack); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
364 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
365 while (*start) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
366 { |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
367 const char *end = strchr(start, ','); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
368 char *field = (end != NULL) ? |
116
d062312ea850
Fix th_strndup_trim() usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
369 th_strndup_trim(start, end - start, TH_TRIM_BOTH) : |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
370 th_strdup_trim(start, TH_TRIM_BOTH); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
371 |
118 | 372 if (field != NULL) |
373 { | |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
374 PSFStackItem item; |
118 | 375 int found = argMatchPSFieldError(field); |
376 th_free(field); | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
377 |
118 | 378 if (found < 0) |
379 return FALSE; | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
380 |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
381 memset(&item, 0, sizeof(item)); |
118 | 382 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
|
383 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
|
384 |
118 | 385 if (!siStackAddItem(stack, &item)) |
386 return FALSE; | |
387 } | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
388 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
389 if (!end) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
390 break; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
391 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
392 start = end + 1; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
393 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
394 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
395 return TRUE; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
396 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
397 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
398 |
280
08695f046565
#ifdef out the character set translation tables used by the fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
399 #ifndef HAVE_ICONV |
08695f046565
#ifdef out the character set translation tables used by the fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
400 |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
401 static const uint8_t si_lang_iso88591_to_cp850[16*6] = { |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
402 0xff, 0xad, 0xbd, 0x9c, 0xcf, 0xbe, 0xdd, 0xf5, 0xf9, 0xb8, 0xa6, 0xae, 0xaa, 0xf0, 0xa9, 0xee, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
403 0xf8, 0xf1, 0xfd, 0xfc, 0xef, 0xe6, 0xf4, 0xfa, 0xf7, 0xfb, 0xa7, 0xaf, 0xac, 0xab, 0xf3, 0xa8, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
404 0xb7, 0xb5, 0xb6, 0xc7, 0x8e, 0x8f, 0x92, 0x80, 0xd4, 0x90, 0xd2, 0xd3, 0xde, 0xd6, 0xd7, 0xd8, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
405 0xd1, 0xa5, 0xe3, 0xe0, 0xe2, 0xe5, 0x99, 0x9e, 0x9d, 0xeb, 0xe9, 0xea, 0x9a, 0xed, 0xe8, 0xe1, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
406 0x85, 0xa0, 0x83, 0xc6, 0x84, 0x86, 0x91, 0x87, 0x8a, 0x82, 0x88, 0x89, 0x8d, 0xa1, 0x8c, 0x8b, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
407 0xd0, 0xa4, 0x95, 0xa2, 0x93, 0xe4, 0x94, 0xf6, 0x9b, 0x97, 0xa3, 0x96, 0x81, 0xec, 0xe7, 0x98, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
408 }; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
409 |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
410 static const uint8_t si_lang_iso88591_to_cp437[16*6] = { |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
411 0xff, 0xad, 0x9b, 0x9c, 0x00, 0x9d, 0x00, 0x00, 0x00, 0x00, 0xa6, 0xae, 0xaa, 0x00, 0x00, 0x00, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
412 0xf8, 0xf1, 0xfd, 0x00, 0x00, 0xe6, 0x00, 0xfa, 0x00, 0x00, 0xa7, 0xaf, 0xac, 0xab, 0x00, 0xa8, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
413 0x00, 0x00, 0x00, 0x00, 0x8e, 0x8f, 0x92, 0x80, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
414 0x00, 0xa5, 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0x00, 0x00, 0xe1, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
415 0x85, 0xa0, 0x83, 0x00, 0x84, 0x86, 0x91, 0x87, 0x8a, 0x82, 0x88, 0x89, 0x8d, 0xa1, 0x8c, 0x8b, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
416 0x00, 0xa4, 0x95, 0xa2, 0x93, 0x00, 0x94, 0xf6, 0x00, 0x97, 0xa3, 0x96, 0x81, 0x00, 0x00, 0x98, |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
417 }; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
418 |
280
08695f046565
#ifdef out the character set translation tables used by the fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
419 #endif |
08695f046565
#ifdef out the character set translation tables used by the fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
420 |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
421 |
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
|
422 char *siConvertCharset(const char *src) |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
423 { |
157
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
424 #ifdef HAVE_ICONV |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
425 size_t srcLeft = strlen(src) + 1; |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
426 size_t outLeft = srcLeft * 2; |
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
|
427 char *srcPtr = (char *) src; |
157
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
428 char *outBuf, *outPtr; |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
429 |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
430 if ((outBuf = outPtr = th_malloc(outLeft + 1)) == NULL) |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
431 return NULL; |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
432 |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
433 while (srcLeft > 0) |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
434 { |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
435 size_t ret = iconv(setIConvCtx, &srcPtr, &srcLeft, &outPtr, &outLeft); |
157
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
436 if (ret == (size_t) -1) |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
437 break; |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
438 } |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
439 |
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
|
440 #else |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
441 // Fallback conversion of ISO-8859-1 to X |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
442 size_t srcSize = strlen(src), outSize, minLeft; |
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
|
443 const uint8_t *srcPtr = (const uint8_t *) src; |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
444 const uint8_t *tab; |
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
|
445 uint8_t *outBuf, *outPtr; |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
446 |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
447 switch (setOutLang) |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
448 { |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
449 case TH_LANG_UTF8: |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
450 outSize = srcSize * 2; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
451 minLeft = 2; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
452 break; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
453 |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
454 default: |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
455 outSize = srcSize; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
456 minLeft = 1; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
457 } |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
458 |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
459 if ((outBuf = outPtr = th_malloc(outSize)) == NULL) |
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
|
460 return NULL; |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
461 |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
462 while (srcSize > 0 && outSize >= minLeft) |
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
|
463 { |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
464 switch (setOutLang) |
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
|
465 { |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
466 case TH_LANG_UTF8: |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
467 // Not 100% correct really, but close enough |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
468 if (*srcPtr < 0x80) |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
469 { |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
470 *outPtr++ = *srcPtr; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
471 outSize--; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
472 } |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
473 else |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
474 if (*srcPtr < 0xBF) |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
475 { |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
476 *outPtr++ = 0xC2; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
477 *outPtr++ = *srcPtr; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
478 outSize -= 2; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
479 } |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
480 else |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
481 { |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
482 *outPtr++ = 0xC3; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
483 *outPtr++ = *srcPtr - 0x40; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
484 outSize -= 2; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
485 } |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
486 break; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
487 |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
488 case TH_LANG_ISO88591: |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
489 *outPtr++ = *srcPtr; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
490 outSize--; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
491 break; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
492 |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
493 case TH_LANG_CP850: |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
494 case TH_LANG_CP437: |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
495 // Not 100% correct either, but close enough |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
496 tab = (setOutLang == TH_LANG_CP850) ? si_lang_iso88591_to_cp850 : si_lang_iso88591_to_cp437; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
497 |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
498 if (*srcPtr < 0x7f) |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
499 *outPtr++ = *srcPtr; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
500 else |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
501 if (*srcPtr >= 0xA0) |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
502 *outPtr++ = tab[*srcPtr - 0xA0]; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
503 else |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
504 *outPtr++ = '?'; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
505 |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
506 outSize--; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
507 break; |
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
|
508 } |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
509 |
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
|
510 srcPtr++; |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
511 srcSize--; |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
512 } |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
513 |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
514 *outPtr++ = 0; |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
515 #endif |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
516 |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
517 return (char *) outBuf; |
157
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
518 } |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
519 |
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
520 |
283 | 521 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
|
522 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
|
523 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
|
524 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
525 char buf[64]; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
526 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
|
527 BOOL f_neg = FALSE; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
528 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
529 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
|
530 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
|
531 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
532 if (vret == EOF) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
533 return 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
534 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
535 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
|
536 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
537 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
538 |
283 | 539 static int siItemFormatStrPrintDo(th_vprintf_ctx *ctx, |
540 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
|
541 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
|
542 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
543 int ret = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
544 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
545 while (*fmt) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
546 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
547 if (*fmt != '%') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
548 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
549 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
|
550 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
551 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
552 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
553 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
554 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
|
555 BOOL end = FALSE; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
556 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
557 fmt++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
558 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
559 // Check for flags |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
560 while (!end) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
561 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
562 switch (*fmt) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
563 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
564 case '#': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
565 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
|
566 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
567 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
568 case '+': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
569 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
|
570 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
571 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
572 case '0': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
573 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
|
574 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
575 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
576 case '-': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
577 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
|
578 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
579 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
580 case ' ': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
581 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
|
582 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
583 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
584 case '\'': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
585 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
|
586 break; |
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 default: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
589 end = TRUE; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
590 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
591 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
592 if (!end) fmt++; |
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 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
595 // Get field width |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
596 if (*fmt == '*') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
597 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
598 return -101; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
599 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
600 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
601 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
602 f_width = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
603 while (th_isdigit(*fmt)) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
604 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
|
605 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
606 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
607 // Check for field precision |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
608 if (*fmt == '.') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
609 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
610 fmt++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
611 if (*fmt == '*') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
612 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
613 return -102; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
614 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
615 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
616 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
617 // 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
|
618 f_prec = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
619 while (th_isdigit(*fmt)) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
620 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
|
621 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
622 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
623 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
624 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
625 // 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
|
626 switch (*fmt) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
627 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
628 case 0: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
629 return -104; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
630 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
631 case 'o': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
632 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
|
633 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
|
634 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
635 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
636 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
637 case 'u': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
638 case 'i': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
639 case 'd': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
640 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
|
641 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
|
642 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
643 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
644 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
645 case 'x': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
646 case 'X': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
647 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
|
648 if (*fmt == 'X') |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
649 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
|
650 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
|
651 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
652 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
653 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
654 case 's': |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
655 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
|
656 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
|
657 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
658 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
659 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
660 //case '%': |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
661 default: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
662 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
|
663 goto out; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
664 break; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
665 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
666 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
667 fmt++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
668 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
669 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
670 out: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
671 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
|
672 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
673 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
674 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
675 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
|
676 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
677 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
|
678 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
679 ctx->size += 64; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
680 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
|
681 return EOF; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
682 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
683 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
684 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
|
685 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
686 ctx->pos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
687 ctx->ipos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
688 return ch; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
689 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
690 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
691 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
692 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
|
693 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
694 th_vprintf_ctx ctx; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
695 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
696 ctx.size = 128; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
697 ctx.buf = th_malloc(ctx.size); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
698 ctx.pos = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
699 ctx.ipos = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
700 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
701 if (ctx.buf == NULL) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
702 return NULL; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
703 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
704 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
|
705 goto err; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
706 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
707 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
|
708 goto err; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
709 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
710 return ctx.buf; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
711 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
712 err: |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
713 th_free(ctx.buf); |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
714 return NULL; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
715 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
716 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
717 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
718 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
|
719 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
720 ctx->pos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
721 ctx->ipos++; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
722 return ch; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
723 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
724 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
725 |
283 | 726 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
|
727 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
728 th_vprintf_ctx ctx; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
729 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
730 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
|
731 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
732 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
|
733 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
734 |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
735 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
736 // |
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
737 // Parse a format string into a PSFStack structure |
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
738 // |
283 | 739 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
|
740 { |
83 | 741 const char *start = NULL; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
742 int mode = 0; |
113
cd97e7517e21
Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
743 BOOL rval = TRUE; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
744 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
745 siClearStack(stack); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
746 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
747 while (mode != -1) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
748 switch (mode) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
749 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
750 case 0: |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
751 if (*fmt == '@') |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
752 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
753 start = fmt + 1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
754 mode = 1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
755 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
756 else |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
757 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
758 start = fmt; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
759 mode = 2; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
760 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
761 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
762 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
763 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
764 case 1: |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
765 if (*fmt != '@') |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
766 { |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
767 if (*fmt == 0) |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
768 mode = -1; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
769 fmt++; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
770 break; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
771 } |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
772 |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
773 if (fmt - start == 0) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
774 { |
177 | 775 // "@@" 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
|
776 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
|
777 memset(&item, 0, sizeof(item)); |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
778 item.cmd = -2; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
779 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
|
780 |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
781 if (!siStackAddItem(stack, &item)) |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
782 return FALSE; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
783 } |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
784 else |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
785 { |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
786 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
|
787 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
|
788 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
789 *pfield = 0; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
790 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
|
791 } |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
792 |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
793 int ret = argMatchPSFieldError(field); |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
794 if (ret >= 0) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
795 { |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
796 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
|
797 memset(&item, 0, sizeof(item)); |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
798 item.cmd = ret; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
799 |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
800 if (fopt != NULL) |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
801 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
802 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
|
803 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
804 item.flags |= OFMT_FORMAT; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
805 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
|
806 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
807 else |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
808 { |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
809 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
|
810 rval = FALSE; |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
811 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
812 } |
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
813 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
814 if (!siStackAddItem(stack, &item)) |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
815 rval = FALSE; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
816 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
817 else |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
818 rval = FALSE; |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
819 |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
820 th_free(fopt); |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
821 th_free(field); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
822 } |
143
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
823 |
e481947fd051
Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
824 mode = 0; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
825 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
826 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
827 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
828 case 2: |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
829 if (*fmt == 0 || *fmt == '@') |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
830 { |
300
85d92bcbebf3
Be more diligent about not doing structure reuse, easy to have either uninitialized
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
831 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
|
832 memset(&item, 0, sizeof(item)); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
833 item.cmd = -1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
834 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
|
835 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
836 if (!siStackAddItem(stack, &item)) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
837 return FALSE; |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
838 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
839 mode = (*fmt == 0) ? -1 : 0; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
840 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
841 else |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
842 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
843 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
844 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
845 |
113
cd97e7517e21
Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
846 return rval; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
847 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
848 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
849 |
283 | 850 static BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
2 | 851 { |
852 switch (optN) | |
853 { | |
854 case 0: | |
855 argShowHelp(); | |
856 exit(0); | |
857 break; | |
858 | |
173
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
859 case 10: |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
860 argShowLicense(); |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
861 exit(0); |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
862 break; |
23dcc2dc47a9
Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
863 |
2 | 864 case 1: |
172
6dcf4ca1dce7
Change to match th-libs' verbosity level changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
865 th_verbosity++; |
2 | 866 break; |
867 | |
868 case 2: | |
869 optParsable = TRUE; | |
870 break; | |
871 | |
872 case 3: | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
873 if (!argParsePSFields(&optFormat, optArg)) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
874 return FALSE; |
2 | 875 break; |
876 | |
877 case 4: | |
878 optHexadecimal = TRUE; | |
879 break; | |
880 | |
7 | 881 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
|
882 optFieldNamePrefix = FALSE; |
7 | 883 break; |
884 | |
29 | 885 case 6: |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
886 optOneLineFieldSep = optArg; |
29 | 887 break; |
888 | |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
889 case 7: |
111 | 890 optFieldOutput = FALSE; |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
891 optParsable = FALSE; |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
892 if (!argParsePSFormatStr(&optFormat, optArg)) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
893 return FALSE; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
894 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
895 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
896 case 8: |
252
9e45cb6f12a5
Use th_pstr_cpy() for setting certain variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
897 th_pstr_cpy(&setHVSCPath, optArg); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
898 break; |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
899 |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
900 case 9: |
252
9e45cb6f12a5
Use th_pstr_cpy() for setting certain variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
901 th_pstr_cpy(&setSLDBPath, optArg); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
902 break; |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
903 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
904 case 13: |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
905 th_pstr_cpy(&setSTILDBPath, optArg); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
906 break; |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
907 |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
908 case 11: |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
909 optEscapeChars = optArg; |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
910 break; |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
911 |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
912 case 12: |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
913 optRecurseDirs = TRUE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
914 break; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
915 |
2 | 916 default: |
917 THERR("Unknown option '%s'.\n", currArg); | |
918 return FALSE; | |
919 } | |
920 | |
921 return TRUE; | |
922 } | |
923 | |
924 | |
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
|
925 static char * siEscapeString(const char *str, const char *esc) |
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
|
926 { |
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
|
927 if (str == NULL) |
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
|
928 return NULL; |
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
|
929 |
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
|
930 if (esc == NULL) |
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
|
931 return th_strdup(str); |
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
|
932 |
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
|
933 size_t len = 0, size = strlen(str) + 1; |
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
|
934 char *buf = th_malloc(size); |
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
|
935 if (buf == NULL) |
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
|
936 return NULL; |
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
|
937 |
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
|
938 while (*str) |
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
|
939 { |
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
|
940 if (strchr(esc, *str) != NULL || *str == '\\') |
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
|
941 { |
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
|
942 if (!th_strbuf_putch(&buf, &size, &len, '\\')) |
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
|
943 goto err; |
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
|
944 } |
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
|
945 if (!th_strbuf_putch(&buf, &size, &len, *str)) |
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
|
946 goto err; |
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
|
947 |
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
|
948 str++; |
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
|
949 } |
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
|
950 |
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
|
951 if (!th_strbuf_putch(&buf, &size, &len, 0)) |
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
|
952 goto err; |
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
|
953 |
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
|
954 return buf; |
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
|
955 |
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
|
956 err: |
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
|
957 th_free(buf); |
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
|
958 return NULL; |
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
|
959 } |
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
|
960 |
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
|
961 |
62
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
962 static void siPrintStrEscapes(FILE *outFile, const char *str) |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
963 { |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
964 while (*str) |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
965 { |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
966 if (*str == '\\') |
82 | 967 switch (*(++str)) |
62
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
968 { |
82 | 969 case 'n': fputc('\n', outFile); break; |
970 case 'r': fputc('\r', outFile); break; | |
971 case 't': fputc('\r', outFile); break; | |
972 case '\\': fputc('\\', outFile); break; | |
973 default: fputc(*str, outFile); break; | |
62
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
974 } |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
975 else |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
976 fputc(*str, outFile); |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
977 |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
978 str++; |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
979 } |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
980 } |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
981 |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
982 |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
983 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
|
984 { |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
985 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
|
986 { |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
987 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
|
988 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
|
989 else |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
990 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
|
991 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
|
992 } |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
993 } |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
994 |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
995 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
996 static void siPrintFieldPrefix(FILE *outFile, const PSFOption *opt) |
2 | 997 { |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
998 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
|
999 (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
|
1000 FALSE); |
2 | 1001 } |
1002 | |
1003 | |
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
|
1004 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
|
1005 { |
111 | 1006 if (optFieldOutput) |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1007 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
|
1008 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
|
1009 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
|
1010 fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : ", ", outFile); |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
1011 } |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
1012 |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
1013 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1014 static const char *siGetInfoFormat(const PSFStackItem *item, const int otype) |
2 | 1015 { |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1016 switch (otype) |
146 | 1017 { |
1018 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
|
1019 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
|
1020 return item->fmt; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
1021 else |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1022 return optHexadecimal ? "$%04x" : "%d"; |
146 | 1023 |
1024 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
|
1025 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
|
1026 return item->fmt; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
1027 else |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1028 return "%s"; |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
1029 |
155
de75385f75e2
Simplify by removing few lines of duplicate code.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1030 default: |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1031 return NULL; |
146 | 1032 } |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1033 } |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1034 |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1035 |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1036 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
|
1037 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
|
1038 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
|
1039 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
|
1040 { |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1041 char *str, *tmp; |
2 | 1042 |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1043 if (setUseOutConv && d_str != NULL && 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
|
1044 { |
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
|
1045 char *tmp2 = siConvertCharset(d_str); |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1046 tmp = siEscapeString(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
|
1047 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
|
1048 } |
157
8fc887cb56d0
Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
1049 else |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1050 tmp = siEscapeString(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
|
1051 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1052 if ((str = siItemFormatStrPrint(fmt, otype, tmp, d_int)) != NULL) |
146 | 1053 fputs(str, outFile); |
3 | 1054 |
146 | 1055 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
|
1056 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
|
1057 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1058 *shown = TRUE; |
2 | 1059 } |
1060 | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1061 |
268
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1062 #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
|
1063 siPrintFieldPrefix(outFile, opt); \ |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1064 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
|
1065 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
|
1066 } while (0) |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1067 |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1068 #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
|
1069 siPrintFieldPrefix(outFile, opt); \ |
6312d33d1361
Refactor and improve the field formatting / printing to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1070 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
|
1071 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
|
1072 } while (0) |
9
c1fba4abf56f
Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
1073 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1074 |
226
c32015f4969e
Rename PSIDHeader struct to SIDLibPSIDHeader to conform with the SIDLib
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
1075 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
|
1076 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
|
1077 { |
114 | 1078 const PSFOption *opt = &optPSOptions[item->cmd]; |
150
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1079 char tmp[128]; |
146 | 1080 |
114 | 1081 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
|
1082 { |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
1083 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
|
1084 case 1: PRS(psid->magic, FALSE); break; |
146 | 1085 case 2: |
1086 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
|
1087 PRS(tmp, FALSE); |
146 | 1088 break; |
1089 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
|
1090 PRS((psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in", FALSE); |
146 | 1091 break; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1092 case 4: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1093 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
|
1094 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
|
1095 break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1096 case 5: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1097 if (psid->version >= 2) |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1098 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
|
1099 break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1100 case 6: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1101 if (psid->version >= 2) |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1102 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
|
1103 break; |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
1104 |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
1105 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
|
1106 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
|
1107 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
|
1108 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
|
1109 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
|
1110 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
|
1111 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
|
1112 |
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
|
1113 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
|
1114 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
|
1115 { |
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
|
1116 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
|
1117 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
|
1118 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
|
1119 |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1120 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
|
1121 } |
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
|
1122 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
|
1123 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
|
1124 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
|
1125 { |
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
|
1126 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
|
1127 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
|
1128 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
|
1129 |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1130 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
|
1131 } |
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
|
1132 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
|
1133 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
|
1134 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
|
1135 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
|
1136 break; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1137 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
|
1138 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
|
1139 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
|
1140 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
|
1141 |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
1142 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
|
1143 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
|
1144 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
|
1145 |
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
|
1146 case 21: |
140
9f96b37c4f75
Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
1147 { |
150
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1148 size_t i, k; |
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1149 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
|
1150 sprintf(&tmp[k], "%02x", psid->hash[i]); |
0288c4d138f7
Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1151 |
156
717d143612e2
Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
1152 PRS(tmp, FALSE); |
140
9f96b37c4f75
Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
1153 } |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1154 break; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1155 |
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
|
1156 case 22: |
142
da29f147afcb
Better check for number of songlengths.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
1157 if (psid->lengths != NULL && psid->lengths->nlengths > 0) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1158 { |
140
9f96b37c4f75
Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
1159 siPrintFieldPrefix(outFile, opt); |
246
f50947e8ff93
Move two index variables from block scope to loop scope.
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
1160 for (int i = 0; i < psid->lengths->nlengths; i++) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1161 { |
114 | 1162 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
|
1163 |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
1164 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
|
1165 len / 60, len % 60, |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
1166 (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
|
1167 |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
1168 siPrintPSIDInfoLine(outFile, shown, |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
1169 siGetInfoFormat(item, OTYPE_STR), |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
1170 OTYPE_STR, |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
1171 tmp, |
d5ab136cdc97
Changes to the STIL and songlengths entry output formats .. just
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
1172 -1, FALSE); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1173 } |
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
|
1174 siPrintFieldSeparator(outFile, FALSE, TRUE); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1175 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1176 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
|
1177 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1178 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
|
1179 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
|
1180 { |
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
|
1181 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
|
1182 |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
1183 // 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
|
1184 // 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
|
1185 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
|
1186 { |
311
ee56f1f2b528
Change how the STIL subtune are handled internally. Also fix a bug that
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
1187 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
|
1188 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
|
1189 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
|
1190 } |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
1191 |
311
ee56f1f2b528
Change how the STIL subtune are handled internally. Also fix a bug that
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
1192 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
|
1193 { |
311
ee56f1f2b528
Change how the STIL subtune are handled internally. Also fix a bug that
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
1194 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
|
1195 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
|
1196 |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
1197 // 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
|
1198 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
|
1199 { |
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
|
1200 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
|
1201 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
|
1202 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
|
1203 } |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1204 |
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
|
1205 // 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
|
1206 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
|
1207 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
|
1208 { |
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
|
1209 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
|
1210 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
|
1211 { |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1212 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
|
1213 { |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1214 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
|
1215 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
|
1216 } |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1217 else |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1218 { |
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1219 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
|
1220 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
|
1221 } |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1222 |
281
514d861516b0
Further work on the STIL fields output format. It's not perfect, nor
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1223 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
|
1224 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
|
1225 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
|
1226 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
|
1227 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
|
1228 -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
|
1229 |
86f5c9ce26a8
Improve the STIL data output by not outputting field separator for the last item.
Matti Hamalainen <ccr@tnsp.org>
parents:
300
diff
changeset
|
1230 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
|
1231 ++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
|
1232 } |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1233 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1234 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1235 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1236 break; |
29 | 1237 } |
2 | 1238 } |
1239 | |
0 | 1240 |
269
cea4a7df9efd
Rename siError() to siPSIDError() and make the printed output more logical.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
1241 void siPSIDError(th_ioctx *fh, const int err, const char *msg) |
187 | 1242 { |
1243 (void) err; | |
269
cea4a7df9efd
Rename siError() to siPSIDError() and make the printed output more logical.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
1244 THERR("%s - %s\n", msg, fh->filename); |
187 | 1245 } |
1246 | |
1247 | |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1248 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
|
1249 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1250 (void) err; |
293
c3ebab7f9094
Fix one more format string to use proper PRIu_SIZE_T.
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
1251 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
|
1252 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1253 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1254 |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1255 BOOL siHandleSIDFile(const char *filename) |
19 | 1256 { |
226
c32015f4969e
Rename PSIDHeader struct to SIDLibPSIDHeader to conform with the SIDLib
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
1257 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
|
1258 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
|
1259 FILE *outFile; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1260 BOOL shown = FALSE; |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
1261 int res; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1262 |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1263 outFile = stdout; |
19 | 1264 |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
1265 if ((res = th_io_fopen(&inFile, &th_stdio_io_ops, filename, "rb")) != THERR_OK) |
19 | 1266 { |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
1267 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
|
1268 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
|
1269 goto error; |
19 | 1270 } |
1271 | |
269
cea4a7df9efd
Rename siError() to siPSIDError() and make the printed output more logical.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
1272 th_io_set_handlers(inFile, siPSIDError, NULL); |
187 | 1273 |
19 | 1274 // Read PSID data |
243
a3dd87b7c00b
Oops, forgot to adjust the code for change in sidlib_read_sid_file_alloc() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1275 if ((res = sidlib_read_sid_file_alloc(inFile, &psid, setSLDBNewFormat)) != THERR_OK) |
19 | 1276 goto error; |
1277 | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1278 // Get songlength information, if any |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1279 if (sidSLDB != NULL) |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1280 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
|
1281 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1282 // 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
|
1283 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
|
1284 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1285 psid->stil = sidlib_stildb_get_node(sidSTILDB, siStripHVSCPath(filename)); |
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 (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
|
1287 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
|
1288 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1289 |
19 | 1290 // Output |
147
f636c55c7cc4
Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
1291 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
|
1292 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1293 PSFStackItem *item = &optFormat.items[index]; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1294 switch (item->cmd) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1295 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1296 case -1: |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1297 siPrintStrEscapes(outFile, item->str); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1298 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1299 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1300 case -2: |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1301 fputc(item->chr, outFile); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1302 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1303 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1304 default: |
126
c1462b7880e8
Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
1305 siPrintPSIDInformationField(outFile, filename, psid, &shown, item); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1306 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1307 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1308 } |
153
e3be2ae6120e
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
1309 |
188
489eb428cf65
Add separator empty line between "files" when in normal output mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
1310 if (optFieldOutput && shown) |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1311 { |
188
489eb428cf65
Add separator empty line between "files" when in normal output mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
1312 fprintf(outFile, "\n"); |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
1313 } |
19 | 1314 |
1315 // Shutdown | |
1316 error: | |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1317 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
|
1318 th_io_free(inFile); |
19 | 1319 |
1320 return TRUE; | |
1321 } | |
1322 | |
1323 | |
191
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1324 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
|
1325 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1326 th_stat_data sdata; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1327 char *npath; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1328 BOOL ret = TRUE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1329 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1330 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
|
1331 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
|
1332 else |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1333 npath = th_strdup(path); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1334 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1335 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
|
1336 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1337 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
|
1338 ret = FALSE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1339 goto out; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1340 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1341 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1342 optNFiles++; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1343 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1344 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
|
1345 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1346 DIR *dirh; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1347 struct dirent *entry; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1348 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1349 // Check if recursion is disabled |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1350 if (!optRecurseDirs && optNFiles > 1) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1351 goto out; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1352 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1353 if ((dirh = opendir(npath)) == NULL) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1354 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1355 int err = th_get_error(); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1356 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
|
1357 path, th_error_str(err)); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1358 ret = FALSE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1359 goto out; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1360 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1361 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1362 while ((entry = readdir(dirh)) != NULL) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1363 if (entry->d_name[0] != '.') |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1364 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1365 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
|
1366 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1367 ret = FALSE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1368 goto out; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1369 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1370 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1371 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1372 closedir(dirh); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1373 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1374 else |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1375 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
|
1376 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1377 siHandleSIDFile(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1378 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1379 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1380 out: |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1381 th_free(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1382 return ret; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1383 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1384 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1385 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1386 BOOL argHandleFile(char *path) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1387 { |
238 | 1388 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
|
1389 BOOL ret; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1390 |
238 | 1391 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
|
1392 return FALSE; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1393 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1394 // 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
|
1395 if ((pt = strrchr(npath, '/')) != NULL || |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1396 (pt = strrchr(npath, '\\')) != NULL) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1397 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1398 *pt++ = 0; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1399 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1400 else |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1401 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1402 th_free(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1403 npath = th_strdup("."); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1404 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
|
1405 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1406 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1407 // 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
|
1408 if (pt != NULL && *pt != 0) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1409 { |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1410 if (strchr(pt, '*') || strchr(pt, '?')) |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1411 pattern = th_strdup(pt); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1412 else |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1413 filename = th_strdup(pt); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1414 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1415 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1416 ret = argHandleFileDir(npath, filename, pattern); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1417 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1418 th_free(pattern); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1419 th_free(npath); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1420 th_free(filename); |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1421 return ret; |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1422 } |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1423 |
d26bc1adfd14
Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1424 |
0 | 1425 int main(int argc, char *argv[]) |
1426 { | |
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
|
1427 char *setLang = th_strdup(getenv("LANG")); |
230 | 1428 th_ioctx *inFile = NULL; |
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
|
1429 |
259
4df54600633a
Add support for "HVSC_BASE" environment variable as used by STILView by LaLa
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
1430 // 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
|
1431 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
|
1432 |
0 | 1433 // Initialize |
309 | 1434 th_init("SIDInfo", "PSID/RSID information displayer", "0.9.2", |
227 | 1435 "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
|
1436 "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
|
1437 |
172
6dcf4ca1dce7
Change to match th-libs' verbosity level changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
1438 th_verbosity = 0; |
0 | 1439 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1440 memset(&optFormat, 0, sizeof(optFormat)); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
1441 |
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
|
1442 // Get environment language |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1443 if (setLang != NULL) |
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1444 { |
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
|
1445 // Get the character encoding part (e.g. "UTF-8" etc.) and |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
1446 // strip out and lowercase everything (e.g. "utf8") |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
1447 size_t i; |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1448 char *ptr = strchr(setLang, '.'); |
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
|
1449 ptr = (ptr == NULL) ? setLang : ptr + 1; |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
1450 |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
1451 for (i = 0; *ptr; ptr++) |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
1452 { |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
1453 if (*ptr != '-') |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
1454 setLang[i++] = th_tolower(*ptr); |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
1455 } |
47f75154c7db
Add internal fallback ISO-8859-1 to UTF-8 converter and improve iconv() support.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
1456 setLang[i] = 0; |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1457 |
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
|
1458 #ifdef HAVE_ICONV |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1459 // Initialize iconv, check if we have language/charset |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1460 setIConvCtx = iconv_open("utf8", "iso88591"); |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1461 setUseOutConv = setIConvCtx != (iconv_t) -1; |
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
|
1462 #else |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1463 // Check if we can use our fallback converter |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1464 if (strcmp(setLang, "utf8") == 0) |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1465 setOutLang = TH_LANG_UTF8; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1466 else |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1467 if (strcmp(setLang, "iso88591") == 0 || |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1468 strcmp(setLang, "cp819") == 0 || |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1469 strcmp(setLang, "latin1") == 0 || |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1470 strcmp(setLang, "cp28591") == 0) |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1471 setOutLang = TH_LANG_ISO88591; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1472 else |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1473 if (strcmp(setLang, "cp850") == 0) |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1474 setOutLang = TH_LANG_CP850; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1475 else |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1476 if (strcmp(setLang, "cp437") == 0) |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1477 setOutLang = TH_LANG_CP437; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1478 else |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1479 setOutLang = TH_LANG_ISO88591; |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1480 |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1481 setUseOutConv = setOutLang != TH_LANG_ISO88591; |
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
|
1482 #endif |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1483 } |
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
|
1484 |
2 | 1485 // Parse command line arguments |
1486 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
|
1487 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
|
1488 goto out; |
2 | 1489 |
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
|
1490 THMSG(2, "Requested output LANG='%s', use charset conversion=%s\n", |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1491 setLang, setUseOutConv ? "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
|
1492 |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1493 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
|
1494 (!optFieldOutput && optFormat.nitems > 0)) |
29 | 1495 { |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1496 // For one-line format and formatted output (-F), disable parsable |
29 | 1497 optParsable = FALSE; |
180
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1498 |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1499 // 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
|
1500 if (optEscapeChars == NULL) |
6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1501 optEscapeChars = optOneLineFieldSep; |
29 | 1502 } |
153
e3be2ae6120e
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
1503 |
161 | 1504 if (optFieldOutput && optFormat.nitems == 0) |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1505 { |
161 | 1506 // 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
|
1507 siClearStack(&optFormat); |
127
1786b9d77782
Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
1508 |
161 | 1509 for (int i = 0; i < noptPSOptions; i++) |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1510 { |
308
04502257ccdf
Add default formats for certain fields, but use them only for the standard
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1511 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
|
1512 memset(&item, 0, sizeof(item)); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1513 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
|
1514 item.fmt = th_strdup(optPSOptions[i].dfmt); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1515 siStackAddItem(&optFormat, &item); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1516 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
1517 } |
29 | 1518 |
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
|
1519 // Check if HVSC path is set |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1520 if (setHVSCPath != NULL) |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1521 { |
270 | 1522 // 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
|
1523 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
|
1524 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
|
1525 |
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
|
1526 // 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
|
1527 if (setSLDBPath == NULL) |
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
|
1528 setSLDBPath = siCheckHVSCFilePath(SET_SLDB_FILEBASE, ".md5"); |
230 | 1529 |
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
|
1530 if (setSLDBPath == 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
|
1531 setSLDBPath = siCheckHVSCFilePath(SET_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
|
1532 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1533 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
|
1534 setSTILDBPath = siCheckHVSCFilePath(SET_STILDB_FILENAME, NULL); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1535 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1536 |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1537 if (setSLDBPath != NULL) |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1538 { |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1539 // Initialize SLDB |
110 | 1540 int ret = THERR_OK; |
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
|
1541 |
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
|
1542 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
|
1543 |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
1544 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
|
1545 { |
186
2f129ea15405
Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
1546 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
|
1547 setSLDBPath, th_error_str(ret)); |
235 | 1548 goto err1; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1549 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1550 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1551 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
|
1552 |
215
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1553 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
|
1554 setSLDBNewFormat ? "new" : "old", |
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1555 setSLDBNewFormat ? ".md5" : ".txt", |
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1556 setSLDBPath); |
d0baac239f30
Be more informative about SLDB format.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1557 |
236
609bfc1bd628
Change sidlib_sldb_new() API to int sidlib_sldb_new(SIDLibSLDB **pdbh).
Matti Hamalainen <ccr@tnsp.org>
parents:
235
diff
changeset
|
1558 if ((ret = sidlib_sldb_new(&sidSLDB)) != THERR_OK) |
110 | 1559 { |
236
609bfc1bd628
Change sidlib_sldb_new() API to int sidlib_sldb_new(SIDLibSLDB **pdbh).
Matti Hamalainen <ccr@tnsp.org>
parents:
235
diff
changeset
|
1560 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
|
1561 th_error_str(ret)); |
235 | 1562 goto err1; |
110 | 1563 } |
1564 | |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1565 if ((ret = sidlib_sldb_read(inFile, sidSLDB)) != THERR_OK) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1566 { |
285 | 1567 THERR("Error parsing SLDB: %s\n", |
1568 th_error_str(ret)); | |
235 | 1569 goto err1; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1570 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1571 |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1572 if ((ret = sidlib_sldb_build_index(sidSLDB)) != THERR_OK) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1573 { |
285 | 1574 THERR("Error building SLDB index: %s\n", |
1575 th_error_str(ret)); | |
235 | 1576 goto err1; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1577 } |
110 | 1578 |
235 | 1579 err1: |
257
41fe5ec24726
Plug some minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
252
diff
changeset
|
1580 th_io_free(inFile); |
230 | 1581 inFile = NULL; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1582 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1583 |
271
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1584 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
|
1585 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1586 // 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
|
1587 int ret = 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
|
1588 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1589 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
|
1590 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1591 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
|
1592 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
|
1593 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
|
1594 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1595 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1596 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
|
1597 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1598 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
|
1599 setSTILDBPath); |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1600 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1601 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
|
1602 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1603 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
|
1604 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
|
1605 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
|
1606 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1607 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1608 if ((ret = sidlib_stildb_read(inFile, 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
|
1609 { |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1610 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
|
1611 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
|
1612 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
|
1613 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1614 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1615 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
|
1616 { |
285 | 1617 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
|
1618 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
|
1619 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
|
1620 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1621 |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1622 err2: |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1623 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
|
1624 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
|
1625 } |
439d08a11365
Add support for STIL database in output. The output format is probably going
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
1626 |
23 | 1627 // Process files |
1628 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
|
1629 NULL, argHandleFile, OPTH_ONLY_OTHER)) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1630 goto out; |
23 | 1631 |
19 | 1632 if (optNFiles == 0) |
2 | 1633 { |
141
71725be55ed1
Do not show full help if no filenames are specified.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
1634 THERR("No filename(s) specified. Try --help.\n"); |
2 | 1635 } |
1 | 1636 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1637 out: |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1638 |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1639 #ifdef HAVE_ICONV |
278
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1640 if (setUseOutConv) |
d73ccb155878
Implement support for outputting CP850 and CP437 in our simple fallback
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1641 iconv_close(setIConvCtx); |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1642 #endif |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1643 |
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
|
1644 th_free(setLang); |
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
|
1645 |
257
41fe5ec24726
Plug some minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
252
diff
changeset
|
1646 siClearStack(&optFormat); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1647 th_free(setHVSCPath); |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
1648 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
|
1649 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
|
1650 |
222
3a01518fffe0
Rename sidlib functions from si_* prefix to sidlib_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
1651 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
|
1652 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
|
1653 |
19 | 1654 return 0; |
0 | 1655 } |