annotate sidinfo.c @ 32:93a432519b84

Indentation cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 26 Sep 2014 00:16:26 +0300
parents 727c012d5de4
children 39d9df17c8b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1 /*
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
2 * SIDInfo - PSID/RSID information displayer
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
3 * Written by Matti 'ccr' Hämäläinen
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
4 * (C) Copyright 2014 Tecnic Software productions (TNSP)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
5 */
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include "th_args.h"
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "th_endian.h"
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
8 #include "th_string.h"
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "th_crypto.h"
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
11 // Some constants
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
12 #define PSID_MAGIC_LEN 4
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
13 #define PSID_STR_LEN 32
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
14 #define PSID_BUFFER_SIZE (1024 * 16)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
15
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
17 // Flags for various information fields
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
18 enum
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
19 {
32
93a432519b84 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
20 PSF_NONE = 0,
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
21
32
93a432519b84 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
22 PSF_TYPE = 0x00000001,
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
23 PSF_VERSION = 0x00000002,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
24 PSF_DATA_OFFS = 0x00000004,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
25 PSF_LOAD_ADDR = 0x00000008,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
26 PSF_INIT_ADDR = 0x00000010,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
27 PSF_PLAY_ADDR = 0x00000020,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
28 PSF_SONGS = 0x00000040,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
29 PSF_START_SONG = 0x00000080,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
30 PSF_SPEEDS = 0x00000100,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
31 PSF_SID_NAME = 0x00000200,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
32 PSF_SID_AUTHOR = 0x00000400,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
33 PSF_SID_COPYRIGHT = 0x00000800,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
34
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
35 PSF_DATA_SIZE = 0x00100000,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
36 PSF_HASH = 0x00200000,
9
c1fba4abf56f Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
37 PSF_FILENAME = 0x10000000,
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
38
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
39 PSF_ALL = 0xffffffff,
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
40 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
41
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
42
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 typedef struct
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 {
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
45 uint32_t flag;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
46 char *name;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
47 char *lname;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
48 } PSFOption;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
49
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
50
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
51 const PSFOption optPSFlags[] =
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
52 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
53 { PSF_TYPE , "Type" , NULL },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
54 { PSF_VERSION , "Version" , NULL },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
55 { PSF_DATA_OFFS , "DataOffs" , "Data offset" },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
56 { PSF_DATA_SIZE , "DataSize" , "Data size" },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
57 { PSF_LOAD_ADDR , "LoadAddr" , "Load address" },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
58 { PSF_INIT_ADDR , "InitAddr" , "Init address" },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
59 { PSF_PLAY_ADDR , "PlayAddr" , "Play address" },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
60 { PSF_SONGS , "Songs" , "Songs" },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
61 { PSF_START_SONG , "StartSong" , "Start song" },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
62 { PSF_SID_NAME , "Name" , NULL },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
63 { PSF_SID_AUTHOR , "Author" , NULL },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
64 { PSF_SID_COPYRIGHT , "Copyright" , NULL },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
65 { PSF_HASH , "Hash" , NULL },
9
c1fba4abf56f Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
66 { PSF_FILENAME , "Filename" , NULL },
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
67
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
68
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
69 { PSF_ALL , "All" , NULL },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
70 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
71
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
72 const int noptPSFlags = sizeof(optPSFlags) / sizeof(optPSFlags[0]);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
73
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
74
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
75 // Option variables
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
76 BOOL optParsable = FALSE,
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
77 optNoNamePrefix = FALSE,
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
78 optHexadecimal = FALSE,
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
79 optOneLine = FALSE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
80 uint32_t optFields = PSF_ALL;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
81 int optNFiles = 0;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
82
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
83
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
84 // Define option arguments
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
85 static optarg_t optList[] =
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
86 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
87 { 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
88 // { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
89 { 2, 'p', "parsable", "Output in script-parsable format", OPT_NONE },
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
90 { 5, 'n', "noprefix", "Output without field name prefix", OPT_NONE },
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
91 { 6, 'l', "oneline", "Output in one line format", OPT_NONE },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
92 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
93 { 4, 'x', "hex", "Use hexadecimal values", OPT_NONE },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
94 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
95
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
96 static const int optListN = (sizeof(optList) / sizeof(optList[0]));
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
97
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
98
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
99 void argShowHelp(void)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
100 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
101 int index, n;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
102
20
6058339ffe0e Update usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
103 th_print_banner(stdout, th_prog_name, "[options] <sid filename> [sid filename #2 ..]");
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
104 th_args_help(stdout, optList, optListN);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
105 printf(
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
106 "\n"
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
107 "Available fields:\n");
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
108
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
109 for (index = n = 0; index < noptPSFlags; index++)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
110 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
111 const PSFOption *opt = &optPSFlags[index];
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
112 printf("%s%s", opt->name, (index < noptPSFlags - 1) ? ", " : "\n\n");
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
113 if (++n > 5)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
114 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
115 printf("\n");
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
116 n = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
117 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
118 }
5
2892e994243c Add usage example.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
119
2892e994243c Add usage example.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
120 printf("Example: %s -x -p -f hash,copyright somesidfile.sid\n", th_prog_name);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
121 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
122
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
123
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
124 int argMatchPSField(const char *field)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
125 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
126 int index, found = -1;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
127 size_t len = strlen(field);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
128 for (index = 0; index < noptPSFlags; index++)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
129 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
130 const PSFOption *opt = &optPSFlags[index];
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
131 if (strncasecmp(opt->name, field, len) == 0)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
132 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
133 if (found >= 0)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
134 return -2;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
135 found = index;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
136 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
137 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
138
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
139 return found;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
140 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
141
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
142
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
143 BOOL argParsePSField(char *opt, char *end, uint32_t *fields)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
144 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
145 // Trim whitespace
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
146 if (end != NULL)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
147 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
148 *end = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
149 for (end--; end > opt && *end && th_isspace(*end); end--)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
150 *end = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
151 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
152 while (*opt && th_isspace(*opt)) opt++;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
153
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
154 // Match field name
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
155 int found = argMatchPSField(opt);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
156 switch (found)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
157 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
158 case -1:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
159 THERR("No such flag '%s'.\n", opt);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
160 return FALSE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
161
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
162 case -2:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
163 THERR("Flag '%s' is ambiguous.\n", opt);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
164 return FALSE;
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
165
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
166 default:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
167 *fields |= optPSFlags[found].flag;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
168 return TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
169 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
170 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
171
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
172
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
173 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
174 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
175 switch (optN)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
176 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
177 case 0:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
178 argShowHelp();
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
179 exit(0);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
180 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
181
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
182 case 1:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
183 th_verbosityLevel++;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
184 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
185
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
186 case 2:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
187 optParsable = TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
188 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
189
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
190 case 3:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
191 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
192 char *start = optArg;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
193 optFields = PSF_NONE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
194
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
195 while (*start)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
196 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
197 char *end = strchr(start, ',');
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
198
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
199 if (!argParsePSField(start, end, &optFields))
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
200 return FALSE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
201
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
202 if (!end)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
203 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
204
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
205 start = end + 1;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
206 }
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
207
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
208 //fprintf(stderr, "%08x\n", optFields);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
209 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
210 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
211
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
212 case 4:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
213 optHexadecimal = TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
214 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
215
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
216 case 5:
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
217 optNoNamePrefix = TRUE;
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
218 break;
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
219
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
220 case 6:
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
221 optOneLine = TRUE;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
222 break;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
223
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
224 default:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
225 THERR("Unknown option '%s'.\n", currArg);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
226 return FALSE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
227 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
228
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
229 return TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
230 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
231
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
232
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
233 typedef struct
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
234 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
235 char magic[PSID_MAGIC_LEN + 1]; // "PSID" / "RSID" magic identifier
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
236 uint16_t
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
237 version, // Version number
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 dataOffset, // Start of actual c64 data in file
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 loadAddress, // Loading address
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 initAddress, // Initialization address
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 playAddress, // Play one frame
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 nSongs, // Number of subsongs
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 startSong; // Default starting song
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 uint32_t speed; // Speed
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
245 char sidName[PSID_STR_LEN + 1]; // Descriptive text-fields, ASCIIZ
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
246 char sidAuthor[PSID_STR_LEN + 1];
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
247 char sidCopyright[PSID_STR_LEN + 1];
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 // PSIDv2 data
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 uint16_t flags; // Flags
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 uint8_t startPage, pageLength;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 uint16_t reserved;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
254 // Extra data
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 BOOL isRSID;
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
256 size_t dataSize; // Total size of data - header
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
257 th_md5hash_t hash; // Songlength database hash
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 } PSIDHeader;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
262 static void siAppendHash16(th_md5state_t *state, uint16_t data)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
263 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
264 uint8_t ib8[2];
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
265 ib8[0] = data & 0xff;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
266 ib8[1] = data >> 8;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
267 th_md5_append(state, (uint8_t *) &ib8, sizeof(ib8));
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
268 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
269
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
270
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
271 int siReadPSIDFile(FILE *inFile, PSIDHeader *psid)
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
273 th_md5state_t state;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
274 uint8_t tmp8, *fileData = NULL;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
275 int index, ret = -1;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
276 size_t read;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
277 BOOL first;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
278
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
279 memset(psid, 0, sizeof(*psid));
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
280
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
281 if ((fileData = (uint8_t *) th_malloc(PSID_BUFFER_SIZE)) == NULL)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
282 {
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
283 THERR("Error allocating temporary data buffer of %d bytes.\n", PSID_BUFFER_SIZE);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
284 goto error;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
285 }
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
286
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 // Read PSID header in
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
288 if (!th_fread_str(inFile, (uint8_t *) psid->magic, PSID_MAGIC_LEN) ||
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
289 !th_fread_be16(inFile, &psid->version) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
290 !th_fread_be16(inFile, &psid->dataOffset) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
291 !th_fread_be16(inFile, &psid->loadAddress) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
292 !th_fread_be16(inFile, &psid->initAddress) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
293 !th_fread_be16(inFile, &psid->playAddress) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
294 !th_fread_be16(inFile, &psid->nSongs) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
295 !th_fread_be16(inFile, &psid->startSong) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
296 !th_fread_be32(inFile, &psid->speed))
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
298 THERR("Could not read PSID/RSID header.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
302 psid->magic[PSID_MAGIC_LEN] = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
303
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 if ((psid->magic[0] != 'R' && psid->magic[0] != 'P') ||
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 psid->magic[1] != 'S' || psid->magic[2] != 'I' || psid->magic[3] != 'D' ||
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 psid->version < 1 || psid->version > 3)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
308 THERR("Not a supported PSID or RSID file.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
312 psid->isRSID = psid->magic[0] == 'R';
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
314 if (!th_fread_str(inFile, (uint8_t *)psid->sidName, PSID_STR_LEN) ||
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
315 !th_fread_str(inFile, (uint8_t *)psid->sidAuthor, PSID_STR_LEN) ||
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
316 !th_fread_str(inFile, (uint8_t *)psid->sidCopyright, PSID_STR_LEN))
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
318 THERR("Error reading SID file header.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
322 psid->sidName[PSID_STR_LEN] = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
323 psid->sidAuthor[PSID_STR_LEN] = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
324 psid->sidCopyright[PSID_STR_LEN] = 0;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
325
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 // Check if we need to load PSIDv2NG header ...
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 if (psid->version >= 2)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 // Yes, we need to
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
330 if (!th_fread_be16(inFile, &psid->flags) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
331 !th_fread_byte(inFile, &psid->startPage) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
332 !th_fread_byte(inFile, &psid->pageLength) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
333 !th_fread_be16(inFile, &psid->reserved))
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
335 THERR("Error reading PSID/RSID v2+ extra header data.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
340 // Initialize MD5-hash calculation
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
341 th_md5_init(&state);
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
343 // Process actual data
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
344 psid->dataSize = 0;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
345 first = TRUE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
346 do
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
347 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
348 read = fread(fileData, sizeof(uint8_t), PSID_BUFFER_SIZE, inFile);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
349 psid->dataSize += read;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
351 if (first && psid->loadAddress == 0)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
352 {
8
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
353 if (read < 4)
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
354 {
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
355 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
356 goto error;
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
357 }
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
358
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
359 // Strip load address (2 first bytes)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
360 th_md5_append(&state, &fileData[2], read - 2);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
361 first = FALSE;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
362 }
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
363 else
8
cfc74ec918dc Fix handling of "large" SID files.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
364 if (read > 0)
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
365 {
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
366 // Append "as is"
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
367 th_md5_append(&state, fileData, read);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
368 }
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
369 } while (read > 0 && !feof(inFile));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
371 // Append header data to hash
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
372 siAppendHash16(&state, psid->initAddress);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
373 siAppendHash16(&state, psid->playAddress);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
374 siAppendHash16(&state, psid->nSongs);
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 // Append song speed data to hash
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
377 tmp8 = psid->isRSID ? 60 : 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 for (index = 0; index < psid->nSongs && index < 32; index++)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
380 if (psid->isRSID)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
381 tmp8 = 60;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 else
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
383 tmp8 = (psid->speed & (1 << index)) ? 60 : 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
385 th_md5_append(&state, &tmp8, sizeof(tmp8));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 // Rest of songs (more than 32)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 for (index = 32; index < psid->nSongs; index++)
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
390 th_md5_append(&state, &tmp8, sizeof(tmp8));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 // PSIDv2NG specific
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 if (psid->version >= 2)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 // REFER TO SIDPLAY HEADERS FOR MORE INFORMATION
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
396 tmp8 = (psid->flags >> 2) & 3;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
397 if (tmp8 == 2)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
398 th_md5_append(&state, &tmp8, sizeof(tmp8));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 // Calculate the hash
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
402 th_md5_finish(&state, psid->hash);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
403 ret = 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
405 error:
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 // Free buffer
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
407 th_free(fileData);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
408 return ret;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411
31
727c012d5de4 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
412 static void siPrintFieldPrefix(FILE *outFile, const char *name)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
413 {
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
414 if (!optNoNamePrefix)
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
415 fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
416 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
417
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
418
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
419 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const int xindex, const char *xfmt, const char *xaltfmt, ...)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
420 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
421 const PSFOption *opt = &optPSFlags[xindex];
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
422 if (optFields & opt->flag)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
423 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
424 va_list ap;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
425 const char *fmt = optHexadecimal ? (xaltfmt != NULL ? xaltfmt : xfmt) : xfmt;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
426
31
727c012d5de4 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
427 siPrintFieldPrefix(outFile, (optParsable || opt->lname == NULL) ? opt->name : opt->lname);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
428
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
429 va_start(ap, xaltfmt);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
430
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
431 if (optParsable)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
432 vfprintf(outFile, fmt, ap);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
433 else
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
434 vfprintf(outFile, fmt, ap);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
435
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
436 va_end(ap);
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
437
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
438 fprintf(outFile, optOneLine ? "|" : "\n");
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
439 *shown = TRUE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
440 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
441 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
442
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
443 #define PR(xindex, xfmt, xaltfmt, ...) siPrintPSIDInfoLine(outFile, &shown, xindex, xfmt, xaltfmt, __VA_ARGS__ )
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
444
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
445
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
446 void siPrintPSIDInformation(FILE *outFile, const char *filename, const PSIDHeader *psid)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
447 {
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
448 BOOL shown = FALSE;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
449
16
c30fe2b4251f Oops, 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
450 PR(13, "%s", NULL, filename);
9
c1fba4abf56f Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
451
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
452 PR( 0, "%s", NULL, psid->magic);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
453 PR( 1, "%d.%d", NULL, (psid->version & 0xff), (psid->version >> 8));
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
454 PR( 2, "%d", "$%08x", psid->dataOffset);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
455 PR( 3, "%d", "$%08x", psid->dataSize);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
456 PR( 4, "%d", "$%04x", psid->loadAddress);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
457 PR( 5, "%d", "$%04x", psid->initAddress);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
458 PR( 6, "%d", "$%04x", psid->playAddress);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
459 PR( 7, "%d", "$%04x", psid->nSongs);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
460 PR( 8, "%d", "$%04x", psid->startSong);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
461
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
462 PR( 9, "%s", NULL, psid->sidName);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
463 PR(10, "%s", NULL, psid->sidAuthor);
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
464 PR(11, "%s", NULL, psid->sidCopyright);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
465
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
466 if (optFields & PSF_HASH)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
467 {
31
727c012d5de4 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
468 siPrintFieldPrefix(outFile, "Hash");
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
469 th_md5_print(outFile, psid->hash);
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
470 fprintf(outFile, optOneLine ? "|" : "\n");
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
471 }
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
472
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
473 if (shown)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
474 fprintf(outFile, "\n");
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
475 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
476
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
478 BOOL argHandleFile(char *filename)
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
479 {
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
480 static PSIDHeader psid;
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
481 static FILE *inFile = NULL;
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
482 optNFiles++;
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
483
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
484 if ((inFile = fopen(filename, "rb")) == NULL)
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
485 {
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
486 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
487 return TRUE;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
488 }
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
489
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
490 // Read PSID data
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
491 if (siReadPSIDFile(inFile, &psid) != 0)
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
492 {
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
493 THERR("Error reading %s\n", filename);
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
494 goto error;
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
495 }
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
496
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
497 // Output
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
498 siPrintPSIDInformation(stdout, filename, &psid);
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
499
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
500 // Shutdown
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
501 error:
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
502 if (inFile != NULL)
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
503 fclose(inFile);
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
504
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
505 return TRUE;
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
506 }
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
507
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
508
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 int main(int argc, char *argv[])
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 // Initialize
25
055c2355dd0a Bump version.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
512 th_init("SIDInfo", "PSID/RSID information displayer", "0.4", NULL, NULL);
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 th_verbosityLevel = 0;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
515 // Parse command line arguments
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
516 if (!th_args_process(argc, argv, optList, optListN,
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
517 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS))
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
518 return -1;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
519
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
520 if (optOneLine)
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
521 {
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
522 optParsable = FALSE;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
523 optNoNamePrefix = TRUE;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
524 }
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
525
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
526 // Process files
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
527 if (!th_args_process(argc, argv, optList, optListN,
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
528 argHandleOpt, argHandleFile, OPTH_ONLY_OTHER))
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
529 return -2;
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
530
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
531 if (optNFiles == 0)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
532 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
533 argShowHelp();
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
534 THERR("No filename(s) specified.\n");
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
535 }
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
536
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
537 return 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 }