xref: /aosp_15_r20/external/flac/src/metaflac/options.h (revision 600f14f40d737144c998e2ec7a483122d3776fbc)
1 /* metaflac - Command-line FLAC metadata editor
2  * Copyright (C) 2001-2009  Josh Coalson
3  * Copyright (C) 2011-2023  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_ALL_EXCEPT,
58 	OP__REMOVE_VC_FIELD,
59 	OP__REMOVE_VC_FIRSTFIELD,
60 	OP__SET_VC_FIELD,
61 	OP__IMPORT_VC_FROM,
62 	OP__EXPORT_VC_TO,
63 	OP__IMPORT_CUESHEET_FROM,
64 	OP__EXPORT_CUESHEET_TO,
65 	OP__IMPORT_PICTURE_FROM,
66 	OP__EXPORT_PICTURE_TO,
67 	OP__ADD_SEEKPOINT,
68 	OP__ADD_REPLAY_GAIN,
69 	OP__SCAN_REPLAY_GAIN,
70 	OP__ADD_PADDING,
71 	OP__LIST,
72 	OP__APPEND,
73 	OP__REMOVE,
74 	OP__REMOVE_ALL,
75 	OP__MERGE_PADDING,
76 	OP__SORT_PADDING
77 } OperationType;
78 
79 typedef enum {
80 	ARG__BLOCK_NUMBER,
81 	ARG__BLOCK_TYPE,
82 	ARG__EXCEPT_BLOCK_TYPE,
83 	ARG__DATA_FORMAT,
84 	ARG__FROM_FILE
85 } ArgumentType;
86 
87 typedef struct {
88 	FLAC__byte value[16];
89 } Argument_StreaminfoMD5;
90 
91 typedef struct {
92 	FLAC__uint32 value;
93 } Argument_StreaminfoUInt32;
94 
95 typedef struct {
96 	FLAC__uint64 value;
97 } Argument_StreaminfoUInt64;
98 
99 typedef struct {
100 	char *value;
101 } Argument_VcFieldName;
102 
103 typedef struct {
104 	char *field; /* the whole field as passed on the command line, i.e. "NAME=VALUE" */
105 	char *field_name;
106 	/* according to the vorbis spec, field values can contain \0 so simple C strings are not enough here */
107 	unsigned field_value_length;
108 	char *field_value;
109 	FLAC__bool field_value_from_file; /* true if field_value holds a filename for the value, false for plain value */
110 } Argument_VcField;
111 
112 typedef struct {
113 	char *value;
114 } Argument_String;
115 
116 typedef struct {
117 	unsigned num_entries;
118 	unsigned *entries;
119 } Argument_BlockNumber;
120 
121 typedef struct {
122 	FLAC__MetadataType type;
123 	char application_id[4]; /* only relevant if type == FLAC__STREAM_METADATA_TYPE_APPLICATION */
124 	FLAC__bool filter_application_by_id;
125 } Argument_BlockTypeEntry;
126 
127 typedef struct {
128 	unsigned num_entries;
129 	Argument_BlockTypeEntry *entries;
130 } Argument_BlockType;
131 
132 typedef struct {
133 	FLAC__bool is_binary;
134 	FLAC__bool is_headerless;
135 } Argument_DataFormat;
136 
137 typedef struct {
138 	char *file_name;
139 } Argument_FromFile;
140 
141 typedef struct {
142 	char *specification;
143 } Argument_AddSeekpoint;
144 
145 typedef struct {
146 	char *filename;
147 	Argument_AddSeekpoint *add_seekpoint_link;
148 } Argument_ImportCuesheetFrom;
149 
150 typedef struct {
151 	char *filename;
152 	const Argument_BlockNumber *block_number_link; /* may be NULL to mean 'first PICTURE block' */
153 } Argument_ExportPictureTo;
154 
155 typedef struct {
156 	unsigned length;
157 } Argument_AddPadding;
158 
159 typedef struct {
160 	OperationType type;
161 	union {
162 		Argument_StreaminfoMD5 streaminfo_md5;
163 		Argument_StreaminfoUInt32 streaminfo_uint32;
164 		Argument_StreaminfoUInt64 streaminfo_uint64;
165 		Argument_VcFieldName vc_field_name;
166 		Argument_VcField vc_field;
167 		Argument_String filename;
168 		Argument_String specification;
169 		Argument_ImportCuesheetFrom import_cuesheet_from;
170 		Argument_ExportPictureTo export_picture_to;
171 		Argument_AddSeekpoint add_seekpoint;
172 		Argument_AddPadding add_padding;
173 	} argument;
174 } Operation;
175 
176 typedef struct {
177 	ArgumentType type;
178 	union {
179 		Argument_BlockNumber block_number;
180 		Argument_BlockType block_type;
181 		Argument_DataFormat data_format;
182 		Argument_FromFile from_file;
183 	} value;
184 } Argument;
185 
186 typedef struct {
187 	FLAC__bool preserve_modtime;
188 	FLAC__bool prefix_with_filename;
189 	FLAC__bool utf8_convert;
190 	FLAC__bool use_padding;
191 	FLAC__bool cued_seekpoints;
192 	FLAC__bool show_long_help;
193 	FLAC__bool show_version;
194 	FLAC__bool data_format_is_binary;
195 	FLAC__bool data_format_is_binary_headerless;
196 	FLAC__bool application_data_format_is_hexdump;
197 	struct {
198 		Operation *operations;
199 		unsigned num_operations;
200 		unsigned capacity;
201 	} ops;
202 	struct {
203 		struct {
204 			unsigned num_shorthand_ops;
205 			unsigned num_major_ops;
206 			FLAC__bool has_block_type;
207 			FLAC__bool has_except_block_type;
208 		} checks;
209 		Argument *arguments;
210 		unsigned num_arguments;
211 		unsigned capacity;
212 	} args;
213 	unsigned num_files;
214 	char **filenames;
215 } CommandLineOptions;
216 
217 void init_options(CommandLineOptions *options);
218 FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options);
219 void free_options(CommandLineOptions *options);
220 
221 #endif
222