📄 main.c
字号:
/* flac - Command-line FLAC encoder/decoder * Copyright (C) 2000,2001,2002,2003,2004,2005 Josh Coalson * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include <ctype.h>#include <locale.h>#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#ifdef HAVE_CONFIG_H#include <config.h>#endif#if !defined _MSC_VER && !defined __MINGW32__/* unlink is in stdio.h in VC++ */#include <unistd.h> /* for unlink() */#else#define strcasecmp stricmp#endif#include "FLAC/all.h"#include "share/grabbag.h"#include "analyze.h"#include "decode.h"#include "encode.h"#include "local_string_utils.h" /* for flac__strlcat() and flac__strlcpy() */#include "utils.h"#include "vorbiscomment.h"#if 0/*[JEC] was:#if HAVE_GETOPT_LONG*//*[JEC] see flac/include/share/getopt.h as to why the change */# include <getopt.h>#else# include "share/getopt.h"#endiftypedef enum { RAW, WAV, AIF } FileFormat;static int do_it();static FLAC__bool init_options();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 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 int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_last_file);static int decode_file(const char *infilename);static const char *get_encoded_outfilename(const char *infilename);static const char *get_decoded_outfilename(const char *infilename);static const char *get_outfilename(const char *infilename, const char *suffix);static void die(const char *message);static char *local_strdup(const char *source);/* * share__getopt format struct; note that for long options with no * short option equivalent we just set the 'val' field to 0. */static struct share__option long_options_[] = { /* * 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 }, /* * decoding options */ { "decode-through-errors", share__no_argument, 0, 'F' }, { "cue" , share__required_argument, 0, 0 }, { "apply-replaygain-which-is-not-lossless", share__optional_argument, 0, 0 }, /* undocumented */ /* * encoding options */ { "cuesheet" , share__required_argument, 0, 0 }, { "no-cued-seekpoints" , share__no_argument, 0, 0 }, { "tag" , share__required_argument, 0, 'T' }, { "compression-level-0" , share__no_argument, 0, '0' }, { "compression-level-1" , share__no_argument, 0, '1' }, { "compression-level-2" , share__no_argument, 0, '2' }, { "compression-level-3" , share__no_argument, 0, '3' }, { "compression-level-4" , share__no_argument, 0, '4' }, { "compression-level-5" , share__no_argument, 0, '5' }, { "compression-level-6" , share__no_argument, 0, '6' }, { "compression-level-7" , share__no_argument, 0, '7' }, { "compression-level-8" , share__no_argument, 0, '8' }, { "compression-level-9" , share__no_argument, 0, '9' }, { "best" , share__no_argument, 0, '8' }, { "fast" , share__no_argument, 0, '0' }, { "super-secret-totally-impractical-compression-level", share__no_argument, 0, 0 }, { "verify" , share__no_argument, 0, 'V' }, { "force-aiff-format" , share__no_argument, 0, 0 }, { "force-raw-format" , share__no_argument, 0, 0 }, { "lax" , share__no_argument, 0, 0 }, { "replay-gain" , share__no_argument, 0, 0 }, { "sector-align" , share__no_argument, 0, 0 }, { "seekpoint" , share__required_argument, 0, 'S' }, { "padding" , share__required_argument, 0, 'P' },#ifdef FLAC__HAS_OGG { "ogg" , share__no_argument, 0, 0 }, { "serial-number" , share__required_argument, 0, 0 },#endif { "blocksize" , share__required_argument, 0, 'b' }, { "exhaustive-model-search" , share__no_argument, 0, 'e' }, { "max-lpc-order" , share__required_argument, 0, 'l' }, { "mid-side" , share__no_argument, 0, 'm' }, { "adaptive-mid-side" , share__no_argument, 0, 'M' }, { "qlp-coeff-precision-search", share__no_argument, 0, 'p' }, { "qlp-coeff-precision" , share__required_argument, 0, 'q' }, { "rice-partition-order" , share__required_argument, 0, 'r' }, { "endian" , share__required_argument, 0, 0 }, { "channels" , share__required_argument, 0, 0 }, { "bps" , share__required_argument, 0, 0 }, { "sample-rate" , share__required_argument, 0, 0 }, { "sign" , share__required_argument, 0, 0 }, { "input-size" , share__required_argument, 0, 0 }, /* * analysis options */ { "residual-gnuplot", share__no_argument, 0, 0 }, { "residual-text", share__no_argument, 0, 0 }, /* * negatives */ { "no-decode-through-errors" , share__no_argument, 0, 0 }, { "no-silent" , share__no_argument, 0, 0 }, { "no-force" , share__no_argument, 0, 0 }, { "no-seektable" , share__no_argument, 0, 0 }, { "no-delete-input-file" , share__no_argument, 0, 0 }, { "no-replay-gain" , share__no_argument, 0, 0 }, { "no-sector-align" , share__no_argument, 0, 0 }, { "no-lax" , share__no_argument, 0, 0 },#ifdef FLAC__HAS_OGG { "no-ogg" , share__no_argument, 0, 0 },#endif { "no-exhaustive-model-search", share__no_argument, 0, 0 }, { "no-mid-side" , share__no_argument, 0, 0 }, { "no-adaptive-mid-side" , share__no_argument, 0, 0 }, { "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-residual-gnuplot" , share__no_argument, 0, 0 }, { "no-residual-text" , share__no_argument, 0, 0 }, /* * undocumented debugging options for the test suite */ { "disable-constant-subframes", share__no_argument, 0, 0 }, { "disable-fixed-subframes" , share__no_argument, 0, 0 }, { "disable-verbatim-subframes", share__no_argument, 0, 0 }, {0, 0, 0, 0}};/* * global to hold command-line option values */static struct { FLAC__bool show_help; FLAC__bool show_explain; FLAC__bool show_version; FLAC__bool mode_decode; FLAC__bool verify; FLAC__bool force_file_overwrite; FLAC__bool continue_through_decode_errors; replaygain_synthesis_spec_t replaygain_synthesis_spec; FLAC__bool lax; FLAC__bool test_only; FLAC__bool analyze; FLAC__bool use_ogg; FLAC__bool has_serial_number; /* true iff --serial-number was used */ long serial_number; /* this is the Ogg serial number and is unused for native FLAC */ FLAC__bool do_mid_side; FLAC__bool loose_mid_side; FLAC__bool do_exhaustive_model_search; FLAC__bool do_escape_coding; FLAC__bool do_qlp_coeff_prec_search; FLAC__bool force_to_stdout; FLAC__bool force_aiff_format; FLAC__bool force_raw_format; FLAC__bool delete_input; FLAC__bool replay_gain; FLAC__bool sector_align; const char *cmdline_forced_outfilename; const char *output_prefix; analysis_options aopts; int padding; unsigned max_lpc_order; unsigned qlp_coeff_precision; const char *skip_specification; const char *until_specification; const char *cue_specification; int format_is_big_endian; int format_is_unsigned_samples; int format_channels; int format_bps; int format_sample_rate; long format_input_size; int blocksize; int min_residual_partition_order; int max_residual_partition_order; int rice_parameter_search_dist; char requested_seek_points[50000]; /* bad MAGIC NUMBER but buffer overflow is checked */ int num_requested_seek_points; /* -1 => no -S options were given, 0 => -S- was given */ const char *cuesheet_filename; FLAC__bool cued_seekpoints; unsigned num_files; char **filenames; FLAC__StreamMetadata *vorbis_comment; struct { FLAC__bool disable_constant_subframes; FLAC__bool disable_fixed_subframes; FLAC__bool disable_verbatim_subframes; } debug;} option_values;/* * miscellaneous globals */static FLAC__int32 align_reservoir_0[588], align_reservoir_1[588]; /* for carrying over samples from --sector-align */static FLAC__int32 *align_reservoir[2] = { align_reservoir_0, align_reservoir_1 };static unsigned align_reservoir_samples = 0; /* 0 .. 587 */int main(int argc, char *argv[]){ int retval = 0; setlocale(LC_ALL, ""); if(!init_options()) { flac__utils_printf(stderr, 1, "ERROR: allocating memory\n"); retval = 1; } else { if((retval = parse_options(argc, argv)) == 0) retval = do_it(); } free_options(); return retval;}int do_it(){ int retval = 0; if(option_values.show_version) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -