Mercurial > hg > sidinfo
annotate sidinfo.c @ 135:b4b1aac8761c
Add preprocessor guards around iconv stuff.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 02 Jun 2017 04:27:42 +0300 |
parents | b9a3f93f69d1 |
children | d40c371ce1f9 |
rev | line source |
---|---|
2 | 1 /* |
2 * SIDInfo - PSID/RSID information displayer | |
108 | 3 * Written by Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
131 | 4 * (C) Copyright 2014-2017 Tecnic Software productions (TNSP) |
2 | 5 */ |
0 | 6 #include "th_args.h" |
2 | 7 #include "th_string.h" |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
8 #include "th_file.h" |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
9 #include "sidlib.h" |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
10 #ifdef HAVE_ICONV |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
11 #include <iconv.h> |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
12 #endif |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
13 |
0 | 14 |
28 | 15 // Some constants |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
16 #define SET_DEF_CHARSET "utf-8" |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
17 #define SET_SLDB_FILENAME "Songlengths.txt" |
1 | 18 |
121 | 19 |
112
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
20 enum |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
21 { |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
22 OTYPE_OTHER = 0, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
23 OTYPE_STR = 1, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
24 OTYPE_INT = 2, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
25 }; |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
26 |
0 | 27 |
28 typedef struct | |
29 { | |
63 | 30 int cmd; |
31 char *str; | |
32 char chr; | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
33 int flags; |
63 | 34 } PSFStackItem; |
35 | |
36 | |
37 typedef struct | |
38 { | |
39 int nitems, nallocated; | |
40 PSFStackItem *items; | |
41 } PSFStack; | |
42 | |
43 | |
44 typedef struct | |
45 { | |
2 | 46 char *name; |
47 char *lname; | |
112
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
48 int type; |
2 | 49 } PSFOption; |
50 | |
51 | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
52 static const PSFOption optPSOptions[] = |
2 | 53 { |
112
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
54 { "Filename" , NULL , OTYPE_STR }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
55 { "Type" , NULL , OTYPE_STR }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
56 { "Version" , NULL , OTYPE_STR }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
57 { "PlayerType" , "Player type" , OTYPE_STR }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
58 { "PlayerCompat" , "Player compatibility" , OTYPE_STR }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
59 { "VideoClock" , "Video clock speed" , OTYPE_STR }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
60 { "SIDModel" , "SID model" , OTYPE_STR }, |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
61 |
112
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
62 { "DataOffs" , "Data offset" , OTYPE_INT }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
63 { "DataSize" , "Data size" , OTYPE_INT }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
64 { "LoadAddr" , "Load address" , OTYPE_INT }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
65 { "InitAddr" , "Init address" , OTYPE_INT }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
66 { "PlayAddr" , "Play address" , OTYPE_INT }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
67 { "Songs" , "Songs" , OTYPE_INT }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
68 { "StartSong" , "Start song" , OTYPE_INT }, |
28 | 69 |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
70 { "SID2Model" , "2nd SID model" , OTYPE_INT }, |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
71 { "SID3Model" , "3rd SID model" , OTYPE_INT }, |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
72 { "SID2Addr" , "2nd SID address" , OTYPE_INT }, |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
73 { "SID3Addr" , "3rd SID address" , OTYPE_INT }, |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
74 |
112
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
75 { "Name" , NULL , OTYPE_STR }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
76 { "Author" , NULL , OTYPE_STR }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
77 { "Copyright" , NULL , OTYPE_STR }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
78 { "Hash" , NULL , OTYPE_OTHER }, |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
79 |
55d99dc7c35c
Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
80 { "Songlengths" , "Song lengths" , OTYPE_OTHER }, |
2 | 81 }; |
82 | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
83 static const int noptPSOptions = sizeof(optPSOptions) / sizeof(optPSOptions[0]); |
2 | 84 |
85 | |
28 | 86 // Option variables |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
87 char *setHVSCPath = NULL, |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
88 *setSLDBPath = NULL; |
2 | 89 BOOL optParsable = FALSE, |
7 | 90 optNoNamePrefix = FALSE, |
29 | 91 optHexadecimal = FALSE, |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
92 optOneLine = FALSE, |
111 | 93 optFieldOutput = TRUE; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
94 char *optFieldSep = NULL; |
19 | 95 int optNFiles = 0; |
2 | 96 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
97 PSFStack optFormat; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
98 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
99 SIDLibSLDB *sidSLDB = NULL; |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
100 |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
101 #ifdef HAVE_ICONV |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
102 BOOL setUseChConv; |
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
103 iconv_t setChConv; |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
104 #endif |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
105 |
2 | 106 |
28 | 107 // Define option arguments |
121 | 108 static const th_optarg optList[] = |
2 | 109 { |
110 { 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
|
111 // { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
2 | 112 { 2, 'p', "parsable", "Output in script-parsable format", OPT_NONE }, |
7 | 113 { 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
|
114 { 6, 'l', "line", "Output in one line format, -l <field separator>", OPT_ARGREQ }, |
2 | 115 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ }, |
116 { 4, 'x', "hex", "Use hexadecimal values", OPT_NONE }, | |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
117 { 7, 'F', "format", "Use given format string (see below)", OPT_ARGREQ }, |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
118 { 8, 'H', "hvsc", "Specify path to HVSC documents directory", OPT_ARGREQ }, |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
119 { 9, 'S', "sldb", "Specify Songlengths.txt file (use -H if possible)", OPT_ARGREQ }, |
2 | 120 }; |
121 | |
44
7b137e4e817c
Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
122 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
2 | 123 |
124 | |
125 void argShowHelp(void) | |
126 { | |
75
92a4065c41d0
Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
127 int index, len; |
2 | 128 |
20 | 129 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
|
130 th_args_help(stdout, optList, optListN, 0); |
2 | 131 printf( |
132 "\n" | |
133 "Available fields:\n"); | |
3 | 134 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
135 for (len = index = 0; index < noptPSOptions; index++) |
2 | 136 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
137 const PSFOption *opt = &optPSOptions[index]; |
75
92a4065c41d0
Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
138 len += strlen(opt->name) + 3; |
92a4065c41d0
Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
139 if (len >= 72) |
2 | 140 { |
141 printf("\n"); | |
75
92a4065c41d0
Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
142 len = 0; |
2 | 143 } |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
144 printf("%s%s", opt->name, (index < noptPSOptions - 1) ? ", " : "\n\n"); |
2 | 145 } |
58 | 146 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
147 printf( |
61 | 148 "Example: %s -x -p -f hash,copyright somesidfile.sid\n" |
149 "\n" | |
150 "Format strings for '-F' option are composed of @fields@ that\n" | |
151 "are expanded to their value. Also, escape sequences \\r, \\n and \\t\n" | |
152 "can be used: -F \"hash=@hash@\\ncopy=@copyright@\\n\"\n" | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
153 "\n" |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
154 "When specifying HVSC path, it is preferable to use -H/--hvsc option,\n" |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
155 "as STIL.txt and Songlengths.txt will be automatically used from there.\n" |
61 | 156 , th_prog_name); |
2 | 157 } |
158 | |
159 | |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
160 int argMatchPSField(const char *field) |
2 | 161 { |
162 int index, found = -1; | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
163 for (index = 0; index < noptPSOptions; index++) |
2 | 164 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
165 const PSFOption *opt = &optPSOptions[index]; |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
166 if (th_strcasecmp(opt->name, field) == 0) |
2 | 167 { |
168 if (found >= 0) | |
169 return -2; | |
170 found = index; | |
171 } | |
172 } | |
173 | |
174 return found; | |
175 } | |
176 | |
177 | |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
178 int argMatchPSFieldError(const char *field) |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
179 { |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
180 int found = argMatchPSField(field); |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
181 switch (found) |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
182 { |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
183 case -1: |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
184 THERR("No such field '%s'.\n", field); |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
185 break; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
186 |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
187 case -2: |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
188 THERR("Field '%s' is ambiguous.\n", field); |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
189 break; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
190 } |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
191 return found; |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
192 } |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
193 |
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
194 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
195 BOOL siStackAddItem(PSFStack *stack, const PSFStackItem *item) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
196 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
197 if (stack->items == NULL || stack->nitems + 1 >= stack->nallocated) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
198 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
199 stack->nallocated += 16; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
200 if ((stack->items = th_realloc(stack->items, stack->nallocated * sizeof(PSFStackItem))) == NULL) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
201 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
202 THERR("Could not allocate memory for format item stack.\n"); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
203 return FALSE; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
204 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
205 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
206 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
207 memcpy(stack->items + stack->nitems, item, sizeof(PSFStackItem)); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
208 stack->nitems++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
209 return TRUE; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
210 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
211 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
212 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
213 void siClearStack(PSFStack *stack) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
214 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
215 if (stack != NULL) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
216 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
217 if (stack->nitems > 0 && stack->items != NULL) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
218 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
219 int n; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
220 for (n = 0; n < stack->nitems; n++) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
221 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
222 if (stack->items[n].cmd == -1) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
223 th_free(stack->items[n].str); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
224 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
225 th_free(stack->items); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
226 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
227 memset(stack, 0, sizeof(PSFStack)); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
228 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
229 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
230 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
231 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
232 BOOL argParsePSFields(PSFStack *stack, const char *fmt) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
233 { |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
234 const char *start = fmt; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
235 siClearStack(stack); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
236 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
237 while (*start) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
238 { |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
239 PSFStackItem item; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
240 const char *end = strchr(start, ','); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
241 char *field = (end != NULL) ? |
116
d062312ea850
Fix th_strndup_trim() usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
242 th_strndup_trim(start, end - start, TH_TRIM_BOTH) : |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
243 th_strdup_trim(start, TH_TRIM_BOTH); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
244 |
118 | 245 if (field != NULL) |
246 { | |
247 int found = argMatchPSFieldError(field); | |
248 th_free(field); | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
249 |
118 | 250 if (found < 0) |
251 return FALSE; | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
252 |
118 | 253 item.cmd = found; |
254 item.str = NULL; | |
255 if (!siStackAddItem(stack, &item)) | |
256 return FALSE; | |
257 } | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
258 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
259 if (!end) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
260 break; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
261 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
262 start = end + 1; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
263 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
264 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
265 return TRUE; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
266 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
267 |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
268 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
269 // |
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
270 // Parse a format string into a PSFStack structure |
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
271 // |
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
272 BOOL argParsePSFormatStr(PSFStack *stack, const char *fmt) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
273 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
274 PSFStackItem item; |
83 | 275 const char *start = NULL; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
276 int mode = 0; |
113
cd97e7517e21
Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
277 BOOL rval = TRUE; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
278 |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
279 siClearStack(stack); |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
280 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
281 while (mode != -1) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
282 switch (mode) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
283 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
284 case 0: |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
285 if (*fmt == '@') |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
286 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
287 start = fmt + 1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
288 mode = 1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
289 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
290 else |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
291 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
292 start = fmt; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
293 mode = 2; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
294 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
295 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
296 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
297 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
298 case 1: |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
299 if (*fmt == '@') |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
300 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
301 if (fmt - start == 0) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
302 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
303 item.cmd = -2; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
304 item.str = NULL; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
305 item.chr = '@'; |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
306 if (!siStackAddItem(stack, &item)) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
307 return FALSE; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
308 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
309 else |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
310 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
311 char *field = th_strndup_trim(start, fmt - start, TH_TRIM_BOTH); |
78
9fb70b7b34ff
Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
312 int ret = argMatchPSFieldError(field); |
113
cd97e7517e21
Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
313 th_free(field); |
81 | 314 if (ret >= 0) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
315 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
316 item.cmd = ret; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
317 item.str = NULL; |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
318 if (!siStackAddItem(stack, &item)) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
319 return FALSE; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
320 } |
113
cd97e7517e21
Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
321 else |
cd97e7517e21
Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
322 rval = FALSE; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
323 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
324 mode = 0; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
325 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
326 else |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
327 if (*fmt == 0) |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
328 mode = -1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
329 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
330 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
331 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
332 case 2: |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
333 if (*fmt == 0 || *fmt == '@') |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
334 { |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
335 item.cmd = -1; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
336 item.str = th_strndup(start, fmt - start); |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
337 if (!siStackAddItem(stack, &item)) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
338 return FALSE; |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
339 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
340 mode = (*fmt == 0) ? -1 : 0; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
341 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
342 else |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
343 fmt++; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
344 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
345 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
346 |
113
cd97e7517e21
Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
347 return rval; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
348 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
349 |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
350 |
2 | 351 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
352 { | |
353 switch (optN) | |
354 { | |
355 case 0: | |
356 argShowHelp(); | |
357 exit(0); | |
358 break; | |
359 | |
360 case 1: | |
361 th_verbosityLevel++; | |
362 break; | |
363 | |
364 case 2: | |
365 optParsable = TRUE; | |
366 break; | |
367 | |
368 case 3: | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
369 if (!argParsePSFields(&optFormat, optArg)) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
370 return FALSE; |
2 | 371 break; |
372 | |
373 case 4: | |
374 optHexadecimal = TRUE; | |
375 break; | |
376 | |
7 | 377 case 5: |
378 optNoNamePrefix = TRUE; | |
379 break; | |
380 | |
29 | 381 case 6: |
382 optOneLine = TRUE; | |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
383 optFieldSep = optArg; |
29 | 384 break; |
385 | |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
386 case 7: |
111 | 387 optFieldOutput = FALSE; |
79
5709d0beb394
Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
388 if (!argParsePSFormatStr(&optFormat, optArg)) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
389 return FALSE; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
390 break; |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
391 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
392 case 8: |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
393 setHVSCPath = th_strdup(optArg); |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
394 break; |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
395 |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
396 case 9: |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
397 setSLDBPath = th_strdup(optArg); |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
398 break; |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
399 |
2 | 400 default: |
401 THERR("Unknown option '%s'.\n", currArg); | |
402 return FALSE; | |
403 } | |
404 | |
405 return TRUE; | |
406 } | |
407 | |
408 | |
62
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
409 static void siPrintStrEscapes(FILE *outFile, const char *str) |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
410 { |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
411 while (*str) |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
412 { |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
413 if (*str == '\\') |
82 | 414 switch (*(++str)) |
62
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
415 { |
82 | 416 case 'n': fputc('\n', outFile); break; |
417 case 'r': fputc('\r', outFile); break; | |
418 case 't': fputc('\r', outFile); break; | |
419 case '\\': fputc('\\', outFile); break; | |
420 default: fputc(*str, outFile); break; | |
62
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
421 } |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
422 else |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
423 fputc(*str, outFile); |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
424 |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
425 str++; |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
426 } |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
427 } |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
428 |
0d01efc3c803
Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
429 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
430 static void siPrintFieldPrefix(FILE *outFile, const PSFOption *opt) |
2 | 431 { |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
432 const char *name = (optParsable || opt->lname == NULL) ? opt->name : opt->lname; |
111 | 433 if (!optNoNamePrefix && optFieldOutput) |
29 | 434 fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name); |
2 | 435 } |
436 | |
437 | |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
438 static void siPrintFieldSeparator(FILE *outFile) |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
439 { |
111 | 440 if (optFieldOutput) |
83 | 441 fputs(optOneLine ? optFieldSep : "\n", outFile); |
33
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
442 } |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
443 |
39d9df17c8b1
Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
444 |
125 | 445 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const PSFOption *opt, const char *xfmt, const char *xaltfmt, ...) |
2 | 446 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
447 va_list ap; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
448 const char *fmt = optHexadecimal ? (xaltfmt != NULL ? xaltfmt : xfmt) : xfmt; |
2 | 449 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
450 siPrintFieldPrefix(outFile, opt); |
2 | 451 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
452 va_start(ap, xaltfmt); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
453 vfprintf(outFile, fmt, ap); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
454 va_end(ap); |
3 | 455 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
456 siPrintFieldSeparator(outFile); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
457 *shown = TRUE; |
2 | 458 } |
459 | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
460 |
125 | 461 #define PR(xfmt, xaltfmt, ...) siPrintPSIDInfoLine(outFile, shown, opt, xfmt, xaltfmt, __VA_ARGS__ ) |
9
c1fba4abf56f
Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
462 |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
463 |
114 | 464 static void siPrintPSIDInformationField(FILE *outFile, const char *filename, const PSIDHeader *psid, BOOL *shown, const PSFStackItem *item) |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
465 { |
114 | 466 const PSFOption *opt = &optPSOptions[item->cmd]; |
467 switch (item->cmd) | |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
468 { |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
469 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
|
470 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
|
471 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
|
472 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
|
473 case 4: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
474 if (psid->version >= 2) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
475 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
|
476 break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
477 case 5: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
478 if (psid->version >= 2) |
132
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
479 PR("%s", NULL, si_get_sid_clock_str((psid->flags >> 2) & PSF_CLOCK_MASK)); |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
480 break; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
481 case 6: |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
482 if (psid->version >= 2) |
132
b3e034b8c4b9
Change how certain flags (for SID model and clock) are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
483 PR("%s", NULL, si_get_sid_model_str((psid->flags >> 4) & PSF_MODEL_MASK)); |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
484 break; |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
485 |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
486 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
|
487 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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 case 13: PR("%d", "$%04x", psid->startSong); break; |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
493 |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
494 case 14: |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
495 if (psid->version >= 3) |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
496 { |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
497 int flags = (psid->flags >> 6) & PSF_MODEL_MASK; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
498 if (flags == PSF_MODEL_UNKNOWN) |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
499 flags = (psid->flags >> 4) & PSF_MODEL_MASK; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
500 |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
501 PR("%s", NULL, si_get_sid_model_str(flags)); |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
502 } |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
503 break; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
504 case 15: |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
505 if (psid->version >= 4) |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
506 { |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
507 int flags = (psid->flags >> 8) & PSF_MODEL_MASK; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
508 if (flags == PSF_MODEL_UNKNOWN) |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
509 flags = (psid->flags >> 4) & PSF_MODEL_MASK; |
35
79e6d08b473f
Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
510 |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
511 PR("%s", NULL, si_get_sid_model_str(flags)); |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
512 } |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
513 break; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
514 case 16: |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
515 if (psid->version >= 3) |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
516 PR("%d", "$%04x", 0xD000 | (psid->sid2Addr << 4)); |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
517 break; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
518 case 17: |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
519 if (psid->version >= 4) |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
520 PR("%d", "$%04x", 0xD000 | (psid->sid3Addr << 4)); |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
521 break; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
522 |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
523 case 18: PR("%s", NULL, psid->sidName); break; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
524 case 19: PR("%s", NULL, psid->sidAuthor); break; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
525 case 20: PR("%s", NULL, psid->sidCopyright); break; |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
526 |
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
527 case 21: |
114 | 528 siPrintFieldPrefix(outFile, opt); |
529 th_md5_print(outFile, psid->hash); | |
530 siPrintFieldSeparator(outFile); | |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
531 break; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
532 |
134
b9a3f93f69d1
Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents:
132
diff
changeset
|
533 case 22: |
114 | 534 siPrintFieldPrefix(outFile, opt); |
535 if (psid->lengths != NULL) | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
536 { |
114 | 537 int i; |
538 for (i = 0; i < psid->lengths->nlengths; i++) | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
539 { |
114 | 540 int len = psid->lengths->lengths[i]; |
541 fprintf(outFile, "%d:%d%s", len / 60, len % 60, | |
542 (i < psid->lengths->nlengths - 1) ? " " : ""); | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
543 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
544 } |
114 | 545 siPrintFieldSeparator(outFile); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
546 break; |
29 | 547 } |
2 | 548 } |
549 | |
0 | 550 |
19 | 551 BOOL argHandleFile(char *filename) |
552 { | |
126
c1462b7880e8
Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
553 PSIDHeader *psid = NULL; |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
554 th_ioctx *inFile = NULL; |
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
555 FILE *outFile; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
556 int index; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
557 BOOL shown = FALSE; |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
558 |
19 | 559 optNFiles++; |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
560 outFile = stdout; |
19 | 561 |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
562 if ((inFile = th_io_fopen(&th_stdio_io_ops, filename, "rb")) == NULL) |
19 | 563 { |
564 THERR("Could not open file '%s'.\n", filename); | |
126
c1462b7880e8
Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
565 goto error; |
19 | 566 } |
567 | |
568 // Read PSID data | |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
569 if (si_read_sid_file(inFile, &psid) != 0) |
23 | 570 { |
571 THERR("Error reading %s\n", filename); | |
19 | 572 goto error; |
23 | 573 } |
19 | 574 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
575 // Get songlength information, if any |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
576 if (sidSLDB != NULL) |
126
c1462b7880e8
Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
577 psid->lengths = si_sldb_get_by_hash(sidSLDB, psid->hash); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
578 |
19 | 579 // Output |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
580 for (index = 0; index < optFormat.nitems; index++) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
581 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
582 PSFStackItem *item = &optFormat.items[index]; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
583 switch (item->cmd) |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
584 { |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
585 case -1: |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
586 siPrintStrEscapes(outFile, item->str); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
587 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
588 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
589 case -2: |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
590 fputc(item->chr, outFile); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
591 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
592 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
593 default: |
126
c1462b7880e8
Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
594 siPrintPSIDInformationField(outFile, filename, psid, &shown, item); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
595 break; |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
596 } |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
597 } |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
598 |
111 | 599 if (optFieldOutput) |
55
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
600 { |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
601 if (shown && optOneLine) |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
602 fprintf(outFile, "\n"); |
54b48086a1d0
Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
603 } |
19 | 604 |
605 // Shutdown | |
606 error: | |
126
c1462b7880e8
Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
607 si_free_sid_file(psid); |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
608 th_io_free(inFile); |
19 | 609 |
610 return TRUE; | |
611 } | |
612 | |
613 | |
0 | 614 int main(int argc, char *argv[]) |
615 { | |
616 // Initialize | |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
617 th_init("SIDInfo", "PSID/RSID information displayer", "0.6.1", NULL, NULL); |
0 | 618 th_verbosityLevel = 0; |
619 | |
59
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
620 memset(&optFormat, 0, sizeof(optFormat)); |
718cdb563531
Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
621 |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
622 // Initialize iconv, check if we have language/charset |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
623 #ifdef HAVE_ICONV |
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
624 char *setLang = th_strdup(getenv("LANG")); |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
625 if (setLang != NULL) |
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
626 { |
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
627 char *ptr = strchr(setLang, '.'); |
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
628 if (ptr != NULL) strcpy(setLang, ptr + 1); |
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
629 } |
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
630 |
129 | 631 setChConv = iconv_open(setLang != NULL ? setLang : SET_DEF_CHARSET, "iso88591"); |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
632 setUseChConv = setChConv != (iconv_t) -1; |
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
633 th_free(setLang); |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
634 #endif |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
635 |
2 | 636 // Parse command line arguments |
637 if (!th_args_process(argc, argv, optList, optListN, | |
23 | 638 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS)) |
2 | 639 return -1; |
640 | |
29 | 641 if (optOneLine) |
642 { | |
643 optParsable = FALSE; | |
644 optNoNamePrefix = TRUE; | |
645 } | |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
646 |
111 | 647 if (optFieldOutput && !optFormat.nitems) |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
648 { |
115 | 649 PSFStackItem item; |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
650 int i; |
127
1786b9d77782
Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
651 |
115 | 652 memset(&item, 0, sizeof(item)); |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
653 siClearStack(&optFormat); |
127
1786b9d77782
Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
654 |
109
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
655 for (i = 0; i < noptPSOptions; i++) |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
656 { |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
657 item.cmd = i; |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
658 siStackAddItem(&optFormat, &item); |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
659 } |
59b5b99f4280
Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
660 } |
29 | 661 |
90 | 662 // Check paths |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
663 if (setHVSCPath != NULL) |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
664 { |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
665 if (setSLDBPath == NULL) |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
666 setSLDBPath = th_strdup_printf("%s%c%s", setHVSCPath, TH_DIR_SEPARATOR, SET_SLDB_FILENAME); |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
667 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
668 |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
669 if (setSLDBPath != NULL) |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
670 { |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
671 // Initialize SLDB |
110 | 672 int ret = THERR_OK; |
127
1786b9d77782
Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
673 th_ioctx *inFile = NULL; |
1786b9d77782
Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
674 if ((inFile = th_io_fopen(&th_stdio_io_ops, setSLDBPath, "r")) == NULL) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
675 { |
106 | 676 THERR("Could not open SLDB '%s'.\n", |
677 setSLDBPath); | |
110 | 678 goto err; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
679 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
680 |
115 | 681 THMSG(1, "Reading SLDB.\n"); |
110 | 682 if ((sidSLDB = si_sldb_new()) == NULL) |
683 { | |
684 THERR("Could not allocate SLDB structure!\n"); | |
685 goto err; | |
686 } | |
687 | |
127
1786b9d77782
Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
688 if ((ret = si_sldb_read(inFile, sidSLDB)) != THERR_OK) |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
689 { |
106 | 690 THERR("Error parsing SLDB: %d, %s\n", |
691 ret, th_error_str(ret)); | |
110 | 692 goto err; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
693 } |
127
1786b9d77782
Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
694 th_io_close(inFile); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
695 |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
696 if ((ret = si_sldb_build_index(sidSLDB)) != THERR_OK) |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
697 { |
106 | 698 THERR("Error building SLDB index: %d, %s.\n", |
699 ret, th_error_str(ret)); | |
110 | 700 goto err; |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
701 } |
110 | 702 |
703 err: | |
127
1786b9d77782
Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
704 th_io_close(inFile); |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
705 } |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
706 |
23 | 707 // Process files |
708 if (!th_args_process(argc, argv, optList, optListN, | |
709 argHandleOpt, argHandleFile, OPTH_ONLY_OTHER)) | |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
710 goto out; |
23 | 711 |
19 | 712 if (optNFiles == 0) |
2 | 713 { |
714 argShowHelp(); | |
19 | 715 THERR("No filename(s) specified.\n"); |
2 | 716 } |
1 | 717 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
718 out: |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
719 |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
720 #ifdef HAVE_ICONV |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
721 if (setUseChConv) |
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
722 iconv_close(setChConv); |
135
b4b1aac8761c
Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
723 #endif |
120
ecbc8cabd6a2
Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
724 |
89
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
725 th_free(setHVSCPath); |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
726 th_free(setSLDBPath); |
d9cb7c635e7b
Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
727 si_sldb_free(sidSLDB); |
19 | 728 return 0; |
0 | 729 } |