1 /* flac - Command-line FLAC encoder/decoder
2 * Copyright (C) 2000,2001,2002 Josh Coalson
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #if !defined _MSC_VER && !defined __MINGW32__
25 /* unlink is in stdio.h in VC++ */
26 #include <unistd.h> /* for unlink() */
28 #define strcasecmp stricmp
37 /*[JEC] was:#if HAVE_GETOPT_LONG*/
38 /*[JEC] see flac/include/share/getopt.h as to why the change */
41 # include "share/getopt.h"
44 typedef enum { RAW, WAV, AIF } FileFormat;
48 static void init_options();
49 static int parse_options(int argc, char *argv[]);
50 static int parse_option(int short_option, const char *long_option, const char *option_argument);
51 static void free_options();
53 static int usage_error(const char *message, ...);
54 static void short_usage();
55 static void show_help();
56 static void show_explain();
57 static void format_mistake(const char *infilename, const char *wrong, const char *right);
59 static int encode_file(const char *infilename, const char *forced_outfilename, FLAC__bool is_last_file);
60 static int decode_file(const char *infilename, const char *forced_outfilename);
62 static void die(const char *message);
63 static char *local_strdup(const char *source);
67 * FLAC__share__getopt format struct; note that for long options with no
68 * short option equivalent we just set the 'val' field to 0.
70 static struct FLAC__share__option long_options_[] = {
74 { "help", 0, 0, 'h' },
75 { "decode", 0, 0, 'd' },
76 { "analyze", 0, 0, 'a' },
77 { "test", 0, 0, 't' },
78 { "stdout", 0, 0, 'c' },
79 { "silent", 0, 0, 's' },
80 { "delete-input-file", 0, 0, 0 },
81 { "output-prefix", 1, 0, 0 },
82 { "output-name", 1, 0, 'o' },
88 { "decode-through-errors", 0, 0, 'F' },
93 { "compression-level-0", 0, 0, '0' },
94 { "compression-level-1", 0, 0, '1' },
95 { "compression-level-2", 0, 0, '2' },
96 { "compression-level-3", 0, 0, '3' },
97 { "compression-level-4", 0, 0, '4' },
98 { "compression-level-5", 0, 0, '5' },
99 { "compression-level-6", 0, 0, '6' },
100 { "compression-level-7", 0, 0, '7' },
101 { "compression-level-8", 0, 0, '8' },
102 { "compression-level-9", 0, 0, '9' },
103 { "best", 0, 0, '8' },
104 { "fast", 0, 0, '0' },
105 { "super-secret-impractical-compression-level", 0, 0, 0 },
106 { "verify", 0, 0, 'V' },
107 { "force-raw-input", 0, 0, 0 },
109 { "sector-align", 0, 0, 0 },
110 { "seekpoint", 1, 0, 'S' },
111 { "padding", 1, 0, 'P' },
115 { "blocksize", 1, 0, 'b' },
116 { "exhaustive-model-search", 0, 0, 'e' },
118 /* @@@ deprecated: */
119 { "escape-coding", 0, 0, 'E' },
121 { "max-lpc-order", 1, 0, 'l' },
122 { "mid-side", 0, 0, 'm' },
123 { "adaptive-mid-side", 0, 0, 'M' },
124 { "qlp-coeff-precision-search", 0, 0, 'p' },
125 { "qlp-coeff-precision", 1, 0, 'q' },
126 { "rice-partition-order", 1, 0, 'r' },
128 /* @@@ deprecated: */
129 { "rice-parameter-search-distance", 1, 0, 'R' },
131 { "endian", 1, 0, 0 },
132 { "channels", 1, 0, 0 },
134 { "sample-rate", 1, 0, 0 },
140 { "residual-gnu-plot", 0, 0, 0 },
141 { "residual-text", 0, 0, 0 },
146 { "no-decode-through-errors", 0, 0, 0 },
147 { "no-silent", 0, 0, 0 },
148 { "no-seektable", 0, 0, 0 },
149 { "no-delete-input-file", 0, 0, 0 },
150 { "no-sector-align", 0, 0, 0 },
151 { "no-lax", 0, 0, 0 },
153 { "no-ogg", 0, 0, 0 },
155 { "no-exhaustive-model-search", 0, 0, 0 },
157 /* @@@ deprecated: */
158 { "no-escape-coding", 0, 0, 0 },
160 { "no-mid-side", 0, 0, 0 },
161 { "no-adaptive-mid-side", 0, 0, 0 },
162 { "no-qlp-coeff-prec-search", 0, 0, 0 },
163 { "no-padding", 0, 0, 0 },
164 { "no-verify", 0, 0, 0 },
165 { "no-residual-gnuplot", 0, 0, 0 },
166 { "no-residual-text", 0, 0, 0 },
173 * global to hold command-line option values
177 FLAC__bool show_help;
178 FLAC__bool show_explain;
179 FLAC__bool mode_decode;
182 FLAC__bool continue_through_decode_errors;
184 FLAC__bool test_only;
187 FLAC__bool do_mid_side;
188 FLAC__bool loose_mid_side;
189 FLAC__bool do_exhaustive_model_search;
190 FLAC__bool do_escape_coding;
191 FLAC__bool do_qlp_coeff_prec_search;
192 FLAC__bool force_to_stdout;
193 FLAC__bool force_raw_format;
194 FLAC__bool delete_input;
195 FLAC__bool sector_align;
196 const char *cmdline_forced_outfilename;
197 const char *output_prefix;
198 analysis_options aopts;
200 unsigned max_lpc_order;
201 unsigned qlp_coeff_precision;
203 int format_is_big_endian;
204 int format_is_unsigned_samples;
207 int format_sample_rate;
209 int min_residual_partition_order;
210 int max_residual_partition_order;
211 int rice_parameter_search_dist;
212 char requested_seek_points[50000]; /* @@@ bad MAGIC NUMBER */
213 int num_requested_seek_points; /* -1 => no -S options were given, 0 => -S- was given */
221 * miscellaneous globals
224 static FLAC__int32 align_reservoir_0[588], align_reservoir_1[588]; /* for carrying over samples from --sector-align */
225 static FLAC__int32 *align_reservoir[2] = { align_reservoir_0, align_reservoir_1 };
226 static unsigned align_reservoir_samples = 0; /* 0 .. 587 */
228 static const char *flac_suffix = ".flac", *ogg_suffix = ".ogg";
231 int main(int argc, char *argv[])
237 if((retval = parse_options(argc, argv)) == 0)
249 if(option_values.show_explain) {
253 else if(option_values.show_help) {
258 if(option_values.num_files == 0) {
264 * tweak options; validate the values
266 if(!option_values.mode_decode) {
267 if(option_values.blocksize < 0) {
268 if(option_values.max_lpc_order == 0)
269 option_values.blocksize = 1152;
271 option_values.blocksize = 4608;
273 if(option_values.max_residual_partition_order < 0) {
274 if(option_values.blocksize <= 1152)
275 option_values.max_residual_partition_order = 2;
276 else if(option_values.blocksize <= 2304)
277 option_values.max_residual_partition_order = 3;
278 else if(option_values.blocksize <= 4608)
279 option_values.max_residual_partition_order = 3;
281 option_values.max_residual_partition_order = 4;
282 option_values.min_residual_partition_order = option_values.max_residual_partition_order;
284 if(option_values.rice_parameter_search_dist < 0) {
285 option_values.rice_parameter_search_dist = 0;
289 if(option_values.test_only) {
290 if(option_values.skip > 0)
291 return usage_error("ERROR: --skip is not allowed in test mode\n");
295 FLAC__ASSERT(option_values.blocksize >= 0 || option_values.mode_decode);
297 if(option_values.format_channels >= 0) {
298 if(option_values.format_channels == 0 || (unsigned)option_values.format_channels > FLAC__MAX_CHANNELS)
299 return usage_error("ERROR: invalid number of channels '%u', must be > 0 and <= %u\n", option_values.format_channels, FLAC__MAX_CHANNELS);
301 if(option_values.format_bps >= 0) {
302 if(option_values.format_bps != 8 && option_values.format_bps != 16 && option_values.format_bps != 24)
303 return usage_error("ERROR: invalid bits per sample '%u' (must be 8/16/24)\n", option_values.format_bps);
305 if(option_values.format_sample_rate >= 0) {
306 if(!FLAC__format_sample_rate_is_valid(option_values.format_sample_rate))
307 return usage_error("ERROR: invalid sample rate '%u', must be > 0 and <= %u\n", option_values.format_sample_rate, FLAC__MAX_SAMPLE_RATE);
309 if(!option_values.mode_decode && ((unsigned)option_values.blocksize < FLAC__MIN_BLOCK_SIZE || (unsigned)option_values.blocksize > FLAC__MAX_BLOCK_SIZE)) {
310 return usage_error("ERROR: invalid blocksize '%u', must be >= %u and <= %u\n", (unsigned)option_values.blocksize, FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE);
312 if(option_values.qlp_coeff_precision > 0 && option_values.qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION) {
313 return usage_error("ERROR: invalid value '%u' for qlp coeff precision, must be 0 or >= %u\n", option_values.qlp_coeff_precision, FLAC__MIN_QLP_COEFF_PRECISION);
316 if(option_values.sector_align) {
317 if(option_values.mode_decode)
318 return usage_error("ERROR: --sector-align only allowed for encoding\n");
319 else if(option_values.skip > 0)
320 return usage_error("ERROR: --sector-align not allowed with --skip\n");
321 else if(option_values.format_channels >= 0 && option_values.format_channels != 2)
322 return usage_error("ERROR: --sector-align can only be done with stereo input\n");
323 else if(option_values.format_bps >= 0 && option_values.format_bps != 16)
324 return usage_error("ERROR: --sector-align can only be done with 16-bit samples\n");
325 else if(option_values.format_sample_rate >= 0 && option_values.format_sample_rate != 44100)
326 return usage_error("ERROR: --sector-align can only be done with a sample rate of 44100\n");
328 if(option_values.num_files > 1 && option_values.cmdline_forced_outfilename) {
329 return usage_error("ERROR: -o/--output-name cannot be used with multiple files\n");
331 if(option_values.cmdline_forced_outfilename && option_values.output_prefix) {
332 return usage_error("ERROR: --output-prefix conflicts with -o/--output-name\n");
335 if(option_values.verbose) {
336 fprintf(stderr, "\n");
337 fprintf(stderr, "flac %s, Copyright (C) 2000,2001,2002 Josh Coalson\n", FLAC__VERSION_STRING);
338 fprintf(stderr, "flac comes with ABSOLUTELY NO WARRANTY. This is free software, and you are\n");
339 fprintf(stderr, "welcome to redistribute it under certain conditions. Type `flac' for details.\n\n");
341 if(!option_values.mode_decode) {
343 if(option_values.padding < 0)
346 sprintf(padopt, " %d", option_values.padding);
352 "%s -P%s -b %u%s -l %u%s%s%s -q %u -r %u,%u%s\n",
353 option_values.delete_input?" --delete-input-file":"",
354 option_values.sector_align?" --sector-align":"",
356 option_values.use_ogg?" --ogg":"",
358 option_values.lax?" --lax":"",
360 (unsigned)option_values.blocksize,
361 option_values.loose_mid_side?" -M":option_values.do_mid_side?" -m":"",
362 option_values.max_lpc_order,
363 option_values.do_exhaustive_model_search?" -e":"",
364 option_values.do_escape_coding?" -E":"",
365 option_values.do_qlp_coeff_prec_search?" -p":"",
366 option_values.qlp_coeff_precision,
367 (unsigned)option_values.min_residual_partition_order,
368 (unsigned)option_values.max_residual_partition_order,
369 option_values.verify? " -V":""
374 if(option_values.mode_decode) {
375 FLAC__bool first = true;
377 if(option_values.num_files == 0) {
378 retval = decode_file("-", 0);
382 if(option_values.num_files > 1)
383 option_values.cmdline_forced_outfilename = 0;
384 for(i = 0, retval = 0; i < option_values.num_files && retval == 0; i++) {
385 if(0 == strcmp(option_values.filenames[i], "-") && !first)
387 retval = decode_file(option_values.filenames[i], 0);
393 FLAC__bool first = true;
395 if(option_values.num_files == 0) {
396 retval = encode_file("-", 0, true);
400 if(option_values.num_files > 1)
401 option_values.cmdline_forced_outfilename = 0;
402 for(i = 0, retval = 0; i < option_values.num_files && retval == 0; i++) {
403 if(0 == strcmp(option_values.filenames[i], "-") && !first)
405 retval = encode_file(option_values.filenames[i], 0, i == (option_values.num_files-1));
416 option_values.show_help = false;
417 option_values.show_explain = false;
418 option_values.mode_decode = false;
419 option_values.verify = false;
420 option_values.verbose = true;
421 option_values.continue_through_decode_errors = false;
422 option_values.lax = false;
423 option_values.test_only = false;
424 option_values.analyze = false;
425 option_values.use_ogg = false;
426 option_values.do_mid_side = true;
427 option_values.loose_mid_side = false;
428 option_values.do_exhaustive_model_search = false;
429 option_values.do_escape_coding = false;
430 option_values.do_qlp_coeff_prec_search = false;
431 option_values.force_to_stdout = false;
432 option_values.force_raw_format = false;
433 option_values.delete_input = false;
434 option_values.sector_align = false;
435 option_values.cmdline_forced_outfilename = 0;
436 option_values.output_prefix = 0;
437 option_values.aopts.do_residual_text = false;
438 option_values.aopts.do_residual_gnuplot = false;
439 option_values.padding = -1;
440 option_values.max_lpc_order = 8;
441 option_values.qlp_coeff_precision = 0;
442 option_values.skip = 0;
443 option_values.format_is_big_endian = -1;
444 option_values.format_is_unsigned_samples = false;
445 option_values.format_channels = -1;
446 option_values.format_bps = -1;
447 option_values.format_sample_rate = -1;
448 option_values.blocksize = -1;
449 option_values.min_residual_partition_order = -1;
450 option_values.max_residual_partition_order = -1;
451 option_values.rice_parameter_search_dist = -1;
452 option_values.requested_seek_points[0] = '\0';
453 option_values.num_requested_seek_points = -1;
455 option_values.num_files = 0;
456 option_values.filenames = 0;
459 int parse_options(int argc, char *argv[])
462 int option_index = 1;
463 FLAC__bool had_error = false;
464 /*@@@ E and R: are deprecated */
465 const char *short_opts = "0123456789ab:cdeFhHl:mMo:pP:q:r:sS:tV";
467 while ((short_option = FLAC__share__getopt_long(argc, argv, short_opts, long_options_, &option_index)) != -1) {
468 switch (short_option) {
469 case 0: /* long option with no equivalent short option */
470 had_error |= (parse_option(short_option, long_options_[option_index].name, FLAC__share__optarg) != 0);
476 default: /* short option */
477 had_error |= (parse_option(short_option, 0, FLAC__share__optarg) != 0);
486 FLAC__ASSERT(FLAC__share__optind <= argc);
488 option_values.num_files = argc - FLAC__share__optind;
490 if(option_values.num_files > 0) {
492 if(0 == (option_values.filenames = malloc(sizeof(char *) * option_values.num_files)))
493 die("out of memory allocating space for file names list");
494 while(FLAC__share__optind < argc)
495 option_values.filenames[i++] = local_strdup(argv[FLAC__share__optind++]);
501 int parse_option(int short_option, const char *long_option, const char *option_argument)
505 if(short_option == 0) {
506 FLAC__ASSERT(0 != long_option);
507 if(0 == strcmp(long_option, "delete-input-file")) {
508 option_values.delete_input = true;
510 else if(0 == strcmp(long_option, "output-prefix")) {
511 FLAC__ASSERT(0 != option_argument);
512 option_values.output_prefix = option_argument;
514 else if(0 == strcmp(long_option, "skip")) {
515 FLAC__ASSERT(0 != option_argument);
516 option_values.skip = (FLAC__uint64)atoi(option_argument); /* @@@ takes a pretty damn big file to overflow atoi() here, but it could happen */
518 else if(0 == strcmp(long_option, "super-secret-impractical-compression-level")) {
519 option_values.do_exhaustive_model_search = true;
520 option_values.do_escape_coding = true;
521 option_values.do_mid_side = true;
522 option_values.loose_mid_side = false;
523 option_values.do_qlp_coeff_prec_search = true;
524 option_values.min_residual_partition_order = 0;
525 option_values.max_residual_partition_order = 16;
526 option_values.rice_parameter_search_dist = 0;
527 option_values.max_lpc_order = 32;
529 else if(0 == strcmp(long_option, "force-raw-input")) {
530 option_values.force_raw_format = true;
532 else if(0 == strcmp(long_option, "lax")) {
533 option_values.lax = true;
535 else if(0 == strcmp(long_option, "sector-align")) {
536 option_values.sector_align = true;
539 else if(0 == strcmp(long_option, "ogg")) {
540 option_values.use_ogg = true;
543 else if(0 == strcmp(long_option, "endian")) {
544 FLAC__ASSERT(0 != option_argument);
545 if(0 == strncmp(option_argument, "big", strlen(option_argument)))
546 option_values.format_is_big_endian = true;
547 else if(0 == strncmp(option_argument, "little", strlen(option_argument)))
548 option_values.format_is_big_endian = false;
550 return usage_error("ERROR: argument to --endian must be \"big\" or \"little\"\n");
552 else if(0 == strcmp(long_option, "channels")) {
553 FLAC__ASSERT(0 != option_argument);
554 option_values.format_channels = atoi(option_argument);
556 else if(0 == strcmp(long_option, "bps")) {
557 FLAC__ASSERT(0 != option_argument);
558 option_values.format_bps = atoi(option_argument);
560 else if(0 == strcmp(long_option, "sample-rate")) {
561 FLAC__ASSERT(0 != option_argument);
562 option_values.format_sample_rate = atoi(option_argument);
564 else if(0 == strcmp(long_option, "sign")) {
565 FLAC__ASSERT(0 != option_argument);
566 if(0 == strncmp(option_argument, "signed", strlen(option_argument)))
567 option_values.format_is_unsigned_samples = false;
568 else if(0 == strncmp(option_argument, "unsigned", strlen(option_argument)))
569 option_values.format_is_unsigned_samples = true;
571 return usage_error("ERROR: argument to --sign must be \"signed\" or \"unsigned\"\n");
573 else if(0 == strcmp(long_option, "residual-gnu-plot")) {
574 option_values.aopts.do_residual_gnuplot = true;
576 else if(0 == strcmp(long_option, "residual-text")) {
577 option_values.aopts.do_residual_text = true;
582 else if(0 == strcmp(long_option, "no-decode-through-errors")) {
583 option_values.continue_through_decode_errors = false;
585 else if(0 == strcmp(long_option, "no-silent")) {
586 option_values.verbose = true;
588 else if(0 == strcmp(long_option, "no-seektable")) {
589 option_values.num_requested_seek_points = 0;
590 option_values.requested_seek_points[0] = '\0';
592 else if(0 == strcmp(long_option, "no-delete-input-file")) {
593 option_values.delete_input = false;
595 else if(0 == strcmp(long_option, "no-sector-align")) {
596 option_values.sector_align = false;
598 else if(0 == strcmp(long_option, "no-lax")) {
599 option_values.lax = false;
602 else if(0 == strcmp(long_option, "no-ogg")) {
603 option_values.use_ogg = false;
606 else if(0 == strcmp(long_option, "no-exhaustive-model-search")) {
607 option_values.do_exhaustive_model_search = false;
610 /* @@@ deprecated: */
611 else if(0 == strcmp(long_option, "no-escape-coding")) {
612 option_values.do_escape_coding = false;
615 else if(0 == strcmp(long_option, "no-mid-side")) {
616 option_values.do_mid_side = option_values.loose_mid_side = false;
618 else if(0 == strcmp(long_option, "no-adaptive-mid-side")) {
619 option_values.loose_mid_side = option_values.do_mid_side = false;
621 else if(0 == strcmp(long_option, "no-qlp-coeff-prec-search")) {
622 option_values.do_qlp_coeff_prec_search = false;
624 else if(0 == strcmp(long_option, "no-padding")) {
625 option_values.padding = -1;
627 else if(0 == strcmp(long_option, "no-verify")) {
628 option_values.verify = false;
630 else if(0 == strcmp(long_option, "no-residual-gnuplot")) {
631 option_values.aopts.do_residual_gnuplot = false;
633 else if(0 == strcmp(long_option, "no-residual-text")) {
634 option_values.aopts.do_residual_text = false;
638 switch(short_option) {
640 option_values.show_help = true;
643 option_values.show_explain = true;
646 option_values.mode_decode = true;
649 option_values.mode_decode = true;
650 option_values.analyze = true;
653 option_values.mode_decode = true;
654 option_values.test_only = true;
657 option_values.force_to_stdout = true;
660 option_values.verbose = false;
663 FLAC__ASSERT(0 != option_argument);
664 option_values.cmdline_forced_outfilename = option_argument;
667 option_values.continue_through_decode_errors = true;
670 option_values.do_exhaustive_model_search = false;
671 option_values.do_escape_coding = false;
672 option_values.do_mid_side = false;
673 option_values.loose_mid_side = false;
674 option_values.qlp_coeff_precision = 0;
675 option_values.min_residual_partition_order = option_values.max_residual_partition_order = 2;
676 option_values.rice_parameter_search_dist = 0;
677 option_values.max_lpc_order = 0;
680 option_values.do_exhaustive_model_search = false;
681 option_values.do_escape_coding = false;
682 option_values.do_mid_side = true;
683 option_values.loose_mid_side = true;
684 option_values.qlp_coeff_precision = 0;
685 option_values.min_residual_partition_order = option_values.max_residual_partition_order = 2;
686 option_values.rice_parameter_search_dist = 0;
687 option_values.max_lpc_order = 0;
690 option_values.do_exhaustive_model_search = false;
691 option_values.do_escape_coding = false;
692 option_values.do_mid_side = true;
693 option_values.loose_mid_side = false;
694 option_values.qlp_coeff_precision = 0;
695 option_values.min_residual_partition_order = 0;
696 option_values.max_residual_partition_order = 3;
697 option_values.rice_parameter_search_dist = 0;
698 option_values.max_lpc_order = 0;
701 option_values.do_exhaustive_model_search = false;
702 option_values.do_escape_coding = false;
703 option_values.do_mid_side = false;
704 option_values.loose_mid_side = false;
705 option_values.qlp_coeff_precision = 0;
706 option_values.min_residual_partition_order = option_values.max_residual_partition_order = 3;
707 option_values.rice_parameter_search_dist = 0;
708 option_values.max_lpc_order = 6;
711 option_values.do_exhaustive_model_search = false;
712 option_values.do_escape_coding = false;
713 option_values.do_mid_side = true;
714 option_values.loose_mid_side = true;
715 option_values.qlp_coeff_precision = 0;
716 option_values.min_residual_partition_order = option_values.max_residual_partition_order = 3;
717 option_values.rice_parameter_search_dist = 0;
718 option_values.max_lpc_order = 8;
721 option_values.do_exhaustive_model_search = false;
722 option_values.do_escape_coding = false;
723 option_values.do_mid_side = true;
724 option_values.loose_mid_side = false;
725 option_values.qlp_coeff_precision = 0;
726 option_values.min_residual_partition_order = option_values.max_residual_partition_order = 3;
727 option_values.rice_parameter_search_dist = 0;
728 option_values.max_lpc_order = 8;
731 option_values.do_exhaustive_model_search = false;
732 option_values.do_escape_coding = false;
733 option_values.do_mid_side = true;
734 option_values.loose_mid_side = false;
735 option_values.qlp_coeff_precision = 0;
736 option_values.min_residual_partition_order = 0;
737 option_values.max_residual_partition_order = 4;
738 option_values.rice_parameter_search_dist = 0;
739 option_values.max_lpc_order = 8;
742 option_values.do_exhaustive_model_search = true;
743 option_values.do_escape_coding = false;
744 option_values.do_mid_side = true;
745 option_values.loose_mid_side = false;
746 option_values.qlp_coeff_precision = 0;
747 option_values.min_residual_partition_order = 0;
748 option_values.max_residual_partition_order = 6;
749 option_values.rice_parameter_search_dist = 0;
750 option_values.max_lpc_order = 8;
753 option_values.do_exhaustive_model_search = true;
754 option_values.do_escape_coding = false;
755 option_values.do_mid_side = true;
756 option_values.loose_mid_side = false;
757 option_values.qlp_coeff_precision = 0;
758 option_values.min_residual_partition_order = 0;
759 option_values.max_residual_partition_order = 6;
760 option_values.rice_parameter_search_dist = 0;
761 option_values.max_lpc_order = 12;
764 return usage_error("ERROR: compression level '9' is reserved\n");
766 option_values.verify = true;
769 FLAC__ASSERT(0 != option_argument);
770 if(option_values.num_requested_seek_points < 0)
771 option_values.num_requested_seek_points = 0;
772 option_values.num_requested_seek_points++;
773 strcat(option_values.requested_seek_points, option_argument);
774 strcat(option_values.requested_seek_points, "<");
777 FLAC__ASSERT(0 != option_argument);
778 option_values.padding = atoi(option_argument);
779 if(option_values.padding < 0)
780 return usage_error("ERROR: argument to -P must be >= 0\n");
783 FLAC__ASSERT(0 != option_argument);
784 option_values.blocksize = atoi(option_argument);
787 option_values.do_exhaustive_model_search = true;
790 option_values.do_escape_coding = true;
793 FLAC__ASSERT(0 != option_argument);
794 option_values.max_lpc_order = atoi(option_argument);
797 option_values.do_mid_side = true;
798 option_values.loose_mid_side = false;
801 option_values.loose_mid_side = option_values.do_mid_side = true;
804 option_values.do_qlp_coeff_prec_search = true;
807 FLAC__ASSERT(0 != option_argument);
808 option_values.qlp_coeff_precision = atoi(option_argument);
811 FLAC__ASSERT(0 != option_argument);
812 p = strchr(option_argument, ',');
814 option_values.min_residual_partition_order = 0;
815 option_values.max_residual_partition_order = atoi(option_argument);
818 option_values.min_residual_partition_order = atoi(option_argument);
819 option_values.max_residual_partition_order = atoi(++p);
823 FLAC__ASSERT(0 != option_argument);
824 option_values.rice_parameter_search_dist = atoi(option_argument);
836 if(0 != option_values.filenames)
837 free(option_values.filenames);
840 int usage_error(const char *message, ...)
844 FLAC__ASSERT(0 != message);
846 va_start(args, message);
848 (void) vfprintf(stderr, message, args);
852 printf("Type \"flac\" for a usage summary or \"flac --help\" for all options\n");
857 static void usage_header()
859 printf("===============================================================================\n");
860 printf("flac - Command-line FLAC encoder/decoder version %s\n", FLAC__VERSION_STRING);
861 printf("Copyright (C) 2000,2001,2002 Josh Coalson\n");
863 printf("This program is free software; you can redistribute it and/or\n");
864 printf("modify it under the terms of the GNU General Public License\n");
865 printf("as published by the Free Software Foundation; either version 2\n");
866 printf("of the License, or (at your option) any later version.\n");
868 printf("This program is distributed in the hope that it will be useful,\n");
869 printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
870 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
871 printf("GNU General Public License for more details.\n");
873 printf("You should have received a copy of the GNU General Public License\n");
874 printf("along with this program; if not, write to the Free Software\n");
875 printf("Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n");
876 printf("===============================================================================\n");
879 static void usage_summary()
883 printf(" Encoding: flac [-s] [--skip #] [<encoding/format-options>] [INPUTFILE [...]]\n");
884 printf(" Decoding: flac -d [-s] [--skip #] [-F] [<format-options>] [INPUTFILE [...]]\n");
885 printf(" Testing: flac -t [-s] [INPUTFILE [...]]\n");
886 printf("Analyzing: flac -a [-s] [--skip #] [<analysis-options>] [INPUTFILE [...]]\n");
894 printf("This is the short help; for all options use 'flac --help'; for even more\n");
895 printf("instructions use 'flac --explain'\n");
897 printf("To encode:\n");
898 printf(" flac [-#] [INPUTFILE [...]]\n");
900 printf(" -# is -0 (fastest compression) to -8 (highest compression); -5 is the default\n");
902 printf("To decode:\n");
903 printf(" flac -d [INPUTFILE [...]]\n");
905 printf("To test:\n");
906 printf(" flac -t [INPUTFILE [...]]\n");
913 printf("generic options:\n");
914 printf(" -h, --help show this screen\n");
915 printf(" -H, --explain show detailed explanation of usage and options\n");
916 printf(" -d, --decode decode (the default behavior is to encode)\n");
917 printf(" -t, --test same as -d except no decoded file is written\n");
918 printf(" -a, --analyze same as -d except an analysis file is written\n");
919 printf(" -c, --stdout write output to stdout\n");
920 printf(" -s, --silent do not write runtime encode/decode statistics\n");
921 printf(" -o, --output-name=FILENAME force the output file name\n");
922 printf(" --output-prefix=STRING prepend STRING to output names\n");
923 printf(" --delete-input-file deletes after a successful encode/decode\n");
924 printf(" --skip=# skip the first # samples of each input file\n");
925 printf("analysis options:\n");
926 printf(" --residual-text include residual signal in text output\n");
927 printf(" --residual-gnuplot generate gnuplot files of residual distribution\n");
928 printf("decoding options:\n");
929 printf(" -F, --decode-through-errors continue decoding through stream errors\n");
930 printf("encoding options:\n");
932 printf(" --ogg output Ogg FLAC stream instead of native FLAC\n");
934 printf(" --lax allow encoder to generate non-Subset files\n");
935 printf(" --sector-align align multiple files on sector boundaries\n");
936 printf(" -V, --verify verify a correct encoding\n");
937 printf(" -S, --seekpoint={#|X|#x} add seek point(s)\n");
938 printf(" -P, --padding=# write a PADDING block of length #\n");
939 printf(" -b, --blocksize=# specify blocksize in samples\n");
940 printf(" -m, --mid-side try mid-side coding for each frame\n");
941 printf(" -M, --adaptive-mid-side adaptive mid-side coding for all frames\n");
942 printf(" -0, --compression-level-0, --fast synonymous with -l 0 -b 1152 -r 2,2\n");
943 printf(" -1, --compression-level-1 synonymous with -l 0 -b 1152 -M -r 2,2\n");
944 printf(" -2, --compression-level-2 synonymous with -l 0 -b 1152 -m -r 3\n");
945 printf(" -3, --compression-level-3 synonymous with -l 6 -b 4608 -r 3,3\n");
946 printf(" -4, --compression-level-4 synonymous with -l 8 -b 4608 -M -r 3,3\n");
947 printf(" -5, --compression-level-5 synonymous with -l 8 -b 4608 -m -r 3,3\n");
948 printf(" -6, --compression-level-6 synonymous with -l 8 -b 4608 -m -r 4\n");
949 printf(" -7, --compression-level-7 synonymous with -l 8 -b 4608 -m -e -r 6\n");
950 printf(" -8, --compression-level-8, --best synonymous with -l 12 -b 4608 -m -e -r 6\n");
951 printf(" -e, --exhaustive-model-search do exhaustive model search (expensive!)\n");
954 printf(" -E, --escape-coding do escape coding in the entropy coder\n");
956 printf(" -l, --max-lpc-order=# max LPC order; 0 => only fixed predictors\n");
957 printf(" -p, --qlp-coeff-precision-search exhaustively search LP coeff quantization\n");
958 printf(" -q, --qlp-coeff-precision=# specify precision in bits\n");
959 printf(" -r, --rice-partition-order=[#,]# [min,]max residual partition order\n");
962 printf(" -R, -rice-parameter-search-distance=# Rice parameter search distance\n");
964 printf("format options:\n");
965 printf(" --endian={big|little} set byte order for samples\n");
966 printf(" --channels=# number of channels\n");
967 printf(" --bps=# number of bits per sample\n");
968 printf(" --sample-rate=# sample rate in Hz\n");
969 printf(" --sign={signed|unsigned} sign of samples\n");
970 printf(" --force-raw-input force input to be treated as raw samples\n");
977 printf("For encoding:\n");
978 printf(" The input file(s) may be a PCM RIFF WAVE file, AIFF file, or raw samples.\n");
979 printf(" The output file(s) will be in native FLAC or Ogg FLAC format\n");
980 printf("For decoding, the reverse is true.\n");
982 printf("A single INPUTFILE may be - for stdin. No INPUTFILE implies stdin. Use of\n");
983 printf("stdin implies -c (write to stdout). Normally you should use:\n");
984 printf(" flac [options] -o outfilename or flac -d [options] -o outfilename\n");
985 printf("instead of:\n");
986 printf(" flac [options] > outfilename or flac -d [options] > outfilename\n");
987 printf("since the former allows flac to seek backwards to write the STREAMINFO or\n");
988 printf("WAVE/AIFF header contents when necessary.\n");
990 printf("flac checks for the presence of a AIFF/WAVE header to decide whether or not to\n");
991 printf("treat an input file as AIFF/WAVE format or raw samples. If any input file is\n");
992 printf("raw you must specify the format options {-fb|fl} -fc -fp and -fs, which will\n");
993 printf("apply to all raw files. You can force AIFF/WAVE files to be treated as raw\n");
994 printf("files using -fr.\n");
996 printf("generic options:\n");
997 printf(" -h, --help show this screen\n");
998 printf(" -H, --explain show detailed explanation of usage and options\n");
999 printf(" -d, --decode decode (the default behavior is to encode)\n");
1000 printf(" -t, --test same as -d except no decoded file is written\n");
1001 printf(" -a, --analyze same as -d except an analysis file is written\n");
1002 printf(" -c, --stdout write output to stdout\n");
1003 printf(" -s, --silent do not write runtime encode/decode statistics\n");
1004 printf(" -o, --output-name=FILENAME force the output file name; usually flac just\n");
1005 printf(" changes the extension\n");
1006 printf(" --output-prefix=STRING prefix each output file name with the given\n");
1007 printf(" STRING. This can be useful for encoding or\n");
1008 printf(" decoding files to a different directory. Make\n");
1009 printf(" sure if your STRING is a path name that it ends\n");
1010 printf(" with a '/' slash.\n");
1011 printf(" --delete-input-file deletes after a successful encode/decode\n");
1012 printf(" --skip=# skip the first # samples of each input file; can\n");
1013 printf(" be used both for encoding and decoding\n");
1014 printf("analysis options:\n");
1015 printf(" --residual-text include residual signal in text output\n");
1016 printf(" --residual-gnuplot generate gnuplot files of residual distribution\n");
1017 printf(" of each subframe\n");
1018 printf("decoding options:\n");
1019 printf(" -F, --decode-through-errors force the decoder to continue decoding through\n");
1020 printf(" stream errors; errors will still be printed, but\n");
1021 printf(" decoding won't stop. Errors will manifest them-\n");
1022 printf(" selves as skips or silent sections in the audio.\n");
1023 printf("encoding options:\n");
1024 #ifdef FLAC__HAS_OGG
1025 printf(" --ogg output Ogg FLAC stream instead of native FLAC\n");
1027 printf(" --lax allow encoder to generate non-Subset files\n");
1028 printf(" --sector-align align the encoding of multiple files on sector\n");
1029 printf(" boundaries\n");
1030 printf(" -V, --verify verify a correct encoding by decoding the output\n");
1031 printf(" in parallel and comparing it to the original\n");
1032 printf(" -S, --seekpoint={#|X|#x} include a point or points in a SEEKTABLE\n");
1033 printf(" # : a specific sample number for a seek point\n");
1034 printf(" X : a placeholder point (always goes at the end of the SEEKTABLE)\n");
1035 printf(" #x : # evenly spaced seekpoints, the first being at sample 0\n");
1036 printf(" You may use many -S options; the resulting SEEKTABLE will be the unique-\n");
1037 printf(" ified union of all such values.\n");
1038 printf(" With no -S options, flac defaults to '-S 100x'. Use -S- for no SEEKTABLE.\n");
1039 printf(" Note: -S #x will not work if the encoder can't determine the input size\n");
1040 printf(" before starting.\n");
1041 printf(" Note: if you use -S # and # is >= samples in the input, there will be\n");
1042 printf(" either no seek point entered (if the input size is determinable\n");
1043 printf(" before encoding starts) or a placeholder point (if input size is not\n");
1044 printf(" determinable)\n");
1045 printf(" -P, --padding=# write a PADDING block of length #; the PADDING\n");
1046 printf(" block goes after any SEEKTABLE block. # must be\n");
1047 printf(" >= 0; the default is no PADDING). Note that the\n");
1048 printf(" overall size in bytes of the PADDING block will\n");
1049 printf(" be # + 4 because of the metadata header.\n");
1050 printf(" -b, --blocksize=# specify the blocksize in samples; the default is\n");
1051 printf(" 1152 for -l 0, else 4608; must be one of 192,\n");
1052 printf(" 576, 1152, 2304, 4608, 256, 512, 1024, 2048,\n");
1053 printf(" 4096, 8192, 16384, or 32768 (unless --lax is\n");
1055 printf(" -m, --mid-side try mid-side coding for each frame (stereo only)\n");
1056 printf(" -M, --adaptive-mid-side adaptive mid-side coding for all frames (stereo\n");
1058 printf(" -0, --compression-level-0, --fast synonymous with -l 0 -b 1152 -r 2,2\n");
1059 printf(" -1, --compression-level-1 synonymous with -l 0 -b 1152 -M -r 2,2\n");
1060 printf(" -2, --compression-level-2 synonymous with -l 0 -b 1152 -m -r 3\n");
1061 printf(" -3, --compression-level-3 synonymous with -l 6 -b 4608 -r 3,3\n");
1062 printf(" -4, --compression-level-4 synonymous with -l 8 -b 4608 -M -r 3,3\n");
1063 printf(" -5, --compression-level-5 synonymous with -l 8 -b 4608 -m -r 3,3\n");
1064 printf(" -5 is the default setting\n");
1065 printf(" -6, --compression-level-6 synonymous with -l 8 -b 4608 -m -r 4\n");
1066 printf(" -7, --compression-level-7 synonymous with -l 8 -b 4608 -m -e -r 6\n");
1067 printf(" -8, --compression-level-8, --best synonymous with -l 12 -b 4608 -m -e -r 6\n");
1068 printf(" -e, --exhaustive-model-search do exhaustive model search (expensive!)\n");
1070 /*@@@ deprecated: */
1071 printf(" -E, --escape-coding do escape coding in the entropy coder\n");
1073 printf(" -l, --max-lpc-order=# max LPC order; 0 => only fixed predictors\n");
1074 printf(" -p, --qlp-coeff-precision-search do exhaustive search of LP coefficient\n");
1075 printf(" quantization (expensive!); overrides -q,\n");
1076 printf(" does nothing if using -l 0\n");
1077 /*@@@@@@ ................................................................................*/
1078 printf(" -q, --qlp-coeff-precision=# specify precision in bits of quantized\n");
1079 printf(" linear-predictor coefficients; 0 => let\n");
1080 printf(" encoder decide (the minimun is %u, the\n", FLAC__MIN_QLP_COEFF_PRECISION);
1081 printf(" default is -q 0)\n");
1082 printf(" -r, --rice-partition-order=[#,]# set [min,]max residual partition order\n");
1083 printf(" (# is 0..16; min defaults to 0; the\n");
1084 printf(" default is -r 0; above 4 doesn't usually\n");
1085 printf(" help much)\n");
1087 /*@@@ deprecated: */
1088 printf(" -R, -rice-parameter-search-distance=# Rice parameter search distance\n");
1090 printf("format options:\n");
1091 printf(" --endian={big|little} set byte order for samples\n");
1092 printf(" --channels=# number of channels\n");
1093 printf(" --bps=# number of bits per sample\n");
1094 printf(" --sample-rate=# sample rate in Hz\n");
1095 printf(" --sign={signed|unsigned} sign of samples\n");
1096 printf(" --force-raw-input force input to be treated as raw samples\n");
1100 format_mistake(const char *infilename, const char *wrong, const char *right)
1102 fprintf(stderr, "WARNING: %s is not a %s file; treating as a %s file\n", infilename, wrong, right);
1105 int encode_file(const char *infilename, const char *forced_outfilename, FLAC__bool is_last_file)
1107 FILE *encode_infile;
1108 char outfilename[4096]; /* @@@ bad MAGIC NUMBER */
1110 FLAC__byte lookahead[12];
1111 unsigned lookahead_length = 0;
1112 FileFormat fmt= RAW;
1115 encode_options_t common_options;
1117 if(0 == strcmp(infilename, "-")) {
1119 encode_infile = file__get_binary_stdin();
1122 infilesize = flac__file_get_filesize(infilename);
1123 if(0 == (encode_infile = fopen(infilename, "rb"))) {
1124 fprintf(stderr, "ERROR: can't open input file %s\n", infilename);
1129 if(!option_values.force_raw_format) {
1130 /* first set format based on name */
1131 if(strlen(infilename) > 3 && 0 == strcasecmp(infilename+(strlen(infilename)-4), ".wav"))
1133 else if(strlen(infilename) > 3 && 0 == strcasecmp(infilename+(strlen(infilename)-4), ".aif"))
1135 else if(strlen(infilename) > 4 && 0 == strcasecmp(infilename+(strlen(infilename)-5), ".aiff"))
1138 /* attempt to guess the file type based on the first 12 bytes */
1139 if((lookahead_length = fread(lookahead, 1, 12, encode_infile)) < 12) {
1141 format_mistake(infilename, fmt == AIF ? "AIFF" : "WAVE", "raw");
1145 if(!strncmp(lookahead, "RIFF", 4) && !strncmp(lookahead+8, "WAVE", 4))
1147 else if(!strncmp(lookahead, "FORM", 4) && !strncmp(lookahead+8, "AIFF", 4))
1151 format_mistake(infilename, fmt == AIF ? "AIFF" : "WAVE", "raw");
1157 if(option_values.sector_align && fmt == RAW && infilesize < 0) {
1158 fprintf(stderr, "ERROR: can't --sector-align when the input size is unknown\n");
1163 if(option_values.format_is_big_endian < 0 || option_values.format_channels < 0 || option_values.format_bps < 0 || option_values.format_sample_rate < 0)
1164 return usage_error("ERROR: for encoding a raw file you must specify a value for --endian, --channels, --bps, and --sample-rate\n");
1167 if(encode_infile == stdin || option_values.force_to_stdout)
1168 strcpy(outfilename, "-");
1170 const char *suffix = (option_values.use_ogg? ogg_suffix : flac_suffix);
1171 strcpy(outfilename, option_values.output_prefix? option_values.output_prefix : "");
1172 strcat(outfilename, infilename);
1173 if(0 == (p = strrchr(outfilename, '.')))
1174 strcat(outfilename, suffix);
1176 if(0 == strcmp(p, suffix)) {
1184 if(0 == forced_outfilename)
1185 forced_outfilename = outfilename;
1186 if(0 != option_values.cmdline_forced_outfilename)
1187 forced_outfilename = option_values.cmdline_forced_outfilename;
1189 common_options.verbose = option_values.verbose;
1190 common_options.skip = option_values.skip;
1191 common_options.verify = option_values.verify;
1192 #ifdef FLAC__HAS_OGG
1193 common_options.use_ogg = option_values.use_ogg;
1195 common_options.lax = option_values.lax;
1196 common_options.do_mid_side = option_values.do_mid_side;
1197 common_options.loose_mid_side = option_values.loose_mid_side;
1198 common_options.do_exhaustive_model_search = option_values.do_exhaustive_model_search;
1199 common_options.do_escape_coding = option_values.do_escape_coding;
1200 common_options.do_qlp_coeff_prec_search = option_values.do_qlp_coeff_prec_search;
1201 common_options.min_residual_partition_order = option_values.min_residual_partition_order;
1202 common_options.max_residual_partition_order = option_values.max_residual_partition_order;
1203 common_options.rice_parameter_search_dist = option_values.rice_parameter_search_dist;
1204 common_options.max_lpc_order = option_values.max_lpc_order;
1205 common_options.blocksize = (unsigned)option_values.blocksize;
1206 common_options.qlp_coeff_precision = option_values.qlp_coeff_precision;
1207 common_options.padding = option_values.padding;
1208 common_options.requested_seek_points = option_values.requested_seek_points;
1209 common_options.num_requested_seek_points = option_values.num_requested_seek_points;
1210 common_options.is_last_file = is_last_file;
1211 common_options.align_reservoir = align_reservoir;
1212 common_options.align_reservoir_samples = &align_reservoir_samples;
1213 common_options.sector_align = option_values.sector_align;
1216 raw_encode_options_t options;
1218 options.common = common_options;
1219 options.is_big_endian = option_values.format_is_big_endian;
1220 options.is_unsigned_samples = option_values.format_is_unsigned_samples;
1221 options.channels = option_values.format_channels;
1222 options.bps = option_values.format_bps;
1223 options.sample_rate = option_values.format_sample_rate;
1225 retval = flac__encode_raw(encode_infile, infilesize, infilename, forced_outfilename, lookahead, lookahead_length, options);
1228 wav_encode_options_t options;
1230 options.common = common_options;
1233 retval = flac__encode_aif(encode_infile, infilesize, infilename, forced_outfilename, lookahead, lookahead_length, options);
1235 retval = flac__encode_wav(encode_infile, infilesize, infilename, forced_outfilename, lookahead, lookahead_length, options);
1238 if(retval == 0 && strcmp(infilename, "-")) {
1239 if(strcmp(forced_outfilename, "-"))
1240 flac__file_copy_metadata(infilename, forced_outfilename);
1241 if(option_values.delete_input)
1248 int decode_file(const char *infilename, const char *forced_outfilename)
1250 static const char *suffixes[] = { ".wav", ".raw", ".ana" };
1251 char outfilename[4096]; /* @@@ bad MAGIC NUMBER */
1254 FLAC__bool treat_as_ogg = false;
1255 decode_options_t common_options;
1257 if(!option_values.test_only && !option_values.analyze) {
1258 if(option_values.force_raw_format && option_values.format_is_big_endian < 0)
1259 return usage_error("ERROR: for decoding to a raw file you must specify a value for --endian\n");
1262 if(0 == strcmp(infilename, "-") || option_values.force_to_stdout)
1263 strcpy(outfilename, "-");
1265 const char *suffix = suffixes[option_values.analyze? 2 : option_values.force_raw_format? 1 : 0];
1266 strcpy(outfilename, option_values.output_prefix? option_values.output_prefix : "");
1267 strcat(outfilename, infilename);
1268 if(0 == (p = strrchr(outfilename, '.')))
1269 strcat(outfilename, suffix);
1271 if(0 == strcmp(p, suffix)) {
1279 if(0 == forced_outfilename)
1280 forced_outfilename = outfilename;
1281 if(0 != option_values.cmdline_forced_outfilename)
1282 forced_outfilename = option_values.cmdline_forced_outfilename;
1284 if(option_values.use_ogg)
1285 treat_as_ogg = true;
1286 else if(0 == strcasecmp(infilename+(strlen(infilename)-4), ".ogg"))
1287 treat_as_ogg = true;
1289 treat_as_ogg = false;
1291 #ifndef FLAC__HAS_OGG
1293 fprintf(stderr, "%s: Ogg support has not been built into this copy of flac\n", infilename);
1298 common_options.verbose = option_values.verbose;
1299 common_options.continue_through_decode_errors = option_values.continue_through_decode_errors;
1300 #ifdef FLAC__HAS_OGG
1301 common_options.is_ogg = treat_as_ogg;
1303 common_options.skip = option_values.skip;
1305 if(!option_values.force_raw_format) {
1306 wav_decode_options_t options;
1308 options.common = common_options;
1310 retval = flac__decode_wav(infilename, option_values.test_only? 0 : forced_outfilename, option_values.analyze, option_values.aopts, options);
1313 raw_decode_options_t options;
1315 options.common = common_options;
1316 options.is_big_endian = option_values.format_is_big_endian;
1317 options.is_unsigned_samples = option_values.format_is_unsigned_samples;
1319 retval = flac__decode_raw(infilename, option_values.test_only? 0 : forced_outfilename, option_values.analyze, option_values.aopts, options);
1322 if(retval == 0 && strcmp(infilename, "-")) {
1323 if(strcmp(forced_outfilename, "-"))
1324 flac__file_copy_metadata(infilename, forced_outfilename);
1325 if(option_values.delete_input && !option_values.test_only && !option_values.analyze)
1332 void die(const char *message)
1334 FLAC__ASSERT(0 != message);
1335 fprintf(stderr, "ERROR: %s\n", message);
1339 char *local_strdup(const char *source)
1342 FLAC__ASSERT(0 != source);
1343 if(0 == (ret = strdup(source)))
1344 die("out of memory during strdup()");