1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
--- mp3gain.c.old 2004-12-23 15:47:04.000000000 -0500
+++ mp3gain.c 2006-03-13 22:15:28.000000000 -0500
@@ -46,7 +46,8 @@
#include <stdio.h>
#include <stdlib.h>
-#include <math.h>
+#include <math.h>
+#include <ctype.h>
#include "apetag.h"
#ifndef WIN32
@@ -1181,10 +1182,11 @@
static
void errUsage(char *progname) {
showVersion(progname);
- fprintf(stderr,"copyright(c) 2001-2004 by Glen Sawyer\n");
+ fprintf(stderr,"copyright(c) 2001-2004 by Glen Sawyer\n");
+ fprintf(stderr,"portions copyright(c) 2006 by Stephan Sokolow\n");
fprintf(stderr,"uses mpglib, which can be found at http://www.mpg123.de\n");
fprintf(stderr,"Usage: %s [options] <infile> [<infile 2> ...]\n",progname);
- fprintf(stderr," --use %c? or %ch for a full list of options\n",SWITCH_CHAR,SWITCH_CHAR);
+ fprintf(stderr," --use %c?, %ch, or --help for a full list of options\n",SWITCH_CHAR,SWITCH_CHAR);
fclose(stdout);
fclose(stderr);
exit(1);
@@ -1195,7 +1197,8 @@
static
void fullUsage(char *progname) {
showVersion(progname);
- fprintf(stderr,"copyright(c) 2001-2004 by Glen Sawyer\n");
+ fprintf(stderr,"copyright(c) 2001-2004 by Glen Sawyer\n");
+ fprintf(stderr,"portions copyright(c) 2006 by Stephan Sokolow\n");
fprintf(stderr,"uses mpglib, which can be found at http://www.mpg123.de\n");
fprintf(stderr,"Usage: %s [options] <infile> [<infile 2> ...]\n",progname);
fprintf(stderr,"options:\n");
@@ -1227,9 +1230,14 @@
fprintf(stderr,"\t%cs d - delete stored tag info (no other processing)\n",SWITCH_CHAR);
fprintf(stderr,"\t%cs s - skip (ignore) stored tag info (do not read or write tags)\n",SWITCH_CHAR);
fprintf(stderr,"\t%cs r - force re-calculation (do not read tag info)\n",SWITCH_CHAR);
- fprintf(stderr,"\t%cu - undo changes made by mp3gain (based on stored tag info)\n",SWITCH_CHAR);
- fprintf(stderr,"\t%cw - \"wrap\" gain change if gain+change > 255 or gain+change < 0\n",SWITCH_CHAR);
- fprintf(stderr,"\t (use \"%c? wrap\" switch for a complete explanation)\n",SWITCH_CHAR);
+ fprintf(stderr,"\t%cu - undo changes made by mp3gain (based on stored tag info)\n",SWITCH_CHAR);
+ fprintf(stderr,"\t%cw - \"wrap\" gain change if gain+change > 255 or gain+change < 0\n",SWITCH_CHAR);
+ fprintf(stderr,"\t (use \"%c? wrap\" switch for a complete explanation)\n",SWITCH_CHAR);
+ fprintf(stderr,"\t-- - force everything beyond this point to be treated as arguments.\n");
+ fprintf(stderr,"long options:\n");
+ fprintf(stderr,"\t--auto - same as %cr %ck %cp\n", SWITCH_CHAR, SWITCH_CHAR, SWITCH_CHAR);
+ fprintf(stderr,"\t--help - show this message\n");
+ fprintf(stderr,"\t--recursive - TODO\n");
fprintf(stderr,"If you specify %cr and %ca, only the second one will work\n",SWITCH_CHAR,SWITCH_CHAR);
fprintf(stderr,"If you do not specify %cc, the program will stop and ask before\n applying gain change to a file that might clip\n",SWITCH_CHAR);
fclose(stdout);
@@ -1245,7 +1253,20 @@
fprintf(stderr, "haveTrackPeak %d trackPeak %f\n",info->haveTrackPeak, info->trackPeak);
fprintf(stderr, "haveMinMaxGain %d min %d max %d\n",info->haveMinMaxGain, info->minGain, info->maxGain);
}
-
+
+void showHelp(int argc, char **argv, int i) {
+ if ((argv[i][2] == 'w')||(argv[i][2] == 'W')) {
+ wrapExplanation();
+ } else {
+ if (i+1 < argc) {
+ if ((argv[i+1][0] == 'w')||(argv[i+1][0] =='W'))
+ wrapExplanation();
+ } else {
+ fullUsage(argv[0]);
+ }
+ }
+ fullUsage(argv[0]);
+}
#ifdef WIN32
int __cdecl main(int argc, char **argv) { /*make sure this one is standard C declaration*/
@@ -1282,7 +1303,7 @@
int fileStart;
int numFiles;
int databaseFormat = 0;
- int i;
+ int i, j;
int *fileok;
int goAhead;
int directGain = 0;
@@ -1303,7 +1324,10 @@
double curAlbumPeak = 0;
unsigned char curAlbumMinGain = 0;
unsigned char curAlbumMaxGain = 0;
- char chtmp;
+ char chtmp;
+
+ /* Variables used in the improved option parser */
+ int parseOptions = !0;
gSuccess = 1;
@@ -1316,28 +1340,28 @@
fileStart = 1;
numFiles = 0;
- for (i = 1; i < argc; i++) {
-#ifdef WIN32
- if ((argv[i][0] == '/')||((argv[i][0] == '-') && (strlen(argv[i])==2))) { /* don't need to force single-character command parameters */
-#else
- if (((argv[i][0] == '/')||(argv[i][0] == '-'))&&
- (strlen(argv[i])==2)) {
-#endif
- fileStart++;
- switch(argv[i][1]) {
- case 'a':
- case 'A':
+ for (i = 1; i < argc; i++) {
+ /*
+ TODO: Implement support for:
+ - consider including the glob-parsing support from vorbisgain's so-called recursive support.
+ */
+ if ((parseOptions) && (argv[i][0] == SWITCH_CHAR) && (strlen(argv[i]) >= 2) ) {
+ fileStart++;
+
+ if (!strcmp(argv[i],"--")) { /* Support for the standard "--" option to force the end of the option parsing. */
+ parseOptions = 0;
+ continue;
+ } else if (argv[i][1] != '-') { /* Ensure that this isn't a long option. */
+ for (j = 1; j < strlen(argv[i]); j++) {
+ switch(tolower(argv[i][j])) {
+ case 'a':
applyTrack = 0;
applyAlbum = !0;
break;
-
- case 'c':
- case 'C':
+ case 'c':
ignoreClipWarning = !0;
break;
-
- case 'd':
- case 'D':
+ case 'd':
if (argv[i][2] != '\0') {
dBGainMod = atof(argv[i]+2);
}
@@ -1352,14 +1376,10 @@
}
}
break;
-
- case 'f':
- case 'F':
+ case 'f':
Reckless = 1;
break;
-
- case 'g':
- case 'G':
+ case 'g':
directGain = !0;
directSingleChannelGain = 0;
if (argv[i][2] != '\0') {
@@ -1376,32 +1396,14 @@
}
}
break;
-
- case 'h':
- case 'H':
- case '?':
- if ((argv[i][2] == 'w')||(argv[i][2] == 'W')) {
- wrapExplanation();
- }
- else {
- if (i+1 < argc) {
- if ((argv[i+1][0] == 'w')||(argv[i+1][0] =='W'))
- wrapExplanation();
- }
- else {
- fullUsage(argv[0]);
- }
- }
- fullUsage(argv[0]);
- break;
-
- case 'k':
- case 'K':
- autoClip = !0;
- break;
-
- case 'l':
- case 'L':
+ case 'h':
+ case '?':
+ showHelp(argc, argv, i);
+ break;
+ case 'k':
+ autoClip = !0;
+ break;
+ case 'l':
directSingleChannelGain = !0;
directGain = 0;
if (argv[i][2] != '\0') {
@@ -1429,9 +1431,7 @@
}
}
break;
-
- case 'm':
- case 'M':
+ case 'm':
if (argv[i][2] != '\0') {
mp3GainMod = atoi(argv[i]+2);
}
@@ -1446,30 +1446,20 @@
}
}
break;
-
- case 'o':
- case 'O':
+ case 'o':
databaseFormat = !0;
break;
-
- case 'p':
- case 'P':
+ case 'p':
saveTime = !0;
break;
-
- case 'q':
- case 'Q':
+ case 'q':
QuietMode = !0;
break;
-
- case 'r':
- case 'R':
+ case 'r':
applyTrack = !0;
applyAlbum = 0;
break;
-
- case 's':
- case 'S':
+ case 's':
chtmp = 0;
if (argv[i][2] == '\0') {
if (i+1 < argc) {
@@ -1482,59 +1472,56 @@
} else {
chtmp = argv[i][2];
}
- switch (chtmp) {
- case 'c':
- case 'C':
- checkTagOnly = !0;
- break;
- case 'd':
- case 'D':
- deleteTag = !0;
- break;
- case 's':
- case 'S':
- skipTag = !0;
- break;
- case 'r':
- case 'R':
- forceRecalculateTag = !0;
- break;
- default:
- errUsage(argv[0]);
- }
-
- break;
-
- case 't':
- case 'T':
+ switch (tolower(chtmp)) {
+ case 'c':
+ checkTagOnly = !0;
+ break;
+ case 'd':
+ deleteTag = !0;
+ break;
+ case 's':
+ skipTag = !0;
+ break;
+ case 'r':
+ forceRecalculateTag = !0;
+ break;
+ default:
+ errUsage(argv[0]);
+ }
+ break;
+ case 't':
UsingTemp = !0;
break;
-
- case 'u':
- case 'U':
+ case 'u':
undoChanges = !0;
break;
-
- case 'v':
- case 'V':
+ case 'v':
showVersion(argv[0]);
- fclose(stdout);
- fclose(stderr);
+ fclose(stdout);
+ fclose(stderr);
exit(0);
-
- case 'w':
- case 'W':
+ case 'w':
wrapGain = !0;
break;
-
- case 'x':
- case 'X':
+ case 'x':
maxAmpOnly = !0;
break;
-
- default:
- fprintf(stderr,"I don't recognize option %s\n",argv[i]);
- }
+ default:
+ fprintf(stderr,"I don't recognize option %s\n",argv[i]);
+ }
+ }
+ } else if (!strncmp(argv[i],"--",2)) { /* This is a long option and must be parsed as such */
+ if (!strcasecmp(argv[i],"--auto")) {
+ autoClip = !0; /* -k */
+ saveTime = !0; /* -p */
+ applyTrack = !0; /* -r */
+ applyAlbum = 0; /* -r */
+ } else if (!strcasecmp(argv[i],"--help")) {
+ showHelp(argc, argv, i);
+ } else if (!strcasecmp(argv[i],"--recursive")) {
+ fprintf(stderr,"Sorry, --recursive has not been implemented yet.\n\t However, the following command seems to be equivalent:\n\t`find /path/to/mp3s -iname \"*.mp3\" -exec mp3gain -r {} \\;`\n\tThe use of --auto in place of -r is recommended.\n");
+ }
+ }
}
}
/* now stored in tagInfo--- maxsample = malloc(sizeof(Float_t) * argc); */
|