src/libFLAC/stream_decoder.c : Fix buffer read overflow.
[platform/upstream/flac.git] / src / metaflac / options.h
1 /* metaflac - Command-line FLAC metadata editor
2  * Copyright (C) 2001-2009  Josh Coalson
3  * Copyright (C) 2011-2013  Xiph.Org Foundation
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #ifndef metaflac__options_h
21 #define metaflac__options_h
22
23 #include "FLAC/format.h"
24
25 #if 0
26 /*[JEC] was:#if HAVE_GETOPT_LONG*/
27 /*[JEC] see flac/include/share/getopt.h as to why the change */
28 #  include <getopt.h>
29 #else
30 #  include "share/getopt.h"
31 #endif
32
33 extern struct share__option long_options_[];
34
35 typedef enum {
36         OP__SHOW_MD5SUM,
37         OP__SHOW_MIN_BLOCKSIZE,
38         OP__SHOW_MAX_BLOCKSIZE,
39         OP__SHOW_MIN_FRAMESIZE,
40         OP__SHOW_MAX_FRAMESIZE,
41         OP__SHOW_SAMPLE_RATE,
42         OP__SHOW_CHANNELS,
43         OP__SHOW_BPS,
44         OP__SHOW_TOTAL_SAMPLES,
45         OP__SET_MD5SUM,
46         OP__SET_MIN_BLOCKSIZE,
47         OP__SET_MAX_BLOCKSIZE,
48         OP__SET_MIN_FRAMESIZE,
49         OP__SET_MAX_FRAMESIZE,
50         OP__SET_SAMPLE_RATE,
51         OP__SET_CHANNELS,
52         OP__SET_BPS,
53         OP__SET_TOTAL_SAMPLES,
54         OP__SHOW_VC_VENDOR,
55         OP__SHOW_VC_FIELD,
56         OP__REMOVE_VC_ALL,
57         OP__REMOVE_VC_FIELD,
58         OP__REMOVE_VC_FIRSTFIELD,
59         OP__SET_VC_FIELD,
60         OP__IMPORT_VC_FROM,
61         OP__EXPORT_VC_TO,
62         OP__IMPORT_CUESHEET_FROM,
63         OP__EXPORT_CUESHEET_TO,
64         OP__IMPORT_PICTURE_FROM,
65         OP__EXPORT_PICTURE_TO,
66         OP__ADD_SEEKPOINT,
67         OP__ADD_REPLAY_GAIN,
68         OP__ADD_PADDING,
69         OP__LIST,
70         OP__APPEND,
71         OP__REMOVE,
72         OP__REMOVE_ALL,
73         OP__MERGE_PADDING,
74         OP__SORT_PADDING
75 } OperationType;
76
77 typedef enum {
78         ARG__BLOCK_NUMBER,
79         ARG__BLOCK_TYPE,
80         ARG__EXCEPT_BLOCK_TYPE,
81         ARG__DATA_FORMAT,
82         ARG__FROM_FILE
83 } ArgumentType;
84
85 typedef struct {
86         FLAC__byte value[16];
87 } Argument_StreaminfoMD5;
88
89 typedef struct {
90         FLAC__uint32 value;
91 } Argument_StreaminfoUInt32;
92
93 typedef struct {
94         FLAC__uint64 value;
95 } Argument_StreaminfoUInt64;
96
97 typedef struct {
98         char *value;
99 } Argument_VcFieldName;
100
101 typedef struct {
102         char *field; /* the whole field as passed on the command line, i.e. "NAME=VALUE" */
103         char *field_name;
104         /* according to the vorbis spec, field values can contain \0 so simple C strings are not enough here */
105         unsigned field_value_length;
106         char *field_value;
107         FLAC__bool field_value_from_file; /* true if field_value holds a filename for the value, false for plain value */
108 } Argument_VcField;
109
110 typedef struct {
111         char *value;
112 } Argument_String;
113
114 typedef struct {
115         unsigned num_entries;
116         unsigned *entries;
117 } Argument_BlockNumber;
118
119 typedef struct {
120         FLAC__MetadataType type;
121         char application_id[4]; /* only relevant if type == FLAC__STREAM_METADATA_TYPE_APPLICATION */
122         FLAC__bool filter_application_by_id;
123 } Argument_BlockTypeEntry;
124
125 typedef struct {
126         unsigned num_entries;
127         Argument_BlockTypeEntry *entries;
128 } Argument_BlockType;
129
130 typedef struct {
131         FLAC__bool is_binary;
132 } Argument_DataFormat;
133
134 typedef struct {
135         char *file_name;
136 } Argument_FromFile;
137
138 typedef struct {
139         char *specification;
140 } Argument_AddSeekpoint;
141
142 typedef struct {
143         char *filename;
144         Argument_AddSeekpoint *add_seekpoint_link;
145 } Argument_ImportCuesheetFrom;
146
147 typedef struct {
148         char *filename;
149         const Argument_BlockNumber *block_number_link; /* may be NULL to mean 'first PICTURE block' */
150 } Argument_ExportPictureTo;
151
152 typedef struct {
153         unsigned length;
154 } Argument_AddPadding;
155
156 typedef struct {
157         OperationType type;
158         union {
159                 Argument_StreaminfoMD5 streaminfo_md5;
160                 Argument_StreaminfoUInt32 streaminfo_uint32;
161                 Argument_StreaminfoUInt64 streaminfo_uint64;
162                 Argument_VcFieldName vc_field_name;
163                 Argument_VcField vc_field;
164                 Argument_String filename;
165                 Argument_String specification;
166                 Argument_ImportCuesheetFrom import_cuesheet_from;
167                 Argument_ExportPictureTo export_picture_to;
168                 Argument_AddSeekpoint add_seekpoint;
169                 Argument_AddPadding add_padding;
170         } argument;
171 } Operation;
172
173 typedef struct {
174         ArgumentType type;
175         union {
176                 Argument_BlockNumber block_number;
177                 Argument_BlockType block_type;
178                 Argument_DataFormat data_format;
179                 Argument_FromFile from_file;
180         } value;
181 } Argument;
182
183 typedef struct {
184         FLAC__bool preserve_modtime;
185         FLAC__bool prefix_with_filename;
186         FLAC__bool utf8_convert;
187         FLAC__bool use_padding;
188         FLAC__bool cued_seekpoints;
189         FLAC__bool show_long_help;
190         FLAC__bool show_version;
191         FLAC__bool application_data_format_is_hexdump;
192         struct {
193                 Operation *operations;
194                 unsigned num_operations;
195                 unsigned capacity;
196         } ops;
197         struct {
198                 struct {
199                         unsigned num_shorthand_ops;
200                         unsigned num_major_ops;
201                         FLAC__bool has_block_type;
202                         FLAC__bool has_except_block_type;
203                 } checks;
204                 Argument *arguments;
205                 unsigned num_arguments;
206                 unsigned capacity;
207         } args;
208         unsigned num_files;
209         char **filenames;
210 } CommandLineOptions;
211
212 void init_options(CommandLineOptions *options);
213 FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options);
214 void free_options(CommandLineOptions *options);
215
216 #endif