/* flac - Command-line FLAC encoder/decoder
- * Copyright (C) 2000,2001,2002,2003,2004,2005,2006 Josh Coalson
+ * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
typedef enum { RAW, WAV, AIF, FLAC, OGGFLAC } FileFormat;
-static int do_it();
+static int do_it(void);
-static FLAC__bool init_options();
+static FLAC__bool init_options(void);
static int parse_options(int argc, char *argv[]);
static int parse_option(int short_option, const char *long_option, const char *option_argument);
-static void free_options();
+static void free_options(void);
static void add_compression_setting_bool(compression_setting_type_t type, FLAC__bool value);
static void add_compression_setting_string(compression_setting_type_t type, const char *value);
static void add_compression_setting_unsigned(compression_setting_type_t type, unsigned value);
static int usage_error(const char *message, ...);
-static void short_usage();
-static void show_version();
-static void show_help();
-static void show_explain();
-static void format_mistake(const char *infilename, const char *wrong, const char *right);
+static void short_usage(void);
+static void show_version(void);
+static void show_help(void);
+static void show_explain(void);
+static void format_mistake(const char *infilename, FileFormat wrong, FileFormat right);
static int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_last_file);
static int decode_file(const char *infilename);
/*
* general options
*/
- { "help" , share__no_argument, 0, 'h' },
- { "explain" , share__no_argument, 0, 'H' },
- { "version" , share__no_argument, 0, 'v' },
- { "decode" , share__no_argument, 0, 'd' },
- { "analyze" , share__no_argument, 0, 'a' },
- { "test" , share__no_argument, 0, 't' },
- { "stdout" , share__no_argument, 0, 'c' },
- { "silent" , share__no_argument, 0, 's' },
- { "totally-silent" , share__no_argument, 0, 0 },
- { "force" , share__no_argument, 0, 'f' },
- { "delete-input-file", share__no_argument, 0, 0 },
- { "output-prefix" , share__required_argument, 0, 0 },
- { "output-name" , share__required_argument, 0, 'o' },
- { "skip" , share__required_argument, 0, 0 },
- { "until" , share__required_argument, 0, 0 },
- { "channel-map" , share__required_argument, 0, 0 }, /* undocumented */
+ { "help" , share__no_argument, 0, 'h' },
+ { "explain" , share__no_argument, 0, 'H' },
+ { "version" , share__no_argument, 0, 'v' },
+ { "decode" , share__no_argument, 0, 'd' },
+ { "analyze" , share__no_argument, 0, 'a' },
+ { "test" , share__no_argument, 0, 't' },
+ { "stdout" , share__no_argument, 0, 'c' },
+ { "silent" , share__no_argument, 0, 's' },
+ { "totally-silent" , share__no_argument, 0, 0 },
+ { "warnings-as-errors", share__no_argument, 0, 'w' },
+ { "force" , share__no_argument, 0, 'f' },
+ { "delete-input-file" , share__no_argument, 0, 0 },
+ { "output-prefix" , share__required_argument, 0, 0 },
+ { "output-name" , share__required_argument, 0, 'o' },
+ { "skip" , share__required_argument, 0, 0 },
+ { "until" , share__required_argument, 0, 0 },
+ { "channel-map" , share__required_argument, 0, 0 }, /* undocumented */
/*
* decoding options
{ "no-qlp-coeff-prec-search" , share__no_argument, 0, 0 },
{ "no-padding" , share__no_argument, 0, 0 },
{ "no-verify" , share__no_argument, 0, 0 },
+ { "no-warnings-as-errors" , share__no_argument, 0, 0 },
{ "no-residual-gnuplot" , share__no_argument, 0, 0 },
{ "no-residual-text" , share__no_argument, 0, 0 },
/*
FLAC__bool show_version;
FLAC__bool mode_decode;
FLAC__bool verify;
+ FLAC__bool treat_warnings_as_errors;
FLAC__bool force_file_overwrite;
FLAC__bool continue_through_decode_errors;
replaygain_synthesis_spec_t replaygain_synthesis_spec;
_wildcard(&argc, &argv);
#endif
- srand(time(0));
+ srand((unsigned)time(0));
setlocale(LC_ALL, "");
if(!init_options()) {
flac__utils_printf(stderr, 1, "ERROR: allocating memory\n");
return retval;
}
-int do_it()
+int do_it(void)
{
int retval = 0;
}
flac__utils_printf(stderr, 2, "\n");
- flac__utils_printf(stderr, 2, "flac %s, Copyright (C) 2000,2001,2002,2003,2004,2005,2006 Josh Coalson\n", FLAC__VERSION_STRING);
+ flac__utils_printf(stderr, 2, "flac %s, Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson\n", FLAC__VERSION_STRING);
flac__utils_printf(stderr, 2, "flac comes with ABSOLUTELY NO WARRANTY. This is free software, and you are\n");
flac__utils_printf(stderr, 2, "welcome to redistribute it under certain conditions. Type `flac' for details.\n\n");
return retval;
}
-FLAC__bool init_options()
+FLAC__bool init_options(void)
{
option_values.show_help = false;
option_values.show_explain = false;
option_values.mode_decode = false;
option_values.verify = false;
+ option_values.treat_warnings_as_errors = false;
option_values.force_file_overwrite = false;
option_values.continue_through_decode_errors = false;
option_values.replaygain_synthesis_spec.apply = false;
int short_option;
int option_index = 1;
FLAC__bool had_error = false;
- const char *short_opts = "0123456789aA:b:cdefFhHl:mMo:pP:q:r:sS:tT:vV";
+ const char *short_opts = "0123456789aA:b:cdefFhHl:mMo:pP:q:r:sS:tT:vVw";
while ((short_option = share__getopt_long(argc, argv, short_opts, long_options_, &option_index)) != -1) {
switch (short_option) {
else if(0 == strcmp(long_option, "no-verify")) {
option_values.verify = false;
}
+ else if(0 == strcmp(long_option, "no-warnings-as-errors")) {
+ option_values.treat_warnings_as_errors = false;
+ }
else if(0 == strcmp(long_option, "no-residual-gnuplot")) {
option_values.aopts.do_residual_gnuplot = false;
}
case 'V':
option_values.verify = true;
break;
+ case 'w':
+ option_values.treat_warnings_as_errors = true;
+ break;
case 'S':
FLAC__ASSERT(0 != option_argument);
if(0 == strcmp(option_argument, "-")) {
return 0;
}
-void free_options()
+void free_options(void)
{
unsigned i;
if(0 != option_values.filenames) {
return 1;
}
-void show_version()
+void show_version(void)
{
printf("flac %s\n", FLAC__VERSION_STRING);
}
-static void usage_header()
+static void usage_header(void)
{
printf("===============================================================================\n");
printf("flac - Command-line FLAC encoder/decoder version %s\n", FLAC__VERSION_STRING);
- printf("Copyright (C) 2000,2001,2002,2003,2004,2005,2006 Josh Coalson\n");
+ printf("Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson\n");
printf("\n");
printf("This program is free software; you can redistribute it and/or\n");
printf("modify it under the terms of the GNU General Public License\n");
printf("===============================================================================\n");
}
-static void usage_summary()
+static void usage_summary(void)
{
printf("Usage:\n");
printf("\n");
printf("\n");
}
-void short_usage()
+void short_usage(void)
{
usage_header();
printf("\n");
printf(" flac -t [INPUTFILE [...]]\n");
}
-void show_help()
+void show_help(void)
{
usage_header();
usage_summary();
printf(" -c, --stdout Write output to stdout\n");
printf(" -s, --silent Do not write runtime encode/decode statistics\n");
printf(" --totally-silent Do not print anything, including errors\n");
+ printf(" -w, --warnings-as-errors Treat all warnings as errors\n");
printf(" -f, --force Force overwriting of output files\n");
printf(" -o, --output-name=FILENAME Force the output file name\n");
printf(" --output-prefix=STRING Prepend STRING to output names\n");
printf(" --tag-from-file=FIELD=FILENAME Like --tag but gets value from file\n");
printf(" -S, --seekpoint={#|X|#x|#s} Add seek point(s)\n");
printf(" -P, --padding=# Write a PADDING block of length #\n");
- printf(" -0, --compression-level-0, --fast Synonymous with -l 0 -b 1152 -r 2,2\n");
- printf(" -1, --compression-level-1 Synonymous with -l 0 -b 1152 -M -r 2,2\n");
+ printf(" -0, --compression-level-0, --fast Synonymous with -l 0 -b 1152 -r 3\n");
+ printf(" -1, --compression-level-1 Synonymous with -l 0 -b 1152 -M -r 3\n");
printf(" -2, --compression-level-2 Synonymous with -l 0 -b 1152 -m -r 3\n");
- printf(" -3, --compression-level-3 Synonymous with -l 6 -b 4608 -r 3,3\n");
- printf(" -4, --compression-level-4 Synonymous with -l 8 -b 4608 -M -r 3,3\n");
- printf(" -5, --compression-level-5 Synonymous with -l 8 -b 4608 -m -r 3,3\n");
- printf(" -6, --compression-level-6 Synonymous with -l 8 -b 4608 -m -r 4\n");
- printf(" -7, --compression-level-7 Synonymous with -l 8 -b 4608 -m -e -r 6\n");
- printf(" -8, --compression-level-8, --best Synonymous with -l 12 -b 4608 -m -e -r 6\n");
+ printf(" -3, --compression-level-3 Synonymous with -l 6 -b 4096 -r 4\n");
+ printf(" -4, --compression-level-4 Synonymous with -l 8 -b 4096 -M -r 4\n");
+ printf(" -5, --compression-level-5 Synonymous with -l 8 -b 4096 -m -r 5\n");
+ printf(" -6, --compression-level-6 Synonymous with -l 8 -b 4096 -m -r 6\n");
+ printf(" -7, --compression-level-7 Synonymous with -l 8 -b 4096 -m -e -r 6\n");
+ printf(" -8, --compression-level-8, --best Synonymous with -l 12 -b 4096 -m -e -r 6\n");
printf(" -b, --blocksize=# Specify blocksize in samples\n");
printf(" -m, --mid-side Try mid-side coding for each frame\n");
printf(" -M, --adaptive-mid-side Adaptive mid-side coding for all frames\n");
printf(" --no-silent\n");
printf(" --no-force\n");
printf(" --no-verify\n");
+ printf(" --no-warnings-as-errors\n");
}
-void show_explain()
+void show_explain(void)
{
usage_header();
usage_summary();
printf(" --totally-silent Do not print anything of any kind, including\n");
printf(" warnings or errors. The exit code will be the\n");
printf(" only way to determine successful completion.\n");
+ printf(" -w, --warnings-as-errors Treat all warnings as errors\n");
printf(" -f, --force Force overwriting of output files\n");
printf(" -o, --output-name=FILENAME Force the output file name; usually flac just\n");
printf(" changes the extension. May only be used when\n");
printf(" --no-cued-seekpoints is specified.\n");
printf(" --picture=SPECIFICATION Import a picture and store it in a PICTURE block.\n");
printf(" More than one --picture command can be specified.\n");
- printf(" The SPECIFICATION is a string whose parts are\n");
- printf(" separated by | characters. Some parts may be\n");
- printf(" left empty to invoke default values. The format:\n");
- printf(" [TYPE]|MIME-TYPE|[DESCRIPTION]|[WIDTHxHEIGHTxDEPTH[/COLORS]]|FILE\n");
+ printf(" The SPECIFICATION can either be a simple filename\n");
+ printf(" for the picture file, or a complete specification\n");
+ printf(" whose parts are separated by | characters. Some\n");
+ printf(" parts may be left empty to invoke default values.\n");
+ printf(" Using a filename is shorthand for \"||||FILE\".\n");
+ printf(" The SPECIFICATION format is:\n");
+ printf(" [TYPE]|[MIME-TYPE]|[DESCRIPTION]|[WIDTHxHEIGHTxDEPTH[/COLORS]]|FILE\n");
printf(" TYPE is optional; it is a number from one of:\n");
printf(" 0: Other\n");
printf(" 1: 32x32 pixels 'file icon' (PNG only)\n");
printf(" 20: Publisher/Studio logotype\n");
printf(" The default is 3 (front cover). There may only be one picture each\n");
printf(" of type 1 and 2 in a file.\n");
- printf(" MIME-TYPE is mandatory; for best compatibility with players, use\n");
- printf(" pictures with MIME type image/jpeg or image/png. The MIME type can\n");
- printf(" also be --> to mean that FILE is actually a URL to an image, though\n");
- printf(" this use is discouraged.\n");
+ printf(" MIME-TYPE is optional; if left blank, it will be detected from the\n");
+ printf(" file. For best compatibility with players, use pictures with MIME\n");
+ printf(" type image/jpeg or image/png. The MIME type can also be --> to\n");
+ printf(" mean that FILE is actually a URL to an image, though this use is\n");
+ printf(" discouraged.\n");
printf(" DESCRIPTION is optional; the default is an empty string\n");
printf(" The next part specfies the resolution and color information. If\n");
printf(" the MIME-TYPE is image/jpeg, image/png, or image/gif, you can\n");
printf(" block of 8192 bytes by default, or 65536 bytes\n");
printf(" if the input audio is more than 20 minutes long.\n");
printf(" -b, --blocksize=# Specify the blocksize in samples; the default is\n");
- printf(" 1152 for -l 0, else 4608; must be one of 192,\n");
+ printf(" 1152 for -l 0, else 4096; must be one of 192,\n");
printf(" 576, 1152, 2304, 4608, 256, 512, 1024, 2048,\n");
printf(" 4096 (and 8192 or 16384 if the sample rate is\n");
printf(" >48kHz) for Subset streams.\n");
- printf(" -0, --compression-level-0, --fast Synonymous with -l 0 -b 1152 -r 2,2\n");
- printf(" -1, --compression-level-1 Synonymous with -l 0 -b 1152 -M -r 2,2\n");
+ printf(" -0, --compression-level-0, --fast Synonymous with -l 0 -b 1152 -r 3\n");
+ printf(" -1, --compression-level-1 Synonymous with -l 0 -b 1152 -M -r 3\n");
printf(" -2, --compression-level-2 Synonymous with -l 0 -b 1152 -m -r 3\n");
- printf(" -3, --compression-level-3 Synonymous with -l 6 -b 4608 -r 3,3\n");
- printf(" -4, --compression-level-4 Synonymous with -l 8 -b 4608 -M -r 3,3\n");
- printf(" -5, --compression-level-5 Synonymous with -l 8 -b 4608 -m -r 3,3\n");
+ printf(" -3, --compression-level-3 Synonymous with -l 6 -b 4096 -r 4\n");
+ printf(" -4, --compression-level-4 Synonymous with -l 8 -b 4096 -M -r 4\n");
+ printf(" -5, --compression-level-5 Synonymous with -l 8 -b 4096 -m -r 5\n");
printf(" -5 is the default setting\n");
- printf(" -6, --compression-level-6 Synonymous with -l 8 -b 4608 -m -r 4\n");
- printf(" -7, --compression-level-7 Synonymous with -l 8 -b 4608 -m -e -r 6\n");
- printf(" -8, --compression-level-8, --best Synonymous with -l 12 -b 4608 -m -e -r 6\n");
+ printf(" -6, --compression-level-6 Synonymous with -l 8 -b 4096 -m -r 6\n");
+ printf(" -7, --compression-level-7 Synonymous with -l 8 -b 4096 -m -e -r 6\n");
+ printf(" -8, --compression-level-8, --best Synonymous with -l 12 -b 4096 -m -e -r 6\n");
printf(" -m, --mid-side Try mid-side coding for each frame\n");
printf(" (stereo only)\n");
printf(" -M, --adaptive-mid-side Adaptive mid-side coding for all frames\n");
printf(" --no-silent\n");
printf(" --no-force\n");
printf(" --no-verify\n");
+ printf(" --no-warnings-as-errors\n");
}
-void format_mistake(const char *infilename, const char *wrong, const char *right)
+void format_mistake(const char *infilename, FileFormat wrong, FileFormat right)
{
- flac__utils_printf(stderr, 1, "WARNING: %s is not a %s file; treating as a %s file\n", infilename, wrong, right);
+ /* WATCHOUT: indexed by FileFormat */
+ static const char * const ff[] = { "raw", "WAVE", "AIFF", "FLAC", "Ogg FLAC" };
+ flac__utils_printf(stderr, 1, "WARNING: %s is not a %s file; treating as a %s file\n", infilename, ff[wrong], ff[right]);
}
int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_last_file)
/* attempt to guess the file type based on the first 12 bytes */
if((lookahead_length = fread(lookahead, 1, 12, encode_infile)) < 12) {
- if(fmt != RAW)
- format_mistake(infilename, fmt == AIF ? "AIFF" : "WAVE", "raw");
+ if(fmt != RAW) {
+ format_mistake(infilename, fmt, RAW);
+ if(option_values.treat_warnings_as_errors) {
+ conditional_fclose(encode_infile);
+ return 1;
+ }
+ }
fmt= RAW;
}
else {
- if(!strncmp((const char *)lookahead, "RIFF", 4) && !strncmp((const char *)lookahead+8, "WAVE", 4))
+ if(!strncmp((const char *)lookahead, "ID3", 3)) {
+ flac__utils_printf(stderr, 1, "ERROR: input file %s has an ID3v2 tag\n", infilename);
+ return 1;
+ }
+ else if(!strncmp((const char *)lookahead, "RIFF", 4) && !strncmp((const char *)lookahead+8, "WAVE", 4))
fmt= WAV;
else if(!strncmp((const char *)lookahead, "FORM", 4) && !strncmp((const char *)lookahead+8, "AIFF", 4))
fmt= AIF;
else if(!memcmp(lookahead, "OggS", 4))
fmt= OGGFLAC;
else {
- if(fmt != RAW)
- format_mistake(infilename, fmt == AIF ? "AIFF" : "WAVE", "raw");
+ if(fmt != RAW) {
+ format_mistake(infilename, fmt, RAW);
+ if(option_values.treat_warnings_as_errors) {
+ conditional_fclose(encode_infile);
+ return 1;
+ }
+ }
fmt= RAW;
}
}
common_options.until_specification.is_relative = true;
common_options.verify = option_values.verify;
+ common_options.treat_warnings_as_errors = option_values.treat_warnings_as_errors;
#if FLAC__HAS_OGG
common_options.use_ogg = option_values.use_ogg;
/* set a random serial number if one has not yet been specified */
else
common_options.has_cue_specification = false;
+ common_options.treat_warnings_as_errors = option_values.treat_warnings_as_errors;
common_options.continue_through_decode_errors = option_values.continue_through_decode_errors;
common_options.replaygain_synthesis_spec = option_values.replaygain_synthesis_spec;
#if FLAC__HAS_OGG