Mercurial > hg > sidinfo
annotate sidinfo.c @ 57:c10c79c266d3
Remove useless code.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 26 Dec 2015 20:02:13 +0200 |
parents | d2148880c71e |
children | 5ea07110f0cf |
rev | line source |
---|---|
2 | 1 /* |
2 * SIDInfo - PSID/RSID information displayer | |
3 * Written by Matti 'ccr' Hämäläinen | |
56 | 4 * (C) Copyright 2014-2015 Tecnic Software productions (TNSP) |
2 | 5 */ |
0 | 6 #include "th_args.h" |
7 #include "th_endian.h" | |
2 | 8 #include "th_string.h" |
0 | 9 #include "th_crypto.h" |
10 | |
28 | 11 // Some constants |
2 | 12 #define PSID_MAGIC_LEN 4 |
13 #define PSID_STR_LEN 32 | |
1 | 14 #define PSID_BUFFER_SIZE (1024 * 16) |
15 | |
0 | 16 |
28 | 17 // Flags for various information fields |
2 | 18 enum |
19 { | |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
20 SIF_NONE = 0, |
2 | 21 |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
22 SIF_TYPE = 0x00000001, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
23 SIF_VERSION = 0x00000002, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
24 SIF_DATA_OFFS = 0x00000004, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
25 SIF_LOAD_ADDR = 0x00000008, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
26 SIF_INIT_ADDR = 0x00000010, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
27 SIF_PLAY_ADDR = 0x00000020, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
28 SIF_SONGS = 0x00000040, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
29 SIF_START_SONG = 0x00000080, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
30 SIF_SPEEDS = 0x00000100, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
31 SIF_SID_NAME = 0x00000200, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
32 SIF_SID_AUTHOR = 0x00000400, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
33 SIF_SID_COPYRIGHT = 0x00000800, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
34 SIF_PLAYER_TYPE = 0x00001000, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
35 SIF_PLAYSID_TUNE = 0x00002000, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
36 SIF_VIDEO_CLOCK = 0x00004000, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
37 SIF_SID_MODEL = 0x00008000, |
2 | 38 |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
39 SIF_DATA_SIZE = 0x00100000, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
40 SIF_HASH = 0x00200000, |
51 | 41 SIF_FILENAME = 0x01000000, |
2 | 42 |
51 | 43 SIF_ALL = 0x0fffffff, |
2 | 44 }; |
45 | |
46 | |
0 | 47 typedef struct |
48 { | |
2 | 49 uint32_t flag; |
50 char *name; | |
51 char *lname; | |
52 } PSFOption; | |
53 | |
54 | |
45 | 55 static const PSFOption optPSFlags[] = |
2 | 56 { |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
57 { SIF_FILENAME , "Filename" , NULL }, |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
58 { SIF_TYPE , "Type" , NULL }, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
59 { SIF_VERSION , "Version" , NULL }, |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
60 { SIF_PLAYER_TYPE , "PlayerType" , "Player type" }, |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
61 { SIF_PLAYSID_TUNE , "PlayerCompat", "Player compatibility" }, |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
62 { SIF_VIDEO_CLOCK , "VideoClock" , "Video clock speed" }, |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
63 { SIF_SID_MODEL , "SIDModel" , "SID model" }, |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
64 |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
65 { SIF_DATA_OFFS , "DataOffs" , "Data offset" }, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
66 { SIF_DATA_SIZE , "DataSize" , "Data size" }, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
67 { SIF_LOAD_ADDR , "LoadAddr" , "Load address" }, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
68 { SIF_INIT_ADDR , "InitAddr" , "Init address" }, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
69 { SIF_PLAY_ADDR , "PlayAddr" , "Play address" }, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
70 { SIF_SONGS , "Songs" , "Songs" }, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
71 { SIF_START_SONG , "StartSong" , "Start song" }, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
72 { SIF_SID_NAME , "Name" , NULL }, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
73 { SIF_SID_AUTHOR , "Author" , NULL }, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
74 { SIF_SID_COPYRIGHT , "Copyright" , NULL }, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
75 { SIF_HASH , "Hash" , NULL }, |
28 | 76 |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
77 { SIF_ALL , "All" , NULL }, |
2 | 78 }; |
79 | |
45 | 80 static const int noptPSFlags = sizeof(optPSFlags) / sizeof(optPSFlags[0]); |
2 | 81 |
82 | |
28 | 83 // Option variables |
2 | 84 BOOL optParsable = FALSE, |
7 | 85 optNoNamePrefix = FALSE, |
29 | 86 optHexadecimal = FALSE, |
87 optOneLine = FALSE; | |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
88 char *optFieldSep = NULL; |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
89 uint32_t optFields = SIF_ALL; |
19 | 90 int optNFiles = 0; |
2 | 91 |
92 | |
28 | 93 // Define option arguments |
44
7b137e4e817c
Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
94 static const th_optarg_t optList[] = |
2 | 95 { |
96 { 0, '?', "help", "Show this help", OPT_NONE }, | |
24
16d6b5029543
Disable verbose option for now, it does not do anything at the moment.
Matti Hamalainen <ccr@tnsp.org>
parents:
23
diff
changeset
|
97 // { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
2 | 98 { 2, 'p', "parsable", "Output in script-parsable format", OPT_NONE }, |
7 | 99 { 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
|
100 { 6, 'l', "line", "Output in one line format, -l <field separator>", OPT_ARGREQ }, |
2 | 101 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ }, |
102 { 4, 'x', "hex", "Use hexadecimal values", OPT_NONE }, | |
103 }; | |
104 | |
44
7b137e4e817c
Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
105 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
2 | 106 |
107 | |
108 void argShowHelp(void) | |
109 { | |
110 int index, n; | |
111 | |
20 | 112 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
|
113 th_args_help(stdout, optList, optListN, 0); |
2 | 114 printf( |
115 "\n" | |
116 "Available fields:\n"); | |
3 | 117 |
2 | 118 for (index = n = 0; index < noptPSFlags; index++) |
119 { | |
120 const PSFOption *opt = &optPSFlags[index]; | |
121 printf("%s%s", opt->name, (index < noptPSFlags - 1) ? ", " : "\n\n"); | |
122 if (++n > 5) | |
123 { | |
124 printf("\n"); | |
125 n = 0; | |
126 } | |
127 } | |
5 | 128 |
129 printf("Example: %s -x -p -f hash,copyright somesidfile.sid\n", th_prog_name); | |
2 | 130 } |
131 | |
132 | |
133 int argMatchPSField(const char *field) | |
134 { | |
135 int index, found = -1; | |
136 size_t len = strlen(field); | |
137 for (index = 0; index < noptPSFlags; index++) | |
138 { | |
139 const PSFOption *opt = &optPSFlags[index]; | |
48 | 140 if (th_strncasecmp(opt->name, field, len) == 0) |
2 | 141 { |
142 if (found >= 0) | |
143 return -2; | |
144 found = index; | |
145 } | |
146 } | |
147 | |
148 return found; | |
149 } | |
150 | |
151 | |
152 BOOL argParsePSField(char *opt, char *end, uint32_t *fields) | |
153 { | |
154 // Trim whitespace | |
155 if (end != NULL) | |
156 { | |
157 *end = 0; | |
158 for (end--; end > opt && *end && th_isspace(*end); end--) | |
159 *end = 0; | |
160 } | |
161 while (*opt && th_isspace(*opt)) opt++; | |
162 | |
163 // Match field name | |
164 int found = argMatchPSField(opt); | |
165 switch (found) | |
166 { | |
167 case -1: | |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
168 THERR("No such field '%s'.\n", opt); |
2 | 169 return FALSE; |
170 | |
171 case -2: | |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
172 THERR("Field '%s' is ambiguous.\n", opt); |
2 | 173 return FALSE; |
3 | 174 |
2 | 175 default: |
176 *fields |= optPSFlags[found].flag; | |
177 return TRUE; | |
178 } | |
179 } | |
180 | |
181 | |
182 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) | |
183 { | |
184 switch (optN) | |
185 { | |
186 case 0: | |
187 argShowHelp(); | |
188 exit(0); | |
189 break; | |
190 | |
191 case 1: | |
192 th_verbosityLevel++; | |
193 break; | |
194 | |
195 case 2: | |
196 optParsable = TRUE; | |
197 break; | |
198 | |
199 case 3: | |
200 { | |
201 char *start = optArg; | |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
202 optFields = SIF_NONE; |
2 | 203 |
204 while (*start) | |
205 { | |
206 char *end = strchr(start, ','); | |
207 | |
208 if (!argParsePSField(start, end, &optFields)) | |
209 return FALSE; | |
210 | |
211 if (!end) | |
212 break; | |
213 | |
214 start = end + 1; | |
215 } | |
216 } | |
217 break; | |
218 | |
219 case 4: | |
220 optHexadecimal = TRUE; | |
221 break; | |
222 | |
7 | 223 case 5: |
224 optNoNamePrefix = TRUE; | |
225 break; | |
226 | |
29 | 227 case 6: |
228 optOneLine = TRUE; | |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
229 optFieldSep = optArg; |
29 | 230 break; |
231 | |
2 | 232 default: |
233 THERR("Unknown option '%s'.\n", currArg); | |
234 return FALSE; | |
235 } | |
236 | |
237 return TRUE; | |
238 } | |
239 | |
240 | |
241 typedef struct | |
242 { | |
243 char magic[PSID_MAGIC_LEN + 1]; // "PSID" / "RSID" magic identifier | |
244 uint16_t | |
245 version, // Version number | |
0 | 246 dataOffset, // Start of actual c64 data in file |
247 loadAddress, // Loading address | |
248 initAddress, // Initialization address | |
249 playAddress, // Play one frame | |
250 nSongs, // Number of subsongs | |
251 startSong; // Default starting song | |
252 uint32_t speed; // Speed | |
2 | 253 char sidName[PSID_STR_LEN + 1]; // Descriptive text-fields, ASCIIZ |
254 char sidAuthor[PSID_STR_LEN + 1]; | |
255 char sidCopyright[PSID_STR_LEN + 1]; | |
0 | 256 |
257 // PSIDv2 data | |
258 uint16_t flags; // Flags | |
259 uint8_t startPage, pageLength; | |
260 uint16_t reserved; | |
261 | |
1 | 262 // Extra data |
0 | 263 BOOL isRSID; |
1 | 264 size_t dataSize; // Total size of data - header |
265 th_md5hash_t hash; // Songlength database hash | |
0 | 266 |
267 } PSIDHeader; | |
268 | |
269 | |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
270 enum |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
271 { |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
272 PSF_PLAYER_TYPE = 0x0001, // 0 = built-in, 1 = Compute! SIDPlayer MUS |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
273 PSF_PLAYSID_TUNE = 0x0002, // 0 = Real C64-compatible, 1 = PlaySID specific (v2NG) |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
274 |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
275 PSF_CLOCK_UNKNOWN = 0x0000, // Video standard used (v2NG) |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
276 PSF_CLOCK_PAL = 0x0004, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
277 PSF_CLOCK_NTSC = 0x0008, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
278 PSF_CLOCK_ANY = 0x000c, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
279 PSF_CLOCK_MASK = 0x000c, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
280 |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
281 PSF_MODEL_UNKNOWN = 0x0000, // SID model (v2NG) |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
282 PSF_MODEL_MOS6581 = 0x0010, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
283 PSF_MODEL_MOS8580 = 0x0020, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
284 PSF_MODEL_ANY = 0x0030, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
285 PSF_MODEL_MASK = 0x0030, |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
286 }; |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
287 |
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
288 |
2 | 289 static void siAppendHash16(th_md5state_t *state, uint16_t data) |
290 { | |
291 uint8_t ib8[2]; | |
292 ib8[0] = data & 0xff; | |
293 ib8[1] = data >> 8; | |
294 th_md5_append(state, (uint8_t *) &ib8, sizeof(ib8)); | |
295 } | |
296 | |
297 | |
298 int siReadPSIDFile(FILE *inFile, PSIDHeader *psid) | |
0 | 299 { |
1 | 300 th_md5state_t state; |
301 uint8_t tmp8, *fileData = NULL; | |
302 int index, ret = -1; | |
303 size_t read; | |
304 BOOL first; | |
305 | |
306 memset(psid, 0, sizeof(*psid)); | |
307 | |
308 if ((fileData = (uint8_t *) th_malloc(PSID_BUFFER_SIZE)) == NULL) | |
309 { | |
310 THERR("Error allocating temporary data buffer of %d bytes.\n", PSID_BUFFER_SIZE); | |
311 goto error; | |
312 } | |
3 | 313 |
0 | 314 // Read PSID header in |
2 | 315 if (!th_fread_str(inFile, (uint8_t *) psid->magic, PSID_MAGIC_LEN) || |
1 | 316 !th_fread_be16(inFile, &psid->version) || |
317 !th_fread_be16(inFile, &psid->dataOffset) || | |
318 !th_fread_be16(inFile, &psid->loadAddress) || | |
319 !th_fread_be16(inFile, &psid->initAddress) || | |
320 !th_fread_be16(inFile, &psid->playAddress) || | |
321 !th_fread_be16(inFile, &psid->nSongs) || | |
322 !th_fread_be16(inFile, &psid->startSong) || | |
323 !th_fread_be32(inFile, &psid->speed)) | |
0 | 324 { |
1 | 325 THERR("Could not read PSID/RSID header.\n"); |
0 | 326 goto error; |
327 } | |
328 | |
2 | 329 psid->magic[PSID_MAGIC_LEN] = 0; |
330 | |
0 | 331 if ((psid->magic[0] != 'R' && psid->magic[0] != 'P') || |
332 psid->magic[1] != 'S' || psid->magic[2] != 'I' || psid->magic[3] != 'D' || | |
333 psid->version < 1 || psid->version > 3) | |
334 { | |
1 | 335 THERR("Not a supported PSID or RSID file.\n"); |
0 | 336 goto error; |
337 } | |
338 | |
1 | 339 psid->isRSID = psid->magic[0] == 'R'; |
0 | 340 |
2 | 341 if (!th_fread_str(inFile, (uint8_t *)psid->sidName, PSID_STR_LEN) || |
342 !th_fread_str(inFile, (uint8_t *)psid->sidAuthor, PSID_STR_LEN) || | |
343 !th_fread_str(inFile, (uint8_t *)psid->sidCopyright, PSID_STR_LEN)) | |
0 | 344 { |
1 | 345 THERR("Error reading SID file header.\n"); |
0 | 346 goto error; |
347 } | |
348 | |
2 | 349 psid->sidName[PSID_STR_LEN] = 0; |
350 psid->sidAuthor[PSID_STR_LEN] = 0; | |
351 psid->sidCopyright[PSID_STR_LEN] = 0; | |
352 | |
0 | 353 // Check if we need to load PSIDv2NG header ... |
354 if (psid->version >= 2) | |
355 { | |
356 // Yes, we need to | |
1 | 357 if (!th_fread_be16(inFile, &psid->flags) || |
358 !th_fread_byte(inFile, &psid->startPage) || | |
359 !th_fread_byte(inFile, &psid->pageLength) || | |
360 !th_fread_be16(inFile, &psid->reserved)) | |
0 | 361 { |
1 | 362 THERR("Error reading PSID/RSID v2+ extra header data.\n"); |
0 | 363 goto error; |
364 } | |
365 } | |
366 | |
1 | 367 // Initialize MD5-hash calculation |
368 th_md5_init(&state); | |
0 | 369 |
1 | 370 // Process actual data |
371 psid->dataSize = 0; | |
372 first = TRUE; | |
2 | 373 do |
374 { | |
1 | 375 read = fread(fileData, sizeof(uint8_t), PSID_BUFFER_SIZE, inFile); |
376 psid->dataSize += read; | |
0 | 377 |
1 | 378 if (first && psid->loadAddress == 0) |
379 { | |
8
cfc74ec918dc
Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
380 if (read < 4) |
cfc74ec918dc
Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
381 { |
cfc74ec918dc
Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
382 THERR("Error reading song data, unexpectedly small file.\n"); |
cfc74ec918dc
Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
383 goto error; |
cfc74ec918dc
Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
384 } |
39
3ce9d2198193
Grab the actual loading address from data block if PSID header loadAddr value is 0.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
385 |
3ce9d2198193
Grab the actual loading address from data block if PSID header loadAddr value is 0.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
386 // Grab the actual load address |
3ce9d2198193
Grab the actual loading address from data block if PSID header loadAddr value is 0.
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
387 psid->loadAddress = TH_LE16_TO_NATIVE(*(uint16_t *) fileData); |
8
cfc74ec918dc
Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
388 |
1 | 389 // Strip load address (2 first bytes) |
390 th_md5_append(&state, &fileData[2], read - 2); | |
391 first = FALSE; | |
392 } | |
393 else | |
8
cfc74ec918dc
Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
394 if (read > 0) |
1 | 395 { |
396 // Append "as is" | |
397 th_md5_append(&state, fileData, read); | |
398 } | |
399 } while (read > 0 && !feof(inFile)); | |
0 | 400 |
1 | 401 // Append header data to hash |
2 | 402 siAppendHash16(&state, psid->initAddress); |
403 siAppendHash16(&state, psid->playAddress); | |
404 siAppendHash16(&state, psid->nSongs); | |
0 | 405 |
406 // Append song speed data to hash | |
1 | 407 tmp8 = psid->isRSID ? 60 : 0; |
0 | 408 for (index = 0; index < psid->nSongs && index < 32; index++) |
409 { | |
1 | 410 if (psid->isRSID) |
411 tmp8 = 60; | |
0 | 412 else |
1 | 413 tmp8 = (psid->speed & (1 << index)) ? 60 : 0; |
0 | 414 |
1 | 415 th_md5_append(&state, &tmp8, sizeof(tmp8)); |
0 | 416 } |
417 | |
418 // Rest of songs (more than 32) | |
419 for (index = 32; index < psid->nSongs; index++) | |
1 | 420 th_md5_append(&state, &tmp8, sizeof(tmp8)); |
0 | 421 |
422 // PSIDv2NG specific | |
423 if (psid->version >= 2) | |
424 { | |
425 // REFER TO SIDPLAY HEADERS FOR MORE INFORMATION | |
1 | 426 tmp8 = (psid->flags >> 2) & 3; |
427 if (tmp8 == 2) | |
428 th_md5_append(&state, &tmp8, sizeof(tmp8)); | |
0 | 429 } |
430 | |
431 // Calculate the hash | |
1 | 432 th_md5_finish(&state, psid->hash); |
433 ret = 0; | |
0 | 434 |
1 | 435 error: |
0 | 436 // Free buffer |
1 | 437 th_free(fileData); |
438 return ret; | |
0 | 439 } |
440 | |
441 | |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
442 const char *siGetSIDClockStr(int flags) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
443 { |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
444 switch (flags & PSF_CLOCK_MASK) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
445 { |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
446 case PSF_CLOCK_UNKNOWN : return "Unknown"; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
447 case PSF_CLOCK_PAL : return "PAL 50Hz"; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
448 case PSF_CLOCK_NTSC : return "NTSC 60Hz"; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
449 case PSF_CLOCK_ANY : return "PAL / NTSC"; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
450 default : return "?"; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
451 } |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
452 } |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
453 |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
454 |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
455 const char *siGetSIDModelStr(int flags) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
456 { |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
457 switch (flags & PSF_MODEL_MASK) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
458 { |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
459 case PSF_MODEL_UNKNOWN : return "Unknown"; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
460 case PSF_MODEL_MOS6581 : return "MOS6581"; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
461 case PSF_MODEL_MOS8580 : return "MOS8580"; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
462 case PSF_MODEL_ANY : return "MOS6581 / MOS8580"; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
463 default : return "?"; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
464 } |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
465 } |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
466 |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
467 |
31 | 468 static void siPrintFieldPrefix(FILE *outFile, const char *name) |
2 | 469 { |
7 | 470 if (!optNoNamePrefix) |
29 | 471 fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name); |
2 | 472 } |
473 | |
474 | |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
475 static void siPrintFieldSeparator(FILE *outFile) |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
476 { |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
477 fprintf(outFile, optOneLine ? optFieldSep : "\n"); |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
478 } |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
479 |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
480 |
29 | 481 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const int xindex, const char *xfmt, const char *xaltfmt, ...) |
2 | 482 { |
483 const PSFOption *opt = &optPSFlags[xindex]; | |
29 | 484 if (optFields & opt->flag) |
2 | 485 { |
486 va_list ap; | |
29 | 487 const char *fmt = optHexadecimal ? (xaltfmt != NULL ? xaltfmt : xfmt) : xfmt; |
2 | 488 |
31 | 489 siPrintFieldPrefix(outFile, (optParsable || opt->lname == NULL) ? opt->name : opt->lname); |
2 | 490 |
491 va_start(ap, xaltfmt); | |
57 | 492 vfprintf(outFile, fmt, ap); |
2 | 493 va_end(ap); |
3 | 494 |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
495 siPrintFieldSeparator(outFile); |
29 | 496 *shown = TRUE; |
2 | 497 } |
498 } | |
499 | |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
500 #define PR(xfmt, xaltfmt, ...) siPrintPSIDInfoLine(outFile, shown, xindex, xfmt, xaltfmt, __VA_ARGS__ ) |
9
c1fba4abf56f
Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
501 |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
502 void siPrintPSIDInformationField(FILE *outFile, const char *filename, const PSIDHeader *psid, BOOL *shown, const int xindex) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
503 { |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
504 switch (xindex) |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
505 { |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
506 case 0: PR("%s", NULL, filename); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
507 case 1: PR("%s", NULL, psid->magic); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
508 case 2: PR("%d.%d", NULL, (psid->version & 0xff), (psid->version >> 8)); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
509 case 3: PR("%s", NULL, (psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in"); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
510 case 4: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
511 if (psid->version >= 2) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
512 PR("%s", NULL, (psid->flags & PSF_PLAYSID_TUNE) ? "PlaySID" : "C64 compatible"); |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
513 break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
514 case 5: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
515 if (psid->version >= 2) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
516 PR("%s", NULL, siGetSIDClockStr(psid->flags)); |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
517 break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
518 case 6: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
519 if (psid->version >= 2) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
520 PR("%s", NULL, siGetSIDModelStr(psid->flags)); |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
521 break; |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
522 |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
523 case 7: PR("%d", "$%08x", psid->dataOffset); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
524 case 8: PR("%d", "$%08x", psid->dataSize); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
525 case 9: PR("%d", "$%04x", psid->loadAddress); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
526 case 10: PR("%d", "$%04x", psid->initAddress); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
527 case 11: PR("%d", "$%04x", psid->playAddress); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
528 case 12: PR("%d", "$%04x", psid->nSongs); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
529 case 13: PR("%d", "$%04x", psid->startSong); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
530 case 14: PR("%s", NULL, psid->sidName); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
531 case 15: PR("%s", NULL, psid->sidAuthor); break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
532 case 16: PR("%s", NULL, psid->sidCopyright); break; |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
533 |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
534 case 17: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
535 { |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
536 const PSFOption *opt = &optPSFlags[xindex]; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
537 if (optFormatStack || (optFields & opt->flag)) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
538 { |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
539 siPrintFieldPrefix(outFile, "Hash"); |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
540 th_md5_print(outFile, psid->hash); |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
541 siPrintFieldSeparator(outFile); |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
542 } |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
543 } |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
544 break; |
29 | 545 } |
2 | 546 } |
547 | |
0 | 548 |
19 | 549 BOOL argHandleFile(char *filename) |
550 { | |
551 static PSIDHeader psid; | |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
552 FILE *inFile = NULL, *outFile; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
553 int index; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
554 BOOL shown = FALSE; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
555 |
19 | 556 optNFiles++; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
557 outFile = stdout; |
19 | 558 |
559 if ((inFile = fopen(filename, "rb")) == NULL) | |
560 { | |
561 THERR("Could not open file '%s'.\n", filename); | |
27
4dd463eebb74
Fix argument handling when file does not exist.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
562 return TRUE; |
19 | 563 } |
564 | |
565 // Read PSID data | |
566 if (siReadPSIDFile(inFile, &psid) != 0) | |
23 | 567 { |
568 THERR("Error reading %s\n", filename); | |
19 | 569 goto error; |
23 | 570 } |
19 | 571 |
572 // Output | |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
573 { |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
574 for (index = 0; index < noptPSFlags - 1; index++) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
575 siPrintPSIDInformationField(outFile, filename, &psid, &shown, index); |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
576 if (shown && optOneLine) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
577 fprintf(outFile, "\n"); |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
578 } |
19 | 579 |
580 // Shutdown | |
581 error: | |
582 if (inFile != NULL) | |
583 fclose(inFile); | |
584 | |
585 return TRUE; | |
586 } | |
587 | |
588 | |
0 | 589 int main(int argc, char *argv[]) |
590 { | |
591 // Initialize | |
50 | 592 th_init("SIDInfo", "PSID/RSID information displayer", "0.5.3", NULL, NULL); |
0 | 593 th_verbosityLevel = 0; |
594 | |
2 | 595 // Parse command line arguments |
596 if (!th_args_process(argc, argv, optList, optListN, | |
23 | 597 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS)) |
2 | 598 return -1; |
599 | |
29 | 600 if (optOneLine) |
601 { | |
602 optParsable = FALSE; | |
603 optNoNamePrefix = TRUE; | |
604 } | |
605 | |
23 | 606 // Process files |
607 if (!th_args_process(argc, argv, optList, optListN, | |
608 argHandleOpt, argHandleFile, OPTH_ONLY_OTHER)) | |
609 return -2; | |
610 | |
19 | 611 if (optNFiles == 0) |
2 | 612 { |
613 argShowHelp(); | |
19 | 614 THERR("No filename(s) specified.\n"); |
2 | 615 } |
1 | 616 |
19 | 617 return 0; |
0 | 618 } |